GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
Simulation.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_PHYSICS_SIMULATION_HPP
5#define GREM_PHYSICS_SIMULATION_HPP
6
8
22
23#include <type_traits> // std::conditional_t
24#include <utility> // std::move
25
26namespace grem::execution {
27
28class Executor; // Forward declaration, to avoid including Executor.hpp.
29
30template <typename EntReg, typename ResReg>
31class Scheduler; // Forward declaration, to avoid including Scheduler.hpp.
32
33} // namespace grem::execution
34
35namespace grem::physics {
36
37template <size_t N>
38class DebugVisualization; // Forward declaration, to avoid including DebugVisualization.hpp.
39
40template <size_t N>
41class Broadphase; // Forward declaration, to avoid including Broadphase.hpp.
42
48template <size_t N>
214
220template <size_t N>
221using EntityRegistry = std::conditional_t<N == 3,
223 Force3D, //
224 Torque3D, //
225 Position3D, //
226 Orientation3D, //
227 Scale3D, //
231 FluidDensity, //
233 Volume, //
234 InverseMass, //
239 Collider3D, //
240 Material, //
241 ObjectFlags, //
246 BroadphaseID, //
260 JointFlags3D, //
261 JointActiveTag>, //
263 Force2D, //
264 Torque2D, //
265 Position2D, //
266 Orientation2D, //
267 Scale2D, //
271 FluidDensity, //
273 Volume, //
274 InverseMass, //
279 Collider2D, //
280 Material, //
281 ObjectFlags, //
286 BroadphaseID, //
296 JointFlags2D, //
300
306template <size_t N>
311 Broadphase<N>, //
315
321template <size_t N>
325
331template <size_t N>
335
341template <size_t N>
345
351template <size_t N>
358 };
359
365 };
366
372 };
373
379 };
380
385 FunctionView<void(Scheduler<N>& scheduler)> addPreSolverTasks = [](Scheduler<N>&) -> void {
386 };
387
393 };
394
400 };
401
406 FunctionView<void(Scheduler<N>& scheduler)> addPostSolverTasks = [](Scheduler<N>&) -> void {
407 };
408
414 };
415
421 };
422};
425
434template <size_t N>
464
471 GREM_API(physics) static void removeResources(ResourceRegistry<N>& resources) noexcept;
472
534
544 GREM_API(physics) static void removeObjectComponents(EntityRegistry<N>& registry, EntityID entityID) noexcept;
545
559
579
599
667 GREM_API(physics)
669 const GenericJointOptions<N>& options);
670
697 GREM_API(physics)
699 const WeldOptions<N>& options = {});
700
729 GREM_API(physics)
731 const HingeJointOptions<N>& options = {});
732
761 GREM_API(physics)
763 const BallJointOptions<N>& options = {});
764
793 GREM_API(physics)
795 const PrismaticJointOptions<N>& options = {});
796
825 GREM_API(physics)
827 const CylinderJointOptions<N>& options = {});
828
843 GREM_API(physics) static void removeJointComponents(EntityRegistry<N>& registry, EntityID entityID) noexcept;
844
870 GREM_API(physics) static void scheduleStep(Scheduler<N>& scheduler, const SimulationOptions<N>& simulationOptions, const ScheduleStepOptions<N>& scheduleStepOptions = {});
871
895 GREM_API(physics) static void scheduleBroadphaseUpdate(Scheduler<N>& scheduler, const SimulationOptions<N>& simulationOptions);
896
919 GREM_API(physics) static void scheduleCollisionDetection(Scheduler<N>& scheduler, const SimulationOptions<N>& simulationOptions);
920
934
938
949
962 GREM_API(physics) explicit Simulation(const SimulationOptions<N>& options, const ScheduleStepOptions<N>& scheduleStepOptions = {});
963
978 GREM_API(physics)
979 explicit Simulation(const SimulationOptions<N>& options,
981
1003 [[nodiscard]] EntityBuilder<N> createObject(ObjectOptions<N>&& options, EntityID::Flags flags = {}) {
1004 EntityBuilder<N> entityBuilder = registry.createEntity(flags);
1005 addObjectComponents(entityBuilder.getRegistry(), resources, entityBuilder.getEntityID(), std::move(options));
1006 return entityBuilder;
1007 }
1008
1019
1036 }
1037
1052
1085 [[nodiscard]] EntityBuilder<N> createGenericJoint(Pair<EntityID> objectIDs, const GenericJointOptions<N>& options, EntityID::Flags flags = {}) {
1086 EntityBuilder<N> entityBuilder = registry.createEntity(flags);
1087 addGenericJointComponents(entityBuilder.getRegistry(), resources, entityBuilder.getEntityID(), objectIDs, options);
1088 return entityBuilder;
1089 }
1090
1116 [[nodiscard]] EntityBuilder<N> createWeld(Pair<EntityID> objectIDs, const WeldOptions<N>& options = {}, EntityID::Flags flags = {}) {
1117 EntityBuilder<N> entityBuilder = registry.createEntity(flags);
1118 addWeldComponents(entityBuilder.getRegistry(), resources, entityBuilder.getEntityID(), objectIDs, options);
1119 return entityBuilder;
1120 }
1121
1148 [[nodiscard]] EntityBuilder<N> createHingeJoint(Pair<EntityID> objectIDs, const HingeJointOptions<N>& options = {}, EntityID::Flags flags = {}) {
1149 EntityBuilder<N> entityBuilder = registry.createEntity(flags);
1150 addHingeJointComponents(entityBuilder.getRegistry(), resources, entityBuilder.getEntityID(), objectIDs, options);
1151 return entityBuilder;
1152 }
1153
1180 [[nodiscard]] EntityBuilder<N> createBallJoint(Pair<EntityID> objectIDs, const BallJointOptions<N>& options = {}, EntityID::Flags flags = {}) {
1181 EntityBuilder<N> entityBuilder = registry.createEntity(flags);
1182 addBallJointComponents(entityBuilder.getRegistry(), resources, entityBuilder.getEntityID(), objectIDs, options);
1183 return entityBuilder;
1184 }
1185
1212 [[nodiscard]] EntityBuilder<N> createPrismaticJoint(Pair<EntityID> objectIDs, const PrismaticJointOptions<N>& options = {}, EntityID::Flags flags = {}) {
1213 EntityBuilder<N> entityBuilder = registry.createEntity(flags);
1214 addPrismaticJointComponents(entityBuilder.getRegistry(), resources, entityBuilder.getEntityID(), objectIDs, options);
1215 return entityBuilder;
1216 }
1217
1244 [[nodiscard]] EntityBuilder<N> createCylinderJoint(Pair<EntityID> objectIDs, const CylinderJointOptions<N>& options = {}, EntityID::Flags flags = {}) {
1245 EntityBuilder<N> entityBuilder = registry.createEntity(flags);
1246 addCylinderJointComponents(entityBuilder.getRegistry(), resources, entityBuilder.getEntityID(), objectIDs, options);
1247 return entityBuilder;
1248 }
1249
1267 GREM_API(physics) void step(execution::Executor& executor);
1268
1284 GREM_API(physics) void step();
1285
1292 void drawDebugVisualization(DebugVisualization<N>& debugVisualization) const {
1293 drawDebugVisualization(debugVisualization, registry, resources);
1294 }
1295};
1296
1297extern template struct Simulation<2>;
1298extern template struct Simulation<3>;
1299
1308
1317
1318} // namespace grem::physics
1319
1320#endif
Definition FunctionView.hpp:29
static GREM_ALWAYS_INLINE unsigned int hardware_concurrency() noexcept
Definition Thread.hpp:113
Temporary reference to an incomplete entity that is currently being built inside of an EntityRegistry...
Definition EntityRegistry.hpp:2033
GREM_ALWAYS_INLINE EntityID getEntityID() const noexcept
Get the entity handle of the entity being built.
Definition EntityRegistry.hpp:2096
GREM_ALWAYS_INLINE EntReg & getRegistry() noexcept
Get the underlying entity registry containing the entity being built.
Definition EntityRegistry.hpp:2078
uint16_t Flags
User-defined flags type.
Definition EntityRegistry.hpp:76
Dynamic container of entities with stable EntityID handles and associated component instances,...
Definition EntityRegistry.hpp:2323
Interface to a pool of execution resources (e.g. threads) for executing ad-hoc parallel tasks and pre...
Definition Executor.hpp:34
Dynamic container of singleton resource instances, available to tasks defined through a Scheduler.
Definition ResourceRegistry.hpp:43
Statically scheduled task graph built by a Scheduler.
Definition Schedule.hpp:35
Statically scheduled task graph builder.
Definition Scheduler.hpp:386
ParallelIndex ParallelCount
Number of a parallel sub-tasks.
Definition Task.hpp:36
Acceleration structure for spatial queries in a simulation.
Definition Broadphase.hpp:57
Set of contacts in a Simulation.
Definition collision.hpp:938
Bundle of draw commands for drawing debugging information about a Simulation.
Definition DebugVisualization.hpp:46
Definition Chunk.hpp:19
Definition Broadphase.hpp:24
JointAttachmentOrientations< 2 > JointAttachmentOrientations2D
Local orientations of the attachment frames of the objects connected by a joint in a 2-dimensional wo...
Definition joints.hpp:76
Length1D Distance
Scalar length quantity.
Definition quantities.hpp:4962
Collider< 2 > Collider2D
Generic collider in 2-dimensional space.
Definition Shape.hpp:2816
JointLinearConstraintImpulses< 2 > JointLinearConstraintImpulses2D
Impulse applied by the linear limits of a joint in a 2-dimensional world.
Definition joints.hpp:188
JointAngularConstraintImpulses< 2 > JointAngularConstraintImpulses2D
Impulse applied by the angular limits of a joint in a 2-dimensional world.
Definition joints.hpp:411
JointFlags< 3 > JointFlags3D
Set of boolean properties of a joint in a 3-dimensional world.
Definition joints.hpp:593
Force< 2 > Force2D
Force in 2-dimensional space. Unit: Newton (AKA kilogram meters per second squared).
Definition quantities.hpp:5695
JointFlags< 2 > JointFlags2D
Set of boolean properties of a joint in a 2-dimensional world.
Definition joints.hpp:592
AngularVelocity< 2 > AngularVelocity2D
Angular velocity in 2-dimensional space. Unit: Radians per second.
Definition quantities.hpp:5947
EntityRegistry< 3 > EntityRegistry3D
Entity registry used by a 3-dimensional Simulation.
Definition Simulation.hpp:299
JointAttachmentOffsets< 3 > JointAttachmentOffsets3D
Local offsets of the attachment frames of the objects connected by a joint in a 3-dimensional world.
Definition joints.hpp:61
Quantity< 1, RadiansPerSecond > AngularSpeed
Scalar angular speed quantity.
Definition quantities.hpp:5955
Simulation< 3 > Simulation3D
Discrete-time simulation of physical interactions between objects and joints in 3-dimensional space.
Definition Simulation.hpp:1316
ScheduleStepOptions< 2 > ScheduleStepOptions2D
Options for scheduling a step of a 2-dimensional Simulation.
Definition Simulation.hpp:423
MomentOfInertiaTensor< 3 > MomentOfInertiaTensor3D
Tensor of moment of inertia quantities in 3-dimensional space. Unit: Kilogram square meters.
Definition quantities.hpp:5826
SimulationOptions< 3 > SimulationOptions3D
Configuration options for a 3-dimensional Simulation.
Definition Simulation.hpp:213
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL clamp(Quantity< N1, UnitT1 > a, Quantity< N2, UnitT2 > b, Quantity< N3, UnitT3 > c)
Definition quantities.hpp:3020
execution::Scheduler< EntityRegistry< N >, ResourceRegistry< N > > Scheduler
Scheduler used by a Simulation.
Definition Simulation.hpp:332
float Scalar
Underlying scalar type of physics quantity components.
Definition quantities.hpp:1480
EntityBuilder< 3 > EntityBuilder3D
Entity builder used by a 3-dimensional Simulation.
Definition Simulation.hpp:324
JointAngularConstraint< 2 > JointAngularConstraint2D
Angular limits of a joint in a 2-dimensional world.
Definition joints.hpp:362
JointLinearConstraint< 3 > JointLinearConstraint3D
Linear limits of a joint in a 3-dimensional world.
Definition joints.hpp:140
execution::Schedule< EntityRegistry< N >, ResourceRegistry< N > > Schedule
Schedule used by a Simulation.
Definition Simulation.hpp:342
LocalInertiaOrientation< 2 > LocalInertiaOrientation2D
Local inertia orientation of an object in 2-dimensional space. Unit: Radians.
Definition quantities.hpp:5885
Orientation< 2 > Orientation2D
Absolute orientation in 2-dimensional space. Unit: Radians.
Definition quantities.hpp:4592
Orientation< 3 > Orientation3D
Absolute orientation in 3-dimensional space. Unit: Radians.
Definition quantities.hpp:4593
JointAttachmentOrientations< 3 > JointAttachmentOrientations3D
Local orientations of the attachment frames of the objects connected by a joint in a 3-dimensional wo...
Definition joints.hpp:77
InverseMomentOfInertiaTensor< 2 > InverseMomentOfInertiaTensor2D
Tensor of inverse moment of inertia quantities in 2-dimensional space. Unit: Per kilogram square mete...
Definition quantities.hpp:5849
Schedule< 3 > Schedule3D
Schedule used by a 3-dimensional Simulation.
Definition Simulation.hpp:344
Quantity< 1, CubicMeters > Volume
Scalar volume quantity.
Definition quantities.hpp:5539
Quantity< 1, Seconds > Time
Scalar relative time duration quantity.
Definition quantities.hpp:5518
LinearAcceleration< 2 > LinearAcceleration2D
Linear acceleration in 2-dimensional space. Unit: Meters per second squared.
Definition quantities.hpp:5662
Quantity< 1, PerKilogram > InverseMass
Scalar inverse mass quantity.
Definition quantities.hpp:5511
Force< 3 > Force3D
Force in 3-dimensional space. Unit: Newton (AKA kilogram meters per second squared).
Definition quantities.hpp:5696
Scale< 3 > Scale3D
Dimensionless scale in 3-dimensional space. Unitless.
Definition quantities.hpp:3987
InverseMomentOfInertiaTensor< 3 > InverseMomentOfInertiaTensor3D
Tensor of inverse moment of inertia quantities in 3-dimensional space. Unit: Per kilogram square mete...
Definition quantities.hpp:5850
AngularMomentum< 2 > AngularMomentum2D
Angular momentum in 2-dimensional space. Unit: kilogram square meters per second.
Definition quantities.hpp:6056
JointAngularConstraintImpulses< 3 > JointAngularConstraintImpulses3D
Impulse applied by the angular limits of a joint in a 3-dimensional world.
Definition joints.hpp:412
LinearMomentum1D Momentum
Scalar linear momentum quantity.
Definition quantities.hpp:5790
MomentOfInertiaTensor< 2 > MomentOfInertiaTensor2D
Tensor of moment of inertia quantities in 2-dimensional space. Unit: Kilogram square meters.
Definition quantities.hpp:5825
AngularVelocity< 3 > AngularVelocity3D
Angular velocity in 3-dimensional space. Unit: Radians per second.
Definition quantities.hpp:5948
ObjectBounds< 3 > ObjectBounds3D
Bounds of a 3-dimensional object.
Definition objects.hpp:245
execution::EntityID EntityID
Opaque handle to a specific entity in a Simulation's EntityRegistry.
Definition EntityID.hpp:16
JointAttachmentOffsets< 2 > JointAttachmentOffsets2D
Local offsets of the attachment frames of the objects connected by a joint in a 2-dimensional world.
Definition joints.hpp:60
ObjectBounds< 2 > ObjectBounds2D
Bounds of a 2-dimensional object.
Definition objects.hpp:244
Schedule< 2 > Schedule2D
Schedule used by a 2-dimensional Simulation.
Definition Simulation.hpp:343
CenterOfBuoyancy< 2 > CenterOfBuoyancy2D
World-space offset of the center of buoyancy of an object in a 2-dimensional world.
Definition objects.hpp:55
Scheduler< 3 > Scheduler3D
Scheduler used by a 3-dimensional Simulation.
Definition Simulation.hpp:334
LinearVelocity1D Speed
Scalar linear velocity quantity.
Definition quantities.hpp:5631
Scale1D Coefficient
Unitless scalar quantity.
Definition quantities.hpp:3988
EntityRegistry< 2 > EntityRegistry2D
Entity registry used by a 2-dimensional Simulation.
Definition Simulation.hpp:298
JointAngularConstraint< 3 > JointAngularConstraint3D
Angular limits of a joint in a 3-dimensional world.
Definition joints.hpp:363
LinearVelocity< 2 > LinearVelocity2D
Linear velocity in 2-dimensional space. Unit: Meters per second.
Definition quantities.hpp:5620
execution::EntityBuilder< EntityRegistry< N > > EntityBuilder
Entity builder used by a Simulation.
Definition Simulation.hpp:322
execution::ResourceRegistry< SimulationOptions< N >, CollisionEvents< N >, SeparationEvents< N >, Broadphase< N >, Contacts< N > > ResourceRegistry
Resource registry used by a Simulation.
Definition Simulation.hpp:307
Torque< 3 > Torque3D
Torque in 3-dimensional space. Unit: Newton meters (AKA kilogram square meters per second squared).
Definition quantities.hpp:5720
EntityBuilder< 2 > EntityBuilder2D
Entity builder used by a 2-dimensional Simulation.
Definition Simulation.hpp:323
JointDistanceConstraintImpulses< 3 > JointDistanceConstraintImpulses3D
Impulse applied by the distance limit of a joint in a 3-dimensional world.
Definition joints.hpp:300
Scheduler< 2 > Scheduler2D
Scheduler used by a 2-dimensional Simulation.
Definition Simulation.hpp:333
LocalInertiaOrientation< 3 > LocalInertiaOrientation3D
Local inertia orientation of an object in 3-dimensional space. Unit: Radians.
Definition quantities.hpp:5886
ResourceRegistry< 2 > ResourceRegistry2D
Resource registry used by a 2-dimensional Simulation.
Definition Simulation.hpp:313
InversePrincipalMomentsOfInertia< 2 > InversePrincipalMomentsOfInertia2D
Inverse principal moments of inertia in 2-dimensional inertia major axis space. Unit: Per kilogram sq...
Definition quantities.hpp:5897
ObjectContacts< 2 > ObjectContacts2D
Potential contacts of a 2-dimensional object.
Definition objects.hpp:177
std::conditional_t< N==3, execution::EntityRegistry< Force3D, Torque3D, Position3D, Orientation3D, Scale3D, LinearVelocity3D, AngularVelocity3D, LinearAcceleration3D, FluidDensity, CenterOfBuoyancy3D, Volume, InverseMass, InversePrincipalMomentsOfInertia3D, LocalInertiaOrientation3D, MomentOfInertiaTensor3D, InverseMomentOfInertiaTensor3D, Collider3D, Material, ObjectFlags, ObjectContacts3D, ObjectBounds3D, ObjectActivity, ObjectActiveTag, BroadphaseID, JointConnectedObjects, JointAttachmentOffsets3D, JointAttachmentOrientations3D, JointLinearConstraint3D, JointLinearConstraintImpulses3D, JointDistanceConstraint3D, JointDistanceConstraintImpulses3D, JointAngularConstraint3D, JointAngularConstraintImpulses3D, JointConeConstraint3D, JointConeConstraintImpulses3D, JointTwistConstraint3D, JointTwistConstraintImpulses3D, JointFlags3D, JointActiveTag >, execution::EntityRegistry< Force2D, Torque2D, Position2D, Orientation2D, Scale2D, LinearVelocity2D, AngularVelocity2D, LinearAcceleration2D, FluidDensity, CenterOfBuoyancy2D, Volume, InverseMass, InversePrincipalMomentsOfInertia2D, LocalInertiaOrientation2D, MomentOfInertiaTensor2D, InverseMomentOfInertiaTensor2D, Collider2D, Material, ObjectFlags, ObjectContacts2D, ObjectBounds2D, ObjectActivity, ObjectActiveTag, BroadphaseID, JointConnectedObjects, JointAttachmentOffsets2D, JointAttachmentOrientations2D, JointLinearConstraint2D, JointLinearConstraintImpulses2D, JointDistanceConstraint2D, JointDistanceConstraintImpulses2D, JointAngularConstraint2D, JointAngularConstraintImpulses2D, JointFlags2D, JointActiveTag > > EntityRegistry
Entity registry used by a Simulation.
Definition Simulation.hpp:221
JointDistanceConstraintImpulses< 2 > JointDistanceConstraintImpulses2D
Impulse applied by the distance limit of a joint in a 2-dimensional world.
Definition joints.hpp:299
JointDistanceConstraint< 3 > JointDistanceConstraint3D
Distance limit of a joint in a 3-dimensional world.
Definition joints.hpp:248
Position< 3 > Position3D
Absolute position in 3-dimensional space. Unit: Meters.
Definition quantities.hpp:4952
Rate1D Frequency
Scalar frequency quantity.
Definition quantities.hpp:5576
JointLinearConstraintImpulses< 3 > JointLinearConstraintImpulses3D
Impulse applied by the linear limits of a joint in a 3-dimensional world.
Definition joints.hpp:189
ObjectContacts< 3 > ObjectContacts3D
Potential contacts of a 3-dimensional object.
Definition objects.hpp:178
CenterOfBuoyancy< 3 > CenterOfBuoyancy3D
World-space offset of the center of buoyancy of an object in a 3-dimensional world.
Definition objects.hpp:56
LinearVelocity< 3 > LinearVelocity3D
Linear velocity in 3-dimensional space. Unit: Meters per second.
Definition quantities.hpp:5621
Quantity< 1, Radians > Angle
Angle quantity.
Definition quantities.hpp:4019
SimulationOptions< 2 > SimulationOptions2D
Configuration options for a 2-dimensional Simulation.
Definition Simulation.hpp:212
LinearAcceleration< 3 > LinearAcceleration3D
Linear acceleration in 3-dimensional space. Unit: Meters per second squared.
Definition quantities.hpp:5663
Collider< 3 > Collider3D
Generic collider in 3-dimensional space.
Definition Shape.hpp:2817
Torque< 2 > Torque2D
Torque in 2-dimensional space. Unit: Newton meters (AKA kilogram square meters per second squared).
Definition quantities.hpp:5719
JointLinearConstraint< 2 > JointLinearConstraint2D
Linear limits of a joint in a 2-dimensional world.
Definition joints.hpp:139
JointDistanceConstraint< 2 > JointDistanceConstraint2D
Distance limit of a joint in a 2-dimensional world.
Definition joints.hpp:247
Position< 2 > Position2D
Absolute position in 2-dimensional space. Unit: Meters.
Definition quantities.hpp:4951
Simulation< 2 > Simulation2D
Discrete-time simulation of physical interactions between objects and joints in 2-dimensional space.
Definition Simulation.hpp:1307
Scale< 2 > Scale2D
Dimensionless scale in 2-dimensional space. Unitless.
Definition quantities.hpp:3986
InversePrincipalMomentsOfInertia< 3 > InversePrincipalMomentsOfInertia3D
Inverse principal moments of inertia in 3-dimensional inertia major axis space. Unit: Per kilogram sq...
Definition quantities.hpp:5899
ScheduleStepOptions< 3 > ScheduleStepOptions3D
Options for scheduling a step of a 3-dimensional Simulation.
Definition Simulation.hpp:424
ResourceRegistry< 3 > ResourceRegistry3D
Resource registry used by a 3-dimensional Simulation.
Definition Simulation.hpp:314
Definition Pair.hpp:53
Configuration options for a spherical joint.
Definition joints.hpp:781
Opaque handle to an entity in a Broadphase.
Definition Broadphase.hpp:29
Configuration options for a collision algorithm.
Definition collision.hpp:373
List of collision start events between the objects in a Simulation.
Definition collision.hpp:133
Configuration options for a cylindrical joint.
Definition joints.hpp:912
Effective fluid density of an object's surroundings.
Definition objects.hpp:28
Configuration options for a generic joint.
Definition joints.hpp:606
Configuration options for a revolute joint.
Definition joints.hpp:723
Tag component that is added to joints with active connected objects.
Definition joints.hpp:598
Cone-shaped angular limit of a joint in a 3-dimensional world.
Definition joints.hpp:417
Impulse applied by the cone-shaped angular limit of a joint in a 3-dimensional world.
Definition joints.hpp:460
Ordered pair of handles to the objects connected by a joint.
Definition joints.hpp:41
Angular limit of a joint in a 3-dimensional world around the local Y axes of the connected objects' a...
Definition joints.hpp:488
Impulse applied by the angular limit of a joint in a 3-dimensional world around the local Y axes of t...
Definition joints.hpp:541
Properties regarding the dynamics of an object.
Definition objects.hpp:61
Tag component that is added to entities with a non-zero-energy ObjectActivity.
Definition objects.hpp:224
Activity information of an object.
Definition objects.hpp:183
Set of boolean properties of an object.
Definition objects.hpp:153
Configuration options for an object.
Definition objects.hpp:253
Configuration options for a prismatic joint.
Definition joints.hpp:845
Options for scheduling a step of a Simulation.
Definition Simulation.hpp:352
FunctionView< void(Scheduler< N > &scheduler)> addPreSolverTasks
Definition Simulation.hpp:385
FunctionView< void(Scheduler< N > &scheduler)> addPostBroadphaseUpdateTasks
Definition Simulation.hpp:364
FunctionView< void(Scheduler< N > &scheduler)> addPostRestitutionTasks
Definition Simulation.hpp:420
FunctionView< void(Scheduler< N > &scheduler)> addPreBroadphaseUpdateTasks
Definition Simulation.hpp:357
FunctionView< void(Scheduler< N > &scheduler)> addPreSolverIterationTasks
Definition Simulation.hpp:392
FunctionView< void(Scheduler< N > &scheduler)> addPreRestitutionTasks
Definition Simulation.hpp:413
FunctionView< void(Scheduler< N > &scheduler)> addPostCollisionDetectionTasks
Definition Simulation.hpp:378
FunctionView< void(Scheduler< N > &scheduler)> addPostSolverIterationTasks
Definition Simulation.hpp:399
FunctionView< void(Scheduler< N > &scheduler)> addPreCollisionDetectionTasks
Definition Simulation.hpp:371
FunctionView< void(Scheduler< N > &scheduler)> addPostSolverTasks
Definition Simulation.hpp:406
List of collision end events between the objects in a Simulation.
Definition collision.hpp:176
Configuration options for a Simulation.
Definition Simulation.hpp:49
static constexpr size_t MAX_CONTACT_COLOR_COUNT
Definition Simulation.hpp:53
Frequency contactStiffness
Definition Simulation.hpp:182
CollisionAlgorithmOptions< N > collisionAlgorithmOptions
Definition Simulation.hpp:90
size_t subStepCount
Definition Simulation.hpp:77
AngularMomentum2D jointMaxAngularMomentum
Definition Simulation.hpp:203
Coefficient contactDampingRatio
Definition Simulation.hpp:189
AngularSpeed maxRestingAngularSpeed
Definition Simulation.hpp:134
Momentum contactMaxMomentum
Definition Simulation.hpp:210
size_t contactColorCount
Definition Simulation.hpp:85
Coefficient jointWarmstartCoefficient
Definition Simulation.hpp:174
Time restingTimeThreshold
Definition Simulation.hpp:145
Angle maxContactManifoldAngleTolerance
Definition Simulation.hpp:100
Momentum jointMaxMomentum
Definition Simulation.hpp:196
Coefficient contactWarmstartCoefficient
Definition Simulation.hpp:165
Coefficient potentialCollisionVelocitySafetyCoefficient
Definition Simulation.hpp:156
execution::Task::ParallelCount targetParallelism
Definition Simulation.hpp:70
Speed maxRestingSpeed
Definition Simulation.hpp:122
Distance minObjectSizeApproximation
Definition Simulation.hpp:110
Time stepInterval
Definition Simulation.hpp:60
Discrete-time simulation of physical interactions between objects and joints.
Definition Simulation.hpp:435
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,...
static void removeObjectComponents(EntityRegistry< N > &registry, EntityID entityID) noexcept
Remove all components added by addObjectComponents() from an entity in a registry.
static void removeResources(ResourceRegistry< N > &resources) noexcept
Remove all resources required to run a simulation from a resource registry.
static void scheduleCollisionDetection(Scheduler< N > &scheduler, const SimulationOptions< N > &simulationOptions)
Schedule a standalone collision detection pass, separate from a full simulation step,...
void updateObjectMomentOfInertiaTensor(EntityID objectID)
Update the MomentOfInertiaTensor<N> and InverseMomentOfInertiaTensor<N> components of an object given...
Definition Simulation.hpp:1016
static void addWeldComponents(EntityRegistry< N > &registry, const ResourceRegistry< N > &resources, EntityID entityID, Pair< EntityID > objectIDs, const WeldOptions< N > &options={})
static void addPrismaticJointComponents(EntityRegistry< N > &registry, const ResourceRegistry< N > &resources, EntityID entityID, Pair< EntityID > objectIDs, const PrismaticJointOptions< N > &options={})
void step(execution::Executor &executor)
Perform a step of the physics simulation using a specific executor.
Schedule< N > stepSchedule
Definition Simulation.hpp:937
void step()
Perform a step of the physics simulation using a basic sequential executor that runs directly on the ...
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 addRequiredResources(ResourceRegistry< N > &resources, const SimulationOptions< N > &options={})
Add all resources required to run a simulation to a resource registry, reassigning them to their defa...
void updateObjectBounds(EntityID objectID)
Update the ObjectBounds<N> component of an object given its current shape, local center of mass,...
Definition Simulation.hpp:1034
EntityBuilder< N > createGenericJoint(Pair< EntityID > objectIDs, const GenericJointOptions< N > &options, EntityID::Flags flags={})
Create a new simulated generic joint entity that connects two objects.
Definition Simulation.hpp:1085
EntityBuilder< N > createObject(ObjectOptions< N > &&options, EntityID::Flags flags={})
Definition Simulation.hpp:1003
static void drawDebugVisualization(DebugVisualization< N > &debugVisualization, const EntityRegistry< N > &registry, const ResourceRegistry< N > &resources)
Get the debug visualization of the current simulation state.
static void addGenericJointComponents(EntityRegistry< N > &registry, const ResourceRegistry< N > &resources, EntityID entityID, Pair< EntityID > objectIDs, const GenericJointOptions< N > &options)
static void removeJointComponents(EntityRegistry< N > &registry, EntityID entityID) noexcept
Remove all components added by addGenericJointComponents() from an entity in a registry.
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.
Definition Simulation.hpp:1180
EntityRegistry< N > registry
Definition Simulation.hpp:935
void drawDebugVisualization(DebugVisualization< N > &debugVisualization) const
Get the debug visualization of the current simulation state.
Definition Simulation.hpp:1292
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.
Definition Simulation.hpp:1116
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 a...
Definition Simulation.hpp:1244
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 th...
Definition Simulation.hpp:1212
static void addBallJointComponents(EntityRegistry< N > &registry, const ResourceRegistry< N > &resources, EntityID entityID, Pair< EntityID > objectIDs, const BallJointOptions< N > &options={})
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 a...
Definition Simulation.hpp:1148
static void scheduleStep(Scheduler< N > &scheduler, const SimulationOptions< N > &simulationOptions, const ScheduleStepOptions< N > &scheduleStepOptions={})
Schedule a full step of the physics simulation.
static void updateObjectMomentOfInertiaTensor(EntityRegistry< N > &registry, const ResourceRegistry< N > &resources, EntityID objectID)
Update the MomentOfInertiaTensor<N> and InverseMomentOfInertiaTensor<N> components of an object given...
Simulation(const SimulationOptions< N > &options, const ScheduleStepOptions< N > &scheduleStepOptions={})
Construct a physics simulation with all required resources added.
static void addCylinderJointComponents(EntityRegistry< N > &registry, const ResourceRegistry< N > &resources, EntityID entityID, Pair< EntityID > objectIDs, const CylinderJointOptions< N > &options={})
Simulation()
Construct a physics simulation with all required resources added, using the default SimulationOptions...
Definition Simulation.hpp:947
ResourceRegistry< N > resources
Definition Simulation.hpp:936
static void scheduleBroadphaseUpdate(Scheduler< N > &scheduler, const SimulationOptions< N > &simulationOptions)
Schedule a standalone broadphase update pass, separate from a full simulation step,...
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 ...
static void addHingeJointComponents(EntityRegistry< N > &registry, const ResourceRegistry< N > &resources, EntityID entityID, Pair< EntityID > objectIDs, const HingeJointOptions< N > &options={})
void updateBroadphase()
Update the broadphase structure of a simulation by inserting all objects with a broadphase handle of ...
Definition Simulation.hpp:1049
Configuration options for a fully constrained joint.
Definition joints.hpp:683