# Rotate an object from its center

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

## Recommended Posts

Hi. Im new in this 3D world using Direc3D and i have a couple of doubts. First, i have a triangle strip of for vertices(a square) qhich i mapped with a texture. So in the main loop where i begin/end/present the scene i also put something liek this: i=i+0.001; if(i>360) i=0; D3DXMatrixRotationZ(&world, D3DXToDegree(i)); d3ddev->SetTransform(D3DTS_WORLD, &world); Which will make a smooth rotating effect. The problem is the it rotates around the center of the screen and i want it rotate at the ceter of the poligon, what do i have to do?. Also, i ave a weird doubt. In the same example i have 8 vertices which form 4 triangle strips (2 sqares) which one is behind the other, how can i do to mkae one rotates and the other stays without roting? Im using Direct3D and Direct3DX

##### Share on other sites
I don't know much D3D, but you want to create a translation matrix as well, and multiply it with your rotation matrix. Pseudocode:

Matrix rotation, translation, transform;
RotationMatrixZ(&rotation, angle);
TranslationMatrix(&translation, x, y, z);
MatrixMult(&rotation, &translation, &transform);
SetTransform(&transform);

##### Share on other sites
to rotate the polygon around it´s center you´ll have to first translate it, so that it´s center lays on the 'world' origin, because rotations are always performed around the world origin.
So you would have to build a translation matrix like that:

M = T1 * R * T2,
where T2 moves your polygon back to world origin, R rotates it, and T1 moves it back in it´s place. You then can use M as translation matrix and that should do the trick.

##### Share on other sites
Yup, my answer was for if your quad is defined in object space (usually centered at the origin). If your quad is in world space and is not centered at the origin, you'll need to use matches' solution. As a side note though, the way it's typically done is to build the model (in this case a simple quad) at the origin, and then position it via a rotation and a translation.

##### Share on other sites
I will try it, Thanks

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

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

• Total Topics
631729
• Total Posts
3001918
×