When using only one translation matrix, multiple meshes appear overlapping onscreen.
The solution I tried was to create multiple translation matrices to set different initial xyz coordinates for each mesh. It works, but this method seems pretty inefficient in terms of the number of lines of code used. (The final project will probably incorporate 20+ meshes so I was hoping I would not need to create 20 different translation matrices using basically the same section of code).
I'd greatly appreciate any suggestions as to the best way of rendering multiple meshes with the most efficient use of code (i.e fewest instructions with least amount of repetition).
This is only a small graphical demo so getting a high framerate is not the priority, but achieving the result with the most efficient use of code is.
Below Code is a sample of how i'm currently rendering multiple meshes in different positions...
// initial locations for each mesh
D3DXVECTOR3 Translate1(-30.0f, 0.0f, 0.0f);
D3DXVECTOR3 Translate2(-30.0f, 10.0f, 0.0f);
D3DXVECTOR3 Translate3(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 Translate4(0.0f, 10.0f, 0.0f);
//set scaling on all x y and z axis
D3DXVECTOR3 Scaling(g_ScaleX, g_ScaleY, g_ScaleZ);
/////////////////////////////////////////////////////////////////////////
// create first transformation matrix
D3DXMATRIX world1;
// create first translation matrix
D3DXMATRIX matrixTranslate;
D3DXMatrixTransformation(&world1, &ScalingCentre, &ScalingRotation, &Scaling, &RotationCentre, &Rotation, &Translate1);
//D3DXMatrixIdentity(&world1); // set world1 as current transformation matrix
// set world1 as current transformation matrix for future meshes
g_pd3dDevice -> SetTransform(D3DTS_WORLD, &world1);
// recompute normals
g_pd3dDevice -> SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);
// render first mesh
mesh1.Render(g_pd3dDevice);
/////////////////////////////////////////////////////////////////////////
D3DXMATRIX world2;
D3DXMATRIX matrixTranslate2;
D3DXMatrixTransformation(&world2, &ScalingCentre, &ScalingRotation, &Scaling, &RotationCentre, &Rotation, &Translate2);
// set world2 as current transformation matrix for future meshes
g_pd3dDevice -> SetTransform(D3DTS_WORLD, &world2);
// render second mesh
mesh2.Render(g_pd3dDevice);
////////////////////////////////////////////////////////////////////////
D3DXMATRIX world3;
D3DXMATRIX matrixTranslate3;
D3DXMatrixTransformation(&world3, &ScalingCentre, &ScalingRotation, &Scaling, &RotationCentre, &Rotation, &Translate3);
// set world2 as current transformation matrix for future meshes
g_pd3dDevice -> SetTransform(D3DTS_WORLD, &world3);
//render thirdmesh
mesh3.Render(g_pd3dDevice);
//////////////////////////////////////////////////////////////////////