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

Started by
3 comments, last by BornToCode 11 years, 1 month ago

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

Advertisement

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 ]
 

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.

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

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

This topic is closed to new replies.

Advertisement