Game Development Reference
In-Depth Information
data[6]*o.data[0] + data[7]*o.data[3] + data[8]*o.data[6],
data[6]*o.data[1] + data[7]*o.data[4] + data[8]*o.data[7],
data[6]*o.data[2] + data[7]*o.data[5] + data[8]*o.data[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
abcd
ef gh
ijkl
can be thought of as shorthand for
abcd
ef gh
ijkl
0001
×
×
4
matrices with [0 0 0 1] as their bottom line, we end up with another matrix whose
bottomlineis[0001](tryittoconvinceyourself).
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