Difference between revisions of "LlGetRot"

From Second Life Wiki
Jump to navigation Jump to search
m (updated example)
Line 11: Line 11:
|caveats
|caveats
|examples=
|examples=
<pre> //-- rotates an object to face the nearest cardinal direction (N,E,S,W)
<lsl> //-- rotates an object to face the nearest cardinal direction (N,E,S,W)
  //-- assumes build is aligned to root object facing
  //-- assumes build is aligned to root object facing


Line 22: Line 22:
   touch_start( integer vIntTouches )
   touch_start( integer vIntTouches )
   {
   {
     //-- convert our rotation to x/y/z degrees
     //-- convert our rotation to x/y/z radians
     vector vVecBase = llRot2Euler( llGetRot() ) * RAD_TO_DEG;
     vector vRadBase = llRot2Euler( llGetRot() );
     //-- round the z-axis to the nearest 90deg
     //-- round the z-axis to the nearest 90deg (PI_BY_TWO = 90deg in radians)
    float vFltCorrected = (float)(llRound(vVecBase.z / 90) * 90);
     llSetRot( llEuler2Rot( <0.0, 0.0, llRound( vRadBase.z / PI_BY_TWO ) * PI_BY_TWO > ) );
     llSetRot( llEuler2Rot( <.0, .0, vFltCorrected * DEG_TO_RAD> ) );
   }
   }
}</pre>[[User:Void Singer|Void Singer]] 20:10, 6 November 2007 (PST)
}</lsl>
|helpers
|helpers
|also_header
|also_header

Revision as of 18:06, 19 February 2008

Summary

Function: rotation llGetRot( );

Returns a rotation that is the prim's rotation relative to the region plane.

Examples

<lsl> //-- rotates an object to face the nearest cardinal direction (N,E,S,W)

//-- assumes build is aligned to root object facing

default{

 state_entry()
 {
   llSay( 0, "Rotate me in edit, then touch to make me face the nearest compass point" );
 }
 touch_start( integer vIntTouches )
 {
    //-- convert our rotation to x/y/z radians
   vector vRadBase = llRot2Euler( llGetRot() );
    //-- round the z-axis to the nearest 90deg (PI_BY_TWO = 90deg in radians)
   llSetRot( llEuler2Rot( <0.0, 0.0, llRound( vRadBase.z / PI_BY_TWO ) * PI_BY_TWO > ) );
 }
}</lsl>

Notes

llGetRot in Mouselook (see llForceMouselook) for an attachment returns the angle the avatar is looking in.

Deep Notes

Search JIRA for related Issues

Signature

function rotation llGetRot();