Game Development Reference
In-Depth Information
Matrices and Transformations, Again
In Chapter 7, you learned a bit about matrices. Let's summarize some of their properties as a
quick refresher:
A matrix translates points (or vertices in our case) to a new position. This is
ï?®
achieved by multiplying the matrix with the point's position.
A matrix can translate points on each axis by some amount.
ï?®
A matrix can scale points, meaning that it multiplies each coordinate of a
ï?®
point by some constant.
A matrix can rotate a point around an axis.
ï?®
Multiplying an identity matrix with a point has no effect on that point.
ï?®
Multiplying one matrix with another matrix results in a new matrix.
ï?®
Multiplying a point with this new matrix will apply both transformations
encoded in the original matrices to that point.
Multiplying a matrix with an identity matrix has no effect on the matrix.
ï?®
OpenGL ES provides us with three types of matrices:
ï?® Projection matrix : This is used to set up the view frustum's shape and size,
which governs the type of projection and how much of the world is shown.
ï?® Model-view matrix : This is used to transform the models in model space and
to place a model in world space.
ï?® Texture matrix : This is used to manipulate texture coordinates on the fly,
much like we manipulate vertex position with the model-view matrix. This
functionality is broken on some devices. We won't use it in this topic.
Now that we are working in 3D, we have more options at our disposal. We can, for example,
rotate a model not only around the z axis, as we did with Bob, but around any arbitrary axis.
The only thing that really changes, though, is the additional z axis we can now use to place our
objects. We were actually already working in 3D when we rendered Bob back in Chapter 7; we
just ignored the z axis. But there's more that we can do.
The Matrix Stack
Up until now, we have used matrices like this with OpenGL ES:
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(−1, 1, -1, 1, -10, 10);
The first statement sets the currently active matrix. All subsequent matrix operations will be
executed on that matrix. In this case, we set the active matrix to an identity matrix and then
 
Search WWH ::




Custom Search