i cant seem to be able to make transformations with each mesh with directx

Started by
4 comments, last by stanlo 17 years ago
i load 2 meshs extract its material then in render i have g_pDirect3DDevice->SetMaterial( &pMeshMaterials ); g_pDirect3DDevice->SetTexture( 0, pMeshTextures ); now i want to use matrices to move each mesh diferent ways when a key is pressed , but for some reason both meshs move the same direction when a key is pressed , so i am thinking do you have to g_pDirect3DDevice->BeginScene(); InitMatrices(); RenderMesh1(); g_pDirect3DDevice->EndScene(); g_pDirect3DDevice->BeginScene(); InitMatrices(); RenderMesh2(); g_pDirect3DDevice->EndScene(); g_pDirect3DDevice->Present(NULL,NULL,NULL,NULL); otherwise i cant think how i would make both meshs move diferently to 1 another thanks
:)
Advertisement
Transformations are handled like states in DirectX. You set a transformation matrix, you render vertices, you set a different transformation matrix you render some more vertices, etc.
It's impossible to tell what you are doing wrong without seeing the contents of InitMatrices or RenderMesh. You're current usage of Begin and End Scene is incorrect.

EDIT: typos
Best regards, Omid
It looks like you are using the same function to transform both meshes.

What you will need to do is update the world transformation for each mesh before its drawn.

eg.
void CDirectX::PositionObject(D3DXVECTOR3 pos){	D3DXMatrixTranslation(&m_World,pos.x,pos.y,pos.z);	m_pDevice->SetTransform(D3DTS_WORLD,&m_World);}gDirectX->PositionObject(D3DXVECTOR3(-2.0f,2.0f,5.0f));gTorus->DrawSubset(0);gDirectX->PositionObject(D3DXVECTOR3( 2.0f,2.0f,5.0f));gSphere->DrawSubset(0);


Similar changes to rotation and scaling can be done this way too before calling the WorldTransform command.

BeginScene/EndScene should be called no more than once per frame. You should be calling BeginScene, rendering both meshes, and then calling End Scene, and then Present.

As for moving objects, the matrices set when you call the Draw* call are what applies to those calls. If you want to draw 2 meshes in two different places, you do something like this:

1) BeginScene
2) SetMatrix (set a transformation for the first object, say translation to 10, 0, 0)
3) Mesh1->Draw
4) SetMatrix (set a transformation for the second object, say translation to -10, 0, 0)
5) Mesh2->Draw
6) EndScene
7) Present

If you also need to set materials for each mesh, just do it before drawing each one.

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
thanks for the reply's
so if i put the matrices matrix values just before
pMesh->DrawSubset( i );
this should devide the meshs so they have there own postion's on the world?
Another thing is after mesh is loaded the textures arnt to great
heres a screen shot
http://img77.imageshack.us/my.php?image=tigergq9.jpg
:)
It looks like you don't have depth testing enabled. Try setting the ZEnable render state to true. Don't forget to clear your depth buffer too.

This topic is closed to new replies.

Advertisement