Game Development Reference
In-Depth Information
"No determinate");
double oneOverDet = 1.0 / determinate;
Matrix result = new Matrix();
result._m11 = (_m22 * _m33 - _m23 * _m32) * oneOverDet;
result._m12 = (_m13 * _m32 - _m12 * _m33) * oneOverDet;
result._m13 = (_m12 * _m23 - _m13 * _m22) * oneOverDet;
result._m21 = (_m23 * _m31 - _m21 * _m33) * oneOverDet;
result._m22 = (_m11 * _m33 - _m13 * _m31) * oneOverDet;
result._m23 = (_m13 * _m21 - _m11 * _m23) * oneOverDet;
result._m31 = (_m21 * _m32 - _m22 * _m31) * oneOverDet;
result._m32 = (_m12 * _m31 - _m11 * _m32) * oneOverDet;
result._m33 = (_m11 * _m22 - _m12 * _m21) * oneOverDet;
result._m41 = -(_m41 * result._m11 + _m42 * result._m21 + _m43 *
result._m31);
result._m42 = -(_m41 * result._m12 + _m42 * result._m22 + _m43 *
result._m32);
result._m43 = -(_m41 * result._m13 + _m42 * result._m23 + _m43 *
result._m33);
return result;
}
With this code, any matrix we will be using can be inverted.
That's it for the Matrix class; it's now useful for both 2D and 3D applications.
Next, we will apply it.
Matrix Operations on Sprites
Create a new game state called MatrixTestState . This state will draw a sprite
and apply various matrices to that sprite. Here is the code to just draw the sprite,
which should be quite familiar to you by now.
class MatrixTestState : IGameObject
{
Sprite _faceSprite = new Sprite();
 
Search WWH ::




Custom Search