Sign in to follow this  
FireSoul

How to use the D3DXComputeBoundingBox function??

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this