Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
Body.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
19
21
22class StateRecorder;
25
34class
35#ifndef JPH_PLATFORM_DOXYGEN // Doxygen gets confused here
36 JPH_EXPORT_GCC_BUG_WORKAROUND alignas(max(JPH_VECTOR_ALIGNMENT, JPH_RVECTOR_ALIGNMENT))
37#endif
38 Body : public NonCopyable
39{
40public:
42
44 inline const BodyID & GetID() const { return mID; }
45
47 inline EBodyType GetBodyType() const { return mBodyType; }
48
50 inline bool IsRigidBody() const { return mBodyType == EBodyType::RigidBody; }
51
53 inline bool IsSoftBody() const { return mBodyType == EBodyType::SoftBody; }
54
56 inline bool IsActive() const { return mMotionProperties != nullptr && mMotionProperties->GetIndexInActiveBodiesInternal() != cInactiveIndex; }
57
59 inline bool IsStatic() const { return mMotionType == EMotionType::Static; }
60
62 inline bool IsKinematic() const { return mMotionType == EMotionType::Kinematic; }
63
65 inline bool IsDynamic() const { return mMotionType == EMotionType::Dynamic; }
66
68 inline bool CanBeKinematicOrDynamic() const { return mMotionProperties != nullptr; }
69
75 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
78 inline bool IsSensor() const { return (mFlags.load(memory_order_relaxed) & uint8(EFlags::IsSensor)) != 0; }
79
83 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); }
84
86 inline bool GetCollideKinematicVsNonDynamic() const { return (mFlags.load(memory_order_relaxed) & uint8(EFlags::CollideKinematicVsNonDynamic)) != 0; }
87
92 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); }
93
95 inline bool GetUseManifoldReduction() const { return (mFlags.load(memory_order_relaxed) & uint8(EFlags::UseManifoldReduction)) != 0; }
96
98 inline bool GetUseManifoldReductionWithBody(const Body &inBody2) const { return ((mFlags.load(memory_order_relaxed) & inBody2.mFlags.load(memory_order_relaxed)) & uint8(EFlags::UseManifoldReduction)) != 0; }
99
101 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); }
102
104 inline bool GetApplyGyroscopicForce() const { return (mFlags.load(memory_order_relaxed) & uint8(EFlags::ApplyGyroscopicForce)) != 0; }
105
107 inline void SetEnhancedInternalEdgeRemoval(bool inApply) { JPH_ASSERT(IsRigidBody()); if (inApply) mFlags.fetch_or(uint8(EFlags::EnhancedInternalEdgeRemoval), memory_order_relaxed); else mFlags.fetch_and(uint8(~uint8(EFlags::EnhancedInternalEdgeRemoval)), memory_order_relaxed); }
108
110 inline bool GetEnhancedInternalEdgeRemoval() const { return (mFlags.load(memory_order_relaxed) & uint8(EFlags::EnhancedInternalEdgeRemoval)) != 0; }
111
113 inline bool GetEnhancedInternalEdgeRemovalWithBody(const Body &inBody2) const { return ((mFlags.load(memory_order_relaxed) | inBody2.mFlags.load(memory_order_relaxed)) & uint8(EFlags::EnhancedInternalEdgeRemoval)) != 0; }
114
116 inline EMotionType GetMotionType() const { return mMotionType; }
117
119 void SetMotionType(EMotionType inMotionType);
120
122 inline BroadPhaseLayer GetBroadPhaseLayer() const { return mBroadPhaseLayer; }
123
125 inline ObjectLayer GetObjectLayer() const { return mObjectLayer; }
126
128 const CollisionGroup & GetCollisionGroup() const { return mCollisionGroup; }
129 CollisionGroup & GetCollisionGroup() { return mCollisionGroup; }
130 void SetCollisionGroup(const CollisionGroup &inGroup) { mCollisionGroup = inGroup; }
131
133 bool GetAllowSleeping() const { return mMotionProperties->mAllowSleeping; }
134 void SetAllowSleeping(bool inAllow);
135
137 inline void ResetSleepTimer();
138
140 inline float GetFriction() const { return mFriction; }
141 void SetFriction(float inFriction) { mFriction = inFriction; }
142
144 inline float GetRestitution() const { return mRestitution; }
145 void SetRestitution(float inRestitution) { mRestitution = inRestitution; }
146
148 inline Vec3 GetLinearVelocity() const { return !IsStatic()? mMotionProperties->GetLinearVelocity() : Vec3::sZero(); }
149
153 void SetLinearVelocity(Vec3Arg inLinearVelocity) { JPH_ASSERT(!IsStatic()); mMotionProperties->SetLinearVelocity(inLinearVelocity); }
154
158 void SetLinearVelocityClamped(Vec3Arg inLinearVelocity) { JPH_ASSERT(!IsStatic()); mMotionProperties->SetLinearVelocityClamped(inLinearVelocity); }
159
161 inline Vec3 GetAngularVelocity() const { return !IsStatic()? mMotionProperties->GetAngularVelocity() : Vec3::sZero(); }
162
166 void SetAngularVelocity(Vec3Arg inAngularVelocity) { JPH_ASSERT(!IsStatic()); mMotionProperties->SetAngularVelocity(inAngularVelocity); }
167
171 void SetAngularVelocityClamped(Vec3Arg inAngularVelocity) { JPH_ASSERT(!IsStatic()); mMotionProperties->SetAngularVelocityClamped(inAngularVelocity); }
172
174 inline Vec3 GetPointVelocityCOM(Vec3Arg inPointRelativeToCOM) const { return !IsStatic()? mMotionProperties->GetPointVelocityCOM(inPointRelativeToCOM) : Vec3::sZero(); }
175
177 inline Vec3 GetPointVelocity(RVec3Arg inPoint) const { JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess(), BodyAccess::EAccess::Read)); return GetPointVelocityCOM(Vec3(inPoint - mPosition)); }
178
181 inline void AddForce(Vec3Arg inForce) { JPH_ASSERT(IsDynamic()); (Vec3::sLoadFloat3Unsafe(mMotionProperties->mForce) + inForce).StoreFloat3(&mMotionProperties->mForce); }
182
185 inline void AddForce(Vec3Arg inForce, RVec3Arg inPosition);
186
189 inline void AddTorque(Vec3Arg inTorque) { JPH_ASSERT(IsDynamic()); (Vec3::sLoadFloat3Unsafe(mMotionProperties->mTorque) + inTorque).StoreFloat3(&mMotionProperties->mTorque); }
190
191 // Get the total amount of force applied to the center of mass this time step (through AddForce calls). Note that it will reset to zero after PhysicsSystem::Update.
192 inline Vec3 GetAccumulatedForce() const { JPH_ASSERT(IsDynamic()); return mMotionProperties->GetAccumulatedForce(); }
193
194 // Get the total amount of torque applied to the center of mass this time step (through AddForce/AddTorque calls). Note that it will reset to zero after PhysicsSystem::Update.
195 inline Vec3 GetAccumulatedTorque() const { JPH_ASSERT(IsDynamic()); return mMotionProperties->GetAccumulatedTorque(); }
196
197 // Reset the total accumulated force, not that this will be done automatically after every time step.
198 JPH_INLINE void ResetForce() { JPH_ASSERT(IsDynamic()); return mMotionProperties->ResetForce(); }
199
200 // Reset the total accumulated torque, not that this will be done automatically after every time step.
201 JPH_INLINE void ResetTorque() { JPH_ASSERT(IsDynamic()); return mMotionProperties->ResetTorque(); }
202
203 // Reset the current velocity and accumulated force and torque.
204 JPH_INLINE void ResetMotion() { JPH_ASSERT(!IsStatic()); return mMotionProperties->ResetMotion(); }
205
207 inline Mat44 GetInverseInertia() const;
208
211 inline void AddImpulse(Vec3Arg inImpulse);
212
215 inline void AddImpulse(Vec3Arg inImpulse, RVec3Arg inPosition);
216
219 inline void AddAngularImpulse(Vec3Arg inAngularImpulse);
220
224 void MoveKinematic(RVec3Arg inTargetPosition, QuatArg inTargetRotation, float inDeltaTime);
225
232 void GetSubmergedVolume(RVec3Arg inSurfacePosition, Vec3Arg inSurfaceNormal, float &outTotalVolume, float &outSubmergedVolume, Vec3 &outRelativeCenterOfBuoyancy) const;
233
245 bool ApplyBuoyancyImpulse(RVec3Arg inSurfacePosition, Vec3Arg inSurfaceNormal, float inBuoyancy, float inLinearDrag, float inAngularDrag, Vec3Arg inFluidVelocity, Vec3Arg inGravity, float inDeltaTime);
246
259 bool ApplyBuoyancyImpulse(float inTotalVolume, float inSubmergedVolume, Vec3Arg inRelativeCenterOfBuoyancy, float inBuoyancy, float inLinearDrag, float inAngularDrag, Vec3Arg inFluidVelocity, Vec3Arg inGravity, float inDeltaTime);
260
262 inline bool IsInBroadPhase() const { return (mFlags.load(memory_order_relaxed) & uint8(EFlags::IsInBroadPhase)) != 0; }
263
265 inline bool IsCollisionCacheInvalid() const { return (mFlags.load(memory_order_relaxed) & uint8(EFlags::InvalidateContactCache)) != 0; }
266
268 inline const Shape * GetShape() const { return mShape; }
269
271 inline RVec3 GetPosition() const { JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess(), BodyAccess::EAccess::Read)); return mPosition - mRotation * mShape->GetCenterOfMass(); }
272
274 inline Quat GetRotation() const { JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess(), BodyAccess::EAccess::Read)); return mRotation; }
275
277 inline RMat44 GetWorldTransform() const;
278
280 inline RVec3 GetCenterOfMassPosition() const { JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess(), BodyAccess::EAccess::Read)); return mPosition; }
281
283 inline RMat44 GetCenterOfMassTransform() const;
284
286 inline RMat44 GetInverseCenterOfMassTransform() const;
287
289 inline const AABox & GetWorldSpaceBounds() const { return mBounds; }
290
291#ifdef JPH_ENABLE_ASSERTS
303 inline void ValidateCachedBounds() const
304 {
305 AABox actual_body_bounds = mShape->GetWorldSpaceBounds(GetCenterOfMassTransform(), Vec3::sOne());
306 JPH_ASSERT(actual_body_bounds == mBounds, "Mismatch between cached bounding box and actual bounding box");
307 }
308
310 inline void ValidateMotion() const
311 {
312 if (!IsStatic() && !IsActive())
313 {
314 // If this fails then you have set a velocity on a body without waking it up.
315 // Use BodyInterface::SetLinearVelocity or BodyInterface::SetAngularVelocity to set the velocity and wake up the body at the same time.
316 JPH_ASSERT(mMotionProperties->GetLinearVelocity().IsNearZero(), "Sleeping body has non-zero linear velocity!");
317 JPH_ASSERT(mMotionProperties->GetAngularVelocity().IsNearZero(), "Sleeping body has non-zero angular velocity!");
318 }
319 }
320#endif // JPH_ENABLE_ASSERTS
321
323 const MotionProperties *GetMotionProperties() const { JPH_ASSERT(!IsStatic()); return mMotionProperties; }
324 MotionProperties * GetMotionProperties() { JPH_ASSERT(!IsStatic()); return mMotionProperties; }
325
327 const MotionProperties *GetMotionPropertiesUnchecked() const { return mMotionProperties; }
328 MotionProperties * GetMotionPropertiesUnchecked() { return mMotionProperties; }
329
331 uint64 GetUserData() const { return mUserData; }
332 void SetUserData(uint64 inUserData) { mUserData = inUserData; }
333
335 inline Vec3 GetWorldSpaceSurfaceNormal(const SubShapeID &inSubShapeID, RVec3Arg inPosition) const;
336
338 inline TransformedShape GetTransformedShape() const { JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess(), BodyAccess::EAccess::Read)); return TransformedShape(mPosition, mRotation, mShape, mID); }
339
341 BodyCreationSettings GetBodyCreationSettings() const;
342
345 void ApplyBodyCreationSettings(const BodyCreationSettings &inBodyCreationSettings, const BroadPhaseLayerInterface &inBPLInterface);
346
348 SoftBodyCreationSettings GetSoftBodyCreationSettings() const;
349
351 void ApplySoftBodyCreationSettings(const SoftBodyCreationSettings &inSoftBodyCreationSettings, const BroadPhaseLayerInterface &inBPLInterface);
352
354 static Body sFixedToWorld;
355
358
361 static inline bool sFindCollidingPairsCanCollide(const Body &inBody1, const Body &inBody2);
362
364 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()); }
365 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()); }
366
368 inline void AddRotationStep(Vec3Arg inAngularVelocityTimesDeltaTime);
369 inline void SubRotationStep(Vec3Arg inAngularVelocityTimesDeltaTime);
370
372 inline void SetObjectLayerInternal(ObjectLayer inLayer, const BroadPhaseLayerInterface &inBPLInterface) { mObjectLayer = inLayer; mBroadPhaseLayer = inBPLInterface.GetBroadPhaseLayer(inLayer); }
373
375 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); }
376
378 inline bool InvalidateContactCacheInternal() { return (mFlags.fetch_or(uint8(EFlags::InvalidateContactCache), memory_order_relaxed) & uint8(EFlags::InvalidateContactCache)) == 0; }
379
381 inline void ValidateContactCacheInternal() { JPH_IF_ENABLE_ASSERTS(uint8 old_val = ) mFlags.fetch_and(uint8(~uint8(EFlags::InvalidateContactCache)), memory_order_relaxed); JPH_ASSERT((old_val & uint8(EFlags::InvalidateContactCache)) != 0); }
382
384 void CalculateWorldSpaceBoundsInternal();
385
387 void SetPositionAndRotationInternal(RVec3Arg inPosition, QuatArg inRotation, bool inResetSleepTimer = true);
388
392 void UpdateCenterOfMassInternal(Vec3Arg inPreviousCenterOfMass, bool inUpdateMassProperties);
393
397 void SetShapeInternal(const Shape *inShape, bool inUpdateMassProperties);
398
400 uint32 GetIndexInActiveBodiesInternal() const { return mMotionProperties != nullptr? mMotionProperties->GetIndexInActiveBodiesInternal() : cInactiveIndex; }
401
403 ECanSleep UpdateSleepStateInternal(float inDeltaTime, float inMaxMovement, float inTimeBeforeSleep);
404
406 void SaveState(StateRecorder &inStream) const;
407
409 void RestoreState(StateRecorder &inStream);
410
412
414
415private:
416 friend class BodyManager;
419
420 Body() = default;
421
422 explicit Body(bool);
423
424 ~Body() { JPH_ASSERT(mMotionProperties == nullptr); }
425
426 inline void GetSleepTestPoints(RVec3 *outPoints) const;
427
428 enum class EFlags : uint8
429 {
430 IsSensor = 1 << 0,
431 CollideKinematicVsNonDynamic = 1 << 1,
432 IsInBroadPhase = 1 << 2,
433 InvalidateContactCache = 1 << 3,
434 UseManifoldReduction = 1 << 4,
435 ApplyGyroscopicForce = 1 << 5,
436 EnhancedInternalEdgeRemoval = 1 << 6,
437 };
438
439 // 16 byte aligned
440 RVec3 mPosition;
441 Quat mRotation;
442 AABox mBounds;
443
444 // 8 byte aligned
445 RefConst<Shape> mShape;
446 MotionProperties * mMotionProperties = nullptr;
447 uint64 mUserData = 0;
448 CollisionGroup mCollisionGroup;
449
450 // 4 byte aligned
451 float mFriction;
452 float mRestitution;
453 BodyID mID;
454
455 // 2 or 4 bytes aligned
456 ObjectLayer mObjectLayer;
457
458 // 1 byte aligned
459 EBodyType mBodyType;
460 BroadPhaseLayer mBroadPhaseLayer;
461 EMotionType mMotionType;
462 atomic<uint8> mFlags = 0;
463
464 // 122 bytes up to here (64-bit mode, single precision, 16-bit ObjectLayer)
465};
466
467static_assert(sizeof(void *) != 8 || JPH_RVECTOR_ALIGNMENT < 16 || JPH_OBJECT_LAYER_BITS > 32 || sizeof(Body) == JPH_IF_SINGLE_PRECISION_ELSE(128, 160), "Body size is incorrect");
468static_assert(alignof(Body) == max(JPH_VECTOR_ALIGNMENT, JPH_RVECTOR_ALIGNMENT), "Body should properly align");
469
471
472#include "Body.inl"
EBodyType
Type of body.
Definition BodyType.h:11
@ RigidBody
Rigid body consisting of a rigid shape.
Definition BodyType.h:12
@ SoftBody
Soft body consisting of a deformable shape.
Definition BodyType.h:13
std::uint8_t uint8
Definition Core.h:565
std::uint64_t uint64
Definition Core.h:569
#define JPH_NAMESPACE_END
Definition Core.h:487
std::uint32_t uint32
Definition Core.h:567
#define JPH_EXPORT_GCC_BUG_WORKAROUND
Definition Core.h:310
#define JPH_IF_SINGLE_PRECISION_ELSE(s, d)
Definition Core.h:651
#define JPH_NAMESPACE_BEGIN
Definition Core.h:481
#define JPH_IF_ENABLE_ASSERTS(...)
Definition IssueReporting.h:30
#define JPH_ASSERT(...)
Definition IssueReporting.h:28
const Quat QuatArg
Definition MathTypes.h:28
const Vec3 Vec3Arg
Definition MathTypes.h:19
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:51
ECanSleep
Enum that determines if an object can go to sleep.
Definition MotionProperties.h:23
EMotionType
Motion type of a physics body.
Definition MotionType.h:11
@ Kinematic
Movable using velocities only, does not respond to forces.
Definition MotionType.h:13
@ Static
Non movable.
Definition MotionType.h:12
@ Dynamic
Responds to forces as a normal physics object.
Definition MotionType.h:14
uint16 ObjectLayer
Layer that objects can be in, determines which other objects it can collide with.
Definition ObjectLayer.h:13
Vec3Arg RVec3Arg
Definition Real.h:30
Mat44 RMat44
Definition Real.h:31
#define JPH_RVECTOR_ALIGNMENT
Definition Real.h:34
Vec3 RVec3
Definition Real.h:29
Axis aligned box.
Definition AABox.h:16
Settings for constructing a rigid body.
Definition BodyCreationSettings.h:31
Definition Body.h:39
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:177
bool IsInBroadPhase() const
Check if this body has been added to the physics system.
Definition Body.h:262
const MotionProperties * GetMotionProperties() const
Access to the motion properties.
Definition Body.h:323
RVec3 GetCenterOfMassPosition() const
Gets the world space position of this body's center of mass.
Definition Body.h:280
EMotionType GetMotionType() const
Get the bodies motion type.
Definition Body.h:116
void SetAngularVelocity(Vec3Arg inAngularVelocity)
Definition Body.h:166
void SetCollisionGroup(const CollisionGroup &inGroup)
Definition Body.h:130
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:174
bool IsDynamic() const
Check if this body is dynamic, which means that it moves and forces can act on it.
Definition Body.h:65
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:133
bool IsSensor() const
Check if this body is a sensor.
Definition Body.h:78
bool GetEnhancedInternalEdgeRemovalWithBody(const Body &inBody2) const
Checks if the combination of this body and inBody2 should use enhanced internal edge removal.
Definition Body.h:113
const AABox & GetWorldSpaceBounds() const
Get world space bounding box.
Definition Body.h:289
void SubPositionStep(Vec3Arg inLinearVelocityTimesDeltaTime)
Definition Body.h:365
void SetUserData(uint64 inUserData)
Definition Body.h:332
bool IsSoftBody() const
Check if this body is a soft body.
Definition Body.h:53
const Shape * GetShape() const
Get the shape of this body.
Definition Body.h:268
bool InvalidateContactCacheInternal()
Invalidate the contact cache (should only be called by the BodyManager), will be reset the next simul...
Definition Body.h:378
uint64 GetUserData() const
Access to the user data, can be used for anything by the application.
Definition Body.h:331
BroadPhaseLayer GetBroadPhaseLayer() const
Get broadphase layer, this determines in which broad phase sub-tree the object is placed.
Definition Body.h:122
float GetRestitution() const
Restitution (dimensionless number, usually between 0 and 1, 0 = completely inelastic collision respon...
Definition Body.h:144
const CollisionGroup & GetCollisionGroup() const
Collision group and sub-group ID, determines which other objects it collides with.
Definition Body.h:128
friend class BodyManager
Definition Body.h:416
void SetIsSensor(bool inIsSensor)
Definition Body.h:75
void SetLinearVelocityClamped(Vec3Arg inLinearVelocity)
Definition Body.h:158
bool GetUseManifoldReductionWithBody(const Body &inBody2) const
Checks if the combination of this body and inBody2 should use manifold reduction.
Definition Body.h:98
void SetLinearVelocity(Vec3Arg inLinearVelocity)
Definition Body.h:153
uint32 GetIndexInActiveBodiesInternal() const
Access to the index in the BodyManager::mActiveBodies list.
Definition Body.h:400
static constexpr uint32 cInactiveIndex
Constant indicating that body is not active.
Definition Body.h:413
Vec3 GetLinearVelocity() const
Get world space linear velocity of the center of mass (unit: m/s).
Definition Body.h:148
ObjectLayer GetObjectLayer() const
Get object layer, this determines which other objects it collides with.
Definition Body.h:125
void SetRestitution(float inRestitution)
Definition Body.h:145
static bool sFindCollidingPairsCanCollide(const Body &inBody1, const Body &inBody2)
Definition Body.inl:30
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:265
void SetObjectLayerInternal(ObjectLayer inLayer, const BroadPhaseLayerInterface &inBPLInterface)
Function to update body's layer (should only be called internally since it also requires updating the...
Definition Body.h:372
bool IsRigidBody() const
Check if this body is a rigid body.
Definition Body.h:50
bool IsStatic() const
Check if this body is static (not movable).
Definition Body.h:59
EBodyType GetBodyType() const
Get the type of body (rigid or soft).
Definition Body.h:47
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:107
bool GetCollideKinematicVsNonDynamic() const
Check if kinematic objects can generate contact points against other kinematic or static objects.
Definition Body.h:86
void SetUseManifoldReduction(bool inUseReduction)
Definition Body.h:92
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:354
void SetAngularVelocityClamped(Vec3Arg inAngularVelocity)
Definition Body.h:171
JPH_INLINE void ResetForce()
Definition Body.h:198
Vec3 GetAccumulatedTorque() const
Definition Body.h:195
bool CanBeKinematicOrDynamic() const
Check if a body could be made kinematic or dynamic (if it was created dynamic or with mAllowDynamicOr...
Definition Body.h:68
friend class BodyWithMotionProperties
Definition Body.h:417
bool GetEnhancedInternalEdgeRemoval() const
Check if enhanced internal edge removal is turned on.
Definition Body.h:110
void SetInBroadPhaseInternal(bool inInBroadPhase)
Flag if body is in the broadphase (should only be called by the BroadPhase).
Definition Body.h:375
MotionProperties * GetMotionProperties()
Definition Body.h:324
Quat GetRotation() const
World space rotation of the body.
Definition Body.h:274
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:338
JPH_INLINE void ResetTorque()
Definition Body.h:201
bool IsKinematic() const
Check if this body is kinematic (keyframed), which means that it will move according to its current v...
Definition Body.h:62
float GetFriction() const
Friction (dimensionless number, usually between 0 and 1, 0 = no friction, 1 = friction force equals f...
Definition Body.h:140
const MotionProperties * GetMotionPropertiesUnchecked() const
Access to the motion properties (version that does not check if the object is kinematic or dynamic).
Definition Body.h:327
CollisionGroup & GetCollisionGroup()
Definition Body.h:129
void SetApplyGyroscopicForce(bool inApply)
Set to indicate that the gyroscopic force should be applied to this body (aka Dzhanibekov effect,...
Definition Body.h:101
JPH_OVERRIDE_NEW_DELETE const BodyID & GetID() const
Get the id of this body.
Definition Body.h:44
MotionProperties * GetMotionPropertiesUnchecked()
Definition Body.h:328
Vec3 GetAccumulatedForce() const
Definition Body.h:192
Vec3 GetAngularVelocity() const
Get world space angular velocity of the center of mass (unit: rad/s).
Definition Body.h:161
RVec3 GetPosition() const
World space position of the body.
Definition Body.h:271
friend class SoftBodyWithMotionPropertiesAndShape
Definition Body.h:418
void AddForce(Vec3Arg inForce)
Definition Body.h:181
void SetCollideKinematicVsNonDynamic(bool inCollide)
Definition Body.h:83
bool IsActive() const
If this body is currently actively simulating (true) or sleeping (false).
Definition Body.h:56
bool GetUseManifoldReduction() const
Check if this body can use manifold reduction.
Definition Body.h:95
JPH_INLINE void ResetMotion()
Definition Body.h:204
void AddTorque(Vec3Arg inTorque)
Definition Body.h:189
void ValidateContactCacheInternal()
Reset the collision cache invalid flag (should only be called by the BodyManager).
Definition Body.h:381
void SetFriction(float inFriction)
Definition Body.h:141
bool GetApplyGyroscopicForce() const
Check if the gyroscopic force is being applied for this body.
Definition Body.h:104
void AddPositionStep(Vec3Arg inLinearVelocityTimesDeltaTime)
Update position using an Euler step (used during position integrate & constraint solving).
Definition Body.h:364
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition BodyID.h:13
Definition BroadPhaseLayer.h:18
Interface that the application should implement to allow mapping object layers to broadphase layers.
Definition BroadPhaseLayer.h:61
virtual BroadPhaseLayer GetBroadPhaseLayer(ObjectLayer inLayer) const =0
Convert an object layer to the corresponding broadphase layer.
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:30
static constexpr uint32 cInactiveIndex
Constant indicating that body is not active.
Definition MotionProperties.h:284
NonCopyable()=default
Definition Quat.h:33
Definition Reference.h:166
Base class for all shapes (collision volume of a body). Defines a virtual interface for collision det...
Definition Shape.h:185
Definition SoftBodyCreationSettings.h:18
Definition StateRecorder.h:110
A sub shape id contains a path to an element (usually a triangle or other primitive type) of a compou...
Definition SubShapeID.h:23
Definition TransformedShape.h:26
Definition Vec3.h:17
static JPH_INLINE Vec3 sOne()
Vector with all ones.
Definition Vec3.inl:157
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:125
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:167
constexpr float2 max(const float2 &inA, const float2 &inB)
Definition HLSLToCPP.h:69