Sign in to follow this  
Magmatwister

How do you rotate individual primitives?

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


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