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

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

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

It assumes SL avatar coordinate conventions (X=forward, Y=left, Z=up). Unlike LSL functions, it also assumes the input rotation is normalized. The x component of the returned vector is roll (bank), the y component is pitch (elevation), and the z component is yaw (heading).

The following is another version, perhaps easier to remember and to inline but less precise (rotations are not normalized to save memory under Mono, but that doesn't change the result):

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 but also less precise (returns a normalized rotation):

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