## Matrices

Later you will see how to specify a view frustum, and thus a projection. OpenGL ES expresses projections in the form of so-called matrices. For our purposes we don't need to know the internals of matrices. We only need to know what they do to the points we define in our scene. Here's the executive summary of matrices:

■ A matrix encodes transformations to be applied to a point. A transformation can be a projection, a translation (in which the point is moved around), a rotation around another point and axis, or a scale, among other thing.

■ By multiplying such a matrix with a point, we apply the transformation to the point. For example, multiplying a point with a matrix that encodes a translation by 10 units on the x-axis will move the point 10 units on the x-axis and thereby modify its coordinates.

■ We can concatenate transformations stored in separate matrices into a single matrix by multiplying the matrices. When we multiply this single concatenated matrix with a point, all the transformations stored in that matrix will be applied to that point. The order in which the transformations are applied is dependent on the order in which we multiplied the matrices with each other.

■ There's a special matrix called an identity matrix. If we multiply a matrix or a point with it, nothing will happen. Think of multiplying a point or matrix by an identity matrix as multiplying a number by 1. It simply has no effect. The relevance of the identity matrix will become clear once we learn how OpenGL ES handles matrices (see the section "Matrix Modes and Active Matrices"). A classic hen and egg problem.

NOTE: When I talk about points in this context, I actually mean 3D vectors.

OpenGL ES has three different matrices that it applies to the points of our models:

■ Model-view matrix: We can use this matrix to move, rotate, or scale the points of our triangles around (this is the model part of the model-view matrix). This matrix is also used to specify the position and orientation of our camera (this is the view part).

■ Projection matrix: The name says it all—this matrix encodes a projection, and thus the view frustum of our camera.

■ Texture matrix: This matrix allow us to manipulate so-called texture coordinates (which we'll discuss later). However, we'll avoid using this matrix in this book since this part of OpenGL ES is broken on a couple of devices thanks to buggy drivers.

## Post a comment