Advertisement
ZornTaov

Rotate around vector

Jan 8th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. RotOffset(vector offset, vector ammount)
  4. {
  5.     rotation vRotArc       = llEuler2Rot( ammount * DEG_TO_RAD );
  6.     //-- creates a rotation constant, 30 degrees around the X axis
  7.  
  8.     vector   vPosOffset     = offset;
  9.     //-- creates an offset one meter in the positive Y direction
  10.    
  11.     vector   vPosRotOffset  = vPosOffset * vRotArc;
  12.     //-- rotates the offset to get the motion caused by the rotation
  13.  
  14.     vector   vPosOffsetDiff = vPosOffset - vPosRotOffset;
  15.     //-- gets the local difference between the current offset and the rotated one
  16.  
  17.     vector   vPosRotDiff    = vPosOffsetDiff * llGetLocalRot();
  18.     //-- rotates the difference in the offsets to be relative to the global rotation.
  19.  
  20.     vector   vPosNew        = llGetLocalPos() + vPosRotDiff;
  21.     //-- finds the prims new position by adding the rotated offset difference
  22.  
  23.     rotation vRotNew        = vRotArc * llGetLocalRot();
  24.     //-- finds rot to continue facing offset point
  25.     //llSetPos(vPosNew);
  26.     //llSetLocalRot(vRotNew);
  27.     llSetLinkPrimitiveParamsFast( LINK_THIS, [PRIM_POSITION, vPosNew, PRIM_ROTATION, vRotNew] );
  28.                        
  29. }
  30.  
  31. integer IS_ON = FALSE;
  32. set_Rot()
  33. {
  34.     if (IS_ON)
  35.     {
  36.         RotOffset(<0,0,-(0.315/2)>,<0,-90,0>);
  37.     }
  38.     else
  39.     {
  40.         RotOffset(<0,0,-(0.315/2)>,<0,90,0>);
  41.     }
  42. }
  43.  
  44. default
  45. {
  46.     state_entry()
  47.     {
  48.         //llSay(0, "Hello, Avatar!");
  49.     }
  50.  
  51.     touch_start(integer total_number)
  52.     {
  53.         IS_ON = !IS_ON;
  54.            
  55.            
  56.         set_Rot();
  57.         //llSay(0, "Touched.");
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement