Jump to content
  • Advertisement
Sign in to follow this  
PetrCBR

Transforming part of the mesh

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

If you intended to correct an error in the post then please contact us.

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
  float AngleX = D3DXToRadian (RotX);
  float AngleY = D3DXToRadian (RotY);
  float AngleZ = D3DXToRadian (RotZ);

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


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


Link to post
Share on other sites
Quote:
Original post by DesignerX
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.


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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!