Difference between revisions of "User:Dora Gustafson/llAxes2Rot right and wrong"

From Second Life Wiki
Jump to: navigation, search
(llAxes2Rot right and wrong)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
To see if it really matters this demands on unit vectors and orthogonality, I made a test script to satisfy my own curiosity:
+
{{LSL Header}}
<lsl>
+
==llAxes2Rot right and wrong==
 +
Does it matter if all three vectors are mutually orthogonal unit vectors?<br>
 +
I made a test script to satisfy my own curiosity:
 +
<source lang="lsl2">
 
key model;
 
key model;
 
integer tog=0;
 
integer tog=0;
Line 85: Line 88:
 
     }
 
     }
 
}
 
}
</lsl>
+
</source>
 
How to use:
 
How to use:
 
rezz a prim say x,y,z = 5.0, 0.2, 0.2 meters, put he script in and touch the prim.
 
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.
 
It will point you for 4 sec with each routine in turn.
Move around and fly up to see where the prim will point.
+
Move around and fly up to see where the prim will point.<br>
 
Each routine will color the prim its own color:
 
Each routine will color the prim its own color:
* Red: "Bastard" routine.
+
* Red: "Bastard" routine, Not unit and not orthogonal.
 
* Yellow: "Norm" routine, unit vectors but not orthogonal.
 
* Yellow: "Norm" routine, unit vectors but not orthogonal.
* Green: "True" routine, true direction.
+
* Green: "True" routine, true direction, the demands are met.
* Blue: "Hor" routine, direction in the horizontal plane only.
+
* Blue: "Hor" routine, direction in the horizontal plane only, the demands are met.

Latest revision as of 13:56, 22 January 2015

llAxes2Rot right and wrong

Does it matter if all three vectors are mutually orthogonal unit vectors?
I made a test script to satisfy my own curiosity:

key model;
integer tog=0;
vector lookat;
 
rotation Vec2RotBastard( vector V )
{
    vector UP = < 0.0, 0.0, 1.0 >;
    vector LEFT = llVecNorm(UP%V);
    return llAxes2Rot(V, LEFT, UP);
    // demand for orthogonal, unit vectors is not fulfilled in general:
    // V is a unit vector in special cases only
    // UP and V are orthogonal in special cases only
}
 
rotation Vec2RotNorm( vector V )
{
    V = llVecNorm( V );
    vector UP = < 0.0, 0.0, 1.0 >;
    vector LEFT = llVecNorm(UP%V);
    return llAxes2Rot(V, LEFT, UP);
    // demand for orthogonal vectors is not fulfilled in general:
    // UP and V are orthogonal in special cases only
}
 
rotation Vec2RotTrue( 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 Vec2RotHor( 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
{
    touch_end(integer n)
    {
        llSetTimerEvent( 4.0 );
        model = llDetectedKey(0);
    }
 
    timer()
    {
        lookat = llList2Vector( llGetObjectDetails( model, [OBJECT_POS]), 0 );
        if ( lookat != ZERO_VECTOR )
        {
            if ( !tog )
            {
                llSetColor ( <1.0, 0.2, 0.0>, ALL_SIDES );
                llSetRot( Vec2RotBastard( lookat - llGetPos()));
            }
            else if ( tog == 1 )
            {
                llSetColor ( <1.0, 1.0, 0.0>, ALL_SIDES );
                llSetRot( Vec2RotNorm( lookat - llGetPos()));
            }
            else if ( tog == 2 )
            {
                llSetColor ( <0.4, 1.0, 0.0>, ALL_SIDES );
                llSetRot( Vec2RotTrue( lookat - llGetPos()));
            }
            else if ( tog == 3 )
            {
                llSetColor ( <0.0, 0.6, 1.0>, ALL_SIDES );
                llSetRot( Vec2RotHor( lookat - llGetPos()));
            }
            tog = ++tog % 4;
        }
        else
        {
            llSetColor ( <0.0, 0.0, 0.0>, ALL_SIDES );
            llSetTimerEvent( 0.0 );
        }
    }
}

How to use: 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:

  • Red: "Bastard" routine, Not unit and not orthogonal.
  • Yellow: "Norm" routine, unit vectors but not orthogonal.
  • Green: "True" routine, true direction, the demands are met.
  • Blue: "Hor" routine, direction in the horizontal plane only, the demands are met.