Game Development Reference
In-Depth Information
In terms of code, we represent matrices as a float array of 16 elements. This translates to a 4-by-4
matrix; that is, a matrix that has four rows and four columns. The following declares a 4-by-4 matrix
(total 16 elements) of type float that is private to the class that it is located in:
private float[] m_OrientationMatrix = new float[16];
Built-in Android Matrix Class
There is a Matrix class available in the standard Android class library that provides many matrix
functions. You can access this class by using the following import statement:
import android.opengl.Matrix;
The Identity Matrix
The identity matrix is a square matrix that has an equal number of rows and columns that contain a
1 diagonally, with the rest of the values set to 0. The identity matrix can be used to initialize or reset
the value of a matrix variable. A matrix multiplied by the identity matrix returns the original matrix.
This is the equivalent of multiplying a number by 1. For example, let's say you have a matrix that
keeps track of an object's rotation. In order to reset the object back to its original rotation, you would
set the matrix to the identity matrix (see Figure 3-17 ).
Figure 3-17. The identity matrix
In terms of code, you can set a matrix to the identity matrix, using the following statement:
//static void setIdentityM(float[] sm, int smOffset)
Matrix.setIdentityM(m_OrientationMatrix, 0);
The matrix contained in the float array m_OrientationMatrix will be set to the identity matrix. There is
0 offset into the array to the start of the matrix data.
Matrix Transpose
The transpose of a matrix is created by rewriting the rows of the matrix as columns. You will have
to use the matrix transpose to calculate the value of the normal matrix, which is used in lighting
(see Figure 3-18 ).
 
Search WWH ::




Custom Search