Game Development Reference
In-Depth Information
_m11 = ax * axis.X + angleCos;
_m12 = ax * axis.Y + axis.Z * angleSin;
_m13 = ax * axis.Z - axis.Y * angleSin;
_m21 = ay * axis.X - axis.Z * angleSin;
_m22 = ay * axis.Y + angleCos;
_m23 = ay * axis.Z + axis.X * angleSin;
_m31 = az * axis.X + axis.Y * angleSin;
_m32 = az * axis.Y - axis.X * angleSin;
_m33 = az * axis.Z + angleCos;
}
Sine and cosine can be expensive operations if they are used many times a frame,
and for that reason, their use in the code is minimized. The axis vector should be
normalized, but there is no check in the SetRotate function.
Inverse
The inverse is very useful for reversing the operations of a given matrix. To cal-
culate the inverse, the determinate of the matrix is required. Every square matrix
has its own determinate. A matrix is invertible only if the determinate doesn't
equal zero.
public double Determinate()
{
return _m11 * (_m22 * _m33 - _m23 * _m32) +
_m12 * (_m23 * _m31 - _m21 * _m33) +
_m13 * (_m21 * _m32 - _m22 * _m31);
}
The determinate can then be used to calculate the inverse of the top 3
3 of the
matrix—the scale and rotation parts. The translation part of the matrix is cal-
culated manually.
public Matrix Inverse()
{
double determinate = Determinate();
System.Diagnostics.Debug.Assert(Math.Abs(determinate) >
Double.Epsilon,
 
Search WWH ::




Custom Search