bepu / bepuphysics2

Pure C# 3D real time physics simulation library, now with a higher version number.
Apache License 2.0
2.25k stars 261 forks source link

Broad and Narrow Phase #271

Closed Wishyou-D closed 1 year ago

Wishyou-D commented 1 year ago

Hey, I was wondering what functions are the start and end of broad and narrow phase? How do you define these two phases? Thanks.

RossNordby commented 1 year ago

The "broad phase" covers the updating and use of the simulation-wide acceleration structure. It's split into an update and testing phase: the update phase refits and refines the acceleration structure for the simulation's current state, and the testing phase finds collision pair candidates to feed to the narrow phase.

The narrow phase covers the detailed testing of those collision pair candidates and the bookkeeping associated with the results. The bookkeeping involves updating narrowphase internal caches (like the set of pairs), getting rid of stale collision constraints, adding new collision constraints, and waking up sleeping bodies affected by new constraints.

You can see how the broad phase are narrow phase are used in the Simulation.CollisionDetection function.

The broad phase is updated for the current simulation state, then pair finding tests are invoked (which dumps its results into the narrow phase), and then the narrow phase flush is invoked to handle all the necessary bookkeeping.