Game Development Reference
In-Depth Information
Two matrices can be multiplied only if one has the same number of columns as the other
has rows. Matrix multiplication is not commutative, but it is associative; thus:
M N N M
(M N) P = M (N P)
Scalar Multiplication: The * Operator
This operator, when applied between a matrix and a scalar, multiplies each element in
the matrix m by the scalar s . Two forms are given here, depending on the order in which
the matrix and scalar are encountered:
inline Matrix3x3 operator*(Matrix3x3 m, float s)
{
return Matrix3x3( m.e11*s,
m.e12*s,
m.e13*s,
m.e21*s,
m.e22*s,
m.e23*s,
m.e31*s,
m.e32*s,
m.e33*s);
}
inline Matrix3x3 operator*(float s, Matrix3x3 m)
{
return Matrix3x3( m.e11*s,
m.e12*s,
m.e13*s,
m.e21*s,
m.e22*s,
m.e23*s,
m.e31*s,
m.e32*s,
m.e33*s);
}
Vector Multiplication: The * Operator
This operator, when applied between a vector and a matrix, performs a vector multi‐
plication where the i th column in the matrix is multiplied by the i th component in the
vector. Two forms are given here, depending on the order in which the matrix and vector
are encountered:
inline Vector operator*(Matrix3x3 m, Vector u)
{
return Vector( m.e11*u.x + m.e12*u.y + m.e13*u.z,
m.e21*u.x + m.e22*u.y + m.e23*u.z,
m.e31*u.x + m.e32*u.y + m.e33*u.z);