Game Development Reference
In-Depth Information
data[6] = (+m.data[4]*m.data[2]-m.data[0]*m.data[6]* m.data[15])*det;
data[10] = (-m.data[4]*m.data[1]+m.data[0]*m.data[5]* m.data[15])*det;
data[3] = (m.data[9]*m.data[6]*m.data[3]
-m.data[5]*m.data[10]*m.data[3]
-m.data[9]*m.data[2]*m.data[7]
+m.data[1]*m.data[10]*m.data[7]
+m.data[5]*m.data[2]*m.data[11]
-m.data[1]*m.data[6]*m.data[11])*det;
data[7] = (-m.data[8]*m.data[6]*m.data[3]
+m.data[4]*m.data[10]*m.data[3]
+m.data[8]*m.data[2]*m.data[7]
-m.data[0]*m.data[10]*m.data[7]
-m.data[4]*m.data[2]*m.data[11]
+m.data[0]*m.data[6]*m.data[11])*det;
data[11] =(m.data[8]*m.data[5]*m.data[3]
-m.data[4]*m.data[9]*m.data[3]
-m.data[8]*m.data[1]*m.data[7]
+m.data[0]*m.data[9]*m.data[7]
+m.data[4]*m.data[1]*m.data[11]
-m.data[0]*m.data[5]*m.data[11])*det;
}
You'll notice from this code that the inverse again exists only when the determinant
of the matrix is non-zero.
The Matrix Transpose
Whenever the determinant is non-zero, we can always use the preceding equations to
find the inverse of a matrix. It is not the simplest process, however, and in some cases
we can do much better.
If we have a matrix that represents a rotation only, we can make use of the fact
that the inverse of the transformation is another rotation, about the same axis but
at the opposite angle. This is equivalent to inverting the axis and using the same an-
gle. We can create a matrix that rotates the same degree in the opposite direction by
transposing the original matrix.
The transpose of a matrix
abc
def
ghi
M
=