1
\$\begingroup\$

I'm loading a simple 6 sided cube from a UV-mapped FBX model and I'm using a BoundingBox to test for collisions. Once I determine there's a collision, I want to use the normal vector of the collided surface to correct the movement of whatever collided with the cube. I suppose this is a two-part question:

1) How can I determine which face of the cube was collided with during a collision?

2) How can I get the normal vector of that surface?

\$\endgroup\$
3
  • \$\begingroup\$ Are you using an Axis Aligned Bounding Box (AABB) or an Oriented Bounding Box (OBB)? \$\endgroup\$
    – Steve H
    Jun 22, 2011 at 0:24
  • \$\begingroup\$ I'll be honest, I've never heard of either of them. If I were to make an educated guess based on the names, I'd say AABB. \$\endgroup\$ Jun 22, 2011 at 0:43
  • \$\begingroup\$ Of course the cubes themselves are axis aligned... so would that mean the bounding box is oriented with respect to both the cube and the axes. \$\endgroup\$ Jun 22, 2011 at 19:41

1 Answer 1

1
\$\begingroup\$

The Xna.Framework.BoundingBox isn't designed to help provide that information, it simply is able to check for a collision of the cube as a unit.

Determining which side collided sounds simple but it can actually be complex. You might want to look into SAT (Separating axis therory/Test). The result of which axis and whether it is + or - the center of the cubeBox will help you deduce in which face the collision happened.

Another quick & dirty would be to create 6 boxes around your main box, then when a collision is registered with the main box, see which 'outsideBox' is also involved and calculate a normal based on that. This would have challenges though if penetration is deep. A version of this idea would be to make each face its own thin box so you always know which box (face) the collision is on. Again, deep penetration may challenge that.

Another idea would be to create a class which holds the bounding box and also creates Plane objects that coincide with the faces of the cube. Then you could use the built in Plane intersection tests to see which side the collision was coming from and use that plane's normal.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .