Converting a Matrix to Rotation Angles

Started by
3 comments, last by Zakwayda 18 years, 8 months ago
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]
Binary Fortress Softwarehttp://www.binaryfortress.com
Advertisement
Rotation around y axis:

Y(x)={(cos(x),0,-sin(x),0),(0,1,0,0),(sin(x),0,cos(x),0),(0,0,0,1)}
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?
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
Binary Fortress Softwarehttp://www.binaryfortress.com
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.

This topic is closed to new replies.

Advertisement