1
\$\begingroup\$

I have a box that is drawn around my game that I want to check collisions with. Currently my BoundingBox is made in a way that whatever is inside the box is colliding with it:

BoundingBox bb = new BoundingBox(new Vector3(position.X - 0.1f, position.Y - 0.1f, position.Z - width - 0.1f), new Vector3(position.X + width + 0.1f, position.Y + width + 0.1f, position.Z + 0.1f));

(Note: the +0.1f is added so that it doesn't cause collision when an object is touching it, only when it passed through)

What I want is the inverse. I want a BoundingBox around this box so that only objects outside of the box will cause collision.

Is there an easy way of doing this or am I supposed to make different BoundingBoxes around this existing one? Thanks

\$\endgroup\$
2
  • \$\begingroup\$ I must be missing some subtlety here. Can't you solve this problem with the not operator? \$\endgroup\$ Commented Jan 5, 2015 at 4:23
  • 1
    \$\begingroup\$ @SethBattin The subtlety is that the possible results of an intersection test are ternary (disjoint/intersects/contains), not binary. So applying a binary not operation might not give the desired result. \$\endgroup\$ Commented Jan 6, 2015 at 3:17

2 Answers 2

3
\$\begingroup\$

BoundingBox provides several Contains (MSDN) methods that return ContainmentType (MSDN).

To test if an object is outside your bounding box, test for ContainmentType.Disjoint.

\$\endgroup\$
2
\$\begingroup\$

You need to invert the logic of the test not the box itself. The bounding box can only describe a box. Whether that is a rectangular solid in space or a rectangular hole in infinite space is up to the test performed.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.