phetsims / gas-properties

"Gas Properties" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
6 stars 6 forks source link

collision detection and response #40

Closed pixelzoom closed 5 years ago

pixelzoom commented 5 years ago

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.

pixelzoom commented 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

pixelzoom commented 5 years ago

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.

pixelzoom commented 5 years ago

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.

pixelzoom commented 5 years ago

A couple of things left to do here:

pixelzoom commented 5 years ago

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.
pixelzoom commented 5 years ago

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.