Moving a single mesh

Started by
1 comment, last by Isotest 23 years, 1 month ago
I''m having trouble finding good information on translating or rotating a single mesh. I''ve seen this question answered with using: D3DXMatrixTranslation(&world_matrix,x_value,y_value,z_value); d3d_device->SetTransform(D3DTS_WORLD,&world_matrix ); But I would think this would translate the entire world system. If it only effects one mesh, how do you tell it which one mesh to translate. Say for instance, that I have loaded 9 meshes from files, called g_pMesh1 through g_pMesh9. What if I wanted to move just g_pMesh3 along the x axis 3 units and g_pMesh6 along the z axis 4 units. Could someone demonstrate a few lines of code that would translate just those two meshes? I would really appreciate some insight into this.
Advertisement
let matTrans and matRot be the resultant matrixs of Translation and rotation then this would translate and rotate correctly for you .. hope this helps

lpDev->SetTransform(D3DTS_WORLD,D3DXMatrixMultiply(&matRes,&matRot,&matTrans));



Edited by - nat on March 20, 2001 3:21:16 AM
~~~º¥º -
G''day!

This is a very common question. The World Matrix is badly named. It''s best thought of as the Model Space to World Space Matrix, but of course that''s too long. For moving independant objects you set the World Matrix before you draw each of them, in pseudo-code (because I''m too sleepy to do it properly) :

Build Matrix to move object 1 to the left
SetWorldMatrix
Draw Object 1
Build Matrix to rotate object 2 and move it up
SetWorldMatrix
DrawObject 2

etc.

Does that make more sense?


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
Ah, now I understand. I figured there would be something like a explicit reference to the mesh to transform, but instead it''s like setting a texture for an object - just set the world transform right before any mesh that is to be transformed is rendered. Thanks for the clarification.

This topic is closed to new replies.

Advertisement