The physics system, an ECS system that tracks and updates the state of each physics object in the scene according to its properties.
More...
|
|
| PhysicsSystem (std::weak_ptr< ECSWorld > world) |
| void | setSubsteps (uint8_t newSubsteps) |
| | Sets the number of substeps used for physics integration using XPBD.
|
|
uint8_t | getSubsteps () const |
| | Gets the number of substeps used in the physics solver's XPBD implementation.
|
|
template<typename TConstraint, typename TConstraintData> |
| ConstraintID | registerConstraint (const std::vector< std::pair< EntityID, TConstraintData > > &constraintData, float compliance) |
| | Registers a constraint for the physics system to evaluate every substep.
|
|
void | unregisterConstraint (ConstraintID constraint) |
| | Removes a constraint.
|
|
| SignalTracker () |
| | Constructs a new SignalTracker object.
|
| | SignalTracker (const SignalTracker &other) |
| | Constructs a new SignalTracker.
|
| SignalTracker & | operator= (const SignalTracker &other) |
| | Copy assignment operator.
|
| | SignalTracker (SignalTracker &&other) |
| | Moves resources from another SignalTracker into this one, invalidating them from the other.
|
| SignalTracker & | operator= (SignalTracker &&other) |
| | Moves resources from another SignalTracker into this one, destroying this tracker's resources in the process.
|
| void | connect (const std::string &theirSignal, const std::string &ourObserver, SignalTracker &other) |
| | Method that connects one of this objects SignalObservers to another tracker's Signal.
|
|
|
void | onSimulationActivated () override |
| | Marks this system as requiring initialization on the nearest update.
|
| void | onSimulationStep (uint32_t timestepMillis) override |
| | Updates physics simulation.
|
| void | onEntityEnabled (EntityID entityID) override |
| | Updates this entity's physics properties.
|
| void | onEntityUpdated (EntityID entityID, ComponentType updatedComponent) override |
| | Updates this entity's physics properties.
|
|
void | onEntityDisabled (EntityID entityID) override |
| | Removes entity from to-initialize list.
|
|
bool | isConstraintActive (ConstraintID constraint) const |
| | Whether or not a particular constraint is active.
|
| void | updateProperties (EntityID entityID) |
| | Computes rotational inertia from mass and object bounds.
|
|
void | refreshActiveConstraints () |
| | Determines which constraints are inactive (by virtue of all of their entities being enabled) and which ones aren't.
|
| void | integrateForces (float substepSeconds, std::unordered_map< EntityID, PhysicsStateFull > &previousState, std::unordered_map< EntityID, PhysicsStateFull > ¤tState) |
| | Derives position and rotation updates for physics objects based on their current state and forces acting on them.
|
|
void | deriveVelocities (float substepSeconds, const std::unordered_map< EntityID, PhysicsStateFull > &previousState, std::unordered_map< EntityID, PhysicsStateFull > ¤tState) |
| | Derives actual object velocities after integration and constraint solve.
|
|
void | applyPositionCollisionConstraints (std::map< CollisionPair, CollisionConstraint > &potentialCollisions, float substepSeconds, std::unordered_map< EntityID, PhysicsStateFull > ¤tState) |
| | Correctly applies collision position constraint for each potential collision detected.
|
|
void | applyVelocityCollisionConstraints (std::map< CollisionPair, CollisionConstraint > &constraints, float substepSeconds, std::unordered_map< EntityID, PhysicsStateFull > ¤tState) |
| | Correctly applies collision velocity constraint for each potential collision detected.
|
|
void | applyPositionConstraints (std::map< CollisionPair, CollisionConstraint > &constraints, float substepSeconds, std::unordered_map< EntityID, PhysicsStateFull > ¤tState) |
| | Applies all active position constraints.
|
|
void | applyVelocityConstraints (std::map< CollisionPair, CollisionConstraint > &constraints, float substepSeconds, std::unordered_map< EntityID, PhysicsStateFull > ¤tState) |
| | Applies all active velocity constraints.
|
| void | updateCollisionEventQueue (std::map< CollisionPair, CollisionConstraint > &potentialCollisions, std::queue< CollisionReport > &queuedReports, std::unordered_map< EntityID, PhysicsStateFull > &previousStates, std::unordered_map< EntityID, PhysicsStateFull > ¤tStates, uint8_t nthSubstep) |
| | Tests each pair of potential colliders for intersection, adds collision report to the queue if configured.
|
|
void | onCollided (const CollisionPair &pair, const Collision &collision, std::queue< CollisionReport > &queuedReports) |
| | Registers a pair of entities as intersecting, signalling to collision signal observers if required.
|
|
void | onSeparated (const CollisionPair &pair, std::queue< CollisionReport > &queuedReports) |
| | Removes pair of entities from collision list, appending collision event to queue if required.
|
|
void | registerCollisionSignal (EntityID entity) |
| | Registers collision signals for this entity.
|
|
void | unregisterCollisionSignal (EntityID entity) |
| | Unregisters collision signals for this entity.
|
|
void | reportCollisions (std::queue< CollisionReport > &reports, std::unordered_map< EntityID, std::pair< SignalCollided, SignalSeparated > > signallers) const |
| | Signals all collisions and separations collected over the course of the simulation step, in the order those events occurred.
|
|
bool | wasColliding (const CollisionPair &pair) const |
| | Whether or not a particular pair of entities have their collision tracked by the physics system.
|
|
void | collectPotentialCollisions (float substepSeconds, std::queue< CollisionReport > &queuedReports) |
| | Collects potential collisions and builds constraints from them.
|
|
|
std::set< EntityID > | mEntitiesUninitialized {} |
| | Holds entities that haven't undergone proper initialization, and therefore aren't eligible for proper physics updates.
|
|
std::unordered_map< EntityID, PhysicsStateFull > | mEntityStatePrevious {} |
| | Storage for local entity states prior to the integration step each substep.
|
|
std::unordered_map< EntityID, PhysicsStateFull > | mEntityStateCurrent {} |
| | Storage for current local entity states, eventually pushed to ECS component tables.
|
|
std::unordered_map< EntityID, std::set< ConstraintID > > | mEntityConstraintMap {} |
| | Associates each entity with its set of constraints, used to determine whether the constraint can be evaluated at a given substep.
|
| SweepPrune | mBroadPhase {} |
| | Representation of the structure/technique being used to detect likely collisions.
|
|
std::unordered_map< EntityID, std::unordered_set< EntityID > > | mEntityCollision {} |
| | All currently intersecting entities.
|
|
std::unordered_set< EntityID > | mPotentialColliders {} |
| | A list of entities that may collide this frame.
|
|
std::queue< CollisionReport > | mCollisionReports {} |
| | Storage for collision reports that should be signalled this simulation frame.
|
|
std::unordered_map< EntityID, std::pair< SignalCollided, SignalSeparated > > | mCollisionSignallers {} |
| | Entities whose collision events are signalled by this system.
|
|
std::map< CollisionPair, CollisionConstraint > | mCollisionConstraints {} |
| | Storage for pairs of entities that are likely to collide (or are colliding) this simulation frame.
|
| std::vector< std::pair< std::unique_ptr< BaseConstraint >, std::vector< EntityID > > > | mConstraints {} |
| | A list of all constraints known to the physics system, evaluated every frame.
|
|
std::unordered_set< ConstraintID > | mConstraintsDeleted {} |
| | IDs of constraints that were deleted and which may be reused to define a new constraint.
|
| uint8_t | mSubsteps { 3 } |
| | The number of substeps used in the physics system's XPBD implementation.
|
|
bool | mRequiresInitialization { true } |
| | Whether physics properties for all eligible entities should be recomputed.
|
|
bool | mConstraintsInitialized { true } |
| | Whether we have yet to determine which constraints are active and which are not.
|
The physics system, an ECS system that tracks and updates the state of each physics object in the scene according to its properties.
Relies strongly on the spatial query system to provide information about object overlaps and collisions. Collision events are generated when an object with a certain interaction mask overlaps with objects belonging to one of the layers indicated by that mask.
The physics system implemented here is based on XPBD (Extended Position Based Dynamics). See paper Detailed Rigid Body Simulation using Extended Position Based Dynamics.
- See also
- Spatial Queries