Game Development Reference
In-Depth Information
public static Matrix operator *(Matrix mA, Matrix mB)
{
Matrix result = new Matrix();
result._m11 = mA._m11 * mB._m11 + mA._m12 * mB._m21 + mA._m13 * mB._m31;
result._m12 = mA._m11 * mB._m12 + mA._m12 * mB._m22 + mA._m13 * mB._m32;
result._m13 = mA._m11 * mB._m13 + mA._m12 * mB._m23 + mA._m13 * mB._m33;
result._m21 = mA._m21 * mB._m11 + mA._m22 * mB._m21 + mA._m23 * mB._m31;
result._m22 = mA._m21 * mB._m12 + mA._m22 * mB._m22 + mA._m23 * mB._m32;
result._m23 = mA._m21 * mB._m13 + mA._m22 * mB._m23 + mA._m23 * mB._m33;
result._m31 = mA._m31 * mB._m11 + mA._m32 * mB._m21 + mA._m33 * mB._m31;
result._m32 = mA._m31 * mB._m12 + mA._m32 * mB._m22 + mA._m33 * mB._m32;
result._m33 = mA._m31 * mB._m13 + mA._m32 * mB._m23 + mA._m33 * mB._m33;
result._m41 = mA._m41 * mB._m11 + mA._m42 * mB._m21 + mA._m43 * mA._m31 +
mB._m41;
result._m42 = mA._m41 * mB._m12 + mA._m42 * mB._m22 + mA._m43 * mB._m32 +
mB._m42;
result._m43 = mA._m41 * mB._m13 + mA._m42 * mB._m23 + mA._m43 * mB._m33 +
mB._m43;
return result;
}
The vector matrix multiplication is similar.
public static Vector operator *(Vector v, Matrix m)
{
return new Vector(v.X * m._m11 + v.Y * m._m21 + v.Z * m._m31 + m._m41,
v.X * m._m12 + v.Y * m._m22 + v.Z * m._m32 + m._m42,
v.X * m._m13 + v.Y * m._m23 + v.Z * m._m33 + m._m43);
}
Translating and Scaling
Translation is a pretty simple operation. The last row of the vector is the origin of
the object; it is the translation. Creating a matrix to alter the translation is just the
identity matrix with the last row altered. Here is the translation matrix.
 
Search WWH ::




Custom Search