User:Dora Gustafson/llAxes2Rot right and wrong

From Second Life Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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:curiosity: <lsl> 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 );
       }
   }

} </lsl> 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.