Game Development Reference
In-Depth Information
* of a rigid body.
*/
class Matrix3
{
public:
/**
* Holds the tensor matrix data in array form.
*/
real data[9];
};
and for Matrix4 it 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.
*/
class Matrix4
{
public:
/**
* Holds the transform matrix data in array form.
*/
real data[12];
};
Clearly there is nothing taxing so far; we just have two arrays of numbers.
Just as we did for the Vector3 class in chapter 2, we can add methods to these
classes to implement their mathematics.
9.4.2
M ATRIX M ULTIPLICATION
Since I've said that matrices exist mainly to transform vectors, let's look at this first.
We transform a vector by multiplying it by the matrix
v =
M v
which is often called “post-multiplication” because the vector occurs after the matrix
in the multiplication.
Matrix multiplication works in the same way whether we are multiplying two
matrices together or multiplying a matrix and a vector. In fact we can think of a
vector as simply a matrix with a single column—a 3
×
1matrix.