D3DXMatrixRotationXYZ problem!

Started by
3 comments, last by andrei_dragomir 18 years, 1 month ago
I have a mesh with the shape of a coordinate sistem.The object's arms are initially aligned with the worlds coordinates. the problem:rotation around x and y(x,y==world coordinates) works fine, but rotation around z seems to rotate my object around it's own z coordinate not the worlds(that is, although my object is now not aligned anymore with the world coordinates, it spins around one of it's arms). Here's the code: void SetupMatrices(void) { D3DXMATRIX m_TotalRotation,MatrixPosition; D3DXMATRIX m_MatRotationAboutRight,m_MatRotationAboutLookAt,m_MatRotationAboutUp; //all these matrices are set to identity, but here I put only the relevant code //store the initial position, after I rotate it I translate the object back to this position MatrixPosition._41=m_TotalTransform._41; MatrixPosition._42=m_TotalTransform._42; MatrixPosition._43=m_TotalTransform._43; //perform rotations D3DXMatrixRotationX(&m_MatRotationAboutRight,m_fRotateAboutRight); D3DXMatrixRotationY(&m_MatRotationAboutLookAt,m_fRotateAboutLookAt); D3DXMatrixRotationZ(&m_MatRotationAboutUp,m_fRotateAboutUp); m_TotalRotation=m_MatRotationAboutUp*m_MatRotationAboutLookAt*m_MatRotationAboutRight; //concatenate the rotation and the translation matrix into the D3DTS_WORLD matrix D3DXMatrixMultiply(&m_TotalTransform,&m_TotalRotation,&MatrixPosition); //...call SetTransform...bla bla } I have the same problem if I use D3DXMatrixRotationAxis with three vectors that have the values: Up=(0.0.1) Right=(1.0.0) LookAt=(0.1.0) What kind of problem is this?Can someone tell me a good and clear tutorial on transformation matrices and DirectX (with the relations between local and world coordinates)?I am totally confused about these functions.Sometimes I have to pass the nr of degrees I want to rotate, then if i change something somewhere else in the code, the same function needs the nr of degrees += the nr of degrees the object was previously rotated in world space.Sometimes, a function seems to act in local object space, and sometimes in world space.It was the case with D3DXMatrixRotationYawPitchRoll(don't ask why). Finally, I know this might be a stupid question, but is it possible that problems like this arise because of the compiler I use(Visual C++ 6)?
Advertisement
When you want to rotate an object on all axis I would suggest using D3DXMatrixRotationYawPitchRoll
Quote:
Finally, I know this might be a stupid question, but is it possible that problems like this arise because of the compiler I use(Visual C++ 6)?

No


Use a different matrix for Z axis rotation and multiply it with the object matrix you already have.
That should solve it.

My project`s facebook page is “DreamLand Page”

Try reversing the order of your rotations. That might work the way you expect. Keep in mind that it is likely that everything is working correctly, but you are misunderstanding how rotation works (as many people do). You can only do one rotation around a global axis (the last one). All previous rotations are around local axes.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Quote:
You can only do one rotation around a global axis (the last one). All previous rotations are around local axes.


Not sure what this means. Fix a coordinate system. Then rotate points as many times as you like about any of the coordinate system's axes.
ok, I tried reversing the order of rotations, and I had the same problem with
the same axis (I think it was Up), which is weird(I tried every possible order).
I changed the order I multiply the rotation matrices into totalrotation, although I do not understand why the order of rotations changes anything.i understand this in the case with rotation and translation.

I didn't really understood how to make a different matrix for Z rotation
You say I do the X,Y rotations, multiply them with the TotalTransform matrix,
do the Z rotation and multiply it also with the TotalTransform matrix?

About the D3DXMatrixRotationYawPitchRoll: I tried it and it rotated my object around it's local coordinates.This is ok(although i don't know if this is what this function is supposed to do),but what I want is this:
Define the objects Direction vectors(Up,Right and LookAt),use D3DXMatrixRotationAxis three times to rotate the object around these vectors,
and then use these vectors, for example the LookAt vector, to move the object in
direction .Of course, after rotating, I used D3DXVec3TransformCoord with the totalrotation matrix to transform the vectors.Basicaly I took the code from the camera class and tried to make it work with objects.It didn't.

Can you please tell me more about not doing all three rotations in the same space?in my case it seems I can only do two rotations in world space and the third is done in local object space.

This topic is closed to new replies.

Advertisement