#### Archived

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

# Matrix question in D3D

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

## 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
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
it looks to me like your adding (2,3,0) and then rotating. and then adding (2,3,0) again.

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
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 -

##### Share on other sites
You have to translate the object not the world matrix, thus store your objects positions in world space, translate it to 0,0,0 then rotate it then translate back to original position.

Reg''ds,
Steve

1. 1
2. 2
Rutin
24
3. 3
JoeJ
19
4. 4
5. 5
gaxio
13

• 17
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631729
• Total Posts
3001918
×