Sign in to follow this  
Anddos

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

Recommended Posts

i load 2 meshs extract its material then in render i have g_pDirect3DDevice->SetMaterial( &pMeshMaterials[i] ); g_pDirect3DDevice->SetTexture( 0, pMeshTextures[i] ); 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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this