# Transforming part of the mesh

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

## Recommended Posts

Hi. I'm solving problem about transformating parts of the mesh (trans. frame). I'm need to rotate part of the mesh (eg. car wheel). Locate frame with wheel isn't problem, but wheel is rotated around wrong origin. My code is :
  D3DXMATRIX MAIN;
// OriginalCombinedTransformationMatrix is original matrix for transformate (used fo backup)
MAIN = frame -> OriginalCombinedTransformationMatrix;

D3DXVECTOR3 MS;
D3DXQUATERNION MR;
D3DXVECTOR3 MT;
D3DXMatrixDecompose (&MS, &MR, &MT, &MAIN);

// in AngleX, Y and Z is new rotation

// create rotation matrixes
D3DXMATRIX RX, RY, RZ;
D3DXMatrixRotationX (&RX, AngleX);
D3DXMatrixRotationY (&RY, AngleY);
D3DXMatrixRotationZ (&RZ, AngleZ);

D3DXMATRIX TEMP;

// move to zero origin
D3DXMatrixMultiply (&MAIN, &MAIN, D3DXMatrixTranslation (&TEMP, -MT.x, -MT.y, -MT.z));
// apply new rotation
if (RotX) D3DXMatrixMultiply (&MAIN, &MAIN, &RX);
if (RotY) D3DXMatrixMultiply (&MAIN, &MAIN, &RY);
if (RotZ) D3DXMatrixMultiply (&MAIN, &MAIN, &RZ);
// move to main position
D3DXMatrixMultiply (&MAIN, &MAIN, D3DXMatrixTranslation (&TEMP, MT.x, MT.y, MT.z));

// apply new matrix into matrix which is used for render
frame -> CombinedTransformationMatrix = MAIN;


In this code is bug, but i'm not see it :-/. Can anybody help me with this ?

##### Share on other sites
When transforming an object to origin in order to rotate around itself you need to get the x,y,z center(!) position of the object in order to do the rotation around the origin. so D3DXMatrixDecompose (&MS, &MR, &MT, &MAIN);
might not be the proper solution. (unless it gives you the right x, y, z coordinates).

My advice to you is, get the the width depth and height of your wheel (your modeling program must have a tool for getting this) and calculate the center position vector of your object and store it as the center position and whenever moving the object update the center position vector properly. and when wanting to move object to origin use the center.x,y,z (with negative values as you did) to get the right effect for rotation.

##### Share on other sites
Quote:
 Original post by DesignerXWhen transforming an object to origin in order to rotate around itself you need to get the x,y,z center(!) position of the object in order to do the rotation around the origin. so D3DXMatrixDecompose (&MS, &MR, &MT, &MAIN);might not be the proper solution. (unless it gives you the right x, y, z coordinates).My advice to you is, get the the width depth and height of your wheel (your modeling program must have a tool for getting this) and calculate the center position vector of your object and store it as the center position and whenever moving the object update the center position vector properly. and when wanting to move object to origin use the center.x,y,z (with negative values as you did) to get the right effect for rotation.

CombinedTransformationMatrix is really combined matrix. I'm using D3DXMESH with hierarchy, and before render is need to create this matrix with :
CombinedMatrix = TransformationMatrix * ParentMatrix.
Then in CombinedMatrix is x, y and z to the center of the mesh (not only to center of mesh subset).

• ### What is your GameDev Story?

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

• 9
• 31
• 16
• 11
• 10
• ### Forum Statistics

• Total Topics
634118
• Total Posts
3015607
×