Jump to content
  • Advertisement
Sign in to follow this  
Unfadable

Inverse matrices and orientation

This topic is 4500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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.

Share this post


Link to post
Share on other sites
Yeah, unfortunately my matrices aren't guaranteed to be orthonormal, so I need a general solution. Kramer's rule then?

Share this post


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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!