Sign in to follow this  

Get euler angles from directX view matrix

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

Hello math forum. This is quite a math-noob question. I want to get the yaw, pitch and roll angles from directX view matrix. I have a piece of code that works fine for yaw and pitch but I don't understand it. Can someone explain me how you get angles from X-,Y-,Z-basis and/or tell me how to get roll angle? here is the code
	// The axis basis vectors and camera position are stored inside the 
	// position matrix in the 4 rows of the camera's world matrix.
	D3DXVECTOR3* pZBasis = (D3DXVECTOR3*) &matInvView._31;
	D3DXVECTOR3* pYBasis = (D3DXVECTOR3*) &matInvView._21;
	yaw = atan2f(pZBasis->x, pZBasis->z);
	float fLen = sqrtf(pZBasis->z*pZBasis->z + pZBasis->x*pZBasis->x);
	pitch = atan2f(pZBasis->y, fLen);

thx for your help

Share this post


Link to post
Share on other sites
Quote:
Original post by Adriano
Hello math forum. This is quite a math-noob question.
I want to get the yaw, pitch and roll angles from directX view matrix.
I have a piece of code that works fine for yaw and pitch but I don't understand it.
Can someone explain me how you get angles from X-,Y-,Z-basis and/or tell me how to get roll angle?
here is the code

*** Source Snippet Removed ***

thx for your help
What you have there is a Cartesian-to-spherical coordinate conversion (that, incidentally, will fail when the camera is looking straight up or down). Also, are you sure what you have works? If it really is the inverse view matrix, it doesn't seem like you should be able to get the basis vectors that way...

Anyway, the problem with extracting Euler angles is that there are many possible orders in which to do it (e.g. XYZ, YZX, ZXY, etc.). Presumably you want the same order that the DX 'yaw, pitch, roll' function uses for construction. Google will give you plenty of implementations of matrix-to-Euler-angle conversion, but they may or may not be of the form that you need to match DX.

One thing I'd ask is, are you sure you need Euler angles? Is there any particular reason that you need the orientation in that particular form?

Share this post


Link to post
Share on other sites
thx for the reply.
I googled "matrix-to-Euler-angle conversion" and found a lot of results wich can be more or less interesting. I tryed searching other similar sentences before posting but I didn't find what I was searching. This happens if you aren't able to express yourself well in english :P
In almost each of them, however, are mentioned the limitations of this method.
I know you were about to suggest me to use quaternions to achieve the result and I might consider that if I fail with this euler-angles approach

Share this post


Link to post
Share on other sites

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