Inverse matrices and orientation

Started by
6 comments, last by Unfadable 18 years, 1 month ago
Two quick questions: 1) I'm implementing a matrix library and need an inverse function to find inverse cam/world matrices etc. Is Kramer's rule the way to go? If not, can I get a recommendation. 2) Just curious as to how you guys store your game object's orientation. Euler angles, rotation matrices, quats, etc. I'm leaning towards a matrix, so that I can apply world rotations easily w/o converting from/to euler angles.
Advertisement
Quote:Original post by Unfadable
1) I'm implementing a matrix library and need an inverse function to find inverse cam/world matrices etc. Is Kramer's rule the way to go? If not, can I get a recommendation.

The inverse of an orthonormal matrix is actually just the transpose. So for a 3x3 rotation matrix you can just take the transpose. If you're using a 4x4 homogeneous transformation matrix, then you can invert it in pieces - use RT on the rotational 3x3 submatrix 'R', and use -RTd to invert the 3x1 translation submatrix 'd'.

Quote:Original post by Unfadable
2) Just curious as to how you guys store your game object's orientation. Euler angles, rotation matrices, quats, etc. I'm leaning towards a matrix, so that I can apply world rotations easily w/o converting from/to euler angles.

Most of the time you can get away with Euler angles, but if you experience Gimbal lock problems then you'll have to switch to quaternions. Personally I've always stored Euler angles and created/updated a set of transformation matrices that I pass to DirectX/OpenGL.
Yeah, unfortunately my matrices aren't guaranteed to be orthonormal, so I need a general solution. Kramer's rule then?
For small matrices (4x4 and smaller), you can get away with an explicit formula (like those shown here). For a general NxN matrix, I would use Gauss-Jordan elimination.

Just out of curiosity, which matrices do you expect to be non-orthonormal, besides maybe the perspective matrix?
Cool I'll check that out. Thanks.

The world matrix of some of my objects may have a scale applied to them.

Which reminds me of another question. Is it valid to normalize the basis vectors in a matrix and it still maintain the proper orientation? It seems like it should be, but I've never been sure.
I completely forgot about scaling (I don't use it much). There are also tricks for inverting that transformation. You can compute the length of each basis, divide it out (so normalize the basis vectors), do the transpose thing, and divide out the length again from each of the new basis vectors. In other words, the basis vectors in R and R-1 will have inverse lengths.

This also answers your new question, that you can change the length of the basis vectors and still maintain the same orientation.
You could perhaps include a method for for quick inverse for cases when you KNOW that the matric is orthonormal?
Steven ToveySPUify | Twitter
Quote:
You could perhaps include a method for for quick inverse for cases when you KNOW that the matric is orthonormal?


Oh absolutely. Depending on the scene, this operation may come up a lot and I'd definitely perfer using the transponse.

Zipster, cool trick you've posted. Much appreciated.

This topic is closed to new replies.

Advertisement