# How do you rotate individual primitives?

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

## Recommended Posts

I was wondering how you rotated primitives invidually. I have found a tutorial which shows how to do it, but It doesn't really explain the logic behind it very well. Can anyone help me? I know that it's done by changing the world matrix, but I don't know how and why you can affect it in such a way that It will rotate shapes about their own origins, and not (0,0,0).

##### Share on other sites
It's the order of the transformations that is important. Whenever you apply a rotation transformation it is around the world origin. To rotate something on its own y axis, for example, you place it at the origin, rotate it, then translate it out to where it should be.

For example:

D3DXMATRIXA16 WorldMatrix;
D3DXMATRIXA16 Rotation, Translation;

D3DXMatrixRotation(&Rotation, ... );
D3DXMatrixTranslation(&Translation, ... );

// The following order of multiplying the transforms will orbit the geometry around the origin at a distance:

D3DXMatrixIdentity(&WorldMatrix);
D3DXMatrixMultiply(&WorldMatrix, &WorldMatrix, &Translation);
D3DXMatrixMultiply(&WorldMatrix, &WorldMatrix, &Rotation);

// The following will rotate the geometry around its origin:
D3DXMatrixIdentity(&WorldMatrix);
D3DXMatrixMultiply(&WorldMatrix, &WorldMatrix, &Rotation);
D3DXMatrixMultiply(&WorldMatrix, &WorldMatrix, &Translation);

If you wanted to rotate an arbitrary triangle in a mesh about its origin you would have to work out where it's origin is (you could pick a vertex or average the vertex positions for example). You would then apply a translation matrix that 'moves' that triangles vertices to the origin, apply a rotation and then translate them back out again.

Hope that makes sense,

##### Share on other sites
Thanks alot, your explanation was perfect!

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

• 14
• 29
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631773
• Total Posts
3002265
×