# How to use the D3DXComputeBoundingBox function??

This topic is 4850 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
How would i get the first parameter? (first Position).

Thanks.

##### 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 on other sites
How would i get the vertex array from an existing d3dx mesh object? ( for parameter 1).

Thanks

##### Share on other sites
I'm not recommending that you do it this way, and I'll explain why afterwards:

VertexType *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 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.

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633313
• Total Posts
3011317
• ### Who's Online (See full list)

There are no registered users currently online

×