Problems with axis rotations!
Posted on 2003-03-19
I have a problem with my rotations in my project (using Visual Studio 6 & Directx 8). I have loaded a .x model and with my code I can rotate my object around x,y and z axis (I rotate the object 90 degrees / rotation).
Now to my problem.. If I rotate the object 90 degrees around the "world" y-axis, the objects x-axis turns with the rotation and now points to the same direction as the worlds z-axis. If I then press my "Rotate X-key" to rotate the object around world x-axis, the oject rotates around world z-axis because the objects x-axis had been "moved" to worlds z-axis..
The rotations works fine if I just rotate around a single axis, but if I try to combine the rotations I do not get the result that I need to get.
If I press my button for rotation around x-axis, I just add 90 to my variable m_fXAngle
I also check if m_fXAngle = 360 , set m_fXAngle = 0...
Same thing with m_fYAngle and m_fZAngle!
In my code I use:
D3DXMatrixMultiply(&matFig1, &matRotateZ, &matRotateX);
D3DXMatrixMultiply(&matFig1, &matFig1, &matRotateY);
(I have also tested to change the MatrixMultiply order, but no order gives the correct result)
I have also tested:
D3DXMatrixRotationYawPitchRoll(&matFig1, m_pMesh1->m_fYAngle*D3DX_PI/180, m_pMesh1->m_fXAngle*D3DX_PI/180, m_pMesh1->m_fZAngle*D3DX_PI/180);
but it didn't help, still got the same problem.
What should I do to get the correct rotations ??
If I press my button for rotation around x-axis, I want the object to rotate around WORLD x-axis. (and it does the first time). Then after that I e.g. want to rotate the object around world z-axis. But if i try to do that, the object rotates around world y-axis. (because the objects z-axis points to the same direction as world y-axis on account of the first x-axis rotation).
Is there a way to force the object to rotate around the WORLD x,y,z axis (not the objects x,y,z axis)?
Or is there another way to fix my problem?