Closed pixelzoom closed 5 years ago
Some references from @samreid on Slack:
Sam Reid [10:27 AM] Have you investigated the use of a QuadTree data structure for collision detection? https://gamedevelopment.tutsplus.com/tutorials/quick-tip-use-quadtrees-to-detect-likely-collisions-in-2d-space--gamedev-374 https://stackoverflow.com/questions/4896280/avoid-on2-complexity-for-collision-detection https://github.com/timohausmann/quadtree-js
The latter has this dynamic demo: https://timohausmann.de/quadtree.js/dynamic.html
As of 1.0.0-dev.4, basic collision detection and response seems to be working nicely. It's consolidated in CollisionDetector
, ~300 lines. Performance seems good, very smooth on MacBook Pro. There's still some cleanup and documentation to be done.
With 1.0.0-dev.5 on iPad2 + iOS 9.3.5 + mobile Safari... Animation is not as smooth as on other platforms, but probably acceptable. Animation noticeably pauses/stutters when particles are dispensed via the pump or spinners, and that's not something that can be remedied by adjusting region size.
A couple of things left to do here:
[ ] If we need to squeeze out more performance (see https://github.com/phetsims/gas-properties/issues/38), optimize the number of times that we iterate over particle arrays.
[ ] The Java version implemented a non-standard mode for particle-particle collisions, and the HTML5 version uses the same model (cleaned up and streamlined). I still don't fully understand the implemented model. And in the process of trying to understand it, I discovered that the more standard model is as described in Impact Particles.pdf. Should we stick with the implemented model? Try to fully understand it? Investigate switching to the standard model?
Performance looks good in #38, so it's unlikely that this will be necessary:
- [ ] If we need to squeeze out more performance (see #38), optimize the number of times that we iterate over particle arrays.
Collision detection implementation is working great, and unlikely to change it this late in the game. So I'm made some notes in CollisionDetection.js.
Closing.
This issue is to capture various requirements, notes, references, etc. related to collision detection and response.
The design team is generally happy with the behavior of the Java version, so the plan is to use the same approach for the HTML5 version. The Java implementation is overly general for the HTML5 needs, so I'll be pruning things down to meet the HTML5 requirements. The relevant classes in the Java implementation are identified in https://github.com/phetsims/gas-properties/issues/37#issuecomment-458718765.