61 inline void MoveKinematic(
Vec3Arg inDeltaPosition,
QuatArg inDeltaRotation,
float inDeltaTime);
76 inline void ClampLinearVelocity();
77 inline void ClampAngularVelocity();
118 void ScaleToMass(
float inMass);
121 inline Mat44 GetLocalSpaceInverseInertia()
const;
124 inline Mat44 GetLocalSpaceInverseInertiaUnchecked()
const;
127 inline Mat44 GetInverseInertiaForRotation(
Mat44Arg inRotation)
const;
130 JPH_INLINE
Vec3 MultiplyWorldSpaceInverseInertiaByVector(
QuatArg inBodyRotation,
Vec3Arg inV)
const;
150 JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sVelocityAccess(), BodyAccess::EAccess::ReadWrite));
151 mLinearVelocity = mAngularVelocity =
Vec3::sZero();
152 mForce = mTorque =
Float3(0, 0, 0);
189#ifdef JPH_TRACK_SIMULATION_STATS
191 struct SimulationStats
193 void Reset() { mBroadPhaseTicks = 0; mNarrowPhaseTicks.store(0, memory_order_relaxed); mVelocityConstraintTicks = 0; mPositionConstraintTicks = 0; mUpdateBoundsTicks = 0; mCCDTicks.store(0, memory_order_relaxed); mNumContactConstraints.store(0, memory_order_relaxed); mNumVelocitySteps = 0; mNumPositionSteps = 0; mIsLargeIsland =
false; }
195 uint64 mBroadPhaseTicks = 0;
196 atomic<uint64> mNarrowPhaseTicks = 0;
197 uint64 mVelocityConstraintTicks = 0;
198 uint64 mPositionConstraintTicks = 0;
199 uint64 mUpdateBoundsTicks = 0;
200 atomic<uint64> mCCDTicks = 0;
201 atomic<uint32> mNumContactConstraints = 0;
202 uint8 mNumVelocitySteps = 0;
203 uint8 mNumPositionSteps = 0;
204 bool mIsLargeIsland =
false;
207 const SimulationStats & GetSimulationStats()
const {
return mSimulationStats; }
208 SimulationStats & GetSimulationStats() {
return mSimulationStats; }
219 inline void AddAngularVelocityStep(
Vec3Arg inAngularVelocityChange) {
JPH_DET_LOG(
"AddAngularVelocityStep: " << inAngularVelocityChange);
JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sVelocityAccess(), BodyAccess::EAccess::ReadWrite)); mAngularVelocity += inAngularVelocityChange;
JPH_ASSERT(!mAngularVelocity.IsNaN()); }
220 inline void SubAngularVelocityStep(
Vec3Arg inAngularVelocityChange) {
JPH_DET_LOG(
"SubAngularVelocityStep: " << inAngularVelocityChange);
JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sVelocityAccess(), BodyAccess::EAccess::ReadWrite)); mAngularVelocity -= inAngularVelocityChange;
JPH_ASSERT(!mAngularVelocity.IsNaN()); }
224 inline void ApplyGyroscopicForceInternal(
QuatArg inBodyRotation,
float inDeltaTime);
227 inline void ApplyForceTorqueAndDragInternal(
QuatArg inBodyRotation,
Vec3Arg inGravity,
float inDeltaTime);
236#ifdef JPH_DOUBLE_PRECISION
241 inline void ResetSleepTestSpheres(
const RVec3 *inPoints);
247 inline ECanSleep AccumulateSleepTime(
float inDeltaTime,
float inTimeBeforeSleep);
265 Vec3 mInvInertiaDiagonal;
266 Quat mInertiaRotation;
270 Float3 mForce { 0, 0, 0 };
271 Float3 mTorque { 0, 0, 0 };
273 float mLinearDamping;
274 float mAngularDamping;
275 float mMaxLinearVelocity;
276 float mMaxAngularVelocity;
277 float mGravityFactor;
278 uint32 mIndexInActiveBodies = cInactiveIndex;
279 uint32 mIslandIndex = cInactiveIndex;
285 uint8 mNumVelocityStepsOverride = 0;
286 uint8 mNumPositionStepsOverride = 0;
290#ifdef JPH_DOUBLE_PRECISION
291 Double3 mSleepTestOffset;
293 Sphere mSleepTestSpheres[3];
294 float mSleepTestTimer;
296#ifdef JPH_ENABLE_ASSERTS
301#ifdef JPH_TRACK_SIMULATION_STATS
302 SimulationStats mSimulationStats;
EAllowedDOFs
Enum used in BodyCreationSettings and MotionProperties to indicate which degrees of freedom a body ha...
Definition AllowedDOFs.h:11
@ RotationX
Body can rotate around world space X axis.
Definition AllowedDOFs.h:17
@ TranslationY
Body can move in world space Y axis.
Definition AllowedDOFs.h:15
@ RotationY
Body can rotate around world space Y axis.
Definition AllowedDOFs.h:18
@ TranslationZ
Body can move in world space Z axis.
Definition AllowedDOFs.h:16
@ All
All degrees of freedom are allowed.
Definition AllowedDOFs.h:13
@ TranslationX
Body can move in world space X axis.
Definition AllowedDOFs.h:14
@ RotationZ
Body can rotate around world space Z axis.
Definition AllowedDOFs.h:19
EBodyType
Type of body.
Definition BodyType.h:11
std::uint8_t uint8
Definition Core.h:501
#define JPH_EXPORT
Definition Core.h:275
std::uint64_t uint64
Definition Core.h:504
unsigned int uint
Definition Core.h:500
#define JPH_NAMESPACE_END
Definition Core.h:425
std::uint32_t uint32
Definition Core.h:503
#define JPH_NAMESPACE_BEGIN
Definition Core.h:419
#define JPH_DET_LOG(...)
By default we log nothing.
Definition DeterminismLog.h:155
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
const Quat QuatArg
Definition MathTypes.h:28
const Vec3 Vec3Arg
Definition MathTypes.h:19
const Mat44 & Mat44Arg
Definition MathTypes.h:29
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:50
ECanSleep
Enum that determines if an object can go to sleep.
Definition MotionProperties.h:22
@ CanSleep
Object can go to sleep.
Definition MotionProperties.h:24
@ CannotSleep
Object cannot go to sleep.
Definition MotionProperties.h:23
EMotionQuality
Motion quality, or how well it detects collisions when it has a high velocity.
Definition MotionQuality.h:11
EMotionType
Motion type of a physics body.
Definition MotionType.h:11
@ Dynamic
Responds to forces as a normal physics object.
Definition MotionType.h:14
Vec3 RVec3
Definition Real.h:29
@ Sphere
Definition Shape.h:79
static JPH_INLINE DVec3 sLoadDouble3Unsafe(const Double3 &inV)
Load 3 doubles from memory (reads 64 bits extra which it doesn't use).
Definition DVec3.inl:160
Class that holds 3 floats. Used as a storage class. Convert to Vec3 for calculations.
Definition Float3.h:13
Describes the mass and inertia properties of a body. Used during body construction only.
Definition MassProperties.h:16
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition Mat44.h:13
The Body class only keeps track of state for static bodies, the MotionProperties class keeps the addi...
Definition MotionProperties.h:29
void SetLinearVelocity(Vec3Arg inLinearVelocity)
Set world space linear velocity of the center of mass.
Definition MotionProperties.h:46
uint32 GetIslandIndexInternal() const
Access to the island index.
Definition MotionProperties.h:230
void ClampAngularVelocity()
Definition MotionProperties.inl:36
void SetNumVelocityStepsOverride(uint inN)
Used only when this body is dynamic and colliding. Override for the number of solver velocity iterati...
Definition MotionProperties.h:182
void SetAngularVelocityClamped(Vec3Arg inAngularVelocity)
Set world space angular velocity of the center of mass, will make sure the value is clamped against t...
Definition MotionProperties.h:58
void ClampLinearVelocity()
Clamp velocity according to limit.
Definition MotionProperties.inl:26
Quat GetInertiaRotation() const
Rotation (R) that takes inverse inertia diagonal to local space: .
Definition MotionProperties.h:108
float GetMaxLinearVelocity() const
Maximum linear velocity that a body can achieve. Used to prevent the system from exploding.
Definition MotionProperties.h:67
JPH_INLINE Vec3 GetPointVelocityCOM(Vec3Arg inPointRelativeToCOM) const
Velocity of point inPoint (in center of mass space, e.g. on the surface of the body) of the body (uni...
Definition MotionProperties.h:133
Vec3 GetInverseInertiaDiagonal() const
Diagonal of inverse inertia matrix: D. Should only be called on a dynamic object (static or kinematic...
Definition MotionProperties.h:105
uint GetNumPositionStepsOverride() const
Definition MotionProperties.h:187
void SetInverseInertia(Vec3Arg inDiagonal, QuatArg inRot)
Definition MotionProperties.h:114
float GetGravityFactor() const
Get gravity factor (1 = normal gravity, 0 = no gravity).
Definition MotionProperties.h:88
friend class BodyManager
Definition MotionProperties.h:258
void AddLinearVelocityStep(Vec3Arg inLinearVelocityChange)
Definition MotionProperties.h:217
float GetMaxAngularVelocity() const
Maximum angular velocity that a body can achieve. Used to prevent the system from exploding.
Definition MotionProperties.h:71
void SetLinearVelocityClamped(Vec3Arg inLinearVelocity)
Set world space linear velocity of the center of mass, will make sure the value is clamped against th...
Definition MotionProperties.h:49
uint GetNumVelocityStepsOverride() const
Definition MotionProperties.h:183
float GetInverseMassUnchecked() const
Definition MotionProperties.h:96
Vec3 GetLinearVelocity() const
Get world space linear velocity of the center of mass.
Definition MotionProperties.h:43
Vec3 GetAngularVelocity() const
Get world space angular velocity of the center of mass.
Definition MotionProperties.h:52
void SetMaxAngularVelocity(float inAngularVelocity)
Definition MotionProperties.h:72
JPH_INLINE Vec3 LockAngular(Vec3Arg inV) const
Takes an angular velocity / torque vector inV and returns a vector where the components that are not ...
Definition MotionProperties.h:176
JPH_INLINE void ResetMotion()
Definition MotionProperties.h:148
JPH_INLINE Vec3 GetAccumulatedTorque() const
Definition MotionProperties.h:139
void SetIslandIndexInternal(uint32 inIndex)
Definition MotionProperties.h:231
float GetAngularDamping() const
Get angular damping: dw/dt = -c * w. c. Value should be zero or positive and is usually close to 0.
Definition MotionProperties.h:84
void SubLinearVelocityStep(Vec3Arg inLinearVelocityChange)
Definition MotionProperties.h:218
friend class Body
Definition MotionProperties.h:259
float GetInverseMass() const
Get inverse mass (1 / mass). Should only be called on a dynamic object (static or kinematic bodies ha...
Definition MotionProperties.h:95
void SetGravityFactor(float inGravityFactor)
Definition MotionProperties.h:89
JPH_INLINE UVec4 GetLinearDOFsMask() const
Returns a vector where the linear components that are not allowed by mAllowedDOFs are set to 0 and th...
Definition MotionProperties.h:156
uint32 GetIndexInActiveBodiesInternal() const
Access to the index in the active bodies array.
Definition MotionProperties.h:234
float GetLinearDamping() const
Get linear damping: dv/dt = -c * v. c. Value should be zero or positive and is usually close to 0.
Definition MotionProperties.h:80
void SubAngularVelocityStep(Vec3Arg inAngularVelocityChange)
Definition MotionProperties.h:220
JPH_INLINE void ResetForce()
Definition MotionProperties.h:142
void SetInverseMass(float inInverseMass)
Definition MotionProperties.h:102
void ResetSleepTestTimer()
Reset the sleep test timer without resetting the sleep test spheres.
Definition MotionProperties.h:244
void SetAngularVelocity(Vec3Arg inAngularVelocity)
Set world space angular velocity of the center of mass.
Definition MotionProperties.h:55
static constexpr uint32 cInactiveIndex
Constant indicating that body is not active.
Definition MotionProperties.h:255
JPH_INLINE Vec3 GetAccumulatedForce() const
Definition MotionProperties.h:136
JPH_INLINE Vec3 LockTranslation(Vec3Arg inV) const
Takes a translation vector inV and returns a vector where the components that are not allowed by mAll...
Definition MotionProperties.h:163
void SetMaxLinearVelocity(float inLinearVelocity)
Definition MotionProperties.h:68
JPH_OVERRIDE_NEW_DELETE EMotionQuality GetMotionQuality() const
Motion quality, or how well it detects collisions when it has a high velocity.
Definition MotionProperties.h:34
void SetLinearDamping(float inLinearDamping)
Definition MotionProperties.h:81
void SetAngularDamping(float inAngularDamping)
Definition MotionProperties.h:85
JPH_INLINE UVec4 GetAngularDOFsMask() const
Returns a vector where the angular components that are not allowed by mAllowedDOFs are set to 0 and t...
Definition MotionProperties.h:169
void SetNumPositionStepsOverride(uint inN)
Used only when this body is dynamic and colliding. Override for the number of solver position iterati...
Definition MotionProperties.h:186
EAllowedDOFs GetAllowedDOFs() const
Get the allowed degrees of freedom that this body has (this can be changed by calling SetMassProperti...
Definition MotionProperties.h:37
bool GetAllowSleeping() const
If this body can go to sleep.
Definition MotionProperties.h:40
void AddAngularVelocityStep(Vec3Arg inAngularVelocityChange)
Definition MotionProperties.h:219
JPH_INLINE void ResetTorque()
Definition MotionProperties.h:145
Definition StateRecorder.h:110
static JPH_INLINE UVec4 sReplicate(uint32 inV)
Replicate int inV across all components.
Definition UVec4.inl:56
static JPH_INLINE UVec4 sAnd(UVec4Arg inV1, UVec4Arg inV2)
Logical and (component wise).
Definition UVec4.inl:202
static JPH_INLINE UVec4 sEquals(UVec4Arg inV1, UVec4Arg inV2)
Equals (component wise).
Definition UVec4.inl:143
JPH_INLINE Vec3 Cross(Vec3Arg inV2) const
Cross product.
Definition Vec3.inl:595
JPH_INLINE float Length() const
Length of vector.
Definition Vec3.inl:682
static JPH_INLINE Vec3 sAnd(Vec3Arg inV1, Vec3Arg inV2)
Logical and (component wise).
Definition Vec3.inl:315
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:103
static JPH_INLINE Vec3 sLoadFloat3Unsafe(const Float3 &inV)
Load 3 floats from memory (reads 32 bits extra which it doesn't use).
Definition Vec3.inl:135