Sign in to follow this  
Samurai Jack

What the hell...

Recommended Posts

This is an algebra question. My problem is following: I am reading a list of coordinates: line#0: rx ry rz line#1: rx ry rz ... line#n: rx ry rz All variables (floats) represent a rotation arround each axis in radians. Which means: float rx = rotation on x axis [-2pi..+2pi] float ry = rotation on y axis [-2pi..+2pi] float rz = rotation on z axis [-2pi..+2pi] My problem is, I am usisng DirectX D3DX functions. When i say: D3DXMATRIX mx, my, mz, matrix; D3DXMatrixRotationX(&mx, &rx); D3DXMatrixRotationY(&my, &ry); D3DXMatrixRotationZ(&mz, &rz); matrix = rx * ry * rz; Everything works fine. Now i tried this: D3DXMatrixRotationYawPitchRoll(&matrix, ry, rx, rz); This one does not work! It is not a gimbal lock problem, because i tried it also with quaternions and get the same results. On the other way, when I just try one component: D3DXMatrixRotationYawPitchRoll(&test, 0.0f, rx, 0.0f); test == D3DXMatrixRotationX(&mx, &rx); So each compmonent is the same as above, but when using YPR they get corrupted when they are multiplied all together. Please do not point me to GIMBAL LOCK, because I am sure it is not a Gimbal lock problem. Thank you in advance!

Share this post


Link to post
Share on other sites
First let's have a look at your input. You said:

float rx = rotation on x axis [-2pi..+2pi]
float ry = rotation on y axis [-2pi..+2pi]
float rz = rotation on z axis [-2pi..+2pi]

This seems a bit strange; a rotation expressed in radians has a range [0,2Pi]. Your rotations have a range [-2Pi,+2Pi]; basically it defines that any object can have twice as many (unique) rotations which is not the case. I'm not sure how DX handles this; maybe they expect the angles in the normal [0,2Pi] or [-Pi,Pi] range.

Second I see you are very sure it is not gimbal lock. Please not that just constructing a quaternion out of thee Euler rotation angles is not magically going to remove gimbal lock. But since it is not gimbal lock...

Greetz,

Illco

Share this post


Link to post
Share on other sites
Quote:
Original post by Samurai Jack
D3DXMATRIX mx, my, mz, matrix;
D3DXMatrixRotationX(&mx, &rx);
D3DXMatrixRotationY(&my, &ry);
D3DXMatrixRotationZ(&mz, &rz);
matrix = rx * ry * rz;

Everything works fine. Now i tried this:
D3DXMatrixRotationYawPitchRoll(&matrix, ry, rx, rz);


try this:
D3DXMatrixRotationYawPitchRoll(&matrix, rx, ry, rz);

note that I just changed the yaw axis from y to x, as in your first code sample


Share this post


Link to post
Share on other sites
That is not correct.

D3DXMatrixRotationYawPitchRoll( Y, X, Z ) is the correct order.

Yaw = Y rotation
Pitch = X rotation
Roll = Z rotation

I checked if seperatly:
D3DXMatrixRotationX(&matrix, value) == D3DXMatrixRotationYawPitchRoll(0, value, 0)
also
D3DXMatrixRotationY(&matrix, value) == D3DXMatrixRotationYawPitchRoll(value, 0, 0)
also
D3DXMatrixRotationZ(&matrix, value) == D3DXMatrixRotationYawPitchRoll(0, 0, value)

I double checked that for sure.

Share this post


Link to post
Share on other sites
Quote:
Original post by Samurai Jack
D3DXMATRIX mx, my, mz, matrix;
D3DXMatrixRotationX(&mx, &rx);
D3DXMatrixRotationY(&my, &ry);
D3DXMatrixRotationZ(&mz, &rz);
matrix = rx * ry * rz;

What you are doing here is:

1. rotate rx radians around the x axle
2. rotate ry radians around the y axle
3. rotate rz radians around the z axle
Quote:
Original post by Samurai Jack
D3DXMatrixRotationYawPitchRoll(&matrix, ry, rx, rz);

Now the difference here is that D3DXMatrixRotationYawPitchRoll does the rotations in a different order:

1. rotate ry radians around the y axle
2. rotate rx radians around the x axle
3. rotate rz radians around the z axle

and that will not give the same result.

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