Game Development Reference
In-Depth Information
defines the combination of all those operations. For instance, a matrix that ro-
tates a model 90 degrees, a matrix that scales a model up two times, and a matrix
that moves the model two miles to the left can all be combined into a single
matrix that does all these operations at once. This is done by matrix multi-
plication—multiply the matrices together and the result will be a matrix that is
the combination of all the operations.
Combining operations is not the only advantage to matrices. A matrix can be
inverted; this will perform the opposite operation that the original matrix would
have performed. If a rotation matrix was created to rotate 5 degrees around the
Z axis, and it was then applied to a model, the model's original position could be
restored by inverting the matrix and applying it again. Matrices are applied to a
model by multiplying each vertex by the matrix.
Matrix math can be quite dense; few game developers would be able to write the
code for matrix multiplication immediately when asked. The actual matrix op-
erations are quite simple, but it can take a while to understand them completely.
Don't be discouraged, and if you want a more thorough understanding check the
recommended reading section in Appendix A.
What Is a Matrix?
A matrix is a grid of numbers. Like vectors, matrices come in many dimensions.
The vector we have defined has a dimension of three—X, Y, and Z. The most
commonly used matrix in 3D graphics is 4x4, as is shown in Figure 8.21.
Figure 8.21 shows the matrix described as three axis vectors and one position
vector: the origin. X x X y X z describes the x vector, Y x Y y Y z the y vector, Z x Z y Z z the
z vector, and the origin vector is described as O x O y O z . These three vectors are the
axis of the model and its origin. These can be used to quickly determine an ob-
ject's position and the direction it faces on the X, Y, and Z axes. If the axes are all
normalized, then the object isn't scaled; if the axes all have a length of two, then
the object is scaled to be twice as big. This is a visual way of thinking about
matrices that makes them easier to use.
The final column in Figure 8.21 is [0, 0, 0, 1]. The values in this column will
never change; they are only used when computing projections (from 3D to 2D
space). Such projection operations aren't that common so the matrix we'll use
will be 4x3. The end column will always be [0, 0, 0, 1].
 
Search WWH ::




Custom Search