Game Development Reference

In-Depth Information

}

/**

* Inverts the matrix.

*/

void invert()

{

setInverse(*this);

}

};

Only square matrices have an inverse. For a 3

×

4 matrix, we need to again remem-

ber that our matrix is shorthand for a 4

×

4matrix.The4

×

4 matrix has an inverse

that can be written in much the same way as the 3

3matrix.Andfortunatelyfor

us the resulting matrix will have a bottom row of [0 0 0 1], so we can represent the

inverse as a 3

×

4matrix.

Unfortunately the algebra is more complex still, and it would run to about a page

of equations. Assuming your aim is to implement the code, I'll skip the long equations

and give the implementation:

×

Excerpt from include/cyclone/core.h

/**

* Holds a transform matrix, consisting of a rotation matrix and

* a position. The matrix has 12 elements; it is assumed that the

* remaining four are (0,0,0,1), producing a homogenous matrix.

*/

class Matrix4

{

// ... Other Matrix4 code as before ...

/**

* Returns the determinant of the matrix.

*/

real getDeterminant() const;

/**

* Sets the matrix to be the inverse of the given matrix.

*

* @param m The matrix to invert and use to set this.

*/

void setInverse(const Matrix4 &m);

/** Returns a new matrix containing the inverse of this matrix. */