# Bounding boxes not 'Bounding'

## Recommended Posts

Hi guys, I am trying to have some collision detection between a couple of objects in my program which is in C# with directx9 June'05 sdk. I am using the Directx provided Geometry.ComputeBoundingBox() function for my object (a mesh). I can generate the box in itself w.o problems but, I get the box with a different Z-axis value, and the Z is lesser than it should be. I tried doing it with another object with same result. Am I Doing something wrong or not passing the correct parameters? Heres the bounding box generation n rendering:
using (VertexBuffer vb  = mesh.VertexBuffer)
{
GraphicsStream vxData = vb.Lock(0,0,LockFlags.None);
//vxData,mesh.NumberVertices,mesh.VertexFormat,out current.bSphereCentre);
Geometry.ComputeBoundingBox(vxData,mesh.NumberVertices,mesh.VertexFormat,
out current.bBoxLowerLeft, out current.bBoxUpperRight);
vb.Unlock();
}
Mesh bBox = Mesh.Box(TheDevice,Math.Abs(current.bBoxUpperRight.X-                     current.bBoxLowerLeft.X),
Math.Abs(current.bBoxUpperRight.Y-current.bBoxLowerLeft.Y),
Math.Abs(current.bBoxUpperRight.Z-current.bBoxLowerLeft.Z));
bBox.DrawSubset(0);


I could well be drawing the box wrong... :P Thanks for reading! Tan

##### Share on other sites
You need to set world transform to the position of the bounding box ((lowerleft + upperright) / 2) before you draw it. This is because the center of the mesh does not have to correspond to the center of the bounding box.

##### Share on other sites
And how do I use them for the collision detection if they dont correspond rightly? n wat about Bounding spheres? will they have similar problem?

After reading ur post I changed my collision detection parameter ( i was using bounding spheres this time) such that :

{// distance betn 2 vectors f_distBetnCentres = sqrt(bSphere1.centre - bSphere2.centre); f_distBetnCentres += bSphere1.f_radius/2 + bSphere2.f_radius/2;// Sum of radii f_sumRadi = bSphere1.f_radius + bSphere2.f_radius; if(f_sumRadi > f_distBetnCentres) Collision= true;}

Drawing the bounds is not important, but getting right collision detection is..

Thanks

Tanmay

Forgot to mention : I dont get the right collision detection. It detects collision far too early b4 the meshes reach each other.

##### Share on other sites
Quote:
 Original post by tanmay_therockAnd how do I use them for the collision detection if they dont correspond rightly? n wat about Bounding spheres? will they have similar problem? After reading ur post I changed my collision detection parameter ( i was using bounding spheres this time) such that :*** Source Snippet Removed *** Drawing the bounds is not important, but getting right collision detection is..ThanksTanmayForgot to mention : I dont get the right collision detection. It detects collision far too early b4 the meshes reach each other.

There is nothing wrong with the bounding box, you just draw it at an incorrect position.

Also when you do collision detection between the bounding spheres/boxes you test if the bounds collide, you still have to do collision detection between the polygons of the actual meshes (if the bounds collide of course).

##### Share on other sites
Hey OpWiz,
Thanx... I got the collision detections right. I have different world transform for each entity in the system, and I wasnt multiplying the centres (or the co-ords in case of the box) with this transform matrix before checking for the collision detection.

So now.. Collision detection goes like :
 bSphere1.v3_centre.TransformCoordinate(node1.WorldTransform); bSphere2.v3_centre.TransformCoordinate(node2.WorldTransform); <Collision detection code>

Tan

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628350
• Total Posts
2982211

• 10
• 9
• 24
• 11
• 9