Game Development Reference
In-Depth Information
vector.y * data[1] +
vector.z * data[2] + data[3],
vector.x * data[4] +
vector.y * data[5] +
vector.z * data[6] + data[7],
vector.x * data[8] +
vector.y * data[9] +
vector.z * data[10] + data[11]
);
}
};
Multiplying Two Matrices
We can use exactly the same process to multiply two matrices together. If we multiply
two 3
×
3 matrices together, we get another 3
×
3 matrix. This can be easily done with
this code:
Excerpt from include/cyclone/core.h
/**
* Holds an inertia tensor, consisting of a 3x3 row-major matrix.
* This matrix is not padding to produce an aligned structure, since
* it is most commonly used with a mass (single real) and two
* damping coefficients to make the 12-element characteristics array
* of a rigid body.
*/
class Matrix3
// ... Other Matrix3 code as before ...
/**
* Returns a matrix that is this matrix multiplied by the given
* other matrix.
*/
Matrix3 operator*(const Matrix3 &o) const
{
return Matrix3(
data[0]*o.data[0] + data[1]*o.data[3] + data[2]*o.data[6],
data[0]*o.data[1] + data[1]*o.data[4] + data[2]*o.data[7],
data[0]*o.data[2] + data[1]*o.data[5] + data[2]*o.data[8],
data[3]*o.data[0] + data[4]*o.data[3] + data[5]*o.data[6],
data[3]*o.data[1] + data[4]*o.data[4] + data[5]*o.data[7],
data[3]*o.data[2] + data[4]*o.data[5] + data[5]*o.data[8],