Jump to content
  • Advertisement
Sign in to follow this  
renqilin

Bug of Direct3D!

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

recently I was coding a skin mesh system, I found that D3D is not consistent with conversion between quaternions and matrices. I don't know if it's a bug of d3d, here is some code to recur the "Bug":

    D3DXVECTOR3 tmpTrans;
    D3DXVECTOR3 tmpScale;

    // quaternion2 will be differ from quaternion1 after series of conversion.
    D3DXQUATERNION quaternion1, quaternion2;
    D3DXMATRIX matTemp;

    // at first we generate quaternion1
    D3DXMatrixRotationY(&matTemp, 4.33f);
    D3DXMatrixDecompose(&tmpScale, &quaternion1, &tmpTrans, &matTemp);

    // with quaternion1 we just got, let's generate a matrix which represents
    // the rotation of quaternion1 exactly.
    D3DXMatrixRotationQuaternion(&matTemp, &quaternion1);
    // *!*@#^*!#@(!@&#(!*&@(#&!(#&!(^$*!^@*!^@*
    //      the "Bug" is right here now.
    D3DXMatrixDecompose(&tmpScale, &quaternion2, &tmpTrans, &matTemp);

    // result:
    // quaternion1 = (0.0f, -0.8285f, 0.0f, -0.559f)
    // quaternion2 = (0.0f,  0.8285f, 0.0f, -0.559f)

it's a bit odd. as my expectation, quaternion2 should be equavilent to quaternion1. But now, i'm confused about the result. [Edited by - renqilin on June 11, 2005 10:55:51 PM]

Share this post


Link to post
Share on other sites
Advertisement
For every quaternion described orientation there exists two equivalent representations which are "opposites" of each other.

Share this post


Link to post
Share on other sites
Thanks,Daerax. i know what you mean. quaternion2 is "opposites" of quaternion1. that means :

(axis, angle) are equavilent to (-axis, 2 * PI - angle)

however, the problem is: with each (D3DXMatrixRotationQuaternion,D3DXMatrixDecompose) pair, D3D always "opposites" your input quaternion.

Share this post


Link to post
Share on other sites
It looks to me like a problem with D3DXMatrixDecompose. I did a quick test using a rotation ofπ/4.

The matrix for a π/4 rotation around Y:
    0.707106 0 -0.707107 0
0 1 0 0
0.707107 0 0.707106 0
0 0 0 1
The results of D3DXMatrixDecompose on that matrix: (0, 0.382684, 0, -0.923879), which represents a rotation of -π/4, not π/4.

The correct results should be (0, 0.382684, 0, 0.923879) or (0, -0.382684, 0, -0.923879).

Share this post


Link to post
Share on other sites
I noticed that the values were not really precise negates of each other but thought it unlikely that such a "feature" would have gone unnoticed for so long. Perhaps you really did find a bug there, renqilin. Thats pretty impressive. One of the DirectX MVPs should look into this.

Also, I was going to suggest your clamping your range but it looks like based on the angle used by JohnBolton, that is not where the issue lies. This may very well be a legitimate bug.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!