llAxes2Rot and orthogonality
|
|
Tranquillity Dexler
Registered User
Join date: 20 Feb 2009
Posts: 7
|
06-12-2009 19:41
I don't have a problem but more of a general curiosity. I recently got some very generous help with a function and I am left wondering.
rotation VectorToRotation( vector V ) { V = llVecNorm( V ); vector UP = < 0.0, 0.0, 1.0 >; vector LEFT = llVecNorm(UP % V);
return llAxes2Rot(V, LEFT, UP); }
Let V be an arbitrary vector pointing in the direction of some target.
When I execute this function, the object will look at a target. The thing I find strange is that even though I am specifying the UP axis as the world UP axis, the object can end up with it's UP axis clearly not pointing straight up when the forward axis needs to point up or down at the target. Another thing is, since V is an arbitrary direction, how can V and UP be orthogonal as is required by llAxes2Rot? This function does work so I must be misunderstanding something.
Thank you for any help.
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
06-13-2009 01:38
From: Tranquillity Dexler rotation VectorToRotation( vector V ) { V = llVecNorm( V ); vector UP = < 0.0, 0.0, 1.0 >; vector LEFT = llVecNorm(UP % V);
return llAxes2Rot(V, LEFT, UP); }
This script is a bastard. You may be happy with it and that is allright with me From: Tranquillity Dexler When I execute this function, the object will look at a target.
That is what you think. Will it do it in any case? have you tested all cases? How do you test it? by looking at the picture on your screen? From: Tranquillity Dexler The thing I find strange is that even though I am specifying the UP axis as the world UP axis, the object can end up with it's UP axis clearly not pointing straight up when the forward axis needs to point up or down at the target.
That is because the two vectors you give to llAxes2Rot are not orthogonal. From: Tranquillity Dexler Another thing is, since V is an arbitrary direction, how can V and UP be orthogonal as is required by llAxes2Rot?
They can't, only in special cases they are From: Tranquillity Dexler This function does work That is what you think. Will it work in any case? have you tested all cases? How do you test it? by looking at the picture on your screen? I previously posted a fix to the function. Because of the problems nature you have fix one more parameter. Say: you want 'UP' vertical and 'V' horizontal OR you want to keep the direction of V. rotation VectorToRotation ( vector V ) { V = llVecNorm( V ); vector UP = < 0.0, 0.0, 1.0 >; vector LEFT = llVecNorm(UP%V); V = llVecNorm(LEFT%UP); // you want V confined to the horizontal plane return llAxes2Rot(V, LEFT, UP); } rotation VectorToRotation ( vector V ) { V = llVecNorm( V ); vector UP = < 0.0, 0.0, 1.0 >; vector LEFT = llVecNorm(UP%V); UP = llVecNorm(V%LEFT); // you want to keep the direction of V return llAxes2Rot(V, LEFT, UP); }
_____________________
From Studio Dora
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
llAxes2Rot() test
06-13-2009 05:37
To see if it really matters this demands on unit vectors and orthogonality, I made a test script to satisfy my own curiosity: key model; integer tog; vector lookat;
rotation VectorToRotation( vector V ) { V = llVecNorm( V ); vector UP = < 0.0, 0.0, 1.0 >; vector LEFT = llVecNorm(UP%V); return llAxes2Rot(V, LEFT, UP); }
rotation VectorToRotFix( vector V ) { V = llVecNorm( V ); vector UP = < 0.0, 0.0, 1.0 >; vector LEFT = llVecNorm(UP%V); UP = llVecNorm(V%LEFT); // you want to keep the direction of V return llAxes2Rot(V, LEFT, UP); }
rotation VectorToRotHor( vector V ) { V = llVecNorm( V ); vector UP = < 0.0, 0.0, 1.0 >; vector LEFT = llVecNorm(UP%V); V = llVecNorm(LEFT%UP); // you want V confined to the horizontal plane return llAxes2Rot(V, LEFT, UP); }
default { state_entry() { tog = 0; model = NULL_KEY; llSetTimerEvent( 4.0 ); }
touch_end(integer n) { model = llDetectedKey(0); }
timer() { if ( model != NULL_KEY ) { lookat = llList2Vector( llGetObjectDetails( model, [OBJECT_POS]), 0 ); if ( lookat != ZERO_VECTOR ) { if ( !tog ) { llSetColor ( <1.0, 1.0, 0.0>, ALL_SIDES ); llSetRot( VectorToRotation( lookat - llGetPos())); } else if ( tog == 1 ) { llSetColor ( <0.4, 1.0, 0.0>, ALL_SIDES ); llSetRot( VectorToRotFix( lookat - llGetPos())); } else if ( tog == 2 ) { llSetColor ( <0.0, 0.6, 1.0>, ALL_SIDES ); llSetRot( VectorToRotHor( lookat - llGetPos())); } tog = ++tog % 3; } else llSetTimerEvent( 0.0 ); } } }
rezz a prim say x,y,z = 5.0, 0.2, 0.2 meters, put he script in and touch the prim. It will point you for 4 sec with each routine in turn. Move around and fly up to see where the prim will point. Each routine will color the prim its own color: Yellow: "Bastard" routine. Green: True direction. Blue: Direction in the horizontal plane only. I will not reveal my findings. If you want to find out try for yourself 
_____________________
From Studio Dora
|
|
Tranquillity Dexler
Registered User
Join date: 20 Feb 2009
Posts: 7
|
06-13-2009 06:21
Thank you again Dora, I will try this later on tonight and learn a bit more.
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
06-13-2009 08:15
Very, very, nice work on a testbed script Dora!!!!!!!
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Nexii Malthus
[Cubitar]Mothership
Join date: 24 Apr 2006
Posts: 400
|
06-13-2009 08:40
Yeah, that is pretty cool. Good job. Maybe put it up on the wiki? The wiki script library could really need such higher quality scripts, it is an important repository of resources and knowledge.
_____________________
 Geometric Library, for all your 3D maths needs. https://wiki.secondlife.com/wiki/Geometric Creator of the Vertical Life Client
|
|
Tranquillity Dexler
Registered User
Join date: 20 Feb 2009
Posts: 7
|
06-13-2009 19:15
Ahh. Okay, so for whatever reason the llRot2Axes function is not requiring the axis to actually be orthogonal. As is shown by the bastard function. It also does NOT work. If I am higher than about 20 degrees from the horizontal, the yellow pole will not fully tilt to point at me.
Thank you for the demo code.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
06-13-2009 20:28
From: Tranquillity Dexler Ahh. Okay, so for whatever reason the llRot2Axes function is not requiring the axis to actually be orthogonal. As is shown by the bastard function. It also does NOT work. If I am higher than about 20 degrees from the horizontal, the yellow pole will not fully tilt to point at me. While they are making it behave itself without going crazy, it would generally be a good idea to give orthogonal inputs so that the behavior is what you expect. They probably orthogonalize the vectors within the function itself, but it is not specified how so no assumptions should be made about the outcome (or that it will remain constant over time). Not that we really have official documentation anyway, but going at least by what is on the wikis....
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
06-13-2009 20:50
note that the bastard function does have uses for incrementally conforming a rotation to a planewhich is useful for non vehicle scripts (vehicle scripts can use an attactor IIRC that will keep them upright, I'm not really up on using the vehicle functions though)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|