get colliding face of 2 AABB's?

Started by
2 comments, last by Rattenhirn 11 years, 3 months ago

So far I have 2 AABB's, one stationary and one moving, checking against min(x,y,z) and max(x,y,z) of the 2 AABB's I can tell if they intersect.

Now I would like to implement a "slide against the wall" effect, therefore I need to get the normal of the colliding face, but I have troubles understanding how I can compute which face is colliding.

I googled a lot and found something about SAT ( http://www.codezealot.org/archives/55 ) but I am still confused, is this the only technique to get the colliding face or are there other options available?

I would appreciate some hints or pseudo code to get me started.

Advertisement
SAT works by finding all the common axises (sp?) between the two colliders and see how much they overlap. If one of them doesn't overlap, there's no collision. Otherwise the collision normal can be devised from the overlaps.

AABB's, by definition, have the common axises global x, y and z. With the min/max tests you find out if all of them overlap or not. So what's left to do, is figure out, how much they overlap, and them simply pick the largest overlap, since the axises are also, by definition, the face normals.

I hope that helps!

And maybe someone can let me know what the correct plural of axis is... ;)

thanks, indeed that helped, i got a little confused reading so much stuff about SAT.

now i calculate the distance between the 2 boxes using the min and max values for each axis and take the largest distance which gives me the correct normal.

the plural of axis is axes.

Yes, SAT can get pretty tricky, if more complex geometries are involved. Two AABBs are probably the second easiest, right after two spheres.

I found this website to be very helpful in explaining the theorem, it also has nifty interactive examples:

http://www.metanetsoftware.com/technique/tutorialA.html

Unfortunately it only covers 2D collisions...

This topic is closed to new replies.

Advertisement