GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::physics::Simulation< N > Struct Template Reference

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 > &registry, 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 > &registry, 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 > &registry, EntityID entityID) noexcept
 Remove all components added by addObjectComponents() from an entity in a registry.
static void updateObjectMomentOfInertiaTensor (EntityRegistry< N > &registry, 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 > &registry, 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 > &registry, 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 > &registry, 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 > &registry, 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 > &registry, 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 > &registry, 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 > &registry, 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 > &registry, 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 > &registry, 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 > &registry, 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.

Detailed Description

template<size_t N>
struct grem::physics::Simulation< N >

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.

Template Parameters
Nnumber of dimensions of the world space (must be 2 or 3).

Constructor & Destructor Documentation

◆ Simulation() [1/3]

template<size_t N>
grem::physics::Simulation< N >::Simulation ( )
inline

Construct a physics simulation with all required resources added, using the default SimulationOptions.

Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ Simulation() [2/3]

template<size_t N>
grem::physics::Simulation< N >::Simulation ( const SimulationOptions< N > & options,
const ScheduleStepOptions< N > & scheduleStepOptions = {} )
explicit

Construct a physics simulation with all required resources added.

Parameters
optionsinitial configuration options of the simulation, see SimulationOptions.
scheduleStepOptionsstep scheduling options, see ScheduleStepOptions.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ Simulation() [3/3]

template<size_t N>
grem::physics::Simulation< N >::Simulation ( const SimulationOptions< N > & options,
FunctionView< Schedule< N >(EntityRegistry< N > &registry, ResourceRegistry< N > &resources, const SimulationOptions< N > &simulationOptions)> scheduleStep )
explicit

Construct a physics simulation with all required resources added, with an entirely custom schedule.

Parameters
optionsinitial configuration options of the simulation, see SimulationOptions.
scheduleStepcallback function that builds and returns the custom schedule of the simulation.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback function.

Member Function Documentation

◆ addRequiredResources()

template<size_t N>
void grem::physics::Simulation< N >::addRequiredResources ( ResourceRegistry< N > & resources,
const SimulationOptions< N > & options = {} )
static

Add all resources required to run a simulation to a resource registry, reassigning them to their default state if already present.

Parameters
resourcesresource registry to add the resources to.
optionsinitial configuration options of the simulation, see SimulationOptions.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
The added resources are:
  • SimulationOptions<N>: Configuration options for the simulation.
  • CollisionEvents<N>: Set of collision events that occured in the last simulation step.
  • SeparationEvents<N>: Set of separation events that occured in the last simulation step.
  • Broadphase<N>: An acceleration structure for spatial object queries.
  • Contacts<N>: The set of contacts between objects in the simulation.
  • Internal storage for implementation-specific mid-simulation-step caches that are not user-accessible.
See also
removeResources()

◆ removeResources()

template<size_t N>
void grem::physics::Simulation< N >::removeResources ( ResourceRegistry< N > & resources)
staticnoexcept

Remove all resources required to run a simulation from a resource registry.

Parameters
resourcesresource registry to remove the resources from.

◆ addObjectComponents()

template<size_t N>
void grem::physics::Simulation< N >::addObjectComponents ( EntityRegistry< N > & registry,
const ResourceRegistry< N > & resources,
EntityID entityID,
ObjectOptions< N > && options )
static

Add all components required to create a simulated object to an entity in a registry.

Parameters
registryentity registry containing the given entity.
resourcesresource registry of the simulation. Must contain all resources added by addRequiredResources().
entityIDhandle to the entity to add the components to.
optionsconfiguration of the object to create, see ObjectOptions.
Exceptions
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
If any of the components to be added are already present, they are left unmodified, except for InverseMass and InversePrincipalMomentsOfInertia, which are recalculated if they are infinite.
The added components are:
See also
addRequiredResources()
removeObjectComponents()

◆ removeObjectComponents()

template<size_t N>
void grem::physics::Simulation< N >::removeObjectComponents ( EntityRegistry< N > & registry,
EntityID entityID )
staticnoexcept

Remove all components added by addObjectComponents() from an entity in a registry.

Parameters
registryentity registry containing the given entity.
entityIDhandle to the entity to remove the components from.
See also
addObjectComponents()

◆ updateObjectMomentOfInertiaTensor() [1/2]

template<size_t N>
void grem::physics::Simulation< N >::updateObjectMomentOfInertiaTensor ( EntityRegistry< N > & registry,
const ResourceRegistry< N > & resources,
EntityID objectID )
static

Update the MomentOfInertiaTensor<N> and InverseMomentOfInertiaTensor<N> components of an object given its current orientation in the world.

Parameters
registryentity registry containing the given entity.
resourcesresource registry of the simulation. Must contain all resources added by addRequiredResources().
objectIDhandle to the object entity to update the moment of inertia tensor of.
See also
addRequiredResources()

◆ updateObjectBounds() [1/2]

template<size_t N>
void grem::physics::Simulation< N >::updateObjectBounds ( EntityRegistry< N > & registry,
const ResourceRegistry< N > & resources,
EntityID objectID )
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.

Parameters
registryentity registry containing the given entity.
resourcesresource registry of the simulation. Must contain all resources added by addRequiredResources().
objectIDhandle to the object entity to update the bounds of.
Note
This function automatically sets the object's broadphase handle to null to indicate that it needs to be reinserted into the broadphase on the next broadphase update.
See also
addRequiredResources()
updateBroadphase()

◆ updateBroadphase() [1/2]

template<size_t N>
void grem::physics::Simulation< N >::updateBroadphase ( EntityRegistry< N > & registry,
ResourceRegistry< N > & resources )
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.

Parameters
registryentity registry containing the objects of the world.
resourcesresource registry containing the broadphase to update. Must contain all resources added by addRequiredResources().
Note
A broadphase update is performed automatically at the start of each simulation step, but it may need to be done manually if objects are updated after a simulation step, and the application depends on the broadphase being up-to-date for those objects at some point before the next step is performed.
See also
addRequiredResources()
scheduleBroadphaseUpdate()

◆ addGenericJointComponents()

template<size_t N>
void grem::physics::Simulation< N >::addGenericJointComponents ( EntityRegistry< N > & registry,
const ResourceRegistry< N > & resources,
EntityID entityID,
Pair< EntityID > objectIDs,
const GenericJointOptions< N > & options )
static

Add all components required to create a simulated generic joint that connects two objects to an entity in a registry.

Parameters
registryentity registry containing the given entity.
resourcesresource registry of the simulation. Must contain all resources added by addRequiredResources().
entityIDhandle to the entity to add the components to.
objectIDsordered pair of handles to the two object entities to connect with the joint.
optionsconfiguration of the joint to create, see GenericJointOptions.
Exceptions
physics::Errorif the object IDs are not valid for the given registry.
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
If any of the components to be added are already present, they are left unmodified.
The components of the joint entity are:
See also
addRequiredResources()
addWeldComponents()
addHingeJointComponents()
addBallJointComponents()
addPrismaticJointComponents()
addCylinderJointComponents()
removeJointComponents()

◆ addWeldComponents()

template<size_t N>
void grem::physics::Simulation< N >::addWeldComponents ( EntityRegistry< N > & registry,
const ResourceRegistry< N > & resources,
EntityID entityID,
Pair< EntityID > objectIDs,
const WeldOptions< N > & options = {} )
static

Add all components required to create a simulated weld joint that restricts all motion between two objects to an entity in a registry.

Parameters
registryentity registry containing the given entity.
resourcesresource registry of the simulation. Must contain all resources added by addRequiredResources().
entityIDhandle to the entity to add the components to.
objectIDsordered pair of handles to the two object entities to connect with the joint.
optionsconfiguration of the joint to create, see WeldOptions.
Exceptions
physics::Errorif the object IDs are not valid for the given registry.
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
If any of the components to be added are already present, they are left unmodified.
See also
addRequiredResources()
addGenericJointComponents()
removeJointComponents()

◆ addHingeJointComponents()

template<size_t N>
void grem::physics::Simulation< N >::addHingeJointComponents ( EntityRegistry< N > & registry,
const ResourceRegistry< N > & resources,
EntityID entityID,
Pair< EntityID > objectIDs,
const HingeJointOptions< N > & options = {} )
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.

Parameters
registryentity registry containing the given entity.
resourcesresource registry of the simulation. Must contain all resources added by addRequiredResources().
entityIDhandle to the entity to add the components to.
objectIDsordered pair of handles to the two object entities to connect with the joint.
optionsconfiguration of the joint to create, see HingeJointOptions.
Exceptions
physics::Errorif the object IDs are not valid for the given registry.
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
If any of the components to be added are already present, they are left unmodified.
See also
addRequiredResources()
addGenericJointComponents()
removeJointComponents()

◆ addBallJointComponents()

template<size_t N>
void grem::physics::Simulation< N >::addBallJointComponents ( EntityRegistry< N > & registry,
const ResourceRegistry< N > & resources,
EntityID entityID,
Pair< EntityID > objectIDs,
const BallJointOptions< N > & options = {} )
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.

Parameters
registryentity registry containing the given entity.
resourcesresource registry of the simulation. Must contain all resources added by addRequiredResources().
entityIDhandle to the entity to add the components to.
objectIDsordered pair of handles to the two object entities to connect with the joint.
optionsconfiguration of the joint to create, see BallJointOptions.
Exceptions
physics::Errorif the object IDs are not valid for the given registry.
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
If any of the components to be added are already present, they are left unmodified.
See also
addRequiredResources()
addGenericJointComponents()
removeJointComponents()

◆ addPrismaticJointComponents()

template<size_t N>
void grem::physics::Simulation< N >::addPrismaticJointComponents ( EntityRegistry< N > & registry,
const ResourceRegistry< N > & resources,
EntityID entityID,
Pair< EntityID > objectIDs,
const PrismaticJointOptions< N > & options = {} )
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.

Parameters
registryentity registry containing the given entity.
resourcesresource registry of the simulation. Must contain all resources added by addRequiredResources().
entityIDhandle to the entity to add the components to.
objectIDsordered pair of handles to the two object entities to connect with the joint.
optionsconfiguration of the joint to create, see PrismaticJointOptions.
Exceptions
physics::Errorif the object IDs are not valid for the given registry.
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
If any of the components to be added are already present, they are left unmodified.
See also
addRequiredResources()
addGenericJointComponents()
removeJointComponents()

◆ addCylinderJointComponents()

template<size_t N>
void grem::physics::Simulation< N >::addCylinderJointComponents ( EntityRegistry< N > & registry,
const ResourceRegistry< N > & resources,
EntityID entityID,
Pair< EntityID > objectIDs,
const CylinderJointOptions< N > & options = {} )
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.

Parameters
registryentity registry containing the given entity.
resourcesresource registry of the simulation. Must contain all resources added by addRequiredResources().
entityIDhandle to the entity to add the components to.
objectIDsordered pair of handles to the two object entities to connect with the joint.
optionsconfiguration of the joint to create, see CylinderJointOptions.
Exceptions
physics::Errorif the object IDs are not valid for the given registry.
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
If any of the components to be added are already present, they are left unmodified.
See also
addRequiredResources()
addGenericJointComponents()
removeJointComponents()

◆ removeJointComponents()

template<size_t N>
void grem::physics::Simulation< N >::removeJointComponents ( EntityRegistry< N > & registry,
EntityID entityID )
staticnoexcept

Remove all components added by addGenericJointComponents() from an entity in a registry.

Parameters
registryentity registry containing the given entity.
entityIDhandle to the entity to remove the components from.
See also
addGenericJointComponents()
addWeldComponents()
addHingeJointComponents()
addBallJointComponents()
addPrismaticJointComponents()
addCylinderJointComponents()

◆ scheduleStep()

template<size_t N>
void grem::physics::Simulation< N >::scheduleStep ( Scheduler< N > & scheduler,
const SimulationOptions< N > & simulationOptions,
const ScheduleStepOptions< N > & scheduleStepOptions = {} )
static

Schedule a full step of the physics simulation.

Parameters
schedulerscheduler to schedule the simulation step on.
simulationOptionsconfiguration options of the simulation that the schedule will be executed on.
scheduleStepOptionsstep scheduling options, see ScheduleStepOptions.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
The given schedule should typically be executed once every tick during the application::Application::tick() callback, using the application's tick interval as the step interval.
The given simulationOptions must match the current simulation options when the schedule is executed.
Warning
A schedule containing a simulation step can only be executed given a resource registry containing all of the required resources added by addRequiredResources().
See also
addRequiredResources()

◆ scheduleBroadphaseUpdate()

template<size_t N>
void grem::physics::Simulation< N >::scheduleBroadphaseUpdate ( Scheduler< N > & scheduler,
const SimulationOptions< N > & simulationOptions )
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.

Parameters
schedulerscheduler to schedule the simulation step on.
simulationOptionsconfiguration options of the simulation that the schedule will be executed on.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
All object bounds should be up-to-date before executing a broadphase update.
Warning
A schedule containing a broadphase update can only be executed given a resource registry containing all of the required resources added by addRequiredResources().
See also
addRequiredResources()
updateBroadphase()

◆ scheduleCollisionDetection()

template<size_t N>
void grem::physics::Simulation< N >::scheduleCollisionDetection ( Scheduler< N > & scheduler,
const SimulationOptions< N > & simulationOptions )
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.

Parameters
schedulerscheduler to schedule the simulation step on.
simulationOptionsconfiguration options of the simulation that the schedule will be executed on.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
A broadphase update should be scheduled before collision detection for accurate results.
Warning
A schedule containing a simulation step can only be executed given a resource registry containing all of the required resources added by addRequiredResources().
See also
addRequiredResources()

◆ drawDebugVisualization() [1/2]

template<size_t N>
void grem::physics::Simulation< N >::drawDebugVisualization ( DebugVisualization< N > & debugVisualization,
const EntityRegistry< N > & registry,
const ResourceRegistry< N > & resources )
static

Get the debug visualization of the current simulation state.

Parameters
debugVisualizationdebug visualization to append the draw commands to.
registryentity registry containing the entities involved in the simulation.
resourcesresource registry containing the resources required by the simulation.
See also
addRequiredResources()

◆ createObject()

template<size_t N>
EntityBuilder< N > grem::physics::Simulation< N >::createObject ( ObjectOptions< N > && options,
EntityID::Flags flags = {} )
inlinenodiscard

Create a new simulated object entity and add it to the simulation.

Parameters
optionsconfiguration of the object to create, see ObjectOptions.
flagsuser-defined flags to add to the ID of the created entity.
Exceptions
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Returns
an entity builder for building the object entity. To finish creating the object, call EntityBuilder::build().
Note
See addObjectComponents() for a list of components added to the new entity, which can be accessed through the simulation's registry member.
To destroy the object, call registry.destroyEntity(entityID) on the registry of the simulation, where entityID is the entity handle returned from EntityBuilder::build().

◆ updateObjectMomentOfInertiaTensor() [2/2]

template<size_t N>
void grem::physics::Simulation< N >::updateObjectMomentOfInertiaTensor ( EntityID objectID)
inline

Update the MomentOfInertiaTensor<N> and InverseMomentOfInertiaTensor<N> components of an object given its current orientation in the world.

Parameters
objectIDhandle to the object entity to update the moment of inertia tensor of.

◆ updateObjectBounds() [2/2]

template<size_t N>
void grem::physics::Simulation< N >::updateObjectBounds ( EntityID objectID)
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.

Parameters
objectIDhandle to the object entity to update the bounds of.
Note
This function automatically sets the object's broadphase handle to null to indicate that it needs to be reinserted into the broadphase on the next broadphase update.
See also
updateBroadphase()

◆ updateBroadphase() [2/2]

template<size_t N>
void grem::physics::Simulation< N >::updateBroadphase ( )
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.

Note
A broadphase update is performed automatically at the start of each simulation step, but it may need to be done manually if objects are updated after a simulation step, and the application depends on the broadphase being up-to-date for those objects at some point before the next step is performed.

◆ createGenericJoint()

template<size_t N>
EntityBuilder< N > grem::physics::Simulation< N >::createGenericJoint ( Pair< EntityID > objectIDs,
const GenericJointOptions< N > & options,
EntityID::Flags flags = {} )
inlinenodiscard

Create a new simulated generic joint entity that connects two objects.

Parameters
objectIDsordered pair of handles to the two object entities to connect with the joint.
optionsconfiguration of the joint to create, see GenericJointOptions.
flagsuser-defined flags to add to the ID of the created entity.
Returns
an entity builder for building the joint entity. To finish creating the joint, call EntityBuilder::build().
Exceptions
physics::Errorif the object IDs are not valid for this simulation.
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
See addGenericJointComponents() for a list of components added to the new entity, which can be accessed through the simulation's registry member.
To destroy the joint, call registry.destroyEntity(entityID) on the registry of the simulation, where entityID is the entity handle returned from EntityBuilder::build().
See also
createWeld()
createHingeJoint()
createBallJoint()
createPrismaticJoint()
createCylinderJoint()

◆ createWeld()

template<size_t N>
EntityBuilder< N > grem::physics::Simulation< N >::createWeld ( Pair< EntityID > objectIDs,
const WeldOptions< N > & options = {},
EntityID::Flags flags = {} )
inlinenodiscard

Create a new simulated weld joint entity that restricts all motion between two objects.

Parameters
objectIDsordered pair of handles to the two object entities to connect with the joint.
optionsconfiguration of the joint to create, see WeldOptions.
flagsuser-defined flags to add to the ID of the created entity.
Returns
an entity builder for building the joint entity. To finish creating the joint, call EntityBuilder::build().
Exceptions
physics::Errorif the object IDs are not valid for this simulation.
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
To destroy the joint, call registry.destroyEntity(entityID) on the registry of the simulation, where entityID is the entity handle returned from EntityBuilder::build().
See also
createGenericJoint()

◆ createHingeJoint()

template<size_t N>
EntityBuilder< N > grem::physics::Simulation< N >::createHingeJoint ( Pair< EntityID > objectIDs,
const HingeJointOptions< N > & options = {},
EntityID::Flags flags = {} )
inlinenodiscard

Create a new simulated hinge joint entity that restricts the linear motion between and aligns the X axes of two objects.

Parameters
objectIDsordered pair of handles to the two object entities to connect with the joint.
optionsconfiguration of the joint to create, see HingeJointOptions.
flagsuser-defined flags to add to the ID of the created entity.
Returns
an entity builder for building the joint entity. To finish creating the joint, call EntityBuilder::build().
Exceptions
physics::Errorif the object IDs are not valid for this simulation.
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
To destroy the joint, call registry.destroyEntity(entityID) on the registry of the simulation, where entityID is the entity handle returned from EntityBuilder::build().
See also
createGenericJoint()

◆ createBallJoint()

template<size_t N>
EntityBuilder< N > grem::physics::Simulation< N >::createBallJoint ( Pair< EntityID > objectIDs,
const BallJointOptions< N > & options = {},
EntityID::Flags flags = {} )
inlinenodiscard

Create a new simulated ball joint entity that restricts the linear motion between two objects.

Parameters
objectIDsordered pair of handles to the two object entities to connect with the joint.
optionsconfiguration of the joint to create, see BallJointOptions.
flagsuser-defined flags to add to the ID of the created entity.
Returns
an entity builder for building the joint entity. To finish creating the joint, call EntityBuilder::build().
Exceptions
physics::Errorif the object IDs are not valid for this simulation.
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
To destroy the joint, call registry.destroyEntity(entityID) on the registry of the simulation, where entityID is the entity handle returned from EntityBuilder::build().
See also
createGenericJoint()

◆ createPrismaticJoint()

template<size_t N>
EntityBuilder< N > grem::physics::Simulation< N >::createPrismaticJoint ( Pair< EntityID > objectIDs,
const PrismaticJointOptions< N > & options = {},
EntityID::Flags flags = {} )
inlinenodiscard

Create a new simulated prismatic joint entity that restricts the angular motion between and aligns the X and Y axes of two objects.

Parameters
objectIDsordered pair of handles to the two object entities to connect with the joint.
optionsconfiguration of the joint to create, see PrismaticJointOptions.
flagsuser-defined flags to add to the ID of the created entity.
Returns
an entity builder for building the joint entity. To finish creating the joint, call EntityBuilder::build().
Exceptions
physics::Errorif the object IDs are not valid for this simulation.
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
To destroy the joint, call registry.destroyEntity(entityID) on the registry of the simulation, where entityID is the entity handle returned from EntityBuilder::build().
See also
createGenericJoint()

◆ createCylinderJoint()

template<size_t N>
EntityBuilder< N > grem::physics::Simulation< N >::createCylinderJoint ( Pair< EntityID > objectIDs,
const CylinderJointOptions< N > & options = {},
EntityID::Flags flags = {} )
inlinenodiscard

Create a new simulated cylindrical joint that restricts the angular motion between and aligns the X axes of two objects.

Parameters
objectIDsordered pair of handles to the two object entities to connect with the joint.
optionsconfiguration of the joint to create, see CylinderJointOptions.
flagsuser-defined flags to add to the ID of the created entity.
Returns
an entity builder for building the joint entity. To finish creating the joint, call EntityBuilder::build().
Exceptions
physics::Errorif the object IDs are not valid for this simulation.
execution::Erroron failure to add the components.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
To destroy the joint, call registry.destroyEntity(entityID) on the registry of the simulation, where entityID is the entity handle returned from EntityBuilder::build().
See also
createGenericJoint()

◆ step() [1/2]

template<size_t N>
void grem::physics::Simulation< N >::step ( execution::Executor & executor)

Perform a step of the physics simulation using a specific executor.

Parameters
executorexecutor to execute the step schedule on.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by custom tasks in the simulation's step schedule.
Note
When creating a Simulation, its SimulationOptions::targetParallelism value should roughly correspond to the executor.getMaxParallelism() value of the executor given here to make sure its tasks are distributed across an appropriate number of threads.

◆ step() [2/2]

template<size_t N>
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.

Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by custom tasks in the simulation's step schedule.
Note
When creating a Simulation with the intent of using this basic sequential step() overload, the simulation's SimulationOptions::targetParallelism value should ideally be set to 1 to prevent unnecessary task chunking.

◆ drawDebugVisualization() [2/2]

template<size_t N>
void grem::physics::Simulation< N >::drawDebugVisualization ( DebugVisualization< N > & debugVisualization) const
inline

Get the debug visualization of the current simulation state.

Parameters
debugVisualizationdebug visualization to append the draw commands to.

Member Data Documentation

◆ registry

template<size_t N>
EntityRegistry<N> grem::physics::Simulation< N >::registry {}

Entity registry of the simulation.

◆ resources

template<size_t N>
ResourceRegistry<N> grem::physics::Simulation< N >::resources {}

Resource registry of the simulation.

◆ stepSchedule

template<size_t N>
Schedule<N> grem::physics::Simulation< N >::stepSchedule {}

Schedule for performing one step of the physics simulation.


The documentation for this struct was generated from the following file: