Jump to content
  • Advertisement
Sign in to follow this  
Dospro

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.

If you intended to correct an error in the post then please contact us.

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


Link to post
Share on other sites
Advertisement
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);
RenderQuad();

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!