Creating a Bounding Box

Started by
2 comments, last by MJP 15 years, 11 months ago
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++)
{
 vecs = (Vector3)verts.Read(typeof(Vector3));
}
_mesh.UnlockVertexBuffer();
I'm just wondering if this is a correct way to retrieve all the vertices of a mesh.
Advertisement
Your method should work.

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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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?
Quote:Original post by homer_3
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?


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.

This topic is closed to new replies.

Advertisement