Difference between revisions of "LlSetRot"

From Second Life Wiki
Jump to navigation Jump to search
 
m
 
(32 intermediate revisions by 18 users not shown)
Line 1: Line 1:
{{LSL_Function
{{LSL_Function
|func=LlSetRot|p1_type=rotation|p1_name=rot|
|inject-2={{Issues/SVC-93}}
|func_id=?
|func_id=61|func_sleep=0.2|func_energy=10.0
|func_sleep
|func=llSetRot
|func_energy
|p1_type=rotation|p1_name=rot
|sort
|func_desc=Sets the rotation of the prim to {{LSLP|rot}}.
|func_desc=If the object is not physical, this function sets the rotation. If the object is a child, the position is treated as root
relative and the linked set is adjusted.
|func_footnote
|return_type
|return_text
|return_text
|p1_type|p1_name|p1_desc
|spec=This function is available for nonphysical root prims and all child prims. It has no effect on the root prim if the object is physical. It has no effect for "static objects" as type of [[pathfinding]]
|p2_type|p2_name|p2_desc
|caveats=*If the prim is attached, then this function offsets the rotation by the avatar's rotation.
|p3_type|p3_name|p3_desc
*If the prim is not the root prim it is offset by the root's rotation.
|p4_type|p4_name|p4_desc
**If you are trying to set the rotation of a child prim relative to the root prim then divide the rotation by the root rotation.
|p5_type|p5_name|p5_desc
**If you are trying to set the rotation of a child prim to a global rotation then you need to divide the global rotation by the root rotation '''twice'''.
|p6_type|p6_name|p6_desc
**It is better to use [[llSetLocalRot]] to set the rotation of child prims, even if you are setting it to a global rotation (just divide by the root rotation in that case).
|p7_type|p7_name|p7_desc
**Alternatively see the [[llSetRot#Useful_Snippets|Useful Snippets]] for generalized workarounds that work with [[llSetPrimitiveParams]], [[llSetLinkPrimitiveParams]], and [[llSetLinkPrimitiveParamsFast]]
|p8_type|p8_name|p8_desc
*For small rotation changes, there is an update threshold depending on the time duration between changes. It does not appear to be limited to the 6deg rule any longer.
|p9_type|p9_name|p9_desc
* For "static objects" (type of [[pathfinding]]), the script fails with the error in debug channel:
|p10_type|p10_name|p10_desc
** "Unable to set prim rotation: object contributes to the navmesh."
|p11_type|p11_name|p11_desc
|spec
|p12_type|p12_name|p12_desc
|constants
|constants
|spec
|examples=Drop this script in the root prim of an object to have it rotate in 1 degree increments. Note that it won't work on child prims if the root is rotated.
|caveats
<source lang="lsl2">
|examples
rotation rot_xyzq;
|helpers
 
|also_header
default
|also_functions
{
    state_entry()
    {
        vector xyz_angles = <0,1.0,0>; // This is to define a 1 degree change
        vector angles_in_radians = xyz_angles*DEG_TO_RAD; // Change to Radians
        rot_xyzq = llEuler2Rot(angles_in_radians); // Change to a Rotation
    }
 
    touch_start(integer s)
    {
        llSetRot(llGetRot()*rot_xyzq); //Do the Rotation...
    }
}
</source>
 
Drop this one in a child prim to have it rotate around the world's Y axis in 1 degree increments. It won't work in the root if it is rotated.
 
<source lang="lsl2">
rotation rot_xyzq;
 
default
{
    state_entry()
    {
        vector xyz_angles = <0,1.0,0>; // This is to define a 1 degree change
        vector angles_in_radians = xyz_angles*DEG_TO_RAD; // Change to Radians
        rot_xyzq = llEuler2Rot(angles_in_radians); // Change to a Rotation
    }
 
    touch_start(integer s)
    {
        llSetRot(llGetRot()*rot_xyzq/llGetRootRotation()/llGetRootRotation()); //Do the Rotation...
    }
}
</source>
 
|helpers=
<source lang="lsl2">//-- These correctly set a global rotation for the root prim in all scenarios
llSetLocalRot( rot )
llSetPrimitiveParams( [PRIM_ROT_LOCAL, rot] )
 
//-- These correctly set a global rotation for a child prim in all scenarios
llSetLocalRot( rot / llGetRootRotation() )
llSetPrimitiveParams( [PRIM_ROT_LOCAL, rot / llGetRootRotation() ] )</source>
|also_functions=
{{LSL DefineRow||[[llGetRot]]|}}
{{LSL DefineRow||[[llGetLocalRot]]|}}
{{LSL DefineRow||[[llGetPrimitiveParams]]|}}
{{LSL DefineRow||[[llGetLinkPrimitiveParams]]|}}
{{LSL DefineRow||[[llSetLocalRot]]|}}
{{LSL DefineRow||[[llSetPrimitiveParams]]|}}
{{LSL DefineRow||[[llSetLinkPrimitiveParams]]|}}
{{LSL DefineRow||[[llSetLinkPrimitiveParamsFast]]|}}
{{LSL DefineRow||[[llTargetOmega]]|}}
|also_tests
|also_tests
|also_events
|also_events
|also_articles
|also_articles
|also_footer
|notes
|notes
|mode
|issues
|deprecated
|cat1=Movement
|location
|cat2=Rotation
|inventory
|permission
|negative_index
|cat1
|cat2
|cat3
|cat3
|cat4
|cat4
|cat5
|cat6
}}
}}

Latest revision as of 15:33, 12 September 2015

Summary

Function: llSetRot( rotation rot );

Sets the rotation of the prim to rot.

• rotation rot

Specification

This function is available for nonphysical root prims and all child prims. It has no effect on the root prim if the object is physical. It has no effect for "static objects" as type of pathfinding

Caveats

  • This function causes the script to sleep for 0.2 seconds.
  • If the prim is attached, then this function offsets the rotation by the avatar's rotation.
  • If the prim is not the root prim it is offset by the root's rotation.
    • If you are trying to set the rotation of a child prim relative to the root prim then divide the rotation by the root rotation.
    • If you are trying to set the rotation of a child prim to a global rotation then you need to divide the global rotation by the root rotation twice.
    • It is better to use llSetLocalRot to set the rotation of child prims, even if you are setting it to a global rotation (just divide by the root rotation in that case).
    • Alternatively see the Useful Snippets for generalized workarounds that work with llSetPrimitiveParams, llSetLinkPrimitiveParams, and llSetLinkPrimitiveParamsFast
  • For small rotation changes, there is an update threshold depending on the time duration between changes. It does not appear to be limited to the 6deg rule any longer.
  • For "static objects" (type of pathfinding), the script fails with the error in debug channel:
    • "Unable to set prim rotation: object contributes to the navmesh."
All Issues ~ Search JIRA for related Bugs

Examples

Drop this script in the root prim of an object to have it rotate in 1 degree increments. Note that it won't work on child prims if the root is rotated.

rotation rot_xyzq;

default
{
    state_entry()
    {
        vector xyz_angles = <0,1.0,0>; // This is to define a 1 degree change
        vector angles_in_radians = xyz_angles*DEG_TO_RAD; // Change to Radians
        rot_xyzq = llEuler2Rot(angles_in_radians); // Change to a Rotation
    }

    touch_start(integer s)
    {
        llSetRot(llGetRot()*rot_xyzq); //Do the Rotation...
    }
}

Drop this one in a child prim to have it rotate around the world's Y axis in 1 degree increments. It won't work in the root if it is rotated.

rotation rot_xyzq;

default
{
    state_entry()
    {
        vector xyz_angles = <0,1.0,0>; // This is to define a 1 degree change
        vector angles_in_radians = xyz_angles*DEG_TO_RAD; // Change to Radians
        rot_xyzq = llEuler2Rot(angles_in_radians); // Change to a Rotation
    }

    touch_start(integer s)
    {
        llSetRot(llGetRot()*rot_xyzq/llGetRootRotation()/llGetRootRotation()); //Do the Rotation...
    }
}

Useful Snippets

//-- These correctly set a global rotation for the root prim in all scenarios
llSetLocalRot( rot )
llSetPrimitiveParams( [PRIM_ROT_LOCAL, rot] )

//-- These correctly set a global rotation for a child prim in all scenarios
llSetLocalRot( rot / llGetRootRotation() )
llSetPrimitiveParams( [PRIM_ROT_LOCAL, rot / llGetRootRotation() ] )

Deep Notes

All Issues

~ Search JIRA for related Issues
   llSetRot and llSetPrimitiveParams (using PRIM_ROTATION) incorrectly implemented for child prims.

Signature

function void llSetRot( rotation rot );