Archived

This topic is now archived and is closed to further replies.

EdwardD

DX9 whats the easiest way of doing rotations ?

Recommended Posts

Hi, I wrote an app to load 3D Studio MAX ASE files, however I am having great difficulty understanding how exactly rotation animation is done in DX9, everything else is working just fine (i.e. Scale and Position) I just cant get it to rotate correctly. Whats the easiest way to rotate an object by say 45 Degrees ? Thanks.

Share this post


Link to post
Share on other sites
In my old version of KE, I did this...


BOOL
keCVertex::Rotate(KE_ROTATION *pRot)
{
D3DXMATRIX *matXRot = new D3DXMATRIX;
D3DXMATRIX *matYRot = new D3DXMATRIX;
D3DXMATRIX *matZRot = new D3DXMATRIX;
D3DXMATRIX *matRot = new D3DXMATRIX;

D3DXVECTOR3 vVert;
D3DXVECTOR4 vOut;

(FLOAT)vVert.x = (FLOAT)position.position.x;
(FLOAT)vVert.y = (FLOAT)position.position.y;
(FLOAT)vVert.z = (FLOAT)position.position.z;

// ** Create rotation matrices

D3DXMatrixRotationX(matXRot, (FLOAT)pRot->x);
D3DXMatrixRotationY(matYRot, (FLOAT)pRot->y);
D3DXMatrixRotationZ(matZRot, (FLOAT)pRot->z);

// ** Get the overall rotation matrix

D3DXMatrixMultiply(matRot, matXRot, matYRot);
D3DXMatrixMultiply(matRot, matRot, matZRot);

// ** Rotate each vertex in turn

D3DXVec3Transform(&vOut, &vVert, matRot);

(FLOAT)position.position.x = (FLOAT)vOut.x;
(FLOAT)position.position.y = (FLOAT)vOut.y;
(FLOAT)position.position.z = (FLOAT)vOut.z;

delete matXRot;
delete matYRot;
delete matZRot;
delete matRot;

return TRUE;
}


This funcrion rotated an individual vertex... sure you could use the idea for the thing you need to do

Share this post


Link to post
Share on other sites
I''ve had the exact same problem and I ended up writing something similar to the above code too. The problem I''ve found is that the above works perfect but only if the object is still centered at the origin. As soon as the mesh starts moving around the rotation seems to rotate it around THE origin instead of the object''s origin.

Share this post


Link to post
Share on other sites
What about saving your objects vertices as if the object was still in the center, then aplying rotation matrixes, then adding a vector to all vertices to get to the object to the real positon ? Just a thought though , I think you''ll need a matrix for rotation around any given vector though since if you rotate in x and y for example for the second rotation the y axis of the object isn''t the y axis of the world anymore.

Share this post


Link to post
Share on other sites
ms291052, sounds like you''re multiplying your matrices the wrong way round. Applying a rotation before the translation will rotate the object around it''s own axes at it''s current location.

D3DXMatrixMultiply(&world_mtx, &rotation_mtx, &translation_mtx);
m_pd3dDevice->SetTransform(D3DTS_WORLD, &world_mtx);


Share this post


Link to post
Share on other sites