Unofficial LSL Reference

[[functions:llaxes2rot]]


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

Function: llAxes2Rot

rotation llAxes2Rot(vector fwd, vector left, vector up)

Converts a rotation expressed as three vectors that make an orthonormal basis (i.e. a rotation in matrix form), to a LSL rotation.

Parameters

fwd

A unit vector that is the X vector of the basis.

left

A unit vector that is the Y vector of the basis. It must be perpendicular to X for the function to return any meaningful results.

up

A unit vector that is the Z vector of the basis. It must be perpendicular to X and Y for the function to return any meaningful results.

Return value

Returns a rotation representing the same orientation.

Notes

  • If the vectors are not unit vectors or not orthogonal, the function may return meaningless results. Under these circumstances, it may return unnormalized rotations in some cases. Most other functions that deal with rotations return them normalized. This is a rare exception.
  • The inverse operation (get the axes out of an LSL rotation) is done with llRot2Fwd, llRot2Left and llRot2Up.

Short examples

rotation r;
// This will set r to <0, 0, 1, 0> which is a rotation of 180° around the Z axis.
r = llAxes2Rot(<-1, 0, 0>, <0, -1, 0>, <0, 0, 1>);

// This will set r to <0.5, 0.5, 0.5, 0.5> which is a rotation that corresponds to a transposition of the axes.
r = llAxes2Rot(<0, 1, 0>, <0, 0, 1>, <1, 0, 0>);

This function will return a rotation similar to the one used by llLookAt (pointing its local Z towards the given point, and keeping its local X below the horizon).

LookAtRot-function.lsl
rotation LookAtRot(vector where)
{
    where = llVecNorm(where - llGetPos());
    vector local_y = llVecNorm(<0,0,1> % where);
    return llAxes2Rot(local_y % where, local_y, where);
}

See also

  • llRot2Fwd returns the X axis of an orthonormal basis, given a rotation.
  • llRot2Left returns the Y axis of an orthonormal basis, given a rotation.
  • llRot2Up returns the Z axis of an orthonormal basis, given a rotation.