Archived

This topic is now archived and is closed to further replies.

Isotest

Moving a single mesh

Recommended Posts

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.

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites