Unofficial LSL Reference

[[user:sei:roll_pitch_yaw]]


Unofficial LSL reference

User Tools

Login

You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.

Login

Forgotten your password? Get a new one: Set new password

This is an old revision of the document!


Since this seems to be a FAQ, here is a function to return classic roll/pitch/yaw (as used by planes, for example). llRot2Euler can't be used because classic roll/pitch/yaw requires XYZ rotation order, and SL uses ZYX rotation order.

vector Rot2EulerXYZ(rotation rot)
{
    return <llAtan2(2*(rot.s*rot.x + rot.y*rot.z), 1 - 2*(rot.x*rot.x + rot.y*rot.y)),
            llAsin (2*(rot.s*rot.y - rot.x*rot.z)),
            llAtan2(2*(rot.s*rot.z + rot.x*rot.y), 1 - 2*(rot.y*rot.y + rot.z*rot.z))>;
}

It assumes SL avatar coordinate conventions (X=forward, Y=left, Z=up). The output vector has components output.x=roll, output.y=pitch, output.z=yaw.

The following is another version, perhaps easier to remember but less precise (rotations are not normalized to save memory):

vector Rot2EulerXYZ(rotation rot)
{
    vector result = llRot2Euler(<0,-1,0,1> * rot * <0,1,0,1>);
    return <-result.z, result.y, result.x>;
}

The opposite conversion can also be done in two ways, one more precise:

rotation EulerXYZ2Rot(vector euler)
{
    return <llSin(euler.x/2), 0, 0, llCos(euler.x/2)>
        *  <0, llSin(euler.y/2), 0, llCos(euler.y/2)>
        *  <0, 0, llSin(euler.z/2), llCos(euler.z/2)>;
}

and one symmetrical to the alternative above (needs normalized rotations though):

rotation EulerXYZ2Rot(vector euler)
{
    return <0,0.70710678,0,0.70710678> * llEuler2Rot(<euler.z, euler.y, -euler.x>) * <0,-0.70710678,0,0.70710678>;
}