4 x 4 matrix inversion

Anyone out there have a quick way to invert a 4x4 matrix ?

I am trying to solve the following problem:

  1. There’s a globe that’s been translated/scaled/rotated not only using gl’s translate,scale,rotate routines, but also by multiplying my own 4x4 matrix, and it’s displayed in a window.

  2. I pick a point on the globe. To identify the “world coordinate” of the picked point on the surface of the globe, I have to find the inverse of the matrix used to transform the globe. I would like to use the inverse matrix to multiply to x,y,z coordinate of the picked point on the surface. The result is the world coordinate x,y,z.

I guess I am too lazy to go through my old linear algebra books to find the matrix inversion routines.

I would appreciate any help.

Thanks.

Well, you know how to concatenate the translation, scaling, and rotation matrix into a single transformation matrix right? Just work out the reverse transformation. The inverse translation and inverse scaling matrices are childs play, and so is the rotation matrix when you remember that since it is orthognal, its inverse is simply the transpose. So if M=TSR, for example, then M^-1=(R^-1)(S^-1)(T^-1)=(R^-1)(S^-1)(T’) where T’ is the transposition of T. Of course the actual concatenation of M will be which ever you used.

Or, you can download the Mesa3D code. It has a function for inverting matrices. Not shure how legal is to copy/paste the code, but I guess its ok.

Typically, if you already know the nature of the transformation, you can solve for the inverse of that matrix much faster than solving for the inverse of a matrix in general. Typically, because in a heirarchical model, there may be very many concatenations and so in that case solving for the inverse in general would be better.