Game Development Reference
In-Depth Information
Matrix Subtraction: The − Operator
This operator subtracts matrix m2 from m1 on an element-by-element basis:
inline Matrix3x3 operator-(Matrix3x3 m1, Matrix3x3 m2)
{
return Matrix3x3( m1.e11-m2.e11,
m1.e12-m2.e12,
m1.e13-m2.e13,
m1.e21-m2.e21,
m1.e22-m2.e22,
m1.e23-m2.e23,
m1.e31-m2.e31,
m1.e32-m2.e32,
m1.e33-m2.e33);
}
Scalar Divide: The / Operator
This operator divides every element in the matrix m by the scalar s :
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);
}
Matrix Multiplication: The * Operator
This operator, when applied between two matrices, performs a matrix multiplication.
In matrix multiplication, each element, e ij , is determined by the product of the i th row
in the first matrix and the j th column of the second matrix:
inline Matrix3x3 operator*(Matrix3x3 m1, Matrix3x3 m2)
{
return Matrix3x3(m1.e11*m2.e11 + m1.e12*m2.e21 + m1.e13*m2.e31,
m1.e11*m2.e12 + m1.e12*m2.e22 + m1.e13*m2.e32,
m1.e11*m2.e13 + m1.e12*m2.e23 + m1.e13*m2.e33,
m1.e21*m2.e11 + m1.e22*m2.e21 + m1.e23*m2.e31,
m1.e21*m2.e12 + m1.e22*m2.e22 + m1.e23*m2.e32,
m1.e21*m2.e13 + m1.e22*m2.e23 + m1.e23*m2.e33,
m1.e31*m2.e11 + m1.e32*m2.e21 + m1.e33*m2.e31,
m1.e31*m2.e12 + m1.e32*m2.e22 + m1.e33*m2.e32,
m1.e31*m2.e13 + m1.e32*m2.e23 + m1.e33*m2.e33 );
}