void Matrix4x4::FastInvert()
{
swap(m[0][1], m[1][0]);
swap(m[0][2], m[2][0]);
swap(m[1][2], m[2][1]);
the translation part is then equally easy inverted (by taking the negative translation and multiplying it with the inverted rotation matrix, which is the transpose we just calculated).
float m30 = -(m[0][0] * m[3][0] + m[1][0] * m[3][1] + m[2][0] * m[3][2]); float m31 = -(m[0][1] * m[3][0] + m[1][1] * m[3][1] + m[2][1] * m[3][2]); m[3][2] = -(m[0][2] * m[3][0] + m[1][2] * m[3][1] + m[2][2] * m[3][2]); m[3][1] = m31; m[3][0] = m30; }
it should be noted that this only works if the matrix is unscaled because the row vectors of the rotation matrix are required to have unit length. the calculation should be extendable though if the matrix is scaled equally in all directions.













