Jump to content
  • Advertisement
Sign in to follow this  
Maddibob

World axis-aligned Matrix Rotations

This topic is 4896 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

Has anyone got any ideas on how best to carry out world-axis aligned matrix rotations whilst transforming objects? By this I mean rotate a cube 45 degrees on the world Y axis and then 45 degrees on the world Z axis. At the moment, if I do this, after the first Y rotation, the cube rotates about it's 'new' local Z axis rather than the world's. When I say 'after the first Y rotation', I mean that the Y rotation is multiplied into the object's world transform matrix before the Z axis is. The reason I'm asking is because I'm trying to rotate the object in projection views (e.g. front, side and top) and whilst rotating on the object's local axis is okay, I'd prefer it to rotate around the world axis which are obviously aligned to my views. Does anyone have any thoughts? By the way, I'm using DirectX9 with vc++. Thanks

Share this post


Link to post
Share on other sites
Advertisement
The short answer is, don't re-build your matrix from scratch each frame. Instead, maintain the object's orientation matrix from frame to frame. To rotate around a world axis (or any axis), simply multiply with the appropriate matrix. Also, you will need to re-orthogonalize occasionally to prevent drift (I don't know if DirectX has a function for this).

Share this post


Link to post
Share on other sites
Thanks jyk, that would work well. Is there a way to extract the orientation from a Matrix once it needs to be saved? Let's say for example 3 rotations have taken place in 3 different views, each view's rotation looks correct and the object's maintained Matrix represents it's current orientation.

When I come to save it, can I extract the _CURRENT_ x, y and z rotations so that when I reload the object I can apply the x, y and z and see the object in exactly the correct orientation - assuming I am multiplying Rotation x then y then z?

Thanks

Share this post


Link to post
Share on other sites
Quote:
Is there a way to extract the orientation from a Matrix once it needs to be saved? Let's say for example 3 rotations have taken place in 3 different views, each view's rotation looks correct and the object's maintained Matrix represents it's current orientation.

When I come to save it, can I extract the _CURRENT_ x, y and z rotations so that when I reload the object I can apply the x, y and z and see the object in exactly the correct orientation - assuming I am multiplying Rotation x then y then z?
There are several different ways to represent a rotation or orientation. Commonly used are Euler angles, axis-angle pairs, matrices, and quaternions. There are methods for converting from any of these representations to any other. They can also all be written to a file. If you're worried about memory, Euler angles and (compressed) quaternions require only three entries, while matrices can be stored with six.

Some of the conversions are easier than others. Is there any particular reason you don't want to just write the matrix itself to the file? It would certainly be easier than decomposing it into Euler angles and then reconstructing it.

Share this post


Link to post
Share on other sites
I hadn't thought about writing out and reloading the matrix with the object. At the moment, I'm just saving the position, scale and xyz rotation, which works fine for local-aligned rotations as I can just save this data and reconstruct the matrix upon loading it. As I want to be able to rotate on either, maintaining a matrix and saving/reloading it is the way forward.

I'll give it a go.

Thanks for your help

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!