Sign in to follow this  
Dospro

Rotate an object from its center

Recommended Posts

Dospro    257
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
jyk    2094
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
matches81    474
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
jyk    2094
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this