|
GREM 3.12.0
Game/Rendering Engine Modules for C++
|
Discrete-time simulation of physical interactions between objects and joints. More...
#include <GREM/physics/Simulation.hpp>
Public Member Functions | |
| Simulation () | |
| Construct a physics simulation with all required resources added, using the default SimulationOptions. | |
| Simulation (const SimulationOptions< N > &options, const ScheduleStepOptions< N > &scheduleStepOptions={}) | |
| Construct a physics simulation with all required resources added. | |
| Simulation (const SimulationOptions< N > &options, FunctionView< Schedule< N >(EntityRegistry< N > ®istry, ResourceRegistry< N > &resources, const SimulationOptions< N > &simulationOptions)> scheduleStep) | |
| Construct a physics simulation with all required resources added, with an entirely custom schedule. | |
| EntityBuilder< N > | createObject (ObjectOptions< N > &&options, EntityID::Flags flags={}) |
| Create a new simulated object entity and add it to the simulation. | |
| void | updateObjectMomentOfInertiaTensor (EntityID objectID) |
| Update the MomentOfInertiaTensor<N> and InverseMomentOfInertiaTensor<N> components of an object given its current orientation in the world. | |
| void | updateObjectBounds (EntityID objectID) |
| Update the ObjectBounds<N> component of an object given its current shape, local center of mass, position and orientation in the world, while accounting for one step of potential movement given the object's current velocitiy and the step interval of the simulation. | |
| void | updateBroadphase () |
| Update the broadphase structure of a simulation by inserting all objects with a broadphase handle of null to reflect their new bounds, and cleaning up any references to objects that no longer exist. | |
| EntityBuilder< N > | createGenericJoint (Pair< EntityID > objectIDs, const GenericJointOptions< N > &options, EntityID::Flags flags={}) |
| Create a new simulated generic joint entity that connects two objects. | |
| EntityBuilder< N > | createWeld (Pair< EntityID > objectIDs, const WeldOptions< N > &options={}, EntityID::Flags flags={}) |
| Create a new simulated weld joint entity that restricts all motion between two objects. | |
| EntityBuilder< N > | createHingeJoint (Pair< EntityID > objectIDs, const HingeJointOptions< N > &options={}, EntityID::Flags flags={}) |
| Create a new simulated hinge joint entity that restricts the linear motion between and aligns the X axes of two objects. | |
| EntityBuilder< N > | createBallJoint (Pair< EntityID > objectIDs, const BallJointOptions< N > &options={}, EntityID::Flags flags={}) |
| Create a new simulated ball joint entity that restricts the linear motion between two objects. | |
| EntityBuilder< N > | createPrismaticJoint (Pair< EntityID > objectIDs, const PrismaticJointOptions< N > &options={}, EntityID::Flags flags={}) |
| Create a new simulated prismatic joint entity that restricts the angular motion between and aligns the X and Y axes of two objects. | |
| EntityBuilder< N > | createCylinderJoint (Pair< EntityID > objectIDs, const CylinderJointOptions< N > &options={}, EntityID::Flags flags={}) |
| Create a new simulated cylindrical joint that restricts the angular motion between and aligns the X axes of two objects. | |
| void | step (execution::Executor &executor) |
| Perform a step of the physics simulation using a specific executor. | |
| void | step () |
| Perform a step of the physics simulation using a basic sequential executor that runs directly on the calling thread. | |
| void | drawDebugVisualization (DebugVisualization< N > &debugVisualization) const |
| Get the debug visualization of the current simulation state. | |
Static Public Member Functions | |
| static void | addRequiredResources (ResourceRegistry< N > &resources, const SimulationOptions< N > &options={}) |
| Add all resources required to run a simulation to a resource registry, reassigning them to their default state if already present. | |
| static void | removeResources (ResourceRegistry< N > &resources) noexcept |
| Remove all resources required to run a simulation from a resource registry. | |
| static void | addObjectComponents (EntityRegistry< N > ®istry, const ResourceRegistry< N > &resources, EntityID entityID, ObjectOptions< N > &&options) |
| Add all components required to create a simulated object to an entity in a registry. | |
| static void | removeObjectComponents (EntityRegistry< N > ®istry, EntityID entityID) noexcept |
| Remove all components added by addObjectComponents() from an entity in a registry. | |
| static void | updateObjectMomentOfInertiaTensor (EntityRegistry< N > ®istry, const ResourceRegistry< N > &resources, EntityID objectID) |
| Update the MomentOfInertiaTensor<N> and InverseMomentOfInertiaTensor<N> components of an object given its current orientation in the world. | |
| static void | updateObjectBounds (EntityRegistry< N > ®istry, const ResourceRegistry< N > &resources, EntityID objectID) |
| Update the ObjectBounds<N> component of an object given its current shape, local center of mass, position and orientation in the world, while accounting for one step of potential movement given the object's current velocitiy and the step interval of the simulation. | |
| static void | updateBroadphase (EntityRegistry< N > ®istry, ResourceRegistry< N > &resources) |
| Update the broadphase structure of a simulation by inserting all objects with a broadphase handle of null to reflect their new bounds, and cleaning up any references to objects that no longer exist. | |
| static void | addGenericJointComponents (EntityRegistry< N > ®istry, const ResourceRegistry< N > &resources, EntityID entityID, Pair< EntityID > objectIDs, const GenericJointOptions< N > &options) |
| Add all components required to create a simulated generic joint that connects two objects to an entity in a registry. | |
| static void | addWeldComponents (EntityRegistry< N > ®istry, const ResourceRegistry< N > &resources, EntityID entityID, Pair< EntityID > objectIDs, const WeldOptions< N > &options={}) |
| Add all components required to create a simulated weld joint that restricts all motion between two objects to an entity in a registry. | |
| static void | addHingeJointComponents (EntityRegistry< N > ®istry, const ResourceRegistry< N > &resources, EntityID entityID, Pair< EntityID > objectIDs, const HingeJointOptions< N > &options={}) |
| Add all components required to create a simulated hinge joint that restricts the linear motion between and aligns the X axes of two objects to an entity in a registry. | |
| static void | addBallJointComponents (EntityRegistry< N > ®istry, const ResourceRegistry< N > &resources, EntityID entityID, Pair< EntityID > objectIDs, const BallJointOptions< N > &options={}) |
| Add all components required to create a simulated ball joint that restricts the linear motion between two objects to an entity in a registry. | |
| static void | addPrismaticJointComponents (EntityRegistry< N > ®istry, const ResourceRegistry< N > &resources, EntityID entityID, Pair< EntityID > objectIDs, const PrismaticJointOptions< N > &options={}) |
| Add all components required to create a simulated prismatic joint that restricts the angular motion between and aligns the X and Y axes of two objects to an entity in a registry. | |
| static void | addCylinderJointComponents (EntityRegistry< N > ®istry, const ResourceRegistry< N > &resources, EntityID entityID, Pair< EntityID > objectIDs, const CylinderJointOptions< N > &options={}) |
| Add all components required to create a simulated cylindrical joint that restricts the angular motion between and aligns the X axes of two objects to an entity in a registry. | |
| static void | removeJointComponents (EntityRegistry< N > ®istry, EntityID entityID) noexcept |
| Remove all components added by addGenericJointComponents() from an entity in a registry. | |
| static void | scheduleStep (Scheduler< N > &scheduler, const SimulationOptions< N > &simulationOptions, const ScheduleStepOptions< N > &scheduleStepOptions={}) |
| Schedule a full step of the physics simulation. | |
| static void | scheduleBroadphaseUpdate (Scheduler< N > &scheduler, const SimulationOptions< N > &simulationOptions) |
| Schedule a standalone broadphase update pass, separate from a full simulation step, that updates the broadphase for any objects whose broadphase handle is null. | |
| static void | scheduleCollisionDetection (Scheduler< N > &scheduler, const SimulationOptions< N > &simulationOptions) |
| Schedule a standalone collision detection pass, separate from a full simulation step, that updates the set of collisions between all objects without emitting any events. | |
| static void | drawDebugVisualization (DebugVisualization< N > &debugVisualization, const EntityRegistry< N > ®istry, const ResourceRegistry< N > &resources) |
| Get the debug visualization of the current simulation state. | |
Public Attributes | |
| EntityRegistry< N > | registry {} |
| Entity registry of the simulation. | |
| ResourceRegistry< N > | resources {} |
| Resource registry of the simulation. | |
| Schedule< N > | stepSchedule {} |
| Schedule for performing one step of the physics simulation. | |
Discrete-time simulation of physical interactions between objects and joints.
The simulation uses a right-handed coordinate system and SI units for any physical quantities.
| N | number of dimensions of the world space (must be 2 or 3). |
|
inline |
Construct a physics simulation with all required resources added, using the default SimulationOptions.
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
explicit |
Construct a physics simulation with all required resources added.
| options | initial configuration options of the simulation, see SimulationOptions. |
| scheduleStepOptions | step scheduling options, see ScheduleStepOptions. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
explicit |
Construct a physics simulation with all required resources added, with an entirely custom schedule.
| options | initial configuration options of the simulation, see SimulationOptions. |
| scheduleStep | callback function that builds and returns the custom schedule of the simulation. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
| any | exception thrown by the callback function. |
|
static |
Add all resources required to run a simulation to a resource registry, reassigning them to their default state if already present.
| resources | resource registry to add the resources to. |
| options | initial configuration options of the simulation, see SimulationOptions. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
staticnoexcept |
Remove all resources required to run a simulation from a resource registry.
| resources | resource registry to remove the resources from. |
|
static |
Add all components required to create a simulated object to an entity in a registry.
| registry | entity registry containing the given entity. |
| resources | resource registry of the simulation. Must contain all resources added by addRequiredResources(). |
| entityID | handle to the entity to add the components to. |
| options | configuration of the object to create, see ObjectOptions. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
staticnoexcept |
Remove all components added by addObjectComponents() from an entity in a registry.
| registry | entity registry containing the given entity. |
| entityID | handle to the entity to remove the components from. |
|
static |
Update the MomentOfInertiaTensor<N> and InverseMomentOfInertiaTensor<N> components of an object given its current orientation in the world.
| registry | entity registry containing the given entity. |
| resources | resource registry of the simulation. Must contain all resources added by addRequiredResources(). |
| objectID | handle to the object entity to update the moment of inertia tensor of. |
|
static |
Update the ObjectBounds<N> component of an object given its current shape, local center of mass, position and orientation in the world, while accounting for one step of potential movement given the object's current velocitiy and the step interval of the simulation.
| registry | entity registry containing the given entity. |
| resources | resource registry of the simulation. Must contain all resources added by addRequiredResources(). |
| objectID | handle to the object entity to update the bounds of. |
|
static |
Update the broadphase structure of a simulation by inserting all objects with a broadphase handle of null to reflect their new bounds, and cleaning up any references to objects that no longer exist.
| registry | entity registry containing the objects of the world. |
| resources | resource registry containing the broadphase to update. Must contain all resources added by addRequiredResources(). |
|
static |
Add all components required to create a simulated generic joint that connects two objects to an entity in a registry.
| registry | entity registry containing the given entity. |
| resources | resource registry of the simulation. Must contain all resources added by addRequiredResources(). |
| entityID | handle to the entity to add the components to. |
| objectIDs | ordered pair of handles to the two object entities to connect with the joint. |
| options | configuration of the joint to create, see GenericJointOptions. |
| physics::Error | if the object IDs are not valid for the given registry. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
static |
Add all components required to create a simulated weld joint that restricts all motion between two objects to an entity in a registry.
| registry | entity registry containing the given entity. |
| resources | resource registry of the simulation. Must contain all resources added by addRequiredResources(). |
| entityID | handle to the entity to add the components to. |
| objectIDs | ordered pair of handles to the two object entities to connect with the joint. |
| options | configuration of the joint to create, see WeldOptions. |
| physics::Error | if the object IDs are not valid for the given registry. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
static |
Add all components required to create a simulated hinge joint that restricts the linear motion between and aligns the X axes of two objects to an entity in a registry.
| registry | entity registry containing the given entity. |
| resources | resource registry of the simulation. Must contain all resources added by addRequiredResources(). |
| entityID | handle to the entity to add the components to. |
| objectIDs | ordered pair of handles to the two object entities to connect with the joint. |
| options | configuration of the joint to create, see HingeJointOptions. |
| physics::Error | if the object IDs are not valid for the given registry. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
static |
Add all components required to create a simulated ball joint that restricts the linear motion between two objects to an entity in a registry.
| registry | entity registry containing the given entity. |
| resources | resource registry of the simulation. Must contain all resources added by addRequiredResources(). |
| entityID | handle to the entity to add the components to. |
| objectIDs | ordered pair of handles to the two object entities to connect with the joint. |
| options | configuration of the joint to create, see BallJointOptions. |
| physics::Error | if the object IDs are not valid for the given registry. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
static |
Add all components required to create a simulated prismatic joint that restricts the angular motion between and aligns the X and Y axes of two objects to an entity in a registry.
| registry | entity registry containing the given entity. |
| resources | resource registry of the simulation. Must contain all resources added by addRequiredResources(). |
| entityID | handle to the entity to add the components to. |
| objectIDs | ordered pair of handles to the two object entities to connect with the joint. |
| options | configuration of the joint to create, see PrismaticJointOptions. |
| physics::Error | if the object IDs are not valid for the given registry. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
static |
Add all components required to create a simulated cylindrical joint that restricts the angular motion between and aligns the X axes of two objects to an entity in a registry.
| registry | entity registry containing the given entity. |
| resources | resource registry of the simulation. Must contain all resources added by addRequiredResources(). |
| entityID | handle to the entity to add the components to. |
| objectIDs | ordered pair of handles to the two object entities to connect with the joint. |
| options | configuration of the joint to create, see CylinderJointOptions. |
| physics::Error | if the object IDs are not valid for the given registry. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
staticnoexcept |
Remove all components added by addGenericJointComponents() from an entity in a registry.
| registry | entity registry containing the given entity. |
| entityID | handle to the entity to remove the components from. |
|
static |
Schedule a full step of the physics simulation.
| scheduler | scheduler to schedule the simulation step on. |
| simulationOptions | configuration options of the simulation that the schedule will be executed on. |
| scheduleStepOptions | step scheduling options, see ScheduleStepOptions. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
static |
Schedule a standalone broadphase update pass, separate from a full simulation step, that updates the broadphase for any objects whose broadphase handle is null.
| scheduler | scheduler to schedule the simulation step on. |
| simulationOptions | configuration options of the simulation that the schedule will be executed on. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
static |
Schedule a standalone collision detection pass, separate from a full simulation step, that updates the set of collisions between all objects without emitting any events.
| scheduler | scheduler to schedule the simulation step on. |
| simulationOptions | configuration options of the simulation that the schedule will be executed on. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
static |
Get the debug visualization of the current simulation state.
| debugVisualization | debug visualization to append the draw commands to. |
| registry | entity registry containing the entities involved in the simulation. |
| resources | resource registry containing the resources required by the simulation. |
|
inlinenodiscard |
Create a new simulated object entity and add it to the simulation.
| options | configuration of the object to create, see ObjectOptions. |
| flags | user-defined flags to add to the ID of the created entity. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inline |
Update the MomentOfInertiaTensor<N> and InverseMomentOfInertiaTensor<N> components of an object given its current orientation in the world.
| objectID | handle to the object entity to update the moment of inertia tensor of. |
|
inline |
Update the ObjectBounds<N> component of an object given its current shape, local center of mass, position and orientation in the world, while accounting for one step of potential movement given the object's current velocitiy and the step interval of the simulation.
| objectID | handle to the object entity to update the bounds of. |
|
inline |
Update the broadphase structure of a simulation by inserting all objects with a broadphase handle of null to reflect their new bounds, and cleaning up any references to objects that no longer exist.
|
inlinenodiscard |
Create a new simulated generic joint entity that connects two objects.
| objectIDs | ordered pair of handles to the two object entities to connect with the joint. |
| options | configuration of the joint to create, see GenericJointOptions. |
| flags | user-defined flags to add to the ID of the created entity. |
| physics::Error | if the object IDs are not valid for this simulation. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inlinenodiscard |
Create a new simulated weld joint entity that restricts all motion between two objects.
| objectIDs | ordered pair of handles to the two object entities to connect with the joint. |
| options | configuration of the joint to create, see WeldOptions. |
| flags | user-defined flags to add to the ID of the created entity. |
| physics::Error | if the object IDs are not valid for this simulation. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inlinenodiscard |
Create a new simulated hinge joint entity that restricts the linear motion between and aligns the X axes of two objects.
| objectIDs | ordered pair of handles to the two object entities to connect with the joint. |
| options | configuration of the joint to create, see HingeJointOptions. |
| flags | user-defined flags to add to the ID of the created entity. |
| physics::Error | if the object IDs are not valid for this simulation. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inlinenodiscard |
Create a new simulated ball joint entity that restricts the linear motion between two objects.
| objectIDs | ordered pair of handles to the two object entities to connect with the joint. |
| options | configuration of the joint to create, see BallJointOptions. |
| flags | user-defined flags to add to the ID of the created entity. |
| physics::Error | if the object IDs are not valid for this simulation. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inlinenodiscard |
Create a new simulated prismatic joint entity that restricts the angular motion between and aligns the X and Y axes of two objects.
| objectIDs | ordered pair of handles to the two object entities to connect with the joint. |
| options | configuration of the joint to create, see PrismaticJointOptions. |
| flags | user-defined flags to add to the ID of the created entity. |
| physics::Error | if the object IDs are not valid for this simulation. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inlinenodiscard |
Create a new simulated cylindrical joint that restricts the angular motion between and aligns the X axes of two objects.
| objectIDs | ordered pair of handles to the two object entities to connect with the joint. |
| options | configuration of the joint to create, see CylinderJointOptions. |
| flags | user-defined flags to add to the ID of the created entity. |
| physics::Error | if the object IDs are not valid for this simulation. |
| execution::Error | on failure to add the components. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
| void grem::physics::Simulation< N >::step | ( | execution::Executor & | executor | ) |
Perform a step of the physics simulation using a specific executor.
| executor | executor to execute the step schedule on. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
| any | exception thrown by custom tasks in the simulation's step schedule. |
| void grem::physics::Simulation< N >::step | ( | ) |
Perform a step of the physics simulation using a basic sequential executor that runs directly on the calling thread.
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
| any | exception thrown by custom tasks in the simulation's step schedule. |
|
inline |
Get the debug visualization of the current simulation state.
| debugVisualization | debug visualization to append the draw commands to. |
| EntityRegistry<N> grem::physics::Simulation< N >::registry {} |
Entity registry of the simulation.
| ResourceRegistry<N> grem::physics::Simulation< N >::resources {} |
Resource registry of the simulation.
| Schedule<N> grem::physics::Simulation< N >::stepSchedule {} |
Schedule for performing one step of the physics simulation.