3 ms·
I wrote something like this a couple years ago[1]. I also attempted to support ball-to-ball collisions. I rarely do any graphics type programming so this was a
by Simucal 14y ago
I wrote something like this a couple years ago[1]. I also attempted to support ball-to-ball collisions. I rarely do any graphics type programming so this was a fun diversion.
However, the simulation would slow down considerably after adding a few dozen balls. This was largely due to the quadratic nature of my naive collision detection. In order to remedy the speed problems I implemented[2] a quadtree I found online to assist me in culling a lot of my expensive collision checks. The bounds of the quadtree sections will appear as you begin to add balls.
Unfortunately the quadtree wasn't the performance savior I expected it to be. I didn't notice a dramatic improvement in the number of balls I could support. I also introduced a bug with the quadtree version where certain collisions are missed entirely.
Perhaps I should revisit this simulation and see where I was off.
[1] - http://jsfiddle.net/simucal/RvA9w/33/ http://jsfiddle.net/simucal/RvA9w/33/
[2] - http://jsfiddle.net/simucal/RvA9w/ http://jsfiddle.net/simucal/RvA9w/
- deleted 14y ago[deleted]
- bkanber 14y agoPerformance is great for me too, but when you have a ton of balls the collision detection fails. Probably just a bug in the quadtree. Otherwise, great performance!
- mrhyperpenguin 14y agoInstead of quadtrees take a look at spatial hashing[0]. It's more simple than quadtrees and the performance is similar if not better. [0] http://www.gamedev.net/page/resources/_/technical/game-programming/spatial-hashing-r2697 http://www.gamedev.net/page/resources/_/technical/game-progr...