Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actuallucky6969b

Posted 25 February 2013 - 05:02 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
 


#3lucky6969b

Posted 25 February 2013 - 05:01 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 face, it isn't.

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

Thanks

Jack
 


#2lucky6969b

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

 

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 face, it isn't.

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

Thanks

Jack
 


#1lucky6969b

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]; // the 6th element called m23 of 4x4 matrix
    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

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 face, it isn't.

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

Thanks

Jack
 


PARTNERS