Table of Contents

Start Functions Events Constants Types Language Articles

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

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