Sign in to follow this  
GremlinX

Converting a Matrix to Rotation Angles

Recommended Posts

I have a D3DXMATRIX and I need to get the rotation in radians around the Y axis. Is this possible, and if so where can I get some information/code on how to do it? If this isn't a simple thing, is it possible to get the direction vector from a matrix? Thanks [Edited by - GremlinX on September 5, 2005 10:13:27 PM]

Share this post


Link to post
Share on other sites
Quote:
I have a D3DXMATRIX and I need to get the rotation in radians around the Y axis. Is this possible, and if so where can I get some information/code on how to do it?
You can certainly extract Euler angles from a matrix, but you have to choose an appropriate order and write your code accordingly. I'm guessing though that you may not need anything that complicated. The matrix that you want to extract the y rotation from - how was it constructed in the first place?
Quote:
If this isn't a simple thing, is it possible to get the direction vector from a matrix?
By direction vector, do you mean the 'forward' vector, i.e. the direction an object with that orientation is facing?

Share this post


Link to post
Share on other sites
The matrix is coming from a 3rd party physics engine, so I'm not sure how's it's constructed. However, when I get the 3rd party matrix I convert it to a D3DXMATRIX by just setting the values of the D3DXMATRIX structure... like _11, _12... etc using the values from the 3rd party matrix. Does this answer your question?

By direction vector, I meant forward vector, yes. If I can get the rotation around the Y axis from the matrix I won't need to worry about the forward vector though.

Thanks for your help

Share this post


Link to post
Share on other sites
It will probably be easiest to just extract the forward vector directly. Assuming the source matrix represents only rotation and translation, the basis vectors for the coordinate frame are stored in the first three rows, like this:

11 12 13
21 22 23
31 32 33

=

Xx Xy Xz
Yx Yy Yz
Zx Zy Zz

So if, say, z is forward, just create your forward vector from elements 31, 32 and 33.

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