In my wip game i have to implement Circle-Circle collisions. To implement this i simply calculate the square distance between their Centers (x1-x2)² + (y1-y2)²
. If this is smaller then their sqared radiuses (r1+r2)²
a collision happened. But today i saw this link:
Circle-Circle collision
Here they first use AABB collision to notice if the circles are near. But why should i do this? The circle-circle collision is a simple and not realy expensive calculation. When i use the AABB first i do at least the same number of calculations and if circles are near even more.
Let me explain:
I do an AABB collision detection for every circle with every other.
So i have to do n! / (n-2)!
calculations. n = number of circles to test.
For every AABB colliding circle-pair i then have to do another calculation if they realy collide.
Without the AABB collision detection i only do n! / (n-2)!
calculations and i don't think this calculations are so costly.
What do you think?
n(n-1)
AABB checks (see thatn!/(n-2)! = n(n-1)
?), but typically only few collision checks. Say the AABB is only a factor 2 cheaper (it's probably more), then this is a speedup for smalln
already. – Vincent van der Weele