4#ifndef GREM_PHYSICS_OBJECTS_HPP
5#define GREM_PHYSICS_OBJECTS_HPP
218 [[nodiscard]] constexpr
bool operator==(const
ObjectActivity& other) const noexcept = default;
391 switch (frictionCombine) {
414 switch (frictionCombine) {
437 switch (frictionCombine) {
461 switch (restitutionCombine) {
493 return (inverseMass == 0) ? Mass::INF :
Mass{
Scalar{1} / inverseMass};
541 return (inverseMomentOfInertia == 0) ? MomentOfInertia2D::INF :
MomentOfInertia2D{
Scalar{1} / inverseMomentOfInertia};
581 if constexpr (N == 3) {
583 if (result[index] == 0) {
584 result[index] = PrincipalMomentsOfInertia2D::INF;
608 (void)localInertiaOrientation;
610 if (
isinf(principalMomentsOfInertia)) {
611 principalMomentsOfInertia = {};
630 if (
isinf(principalMomentsOfInertia[index])) {
631 principalMomentsOfInertia[index] = {};
653 (void)localInertiaOrientation;
655 if (
isinf(inversePrincipalMomentsOfInertia)) {
656 inversePrincipalMomentsOfInertia = {};
676 if (
isinf(inversePrincipalMomentsOfInertia[index])) {
677 inversePrincipalMomentsOfInertia[index] = {};
711 const InverseMass inverseEffectiveMassA = inverseMassA +
dot(momentArmA, inverseMomentOfInertiaTensorA * momentArmA);
712 const InverseMass inverseEffectiveMassB = inverseMassB +
dot(momentArmB, inverseMomentOfInertiaTensorB * momentArmB);
713 const InverseMass combinedInverseEffectiveMass = inverseEffectiveMassA + inverseEffectiveMassB;
714 const Mass combinedEffectiveMass =
select(
equal(combinedInverseEffectiveMass, 0),
Mass{},
inverse(combinedInverseEffectiveMass));
715 return combinedEffectiveMass;
748 return combinedEffectiveMasses;
769 const InverseMomentOfInertia2D combinedInverseEffectiveMomentOfInertia = inverseEffectiveMomentOfInertiaA + inverseEffectiveMomentOfInertiaB;
772 return combinedEffectiveMomentOfInertia;
791 (combinedInverseEffectiveMomentOfInertiaTensor == 0)
793 :
inverse(combinedInverseEffectiveMomentOfInertiaTensor);
794 return combinedEffectiveMomentOfInertiaTensor;
811 return linearVelocity +
cross(angularVelocity, offset);
830 linearVelocity += inverseMass * impulse;
831 angularVelocity += inverseMomentOfInertiaTensor *
cross(offset, impulse);
858 applyImpulse<N>(linearVelocity, angularVelocity, inverseMass, inverseMomentOfInertiaTensor, impulse, offset);
872 linearVelocity += inverseMass * linearImpulse;
909 angularVelocity += inverseMomentOfInertiaTensor * angularImpulse;
Definition SmallArrayList.hpp:26
Concept that checks if a type is a valid shape type.
Definition Shape.hpp:1227
Definition Broadphase.hpp:24
void applyLinearImpulse(LinearVelocity< N > &linearVelocity, InverseMass inverseMass, LinearImpulse< N > linearImpulse)
Apply a world-space linear impulse to an object's velocity at its center of mass.
Definition objects.hpp:871
LinearVelocity< N > calculatePointVelocity(LinearVelocity< N > linearVelocity, AngularVelocity< N > angularVelocity, Length< N > offset)
Calculate the linear velocity of a point on an object with linear and angular velocity.
Definition objects.hpp:810
void applyCorrectionImpulse(ObjectActivity &activity, LinearVelocity< N > &linearVelocity, AngularVelocity< N > &angularVelocity, InverseMass inverseMass, const InverseMomentOfInertiaTensor< N > &inverseMomentOfInertiaTensor, LinearImpulse< N > impulse, Length< N > offset)
Apply a world-space impulse to an object's velocity, making it active and marking it as corrected,...
Definition objects.hpp:853
Quantity< N, MetersPerSecondSquared > LinearAcceleration
Linear acceleration quantity.
Definition quantities.hpp:5660
Mass calculateCombinedEffectiveMassAlongAxis(InverseMass inverseMassA, InverseMass inverseMassB, const InverseMomentOfInertiaTensor< N > &inverseMomentOfInertiaTensorA, const InverseMomentOfInertiaTensor< N > &inverseMomentOfInertiaTensorB, Length< N > offsetA, Length< N > offsetB, Direction< N > axis)
Calculate the combined effective mass of two points on two different objects along a given axis.
Definition objects.hpp:706
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL cross(A a, B b)
Definition quantities.hpp:3239
Coefficient calculateCombinedRollingResistance(Coefficient rollingResistanceA, Coefficient rollingResistanceB, Material::FrictionCombine frictionCombineA, Material::FrictionCombine frictionCombineB)
Combine the rolling resistance of two objects based on their friction combination modes.
Definition objects.hpp:434
GREM_ALWAYS_INLINE OrthonormalBasis2D rotate(RollRotation r)
Definition quantities.hpp:4723
AngularQuantity< N, NewtonMeterSeconds > AngularImpulse
Angular impulse quantity.
Definition quantities.hpp:6029
MomentOfInertiaTensor< 3 > MomentOfInertiaTensor3D
Tensor of moment of inertia quantities in 3-dimensional space. Unit: Kilogram square meters.
Definition quantities.hpp:5826
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL midpoint(A a, B b)
Definition quantities.hpp:3497
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL min(Quantity< N1, UnitT1 > a, Quantity< N2, UnitT2 > b)
Definition quantities.hpp:2982
float Scalar
Underlying scalar type of physics quantity components.
Definition quantities.hpp:1480
Quantity< N, NewtonSeconds > LinearImpulse
Linear impulse quantity.
Definition quantities.hpp:5742
Coefficient calculateCombinedKineticFriction(Coefficient kineticFrictionA, Coefficient kineticFrictionB, Material::FrictionCombine frictionCombineA, Material::FrictionCombine frictionCombineB)
Combine the kinetic friction of two objects based on their friction combination modes.
Definition objects.hpp:411
LocalInertiaOrientation< 2 > LocalInertiaOrientation2D
Local inertia orientation of an object in 2-dimensional space. Unit: Radians.
Definition quantities.hpp:5885
Direction< 3 > Direction3D
Normalized unit vector in 3-dimensional space. Unitless.
Definition quantities.hpp:4152
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
GREM_ALWAYS_INLINE constexpr auto transpose(const TensorQuantity< N, UnitT > &a)
Definition quantities.hpp:3870
GREM_ALWAYS_INLINE constexpr auto inverse(Quantity< N, UnitT > a)
Definition quantities.hpp:3860
Basis< 3 > Basis3D
Basis matrix in 3-dimensional space. Unitless.
Definition quantities.hpp:4000
InverseMomentOfInertiaTensor< 2 > InverseMomentOfInertiaTensor2D
Tensor of inverse moment of inertia quantities in 2-dimensional space. Unit: Per kilogram square mete...
Definition quantities.hpp:5849
Quantity< 1, PerKilogram > InverseMass
Scalar inverse mass quantity.
Definition quantities.hpp:5511
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(const Shape< N > &shape, Mass mass)
Calculate the principal moments of inertia of an object given its shape and mass.
Definition objects.hpp:573
void applyAngularCorrectionImpulse(ObjectActivity &activity, AngularVelocity< N > &angularVelocity, const InverseMomentOfInertiaTensor< N > &inverseMomentOfInertiaTensor, AngularImpulse< N > angularImpulse)
Apply a world-space angular impulse to an object's velocity at its center of mass,...
Definition objects.hpp:928
void applyLinearCorrectionImpulse(ObjectActivity &activity, LinearVelocity< N > &linearVelocity, InverseMass inverseMass, LinearImpulse< N > linearImpulse)
Apply a world-space linear impulse to an object's velocity at its center of mass, making it active an...
Definition objects.hpp:889
MomentOfInertia2D calculateCombinedEffectiveMomentOfInertiaAroundAxis(const InverseMomentOfInertiaTensor3D &inverseMomentOfInertiaTensorA, const InverseMomentOfInertiaTensor3D &inverseMomentOfInertiaTensorB, Direction3D axis)
Calculate the combined effective moment of inertia of two objects around a given axis.
Definition objects.hpp:765
InverseMomentOfInertiaTensor< 3 > InverseMomentOfInertiaTensor3D
Tensor of inverse moment of inertia quantities in 3-dimensional space. Unit: Per kilogram square mete...
Definition quantities.hpp:5850
constexpr Direction< N > Y_AXIS
The Y axis in the space with the given number of dimensions.
Definition quantities.hpp:4897
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL select(auto condition, A ifTrue, B ifFalse)
Definition quantities.hpp:3437
MomentOfInertiaTensor< 2 > MomentOfInertiaTensor2D
Tensor of moment of inertia quantities in 2-dimensional space. Unit: Kilogram square meters.
Definition quantities.hpp:5825
ObjectBounds< 3 > ObjectBounds3D
Bounds of a 3-dimensional object.
Definition objects.hpp:245
ObjectOptions< 3 > ObjectOptions3D
Configuration options for an object in a 3-dimensional world.
Definition objects.hpp:375
ObjectBounds< 2 > ObjectBounds2D
Bounds of a 2-dimensional object.
Definition objects.hpp:244
MomentOfInertia< 3 > MomentOfInertia3D
Moment of inertia in 3-dimensional space. Unit: Kilogram square meters.
Definition quantities.hpp:5814
Coefficient calculateCombinedRestitution(Coefficient restitutionA, Coefficient restitutionB, Material::RestitutionCombine restitutionCombineA, Material::RestitutionCombine restitutionCombineB)
Combine the restitution of two objects based on their restitution combination modes.
Definition objects.hpp:457
GREM_ALWAYS_INLINE auto GREM_VECTORCALL isinf(A a)
Definition quantities.hpp:3129
Quantity< 1, Kilograms > Mass
Scalar mass quantity.
Definition quantities.hpp:5504
void applyImpulse(LinearVelocity< N > &linearVelocity, AngularVelocity< N > &angularVelocity, InverseMass inverseMass, const InverseMomentOfInertiaTensor< N > &inverseMomentOfInertiaTensor, LinearImpulse< N > impulse, Length< N > offset)
Apply a world-space impulse to an object's velocity.
Definition objects.hpp:828
CenterOfBuoyancy< 2 > CenterOfBuoyancy2D
World-space offset of the center of buoyancy of an object in a 2-dimensional world.
Definition objects.hpp:55
Scale1D Coefficient
Unitless scalar quantity.
Definition quantities.hpp:3988
AngularTensorQuantity< N, PerKilogramSquareMeter > InverseMomentOfInertiaTensor
Tensor of inverse moment of inertia quantities.
Definition quantities.hpp:5848
MomentOfInertiaTensor2D calculateMomentOfInertiaTensor(PrincipalMomentsOfInertia2D principalMomentsOfInertia, LocalInertiaOrientation2D localInertiaOrientation, Orientation2D orientation)
Calculate the world-space moment of inertia tensor of an object given its principal moments of inerti...
Definition objects.hpp:606
GREM_ALWAYS_INLINE TensorQuantity< N, UnitT > rotateScale(Orientation< N > r, Quantity< N, UnitT > s)
Definition quantities.hpp:4757
InverseMomentOfInertiaTensor2D calculateInverseMomentOfInertiaTensor(InversePrincipalMomentsOfInertia2D inversePrincipalMomentsOfInertia, LocalInertiaOrientation2D localInertiaOrientation, Orientation2D orientation)
Calculate the world-space inverse moment of inertia tensor of an object given its inverse principal m...
Definition objects.hpp:651
Quantity< N, Meters > Length
Relative distance/length offset quantity.
Definition quantities.hpp:4924
Coefficient calculateCombinedStaticFriction(Coefficient staticFrictionA, Coefficient staticFrictionB, Material::FrictionCombine frictionCombineA, Material::FrictionCombine frictionCombineB)
Combine the static friction of two objects based on their friction combination modes.
Definition objects.hpp:388
Mass calculateMass(InverseMass inverseMass)
Calculate the mass of a given inverse mass, while accounting for 0 and infinity.
Definition objects.hpp:492
LocalInertiaOrientation< 3 > LocalInertiaOrientation3D
Local inertia orientation of an object in 3-dimensional space. Unit: Radians.
Definition quantities.hpp:5886
InversePrincipalMomentsOfInertia< 2 > InversePrincipalMomentsOfInertia2D
Inverse principal moments of inertia in 2-dimensional inertia major axis space. Unit: Per kilogram sq...
Definition quantities.hpp:5897
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL dot(A a, B b)
Definition quantities.hpp:3234
AngularQuantity< N, RadiansPerSecond > AngularVelocity
Angular velocity quantity.
Definition quantities.hpp:5946
void applyAngularImpulse(AngularVelocity< N > &angularVelocity, const InverseMomentOfInertiaTensor< N > &inverseMomentOfInertiaTensor, AngularImpulse< N > angularImpulse)
Apply a world-space angular impulse to an object's velocity at its center of mass.
Definition objects.hpp:908
ObjectContacts< 2 > ObjectContacts2D
Potential contacts of a 2-dimensional object.
Definition objects.hpp:177
InverseMass calculateInverseMass(Mass mass)
Calculate the inverse mass of a given mass, while accounting for 0 and infinity.
Definition objects.hpp:479
TensorQuantity< N, Meters > MomentArmTensor
Tensor of moment arm quantities.
Definition quantities.hpp:5922
PrincipalMomentsOfInertia< 3 > PrincipalMomentsOfInertia3D
Principal moments of inertia in 3-dimensional inertia major axis space. Unit: kilogram square meters.
Definition quantities.hpp:5862
Quantity< 1, KilogramsPerCubicMeter > Density
Scalar density quantity.
Definition quantities.hpp:5553
Quantity< N, Absolute< Meters > > Position
Absolute position in world space.
Definition quantities.hpp:4949
Quantity< N, Unitless > Scale
Dimensionless scale.
Definition quantities.hpp:3984
MomentOfInertia< 2 > MomentOfInertia2D
Moment of inertia in 2-dimensional space. Unit: Kilogram square meters.
Definition quantities.hpp:5813
InverseMomentOfInertia< 2 > InverseMomentOfInertia2D
Inverse moment of inertia in 2-dimensional space. Unit: Kilogram square meters.
Definition quantities.hpp:5837
Quantity< N, Mass::Unit > calculateCombinedEffectiveMassesAlongAxes(InverseMass inverseMassA, InverseMass inverseMassB, const InverseMomentOfInertiaTensor< N > &inverseMomentOfInertiaTensorA, const InverseMomentOfInertiaTensor< N > &inverseMomentOfInertiaTensorB, Length< N > offsetA, Length< N > offsetB, OrthonormalBasis< N > axes)
Calculate the combined effective mass of two points on two different objects along each axis of a giv...
Definition objects.hpp:739
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
AngularTensorQuantity< N, KilogramSquareMeters > MomentOfInertiaTensor
Tensor of moment of inertia quantities.
Definition quantities.hpp:5824
PrincipalMomentsOfInertia< 2 > PrincipalMomentsOfInertia2D
Principal moments of inertia in 2-dimensional inertia major axis space. Unit: kilogram square meters.
Definition quantities.hpp:5861
ObjectOptions< 2 > ObjectOptions2D
Configuration options for an object in a 2-dimensional world.
Definition objects.hpp:374
Quantity< N, MetersPerSecond > LinearVelocity
Linear velocity quantity.
Definition quantities.hpp:5618
MomentOfInertia2D calculateMomentOfInertia(InverseMomentOfInertia2D inverseMomentOfInertia)
Calculate the moment of inertia of a given inverse moment of inertia, while accounting for 0 and infi...
Definition objects.hpp:540
InverseMomentOfInertia< 3 > InverseMomentOfInertia3D
Inverse moment of inertia in 3-dimensional space. Unit: Kilogram square meters.
Definition quantities.hpp:5838
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL max(Quantity< N1, UnitT1 > a, Quantity< N2, UnitT2 > b)
Definition quantities.hpp:3001
InverseMomentOfInertia2D calculateInverseMomentOfInertia(MomentOfInertia2D momentOfInertia)
Calculate the inverse moment of inertia of a given moment of inertia, while accounting for 0 and infi...
Definition objects.hpp:506
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL equal(A a, B b)
Definition quantities.hpp:3527
InversePrincipalMomentsOfInertia< 3 > InversePrincipalMomentsOfInertia3D
Inverse principal moments of inertia in 3-dimensional inertia major axis space. Unit: Per kilogram sq...
Definition quantities.hpp:5899
AngularQuantity< N, KilogramSquareMeters > PrincipalMomentsOfInertia
Principal moments of inertia in inertia major axis space.
Definition quantities.hpp:5860
AngularQuantity< N, Meters > MomentArm
Moment arm quantity.
Definition quantities.hpp:5910
MomentOfInertiaTensor< N > calculateCombinedEffectiveMomentOfInertiaTensor(const InverseMomentOfInertiaTensor< N > &inverseMomentOfInertiaTensorA, const InverseMomentOfInertiaTensor< N > &inverseMomentOfInertiaTensorB)
Calculate the combined effective moment of inertia tensor of two objects.
Definition objects.hpp:787
void unreachable()
Definition assertions.hpp:125
GREM_ALWAYS_INLINE qua< T > GREM_VECTORCALL rotation(vec< 3, T > from, vec< 3, T > to)
Definition math.hpp:3214
constexpr Multiply MULTIPLY
Definition algorithms.hpp:92
Description of an axis-aligned box in world space.
Definition Shape.hpp:813
World-space offset of the center of buoyancy of an object.
Definition objects.hpp:45
constexpr bool operator==(const CenterOfBuoyancy &other) const noexcept=default
Compare this value to another for equality.
Generic collider.
Definition Shape.hpp:2812
Normalized unit vector.
Definition quantities.hpp:4105
Effective fluid density of an object's surroundings.
Definition objects.hpp:28
constexpr bool operator==(const FluidDensity &other) const noexcept=default
Compare this value to another for equality.
Local inertia orientation of an object, rotating from inertia major axis space to shape-local space.
Definition quantities.hpp:5873
Properties regarding the dynamics of an object.
Definition objects.hpp:61
RestitutionCombine restitutionCombine
How to combine the restitution when this object collides with another.
Definition objects.hpp:138
Coefficient kineticFriction
Coefficient of kinetic friction of the object.
Definition objects.hpp:100
Coefficient linearDrag
Linear drag coefficient of the object.
Definition objects.hpp:121
Coefficient restitution
Coefficient of restitution of the object.
Definition objects.hpp:114
FrictionCombine
Friction combination mode.
Definition objects.hpp:68
@ MULTIPLY
The two values are multiplied with each other.
Definition objects.hpp:72
@ MAXIMUM
The largest of the two values is used.
Definition objects.hpp:71
@ AVERAGE
The two values are averaged.
Definition objects.hpp:69
@ MINIMUM
The smallest of the two values is used.
Definition objects.hpp:70
RestitutionCombine
Restitution combination mode.
Definition objects.hpp:81
@ MULTIPLY
The two values are multiplied with each other.
Definition objects.hpp:85
@ MAXIMUM
The largest of the two values is used.
Definition objects.hpp:84
@ AVERAGE
The two values are averaged.
Definition objects.hpp:82
@ MINIMUM
The smallest of the two values is used.
Definition objects.hpp:83
Coefficient staticFriction
Coefficient of static friction of the object.
Definition objects.hpp:93
Coefficient rollingResistance
Coefficient of rolling resistance of the object.
Definition objects.hpp:107
FrictionCombine frictionCombine
How to combine the friction when this object collides with another.
Definition objects.hpp:133
Coefficient angularDrag
Angular drag coefficient of the object.
Definition objects.hpp:128
constexpr bool operator==(const Material &other) const noexcept=default
Compare this material to another for equality.
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
bool wasCorrected
Had a correction impulse applied since the start of the last simulation step where it was active.
Definition objects.hpp:193
constexpr ObjectActivity() noexcept=default
Construct the default object activity.
bool isCorrectable
May be affected by the constraint solver.
Definition objects.hpp:187
bool isActive
Currently considered active (moving) in the simulation.
Definition objects.hpp:198
uint16_t stepsResting
Number of consecutive simulation steps that have passed where the object was below resting speed.
Definition objects.hpp:204
Bounds of an object.
Definition objects.hpp:232
Box< N > boundingBox
Definition objects.hpp:233
constexpr bool operator==(const ObjectBounds &other) const noexcept=default
Compare these bounds to another for equality.
Set of boolean properties of an object.
Definition objects.hpp:153
bool emitsCollisionEvents
Emit collision events.
Definition objects.hpp:154
constexpr bool operator==(const ObjectFlags &other) const noexcept=default
Compare these flags to another set of flags for equality.
bool emitsSeparationEvents
Emit separation events.
Definition objects.hpp:155
bool enableResting
Decay the object's velocity towards 0 on when below the resting threshold.
Definition objects.hpp:156
Configuration options for an object.
Definition objects.hpp:253
Collider< N > collider
Definition objects.hpp:340
Orientation< N > orientation
Definition objects.hpp:262
bool operator==(const ObjectOptions &other) const =default
Compare this set of options to another set for equality.
Density surroundingFluidDensity
Definition objects.hpp:292
PrincipalMomentsOfInertia< N > principalMomentsOfInertia
Definition objects.hpp:330
Material material
Definition objects.hpp:345
Scale< N > scale
Definition objects.hpp:267
LocalInertiaOrientation< N > localInertiaOrientation
Definition objects.hpp:335
bool emitsSeparationEvents
Definition objects.hpp:355
Position< N > position
Definition objects.hpp:257
AngularVelocity< N > angularVelocity
Definition objects.hpp:277
bool enableResting
Definition objects.hpp:363
LinearVelocity< N > linearVelocity
Definition objects.hpp:272
LinearAcceleration< N > gravityAcceleration
Definition objects.hpp:283
bool emitsCollisionEvents
Definition objects.hpp:350
Length< N > centerOfBuoyancy
Definition objects.hpp:298
Mass mass
Definition objects.hpp:314
Absolute orientation in world space.
Definition quantities.hpp:4431
Basis whose columns are all unit vectors that are orthogonal to each other.
Definition quantities.hpp:4338
Point shape.
Definition Shape.hpp:1427
Physical quantity type.
Definition quantities.hpp:1504
Generic shape.
Definition Shape.hpp:2471