Rotation

The transformations described here are for left-handed coordinate systems, and so may be different from transformation matrices you have seen elsewhere. For more information, see 3-D Coordinate Systems.

The following transformation rotates the point (x, y, z) around the x-axis, producing a new point (x', y', z')

The following transformation rotates the point around the y-axis:

The following transformation rotates the point around the z-axis:

Note that in these example matrices, the Greek letter theta (θ) stands for the angle of rotation, specified in radians. Angles are measured clockwise when looking along the rotation axis toward the origin.

You can leverage the RotateX, RotateY, and RotateZ helper functions in the D3dutil.cpp file to create rotation matrices. The following is the sample code for the RotateX helper function:

D3DMATRIX RotateX(const float rads)
{
    float    cosine, sine;
 
    cosine = cos(rads);
    sine = sin(rads);
    D3DMATRIX ret = IdentityMatrix();
    ret(1,1) = cosine;
    ret(2,2) = cosine;
    ret(1,2) = -sine;
    ret(2,1) = sine;
    return ret;
}   // end of RotateX()