gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS Misc > perfect Collision Detection Demo + Sourcecode + Explanation!

#123493 - ETkoala - Wed Mar 28, 2007 4:19 pm

It took me a while to get all the formulas, make a demo and prepare the image tutorial, but it's worth for the nice result I got there!.

In the demo are 2 squares (you can move one) which will turn lightred when there is a collision detected. In the SubScreen you can see all the Areas calculated (see image explanation for what are them) while you move your square.

Here's a screenshot with collision and non-collision:
[Images not permitted - Click here to view it]

You can Download (Demo+Source) here: http://etk.scener.org/collisiontesting.rar

And the Explanation (which I strongly recommend for those who want to know how it works):
[Images not permitted - Click here to view it]

I hope this helps many people, atleast it helped me :)

#123494 - Lick - Wed Mar 28, 2007 4:25 pm

Congratulations! You should also inspect Circle- Triangle- Rectangle- collisions. Those are pretty interesting as well. (You could even take it 3D with cones, tubes etc.)
_________________
http://licklick.wordpress.com

#123497 - Darkflame - Wed Mar 28, 2007 4:57 pm

Circles are easy, and rectangles are pretty much the same as squares.

But I must admit I wouldn't no offhand how to do triangles. (especially if rotation was involved)
_________________
Darkflames Reviews --
Make your own at;
Rateoholic:Reviews for anything, by anyone.

#123507 - sajiimori - Wed Mar 28, 2007 6:38 pm

Is this what you're trying to do?
Code:
bool rectanglesIntersect(const Rect* a, const Rect* b)
{
   return a->right >= b->left
      && a->left <= b->right
      && a->bottom >= b->top
      && a->top <= b->bottom;
}