Public Group

# rotation matrix

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

## Recommended Posts

(DirectX 8.1) I have a set of panel that I render as 2d windows in my little app. Now I've saved in the vertex buffer the x,y,z values in screen coordinates in order to not provide a world transformation matrix. Now then I want to rotate one of my panel along the center of the panel itself (x,y,z). What D3DX* function I need to build up my world transformation? D3DMatrixRotationX/Y/Z/Axis are not good to me cause I want to rotate my panel not around the center of the screen (or from an axis that begin from the center of the screen. Thanks in advance.

##### Share on other sites
It might be better now to use local coordinates in the vertex buffer and use the world matrix to translate it to the proper location on the screen. If you do that then setting up the world matrix is simple:
    D3DXMatrix rotation, translation, world;    D3DXMatrixRotationZ( &rotation, angle );    D3DXMatrixTranslation( &translation, x, y, 0.0f );    world = rotation * translation;
If you want to keep screen coordinates in the vertex buffer, then there is just a small addition.
    D3DXMatrix inverseTranslation, rotation, translation, world;    D3DXMatrixTranslation( &inverseTranslation, -x, -y, 0.0f );    D3DXMatrixRotationZ( &rotation, angle );    D3DXMatrixTranslation( &translation, x, y, 0.0f );    world = inverseTranslation * rotation * translation;

BTW, the above code probably doesn't compile, but it is pretty close.

##### Share on other sites
If all you need is to rotate around a particular point, D3DXMatrixTransformation2D() should work fine. It looks like:
D3DXMATRIX *WINAPI D3DXMatrixTransformation2D(D3DXMATRIX *pOut,    CONST D3DXVECTOR2 *pScalingCenter,    FLOAT *pScalingRotation,    CONST D3DXVECTOR2 *pScaling,    CONST D3DXVECTOR2 *pRotationCenter,    FLOAT Rotation,    CONST D3DXVECTOR2 *pTranslation);

Notice the pRotationCenter parameter. Pass in a D3DXVECTOR2 of the point you want to rotate around and pass NULL to the parameters you don't need.

EDIT: I have not used DirectX 8 (I use DirectX 9), so I am assuming this function is in it.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634063
• Total Posts
3015310
×