LPD3DXMESH dimensions

Started by
2 comments, last by TythosEternal 21 years, 1 month ago
How can I get the dimensions of a LPD3DXMESH? If nothing else, can I change the position of the mesh without actually manipulating the vertex buffer (a big can of worms, in my opinion)? Thanks for the help, ahead of time.
"Who's John Galt?"
Advertisement
Helo

If you want to change the position of the mash, you just
set up matrix, and render mash.

Simething like that:

D3DXMatrixTranslation(&temp,x,y,z);
a
D3DXMatrixMultiply(&matWorld,&temp,&matWorld);

g_pd3dDevice->SetTransform(D3DTS_WORLD,&matWorld);

//Render
Right, you can use matrices and transforms to move, resize and rotate a mesh within your ''world''. It is very easy to use. Understanding it is another matter. :o)

Here is a snippet from my render code:

D3DXMATRIX matTranslation, matScale, matRotation;
int mat;
D3DXVECTOR3 vecLocation;

if(m_pCheckerPieces != NULL)
{
for(WORD wdPiece = 0; wdPiece < (m_wdNumPieces/2); wdPiece++)
{
vecLocation = *m_pCheckerPieces[wdPiece].GetVecLocation();

// Set default translation
D3DXMatrixIdentity(&matTranslation);

// Move to X,Y,Z coordinates
// matTranslation is the location matrix for moving the object around
matTranslation._41 = vecLocation.x;
matTranslation._42 = vecLocation.z;
matTranslation._43 = vecLocation.y;

//matScale is the scaling matrix for shrinking this big mesh
D3DXMatrixScaling( &matScale, 0.03f, 0.03f, 0.03f );

// Rotate on Y
/* matRotation is the rotation mesh for rotating this mesh around. I am rotating 180 degrees and it takes radians so I divide 180 by the number of degrees in a radian (around 57.29 degrees if I recall correctly) */
D3DXMatrixRotationY(&matRotation, 180/RADIAN_TO_DEGREES);

// The order in which these matrices are multiplied is VERY important or the mesh could end up somewhere you don''t want it.
matScale *= matRotation;
matScale *= matTranslation;

// Set the matrix
m_pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);

// Display each material
for(mat = 0 ; mat < (signed)m_dwNumMaterials ; mat++)
{
m_pd3dDevice->SetMaterial(&m_ppMeshMaterials[mat]);

// Activate the appropriate texture
m_pd3dDevice->SetTexture(0, m_ppMeshTextures[mat]);

// Draw the mesh subset
m_pCheckerPieceMesh->DrawSubset(mat);
}
}
}
Hi,

I''m not sure what you mean by dimensions but if you''re talking about the size of the object in R3 space then I presume you want a bounding box or sphere.

The matrix maths isn''t hard but if you don''t understand it you will not be able to produce a good renderer or game. Check out any 3D graphics book or web site and you should have no trouble.

This topic is closed to new replies.

Advertisement