rotation matrix
(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.
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:
BTW, the above code probably doesn't compile, but it is pretty close.
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.
If all you need is to rotate around a particular point, D3DXMatrixTransformation2D() should work fine. It looks like:
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement