Archived

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

DX9 whats the easiest way of doing rotations ?

This topic is 5493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 on other sites
In my old version of KE, I did this...

BOOLkeCVertex::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 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 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 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);

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
11
5. 5

• 14
• 30
• 13
• 11
• 11
• Forum Statistics

• Total Topics
631776
• Total Posts
3002304
×