SFML community forums

Help => General => Topic started by: StormWingDelta on April 30, 2014, 08:52:16 pm

Title: Various fast ways of collision detection?
Post by: StormWingDelta on April 30, 2014, 08:52:16 pm
Asking since the usual two loops of each sprite against the others gets slower than I'd like after a while.  I know of quadtrees but puzzled how to get one working for a map that goes all the way out the the max/min boundaries of the datatype.  Could just go for resizing its outer most size area as needed but that would end up causing the treenodes to rebuild their area as well.


Meantime any other ways of fast collision detection that could be used too? ???  Also any ideas on how to get them working for what I have in mind?
Title: Re: Various fast ways of collision detection?
Post by: Ixrec on April 30, 2014, 09:11:03 pm
Like Nexus said in the other thread, all methods to achieve what you want boil down to spatial partitioning.  And if you have an insanely huge map, you are going to have to partition the entirety of that map, be it with a quadtree or something else.

Do you have an actual program that's suffering performance problems because of this?  If not you probably shouldn't be worrying about it yet.
Title: Re: Various fast ways of collision detection?
Post by: StormWingDelta on April 30, 2014, 09:15:51 pm
Was working on collisions in a space shooter I'm working on which is why I was asking.  Didn't think the usual nested loops would lag as bad as they did.  :-[  ::)

Starting work on a quadtree right now actually and checking to see if there is anything else that could either replace or go along with it. :)
Title: Re: Various fast ways of collision detection?
Post by: didii on April 30, 2014, 10:15:05 pm
I don't know how you handle collisions, but you could check for collisions in a couple of steps. You could start with getting the maximum radius from an object (e.g. half diagonal length of a square) and do a circular collision check. This is easy and fast. If they do not collide, you can be certain all the more detailed collision checks will also fail.
Problem with this method is that it's probably less stable in terms of fps. When suddenly lots of objects are close to each other it also suddenly has to do a lot more checks.