Game Development Reference
In-Depth Information
Figure 3-21. Rotation matrix
In terms of code, there is a built-in function in the Matrix class in which you can rotate a matrix in
place around an arbitrary rotation axis you specify by an angle that is specified in degrees.
The rotateM() function rotates the matrix m by angle a in degrees around the axis (x,y,z). You can
also specify and offset to where the matrix data begins.
//rotateM(float[] m, int mOffset, float a, float x, float y, float z)
//Rotates matrix m in place by angle a (in degrees) around the axis (x, y, z)
Matrix.rotateM(m_RotationMatrix, 0,
AngleIncrementDegrees,
m_RotationAxis.x,
m_RotationAxis.y,
m_RotationAxis.z);
Using Matrices to Scale Objects
You can also use a matrix to scale objects. The diagonal of the square 4-by-4 matrix contains the
scaling factors in the x, y, and z directions (see Figure 3-22 ).
Figure 3-22. Scale matrix
In terms of code, the scaleM() function in the Matrix class scales a matrix in place in the x, y,
and z directions.
//static void scaleM(float[] m, int mOffset, float x, float y, float z)
//Scales matrix m in place by sx, sy, and sz
Matrix.scaleM(m_ScaleMatrix, 0, Scale.x, Scale.y, Scale.z);
Combining Matrices
By multiplying matrices together, you can combine the effects of translation, rotation, and scaling on
an object. One key combination matrix we will need in order to render 3D objects in our game will be
the ModelMatrix. The ModelMatrix is a combination of the translation matrix, rotation matrix, and the
scale matrix multiplied together to form a single final matrix (see Figure 3-23 ).
 
Search WWH ::




Custom Search