Re:Modeling Physics in Javascript: Gravity and Drag
by mrhyperpenguin on Saturday September 08, 2012 @03:47PM
(#4493792)
Instead 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-progr...
[deleted]
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/
[2] - http://jsfiddle.net/simucal/RvA9w/