LlGetRot: Difference between revisions

From Second Life Wiki
Jump to navigation Jump to search
No edit summary
Void Singer (talk | contribs)
m +caveat
(8 intermediate revisions by 5 users not shown)
Line 6: Line 6:
|func_footnote
|func_footnote
|return_type=rotation
|return_type=rotation
|return_text=that is the prim's rotation relative to the [[Viewer coordinate frames#Region|region]] plane.
|return_text=that is the prim's rotation relative to the [[Viewer coordinate frames#Region|region]]'s axes.
|constants
|constants
|spec
|spec
|caveats
|caveats=
* [[llGetRot]] incorrectly reports the avatars rotation when called from the root of an attached object, use [[llGetLocalRot]] for root prims, instead
** [[llGetRot]] will return an accurate facing for Avatars seated or in mouselook, but only a rough direction otherwise when called from an attached prim.
|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 24:
   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
Line 39: Line 40:
{{LSL DefineRow||[[llSetPrimitiveParams]]|}}
{{LSL DefineRow||[[llSetPrimitiveParams]]|}}
{{LSL DefineRow||[[llSetLinkPrimitiveParams]]|}}
{{LSL DefineRow||[[llSetLinkPrimitiveParams]]|}}
{{LSL DefineRow||[[llSetLinkPrimitiveParamsFast]]|}}
|also_tests
|also_tests
|also_events
|also_events
|also_articles
|also_articles
|also_footer
|also_footer
|notes=llGetRot in [[Mouselook]] (see [[llForceMouselook]]) for an attachment returns the angle the avatar is looking in.
|notes=
* The tooltip in the in-client editor is incorrect, it will work in scripts in objects that are physical.
|mode
|mode
|deprecated
|deprecated
Line 49: Line 52:
|cat1=Movement
|cat1=Movement
|cat2=Rotation
|cat2=Rotation
|cat3
|cat3=Prim
|cat4
|cat4
|cat5
|cat5
|cat6
|cat6
}}
}}

Revision as of 20:30, 2 April 2012

Summary

Function: rotation llGetRot( );
0.0 Forced Delay
10.0 Energy

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

Caveats

  • llGetRot incorrectly reports the avatars rotation when called from the root of an attached object, use llGetLocalRot for root prims, instead
    • llGetRot will return an accurate facing for Avatars seated or in mouselook, but only a rough direction otherwise when called from an attached prim.

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

  • The tooltip in the in-client editor is incorrect, it will work in scripts in objects that are physical.

Deep Notes

Signature

function rotation llGetRot();