• ### Announcements

#### Archived

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

# Matrix question in D3D

## Recommended Posts

Hi! I want to rotate a cube around its center coordinate but at different lokation than origo. However, instead of rotating around it''s center coordinate (2,3,0 for example) my cube rotates around a different coordinate (4.6,0).. What is wrong with my code?
  D3DXMatrixTranslation(&WorldMatrix,2.0f, 3.0f, 0.0f); D3DXMatrixRotationZ(&RotMat, Radians); D3DXMatrixMultiply(&RotMat, &RotMat, &WorldMatrix); D3DXMatrixTranslation(&WorldMatrix,2.0f, 3.0f, 0.0f); D3DXMatrixMultiply(&WorldMatrix, &WorldMatrix, &RotMat); c3DDevice->SetTransform(D3DTS_WORLD, &WorldMatrix); DrawCube(); 

##### Share on other sites
a person    118
try reverse your transformations. in other words, you must translate the cubes center to 0,0,0 thne rotate, then translate cube back to original position. the translations should cancel out (they are not in your case)

##### Share on other sites
Guest Anonymous Poster

what you want to do is add (2,3,0) and then rotoate -- and then *subtract* (2,3,0). Or, more likely, subtract (2,3,0), rotate, and then add (2,3,0).

-Wyriel

##### Share on other sites
steg    390
As ''a person'' as said, you must translate the cubes centre to the origin (0,0,0) if using an identity world matrix then apply rotation and then translate back to the original position - you can use an inverse translation matrix.

Reg''ds,
Steve

##### Share on other sites
I thought that depending on the where i wanted the object to rotate around, i translated the world matrix to that possision in world space, but apperantly thats not the case. So if i want to rotate around a point -1.0f on the x row. i simply translate the world matrix (-1.0f, 0.0f, 0.0f), right??

//Mikael -