How to use the D3DXComputeBoundingBox function??

Started by
5 comments, last by Psyian 18 years, 9 months ago
Hi, im a bit puzzled about what each of the parameters for the D3DXComputeBoundingBox function, could someone explain to me what each parameter is for? ( in a bit more detail than below) HRESULT D3DXComputeBoundingBox( LPD3DXVECTOR3 pFirstPosition, DWORD NumVertices, DWORD dwStride, D3DXVECTOR3 *pMin, D3DXVECTOR3 *pMax ); Parameters pFirstPosition [in] Pointer to the first position. NumVertices [in] Number of vertices. dwStride [in] Count or number of bytes between vertices. pMin [out] Pointer to a D3DXVECTOR3 structure, describing the returned lower-left corner of the bounding box. pMax [out] Pointer to a D3DXVECTOR3 structure, describing the returned upper-right corner of the bounding box. Thanks
Advertisement
pFirstPosition - Its basically the array containing the vertices of the mesh.

NumVertices - should be obvious.

dwStride - This is the size of each vertex in bytes. Since the D3DXComputeBoundingBox function doesn't know what kind of data you have stored in your vertices (position, normal, tex coords, tangent, etc...), it needs you to provide the number of bytes in each vertex so that it can find the information it needs. You can get this value by doing "sizeof(YOUR_VERTEX_STRUCT)"

pMin - Address of a vector to store the minimum extent of the bounding box.

pMax - Address of a vector to store the maximum extent of the bounding box.

neneboricua
How would i get the first parameter? (first Position).

Thanks.
Maybe this...
struct ULTSTRUCT
{
float x, y, z;
float v, u;
};
ULTSTRUCT *verts = new ULTSTRUCT[10];
D3DXVECTOR3 min, max;
//fill in some data for verts
D3DXComputeBoundingBox(&verts,10,sizeof(ULTSTRUCT),&min,&max);
Insufficent Information: we need more infromationhttp://staff.samods.org/aiursrage2k/
How would i get the vertex array from an existing d3dx mesh object? ( for parameter 1).

Thanks
I'm not recommending that you do it this way, and I'll explain why afterwards:

VertexType *pData;

pMesh->LockVertexBuffer(D3DLOCK_READONLY, (VOID**)&pData);
D3DXComputeBoundingBox(pData,10,sizeof(ULTSTRUCT),&min,&max); // Using the previous example.
pMesh->UnlockVertexBuffer();

The reason you shouldn't do this is because it's horrendously slow. Keep a system memory copy of the vertices and perform the bounding box computation on them. On the other hand, if you only plan on doing the bounding box computation at startup, locking the vertex buffer is entirely okay. The only problem then is that you can't create the Mesh object with flags for write-only access to speed things up.

Chris
Chris ByersMicrosoft DirectX MVP - 2005


Have a look at the methods on the mesh object, do a search for vertex buffers.
Then look up locking methods on vertex buffers, to gain access to the vertices.

Should point u in the right direction.

This topic is closed to new replies.

Advertisement