• Create Account

## How to get the same euler angles in Direct3D as in max

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1lucky6969b  Members

1184
Like
0Likes
Like

Posted 25 February 2013 - 04:53 AM

Let's say the Direct3D Matrix is D3DXMATRIX

and max Matrix is Matrix3

I tried to decompose Matrix3 into head, pitch, bank first, then combine them again using yaw, pitch, roll,

void SimExporter::ConvertMatrix3ToEuler()
{
double sp = elements[1][2];
if (sp <= -1.0f) {
p = -1.570796f;
} else if (sp >= 1.0f) {
p = 1.5707096f;
} else {
p = asin(sp);
}

if (sp > 0.9999f) {
b = 0.0f;
h = atan2(elements[2][0], elements[0][0]); // m31 and m11
}
else
{
h = atan2(elements[0][2], elements[2][2]); // m13 and m33
b = atan2(elements[1][0], elements[1][1]); // m21 and m22
}

}


Then swap b,h

D3DXMatrixRotationYawPitchRoll(&yawpitchroll, b, p, h);

And convert the D3DXMATRIX back to euler to check

What I expected was something like

Original Euler

x: 30, y: 0, z:180

would become

x:30, y:180, z:0

But in fact, it isn't.

What is the general approach to convert a Matrix3 Matrix into a D3DXMATRIX affine matrix?

Thanks

Jack

Edited by lucky6969b, 25 February 2013 - 05:02 AM.

### #2Alundra  Members

2010
Like
0Likes
Like

Posted 25 February 2013 - 09:10 AM

3DSMAX uses Z as up-axis. When you export your scene you get the same coordinate system.

You need to convert that to have the correct coordinate system who is Y as up-axis.

You need to use this conversion matrix :

[ 1 0 0 ]
[ 0 0 1 ]
[ 0 1 0 ]


Edited by Alundra, 25 February 2013 - 09:18 AM.

### #3BornToCode  Members

1178
Like
0Likes
Like

Posted 25 February 2013 - 12:59 PM

To convert your matrix to max matrix, you can just apply an rotation of 90 degress around your X. which will point your Y Axis Upward and your Z in and out. Max by default has Z up and Y in and out.

Edited by BornToCode, 25 February 2013 - 01:00 PM.

### #4lucky6969b  Members

1184
Like
0Likes
Like

Posted 25 February 2013 - 09:26 PM

I couldn't get the y-axis up to work by just multiplying the 3ds max transformation to that one.

I got z-up.

Let me know

Thanks

Jack

### #5BornToCode  Members

1178
Like
0Likes
Like

Posted 25 February 2013 - 09:32 PM

I notice i had a type in my previous post. This is what you want to do .You want to multiply the 3D max transformation with a rotation of 90 degrees around the X to put it in the same space as DX where Y will be Up and Z will be in and out. Currently right now when you render your mesh using the max coordinate as is. You end up seeing your mesh been updside down correct. If that is the case then you need to do the transformation i said which is multiply it with a 90 degree value around the X

Edited by BornToCode, 25 February 2013 - 09:34 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.