Sign in to follow this  

Getting rotation for a DX matrix.

This topic is 3109 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
Hi,

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.
Here,
* 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.
Rohat.

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

Share this post


Link to post
Share on other sites

This topic is 3109 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.

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