RenderWare V2.1

Previous Page Index Next Page

RwMatrix4d *

RwQueryRotateMatrix(RwMatrix4d *matrix, RwV3d *axis,
RwReal *degrees, RwV3d *centre);

Description

Retrieves the rotation component from a matrix comprising only rotations and translations. The rotation is returned as a unit direction vector along the axis of rotation through the origin and an angle in degrees. This function is the inverse of RwRotateMatrix() with the RwCombineOperation rwREPLACE.

Arguments

matrix Pointer to the rotation/translation matrix.

axis Pointer to the vector to receive the unit direction vector along the axis of rotation through the origin.

degrees Pointer to the RwReal to receive the angle of rotation in degrees.

centre Centre of the line of rotation. (i.e. the nearest point thereon to the origin.)

Return Value

The argument matrix if successful, and NULL otherwise.

Comments

A rotation has two possible descriptions in this axis/angle form, since a rotation about a given axis through the origin by a given angle theta is the same as a rotation about an axis in the reverse direction by the angle 360-theta. The angle returned is always in the range CREAL(0.0) to CREAL(180.0). The direction of the axis of rotation returned is chosen to ensure that the angle lies in this range.

The parametric equation of the line of rotation is therefore:

center + lambda * axis

Any rigid body transform may then be expressed as such a rotation as follows:

RwQueryRotateMatrix(rigid, &axis, &degrees, &center);
RwTranslateMatrix(synth, -center.x, -center.y, -center.z, rwREPLACE);
RwRotateMatrix(synth, axis.x, axis.y, axis.z, degrees, rwPOSTCONCAT);
RwTranslateMatrix(synth, center.x, center.y, center.z, rwPOSTCONCAT);

Notice that only matrices known to be composed solely of rotations and translations should be queried with this function. The results of querying other matrices incorporating transforms such as scales are unlikely to be of practical use. RwOrthoNormalizeMatrix() may be applied to extract the rotation/translation component matrix from a more general transformation matrix.

See Also

RwGetMatrixElements()

RwGetMatrixElement()

RwOrthoNormalizeMatrix()

RwRotateMatrix()

RwRotateMatrixCos()