Jump to content
  • Advertisement
Sign in to follow this  

Getting rotation for a DX matrix.

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

hi guys i'm forced to get rotation from the matrix as the other outputs are unreliable and are not accessable to alter the code. I have had a look at the matrix articles and i thought i'd knew how to do it, i'd just pick the p[art of the matrix that is not afftected by other rotations or translations e.g. 33 for y rotation and just use inverse cos. This ofcourse fails whne you times matrices together, and therein lies my problem. I now cannot get the rotation. Please, is there a magic way of getting the rotation? JamesCobras

Share this post

Link to post
Share on other sites
Are you trying to get euler angles out of the matrix? Because that's a touchy thing to attempt. Not unworkable, but very problematic.

Share this post

Link to post
Share on other sites

Seems a very difficult problem to solve :) But I can say something I think :)

You know matrices are built from axis vectors. If you're using row-major ones, first row contains X, second row contains Y and the third row contains Z axis vectors.

Now you can get the axis vectors of the rotated matrix:
mR = [rX, rY, rZ] (right axis)
mU = [uX, uY, uZ] (up axis)
mL = [lX, lY, lZ] (look axis)

and we have our reference axis vectors:
vR = [1, 0, 0] (right axis)
vU = [0, 1, 0] (up axis)
vL = [0, 0, 1] (look axis)

... and here, "dot product" comes to help us :)

kR = [rX, rY, 0]
kU = [0, uY, uZ]
kL = [lX, 0, lZ]
dot (kR, vR) = |kR| . |vR| . cos (Alpha) => cos(Alpha) = dot (kR, vR) / |kR|
dot (kU, vU) = |kU| . |vU| . cos (Beta) => cos(Beta) = dot (kU, vU) / |kU|
dot (kL, vL) = |kL| . |vL| . cos (Theta) => cos(Theta) = dot (kL, vL) / |kL|

From these cos(.) values, you can get the rotation angles in radians by using acosf() function. And you can use D3DXToDegree() to get that angles in degrees.
* Alpha represents rotation angle around z (look) axis vector,
* Beta represents rotation angle around x (right) axis vector,
* Theta represents rotation angle around y (up) axis vector.

This picture can help you to understand how I got these formulas. I'm using this technique to obtain right and up vectors from only look vector.

If anyone saw something wrong, please correct me ;)

Hope this helps.

[Edited by - programci_84 on June 12, 2009 6:01:15 AM]

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!