# Creating a Bounding Box

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

## Recommended Posts

I've been looking into better collision detection methods than what I'm currently using and want to create a box around a mesh to use to check for collision. But I'm not sure how it's done. I'm guessing that I get the vertices of the mesh I want to make the box for and get the 4 highest, lowest, right most, left most, closest, and farthest points and use those to make a cube. The question is, how do I get these points? I've been looking around and came up with this.
int num_verts = _mesh.NumberVertices;
GraphicsStream verts = _mesh.LockVertexBuffer(LockFlags.None);
Vector3[] vecs = new Vector3[num_verts];
for (int i = 0; i < num_verts; i++)
{
}
_mesh.UnlockVertexBuffer();

I'm just wondering if this is a correct way to retrieve all the vertices of a mesh.

##### Share on other sites

However, why not just use the graphicsstream itself, rather than copying the entire buffer?

Or just read one vector at a time, use it and read the next.

You might also look at ComputeBoundingBox.

##### Share on other sites
Is this the ComputBoundingBox function you mean http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.directx.direct3d.geometry.computeboundingbox.aspx ?

It doesn't look like it returns enough information to me. If you only get the lower left and upper right corners of the box, that would be enough for 2D but not 3D. Unless it returns the diagonal corners. Is that what is put in the last 2 vectors?

##### Share on other sites
Quote:
 Original post by homer_3Is this the ComputBoundingBox function you mean http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.directx.direct3d.geometry.computeboundingbox.aspx ?It doesn't look like it returns enough information to me. If you only get the lower left and upper right corners of the box, that would be enough for 2D but not 3D. Unless it returns the diagonal corners. Is that what is put in the last 2 vectors?

Those are 3D points it returns, not 2D. One is just the max X, Y, and Z, the other is min X, Y, and Z. This is the same information you wanted to calculate.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631775
• Total Posts
3002284
×