Difference between revisions of "LlRot2Euler"

From Second Life Wiki
Jump to navigation Jump to search
(Euler may use vectors but they don't belong in the vector category, but the euler category)
m (Missed one syntaxhighlight ....)
 
(9 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{LSL_Function
{{LSL Function
|func_id=15|func_sleep=0.0|func_energy=10.0
|func=llRot2Euler|sort=Rot2Euler
|func=llRot2Euler|sort=Rot2Euler
|func_id=15|func_sleep=0.0|func_energy=10.0
|func_footnote
|func_footnote
|p1_type=rotation|p1_name=quat|p1_desc=Any valid rotation
|p1_type=rotation|p1_name=quat|p1_desc=Any valid rotation
|return_type=vector
|return_type=vector
|return_text=that is the Euler representation (roll, pitch, yaw) of '''quat'''.
|return_text=that is the Euler representation (roll, pitch, yaw) of {{LSLP|quat}}, with each component expressed in radians.
|spec
|spec=The {{LSLGC|Euler}} angle vector (in radians) is converted from a rotation by doing the rotations around the 3 axes in Z, Y, X order.
|caveats=*Angles greater than PI (180 degrees) are returned as negative angles.
|caveats=*Angles greater than [[PI]] radians (180 degrees) are returned as negative angles.
|constants
|constants
|examples=<pre>
|examples=
<syntaxhighlight lang="lsl2">
default
default
{
{
     state_entry()
     state_entry()
     {
     {
         rotation input = <0.0, 1.0, 0.0, 0.0>;//not advised to make your own quaternion
         rotation input = llGetRot();
         llSay(0,"The Rot2Euler of "+(string)input+" is: "+(string)llRot2Euler(input) );
         llSay(0, "The Rot2Euler of " + (string)input + " is: " + (string) llRot2Euler(input) );
     }
     }
}
}
</pre>
</syntaxhighlight>
 
<syntaxhighlight lang="lsl2">
// This script rotates a prim by 15 degrees each time the prim is touched
 
// While not the best way of achieving the result,
// this script demonstrates the use of llRot2Euler and llEuler2Rot
// and the use of more human-friendly degrees rather than radians
 
default
{
    touch_start(integer total_number)
    {
        // Get the object's current rotation as a quarternion
        rotation rot = llGetRot();
        // Convert the rotation to a euler with roll, pitch, and yaw in radians
        vector euler = llRot2Euler(rot);
        // convert the angles from radians to degrees
        euler *= RAD_TO_DEG;
        // Add 15 degrees on the Z axis       
        euler += <0, 0, 15>;
        // Say the current euler values in degrees
        llSay(0, (string) euler);       
        // convert degrees back to radians
        euler *= DEG_TO_RAD;
        // Convert the euler back to a rotation quarternion
        rot =  llEuler2Rot (euler);
        // Apply the updated rotation to the prim 
        llSetRot( rot );
    }
}
</syntaxhighlight>
|helpers
|helpers
|also_functions={{LSL DefineRow||[[llEuler2Rot]]|}}
|also_functions={{LSL DefineRow||[[llEuler2Rot]]|}}
|also_events
|also_events
|also_articles={{LSL DefineRow||{{Wikipedia|Euler_Angles}}|}}
|also_articles={{LSL DefineRow||{{Wikipedia|Euler Angles}}|}}
|also_tests
|also_tests
|notes
|notes
|deepnotes= ===Reference Implementation===
<syntaxhighlight lang="lsl2">
vector uRot2Euler(rotation rot)
{
        vector ret;
        vector temp;
        //x-axis
        temp = <0,0,1>*rot;
        ret.x = llAtan2(temp.z,temp.y)-PI/2;
        rot = rot/llEuler2Rot(<ret.x,0,0>);
        //y-axis
        temp = <0,0,1>*rot;
        ret.y = -llAtan2(temp.z,temp.x)+PI/2;
        rot = rot/llEuler2Rot(<0,ret.y,0>);
        //z-axis
        temp = <1,0,0>*rot;
        ret.z = llAtan2(temp.y,temp.x);
        return ret;
}
</syntaxhighlight>
|permission
|permission
|negative_index
|negative_index

Latest revision as of 00:22, 5 May 2024

Summary

Function: vector llRot2Euler( rotation quat );
0.0 Forced Delay
10.0 Energy

Returns a vector that is the Euler representation (roll, pitch, yaw) of quat, with each component expressed in radians.

• rotation quat Any valid rotation

Specification

The Euler angle vector (in radians) is converted from a rotation by doing the rotations around the 3 axes in Z, Y, X order.

Caveats

  • Angles greater than PI radians (180 degrees) are returned as negative angles.

Examples

default
{
    state_entry()
    {
        rotation input = llGetRot();
        llSay(0, "The Rot2Euler of " + (string)input + " is: " + (string) llRot2Euler(input) );
    }
}
// This script rotates a prim by 15 degrees each time the prim is touched

// While not the best way of achieving the result,
// this script demonstrates the use of llRot2Euler and llEuler2Rot
// and the use of more human-friendly degrees rather than radians

default
{
    touch_start(integer total_number)
    {
        // Get the object's current rotation as a quarternion
        rotation rot = llGetRot();
        // Convert the rotation to a euler with roll, pitch, and yaw in radians
        vector euler = llRot2Euler(rot);
        // convert the angles from radians to degrees
        euler *= RAD_TO_DEG;
        // Add 15 degrees on the Z axis        
        euler += <0, 0, 15>;
        // Say the current euler values in degrees
        llSay(0, (string) euler);         
        // convert degrees back to radians
        euler *= DEG_TO_RAD;
        // Convert the euler back to a rotation quarternion
        rot =  llEuler2Rot (euler);
        // Apply the updated rotation to the prim   
        llSetRot( rot ); 
    }
}

See Also

Functions

•  llEuler2Rot

Articles

•  "Wikipedia logo"Euler Angles

Deep Notes

Reference Implementation

vector uRot2Euler(rotation rot)
{
        vector ret;
        vector temp;

        //x-axis
        temp = <0,0,1>*rot;
        ret.x = llAtan2(temp.z,temp.y)-PI/2;
        rot = rot/llEuler2Rot(<ret.x,0,0>);
        //y-axis
        temp = <0,0,1>*rot;
        ret.y = -llAtan2(temp.z,temp.x)+PI/2;
        rot = rot/llEuler2Rot(<0,ret.y,0>);
        //z-axis
        temp = <1,0,0>*rot;
        ret.z = llAtan2(temp.y,temp.x);
        return ret;
}

Signature

function vector llRot2Euler( rotation quat );