Difference between revisions of "LlRot2Fwd"

From Second Life Wiki
Jump to navigation Jump to search
(Added a note to remind people that they can use <1.0, 0.0, 0.0>*rot instead of llRot2Fwd(rot) with unit quaternions)
(Provide an example)
Line 13: Line 13:
|caveats
|caveats
|constants
|constants
|examples
|examples=
<lsl>
// Move an object 5 metres forwards along its x axis, when touched, no matter how the object is oriented in world.
default
{
    touch_start(integer total_number)
    {
        vector v = llRot2Fwd( llGetRot() );
        llSetPos( llGetPos() + v * 5.0 );
    }
}
</lsl>
|helpers
|helpers
|also_functions=
|also_functions=

Revision as of 07:51, 6 December 2013

Summary

Function: vector llRot2Fwd( rotation q );
0.0 Forced Delay
10.0 Energy

Computes the orientation of the local x-axis relative to the earth.
Returns a vector that is the forward vector defined by q, i.e. a unit vector pointing in the local positive X direction.

• rotation q

Can be useful to identify the orientation of the local frontal-plane of the prim, since it's x-axis is always perpendicular to this local frontal plane.

Specification

Mathematically equivalent to: <lsl>ret = llVecNorm(<1., 0., 0.> * q);</lsl> If q is known to be a unit quaternion then it can be simplified as: <lsl>ret = <1., 0., 0.> * q;</lsl> Keep in mind that object and agent rotations will always be unit quaternions. For example, <1.0, 0.0, 0.0>*llGetRot() is about 25-30% faster than llRot2Fwd(llGetRot()) depending on the VM used. If done often and at extremely fast rates, it can be advantageous to even save <1.0, 0.0, 0.0> to a local/global variable and reuse it.

Examples

<lsl> // Move an object 5 metres forwards along its x axis, when touched, no matter how the object is oriented in world. default {

   touch_start(integer total_number)
   {
       vector v = llRot2Fwd( llGetRot() );
       llSetPos( llGetPos() + v * 5.0 );
   }

}

</lsl>

See Also

Functions

•  llRot2Left
•  llRot2Up
•  llRot2Axis
•  llRot2Angle

Deep Notes

Signature

function vector llRot2Fwd( rotation q );