46 inline bool IsRigidBody()
const {
return mBodyType == EBodyType::RigidBody; }
49 inline bool IsSoftBody()
const {
return mBodyType == EBodyType::SoftBody; }
54 inline bool IsActive()
const {
return mMotionProperties !=
nullptr && mMotionProperties->mIndexInActiveBodies != cInactiveIndex; }
57 inline bool IsStatic()
const {
return mMotionType == EMotionType::Static; }
60 inline bool IsKinematic()
const {
return mMotionType == EMotionType::Kinematic; }
63 inline bool IsDynamic()
const {
return mMotionType == EMotionType::Dynamic; }
73 inline void SetIsSensor(
bool inIsSensor) {
JPH_ASSERT(IsRigidBody());
if (inIsSensor) mFlags.fetch_or(
uint8(EFlags::IsSensor), memory_order_relaxed);
else mFlags.fetch_and(
uint8(~
uint8(EFlags::IsSensor)), memory_order_relaxed); }
76 inline bool IsSensor()
const {
return (mFlags.load(memory_order_relaxed) &
uint8(EFlags::IsSensor)) != 0; }
81 inline void SetCollideKinematicVsNonDynamic(
bool inCollide) {
JPH_ASSERT(IsRigidBody());
if (inCollide) mFlags.fetch_or(
uint8(EFlags::CollideKinematicVsNonDynamic), memory_order_relaxed);
else mFlags.fetch_and(
uint8(~
uint8(EFlags::CollideKinematicVsNonDynamic)), memory_order_relaxed); }
90 inline void SetUseManifoldReduction(
bool inUseReduction) {
JPH_ASSERT(IsRigidBody());
if (inUseReduction) mFlags.fetch_or(
uint8(EFlags::UseManifoldReduction), memory_order_relaxed);
else mFlags.fetch_and(
uint8(~
uint8(EFlags::UseManifoldReduction)), memory_order_relaxed); }
96 inline bool GetUseManifoldReductionWithBody(
const Body &inBody2)
const {
return ((mFlags.load(memory_order_relaxed) & inBody2.mFlags.load(memory_order_relaxed)) &
uint8(EFlags::UseManifoldReduction)) != 0; }
99 inline void SetApplyGyroscopicForce(
bool inApply) {
JPH_ASSERT(IsRigidBody());
if (inApply) mFlags.fetch_or(
uint8(EFlags::ApplyGyroscopicForce), memory_order_relaxed);
else mFlags.fetch_and(
uint8(~
uint8(EFlags::ApplyGyroscopicForce)), memory_order_relaxed); }
132 void SetAllowSleeping(
bool inAllow);
135 inline void ResetSleepTimer();
201 inline Mat44 GetInverseInertia()
const;
205 inline void AddImpulse(
Vec3Arg inImpulse);
213 inline void AddAngularImpulse(
Vec3Arg inAngularImpulse);
217 void MoveKinematic(
RVec3Arg inTargetPosition,
QuatArg inTargetRotation,
float inDeltaTime);
230 bool ApplyBuoyancyImpulse(
RVec3Arg inSurfacePosition,
Vec3Arg inSurfaceNormal,
float inBuoyancy,
float inLinearDrag,
float inAngularDrag,
Vec3Arg inFluidVelocity,
Vec3Arg inGravity,
float inDeltaTime);
233 inline bool IsInBroadPhase()
const {
return (mFlags.load(memory_order_relaxed) &
uint8(EFlags::IsInBroadPhase)) != 0; }
242 inline RVec3 GetPosition()
const {
JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess(), BodyAccess::EAccess::Read));
return mPosition - mRotation * mShape->GetCenterOfMass(); }
245 inline Quat GetRotation()
const {
JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess(), BodyAccess::EAccess::Read));
return mRotation; }
248 inline RMat44 GetWorldTransform()
const;
254 inline RMat44 GetCenterOfMassTransform()
const;
257 inline RMat44 GetInverseCenterOfMassTransform()
const;
294 static inline bool sFindCollidingPairsCanCollide(
const Body &inBody1,
const Body &inBody2);
297 inline void AddPositionStep(
Vec3Arg inLinearVelocityTimesDeltaTime) {
JPH_ASSERT(IsRigidBody());
JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess(), BodyAccess::EAccess::ReadWrite)); mPosition += mMotionProperties->LockTranslation(inLinearVelocityTimesDeltaTime);
JPH_ASSERT(!mPosition.IsNaN()); }
298 inline void SubPositionStep(
Vec3Arg inLinearVelocityTimesDeltaTime) {
JPH_ASSERT(IsRigidBody());
JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess(), BodyAccess::EAccess::ReadWrite)); mPosition -= mMotionProperties->LockTranslation(inLinearVelocityTimesDeltaTime);
JPH_ASSERT(!mPosition.IsNaN()); }
301 inline void AddRotationStep(
Vec3Arg inAngularVelocityTimesDeltaTime);
302 inline void SubRotationStep(
Vec3Arg inAngularVelocityTimesDeltaTime);
305 inline void SetInBroadPhaseInternal(
bool inInBroadPhase) {
if (inInBroadPhase) mFlags.fetch_or(
uint8(EFlags::IsInBroadPhase), memory_order_relaxed);
else mFlags.fetch_and(
uint8(~
uint8(EFlags::IsInBroadPhase)), memory_order_relaxed); }
314 void CalculateWorldSpaceBoundsInternal();
317 void SetPositionAndRotationInternal(
RVec3Arg inPosition,
QuatArg inRotation,
bool inResetSleepTimer =
true);
322 void UpdateCenterOfMassInternal(
Vec3Arg inPreviousCenterOfMass,
bool inUpdateMassProperties);
327 void SetShapeInternal(
const Shape *inShape,
bool inUpdateMassProperties);
338 ECanSleep UpdateSleepStateInternal(
float inDeltaTime,
float inMaxMovement,
float inTimeBeforeSleep);
361 inline void GetSleepTestPoints(
RVec3 *outPoints)
const;
363 enum class EFlags :
uint8
366 CollideKinematicVsNonDynamic = 1 << 1,
367 IsInBroadPhase = 1 << 2,
368 InvalidateContactCache = 1 << 3,
369 UseManifoldReduction = 1 << 4,
370 ApplyGyroscopicForce = 1 << 5,
371 EnhancedInternalEdgeRemoval = 1 << 6,
397 atomic<uint8> mFlags = 0;
EBodyType
Type of body.
Definition: BodyType.h:11
std::uint8_t uint8
Definition: Core.h:453
std::uint64_t uint64
Definition: Core.h:456
#define JPH_TSAN_NO_SANITIZE
Definition: Core.h:596
#define JPH_NAMESPACE_END
Definition: Core.h:378
std::uint32_t uint32
Definition: Core.h:455
#define JPH_EXPORT_GCC_BUG_WORKAROUND
Definition: Core.h:240
#define JPH_IF_SINGLE_PRECISION_ELSE(s, d)
Definition: Core.h:530
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:372
#define JPH_IF_ENABLE_ASSERTS(...)
Definition: IssueReporting.h:35
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:31
ECanSleep
Enum that determines if an object can go to sleep.
Definition: MotionProperties.h:22
EMotionType
Motion type of a physics body.
Definition: MotionType.h:11
uint16 ObjectLayer
Definition: ObjectLayer.h:16
#define JPH_RVECTOR_ALIGNMENT
Definition: Real.h:34
Axis aligned box.
Definition: AABox.h:16
Settings for constructing a rigid body.
Definition: BodyCreationSettings.h:31
Vec3 GetPointVelocity(RVec3Arg inPoint) const
Velocity of point inPoint (in world space, e.g. on the surface of the body) of the body (unit: m/s)
Definition: Body.h:171
bool IsInBroadPhase() const
Check if this body has been added to the physics system.
Definition: Body.h:233
const MotionProperties * GetMotionProperties() const
Access to the motion properties.
Definition: Body.h:263
RVec3 GetCenterOfMassPosition() const
Gets the world space position of this body's center of mass.
Definition: Body.h:251
EMotionType GetMotionType() const
Get the bodies motion type.
Definition: Body.h:114
void SetAngularVelocity(Vec3Arg inAngularVelocity)
Definition: Body.h:161
void SetCollisionGroup(const CollisionGroup &inGroup)
Definition: Body.h:128
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: Body.h:168
bool IsDynamic() const
Check if this body is dynamic, which means that it moves and forces can act on it.
Definition: Body.h:63
bool GetAllowSleeping() const
If this body can go to sleep. Note that disabling sleeping on a sleeping object will not wake it up.
Definition: Body.h:131
bool IsSensor() const
Check if this body is a sensor.
Definition: Body.h:76
bool GetEnhancedInternalEdgeRemovalWithBody(const Body &inBody2) const
Checks if the combination of this body and inBody2 should use enhanced internal edge removal.
Definition: Body.h:111
const AABox & GetWorldSpaceBounds() const
Get world space bounding box.
Definition: Body.h:260
void SubPositionStep(Vec3Arg inLinearVelocityTimesDeltaTime)
Definition: Body.h:298
void SetUserData(uint64 inUserData)
Definition: Body.h:272
bool IsSoftBody() const
Check if this body is a soft body.
Definition: Body.h:49
const Shape * GetShape() const
Get the shape of this body.
Definition: Body.h:239
bool InvalidateContactCacheInternal()
Invalidate the contact cache (should only be called by the BodyManager), will be reset the next simul...
Definition: Body.h:308
uint64 GetUserData() const
Access to the user data, can be used for anything by the application.
Definition: Body.h:271
BroadPhaseLayer GetBroadPhaseLayer() const
Get broadphase layer, this determines in which broad phase sub-tree the object is placed.
Definition: Body.h:120
float GetRestitution() const
Restitution (dimensionless number, usually between 0 and 1, 0 = completely inelastic collision respon...
Definition: Body.h:142
const CollisionGroup & GetCollisionGroup() const
Collision group and sub-group ID, determines which other objects it collides with.
Definition: Body.h:126
void SetIsSensor(bool inIsSensor)
Definition: Body.h:73
void SetLinearVelocityClamped(Vec3Arg inLinearVelocity)
Definition: Body.h:154
JPH_TSAN_NO_SANITIZE uint32 GetIndexInActiveBodiesInternal() const
Access to the index in the BodyManager::mActiveBodies list.
Definition: Body.h:335
bool GetUseManifoldReductionWithBody(const Body &inBody2) const
Checks if the combination of this body and inBody2 should use manifold reduction.
Definition: Body.h:96
void SetLinearVelocity(Vec3Arg inLinearVelocity)
Definition: Body.h:150
Vec3 GetLinearVelocity() const
Get world space linear velocity of the center of mass (unit: m/s)
Definition: Body.h:146
ObjectLayer GetObjectLayer() const
Get object layer, this determines which other objects it collides with.
Definition: Body.h:123
void SetRestitution(float inRestitution)
Definition: Body.h:143
bool IsCollisionCacheInvalid() const
Check if this body has been changed in such a way that the collision cache should be considered inval...
Definition: Body.h:236
bool IsRigidBody() const
Check if this body is a rigid body.
Definition: Body.h:46
bool IsStatic() const
Check if this body is static (not movable)
Definition: Body.h:57
EBodyType GetBodyType() const
Get the type of body (rigid or soft)
Definition: Body.h:43
void SetEnhancedInternalEdgeRemoval(bool inApply)
Set to indicate that extra effort should be made to try to remove ghost contacts (collisions with int...
Definition: Body.h:105
bool GetCollideKinematicVsNonDynamic() const
Check if kinematic objects can generate contact points against other kinematic or static objects.
Definition: Body.h:84
void SetUseManifoldReduction(bool inUseReduction)
Definition: Body.h:90
static Body sFixedToWorld
A dummy body that can be used by constraints to attach a constraint to the world instead of another b...
Definition: Body.h:287
void SetAngularVelocityClamped(Vec3Arg inAngularVelocity)
Definition: Body.h:165
JPH_INLINE void ResetForce()
Definition: Body.h:192
Vec3 GetAccumulatedTorque() const
Definition: Body.h:189
bool CanBeKinematicOrDynamic() const
Check if a body could be made kinematic or dynamic (if it was created dynamic or with mAllowDynamicOr...
Definition: Body.h:66
bool GetEnhancedInternalEdgeRemoval() const
Check if enhanced internal edge removal is turned on.
Definition: Body.h:108
JPH_TSAN_NO_SANITIZE bool IsActive() const
If this body is currently actively simulating (true) or sleeping (false)
Definition: Body.h:54
void SetInBroadPhaseInternal(bool inInBroadPhase)
Flag if body is in the broadphase (should only be called by the BroadPhase)
Definition: Body.h:305
MotionProperties * GetMotionProperties()
Definition: Body.h:264
Quat GetRotation() const
World space rotation of the body.
Definition: Body.h:245
TransformedShape GetTransformedShape() const
Get the transformed shape of this body, which can be used to do collision detection outside of a body...
Definition: Body.h:278
JPH_INLINE void ResetTorque()
Definition: Body.h:195
bool IsKinematic() const
Check if this body is kinematic (keyframed), which means that it will move according to its current v...
Definition: Body.h:60
float GetFriction() const
Friction (dimensionless number, usually between 0 and 1, 0 = no friction, 1 = friction force equals f...
Definition: Body.h:138
const MotionProperties * GetMotionPropertiesUnchecked() const
Access to the motion properties (version that does not check if the object is kinematic or dynamic)
Definition: Body.h:267
CollisionGroup & GetCollisionGroup()
Definition: Body.h:127
void SetApplyGyroscopicForce(bool inApply)
Set to indicate that the gyroscopic force should be applied to this body (aka Dzhanibekov effect,...
Definition: Body.h:99
JPH_OVERRIDE_NEW_DELETE const BodyID & GetID() const
Get the id of this body.
Definition: Body.h:40
MotionProperties * GetMotionPropertiesUnchecked()
Definition: Body.h:268
Vec3 GetAccumulatedForce() const
Definition: Body.h:186
Vec3 GetAngularVelocity() const
Get world space angular velocity of the center of mass (unit: rad/s)
Definition: Body.h:157
RVec3 GetPosition() const
World space position of the body.
Definition: Body.h:242
void AddForce(Vec3Arg inForce)
Definition: Body.h:175
void SetCollideKinematicVsNonDynamic(bool inCollide)
Definition: Body.h:81
bool GetUseManifoldReduction() const
Check if this body can use manifold reduction.
Definition: Body.h:93
JPH_INLINE void ResetMotion()
Definition: Body.h:198
void AddTorque(Vec3Arg inTorque)
Definition: Body.h:183
void ValidateContactCacheInternal()
Reset the collision cache invalid flag (should only be called by the BodyManager).
Definition: Body.h:311
void SetFriction(float inFriction)
Definition: Body.h:139
bool GetApplyGyroscopicForce() const
Check if the gyroscopic force is being applied for this body.
Definition: Body.h:102
void AddPositionStep(Vec3Arg inLinearVelocityTimesDeltaTime)
Update position using an Euler step (used during position integrate & constraint solving)
Definition: Body.h:297
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition: BodyID.h:13
Class that contains all bodies.
Definition: BodyManager.h:44
Definition: BodyManager.cpp:52
Definition: BroadPhaseLayer.h:18
Definition: CollisionGroup.h:20
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
static constexpr uint32 cInactiveIndex
Constant indicating that body is not active.
Definition: MotionProperties.h:229
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition: NonCopyable.h:11
Definition: Reference.h:157
Base class for all shapes (collision volume of a body). Defines a virtual interface for collision det...
Definition: Shape.h:186
Definition: SoftBodyCreationSettings.h:18
Definition: BodyManager.cpp:61
Definition: StateRecorder.h:105
A sub shape id contains a path to an element (usually a triangle or other primitive type) of a compou...
Definition: SubShapeID.h:23
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition: Vec3.inl:107
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:134