How do I render 2 meshes?
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
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
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.
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.
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.
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?
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?
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement