How do I render 2 meshes?

Started by
7 comments, last by ManaStone 22 years, 3 months ago
From the D3D tutorial on the documentation it would seem that I would need 2 devices in order to render 2 different meshes. I think I am wrong, but how else would I do transformation on a single object without it affecting the other? In the code it shows on the tutorial it says that I would do a transformation by calling the D3d device like so: g_pd3dDevice->setTransform( D3DTS_WORLD, &matWorld); because the matrix is named matworld it would seem logical that the code would perform a transformation on the entire world. Would somebody please explain this to me? Also would somebody tell me how I would create a bounding box around a mesh so I can do collisions? Edited by - ManaStone on December 31, 2001 1:03:33 PM
-----------------------------Download my real time 3D RPG.
Advertisement
  D3DUtil_SetRotateXMatrix(matRotateX,anglex);D3DUtil_SetRotateYMatrix(matRotateY,angley);D3DUtil_SetRotateZMatrix(matRotateZ,anglez);D3DUtil_SetTranslateMatrix(world, 0.0, 0.0 , 0.0);D3DMath_MatrixMultiply(world,matRotateY,world);D3DMath_MatrixMultiply(world,matRotateZ,world);D3DMath_MatrixMultiply(world,matRotateX,world);D3DUtil_SetTranslateMatrix(matTrans, xpos, ypos , zpos);D3DMath_MatrixMultiply(world,matTrans,world);g_pd3dDevice->SetTransform(D3DTRANSFORMSTATE_WORLD,&world);Mesh->Render(g_pd3dDevice);  


Where anglex,angley,anglez are the angles you want your mesh rotated. x,y, and zpos are is the position you want it. Mesh is the mesh you''re rendering. You don''t need more than one device.

Ben

I got an error saying that "Render is not a member of ID3DXMESH"
-----------------------------Download my real time 3D RPG.
First, the world matrix isn''t really moving the world. It moves the rendering position. Let''s say you have a cube a 0, 0, 0. You move the world matrix to 1, 1, 1 and the cube will be rendered at 1, 1, 1.

Now if you set the world matrix to the identity matrix(anything times it will equal itself), you won''t move the object. This will solve the problem for rendering other objects.

Create three matrixes. The first will be the world matrix for the first mesh. The second will be the world matrix for the second mesh. The third will be the identity matrix. Fill in the first two and use the D3DXMatrixIdentity function to make an identity matrix for the third. Before you render the first mesh, set the world matrix to the first matrix. Then render. Set the world matrix for the second matrix. Render the second mesh. Then set the world matrix to the third matrix(the identity one). You can now render other objects at their real location.

just set multiple matrixes.
How do I set the first two matrixes to the meshes?
-----------------------------Download my real time 3D RPG.
D3DXMatrix meshmatrix1;
D3DXMatrix meshmatrix2;

//set the matrix''s up, like multiply and transform then

device->SetTransform(D3DTS_WORLD, meshmatrix1;
//render the first mesh here

device->SetTransform(D3DTS_WORLD, meshmatrix2;
//render the second mesh here

something like that.
But how do you assign a mesh to a matrix?
Do you typecast it like this:
D3DXMatrix meshmatrix1= Mesh1(*D3DXMatrix);
D3DXMatrix meshmatrix2= Mesh2 (*D3DXMatrix);

Or does it automaticly assign it in the order you load the meshes?


-----------------------------Download my real time 3D RPG.
After you set the matrix where you want to position it and everything else, you don''t need to assign anything. Anything drawn after you set the world matrix will be at that position. That is why you must set multiple matrixes, maybe one per object even. If you set an identity matrix, the object won''t move from its original position, usually 0, 0, 0.
OK, thank you very much. When you said render I didn''t think you literally meant render it. I thought you were talking about using

device->SetTransform(D3DTS_WORLD,&worldmesh1);

Thanks again. I don''t know what I''d do without this board.

-----------------------------Download my real time 3D RPG.

This topic is closed to new replies.

Advertisement