Game Development Reference
In-Depth Information
data[6]*[0] + data[7]*[3] + data[8]*[6],
data[6]*[1] + data[7]*[4] + data[8]*[7],
data[6]*[2] + data[7]*[5] + data[8]*[8]
Multiplying two matrices together in this way combines their effects. If matrices
A and B are two transformations, then the matrix AB will represent the combined
transformation. Order is crucial for both transformations and matrix multiplication:
the matrix AB is a transformation that would result from first doing B and then do-
ing A . In other words, the order of the transformations is the opposite of the order
of the matrices in the multiplication. This is a “gotcha” that catches even experienced
developers from time to time.
So much for 3
3 matrices; how about 3
4 matrices? From the rules of matrix
multiplication we can't multiply two 3
4 matrices together: the columns of the first
matrix don't match the rows of the second. To make progress we need to return to the
full form of our 4
4 matrix. Remember that the matrix we are storing as
ef gh
can be thought of as shorthand for
ef gh
matrices with [0 0 0 1] as their bottom line, we end up with another matrix whose
So in our code, when we come to multiply two 3
We can certainly multiply two 4
4 matrices together. If we multiply two 4
4 matrices (to combine their
transformations), we magically make the extra values appear, without storing them,
exactly as we did for transforming vectors. The code looks like this:
Excerpt from include/cyclone/core.h
* Holds a transform matrix, consisting of a rotation matrix and
* a position. The matrix has 12 elements; it is assumed that the
* remaining four are (0,0,0,1), producing a homogenous matrix.
Search Nedrilad ::

Custom Search