Sign in to follow this  
homer_3

Creating a Bounding Box

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++)
{
 vecs[i] = (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.

Share this post


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

Share this post


Link to post
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 this post


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

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