Sign in to follow this  
Unfadable

Inverse matrices and orientation

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this