Sign in to follow this  
bjogio

rotation matrix

Recommended Posts

bjogio    242
(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 this post


Link to post
Share on other sites
JohnBolton    1372
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 this post


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

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