Sign in to follow this  

Bug of Direct3D!

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
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

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