XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

BoundingBox.Contains(BoundingSphere) problem

Last post 3/27/2007 11:17 PM by Ronzan. 4 replies.
  • 3/26/2007 9:16 AM

    BoundingBox.Contains(BoundingSphere) problem

    Hi,

    I have come across a problem with the Contains method of the BoundingBox; or maybe it's just me who got it wrong, I'm not sure.

    I am trying to use a BoundingBox as my "world" bounds in 2D.

    Example:

    BoundingBox bbBounds = new BoundingBox(....);     //the world bounds min and max
    BoundingSphere bsBall = new BoundingSphere(....); //the ball's bounding sphere with current position and radius

    bool bIntersects = bbBounds.Contains(bsBall) == ContainmentType.Intersects;
    bool bContains = bbBounds.Contains(bsBall) == ContainmentType.Contains;
    bool bDisjoint = bbBounds.Contains(bsBall) == ContainmentType.Disjoint;

    Even when the ball is inside the world bounds, bIntersects is always "true" and bContains is "false".

    Now if I try the same thing with a BoundingBox instead of a BoundingSphere, i.e. bbBounds.Contains(someBoundingBox), then I get the results I expect.

    Have anyone seen this problem before or is it me who is doing something wrong?

    I have tried to search the forums (including the old forums) etc. but I have been unable to find any information regarding this - If I have missed a thread somewhere, my appologies.

     Thanks,
    Ronzan

  • 3/27/2007 5:13 AM In reply to

    Re: BoundingBox.Contains(BoundingSphere) problem

    Answer
    Reply Quote

    I get the expected results. Perhaps you should check that the actual bounding volumes are the size and placement you expect.

    BoundingBox(Vector3(-5,-5,-5), Vector3(5,5,5)).Contains(BoundingSphere(Vector3(0,0,0),1)) == ContainmentType.Contains

    Cheers,
    Leaf.

  • 3/27/2007 6:55 AM In reply to

    Re: BoundingBox.Contains(BoundingSphere) problem

    Thanks for the reply, much appreciated.

    I found the "problem"; the z-axis!

    Apparently BoundingSphere works diferently than BoundBox, or am I missing something :)

    //not working - box vs sphere
    BoundingBox box1 = new BoundingBox(new Vector3(0,0,0), new Vector3(10,10,0));
    BoundingSphere sphere1 = new BoundingSphere(new Vector3(5,5,0),1);
    bool test1 = box1.Contains(sphere1) == ContainmentType.Contains;

    //working - box vs sphere
    BoundingBox box2 = new BoundingBox(new Vector3(0,0,-1), new Vector3(10,10,1));
    BoundingSphere sphere2 = new BoundingSphere(new Vector3(5, 5, 0),1);
    bool test2 = box2.Contains(sphere2) == ContainmentType.Contains;

    //working - box vs box
    BoundingBox box3a = new BoundingBox(new Vector3(0,0,0), new Vector3(10,10,0));
    BoundingBox box3b = new BoundingBox(new Vector3(5,5,0), new Vector3(6,6,0));
    bool test3 = box3a.Contains(box3b) == ContainmentType.Contains;

    ...as soon as the BoundingShere's z position is between the BoundingBox's min/max z position, it is working.

    Any thoughts on why it is working with the box vs box sample?

    /Ronzan

  • 3/27/2007 8:00 PM In reply to

    Re: BoundingBox.Contains(BoundingSphere) problem

    Answer
    Reply Quote

    A "box" where both min and max z values are zero is, essentially, a plane (more precisely, a rectangle). It can't contain anything except maybe a sphere of radius zero or another plane. That is why your three examples work the way they do:

    1. Box is a plane. Sphere has radius non-zero and intersects box, so box does not contain sphere.

    2. Box is actually a box with z-space of 2 (-1 to 1), sphere has radius of 1 and is positioned inside box, so box contains sphere.

    3. Both boxes are planes so one could, conceivably, contain the other.

     

  • 3/27/2007 11:17 PM In reply to

    Re: BoundingBox.Contains(BoundingSphere) problem

    I just thought that a Sphere with z-pos 0 would act as a cirle :)

    Thanks for clearing it up ProfEclipse.

     /Ronzan

Page 1 of 1 (5 items) Previous Next