Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
BodyInterface.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
13#include <Jolt/Core/Reference.h>
14
16
17class Body;
21class BroadPhase;
22class BodyManager;
24class PhysicsMaterial;
25class SubShapeID;
26class Shape;
30class AABox;
31
35{
36public:
38 void Init(BodyLockInterface &inBodyLockInterface, BodyManager &inBodyManager, BroadPhase &inBroadPhase) { mBodyLockInterface = &inBodyLockInterface; mBodyManager = &inBodyManager; mBroadPhase = &inBroadPhase; }
39
42 Body * CreateBody(const BodyCreationSettings &inSettings);
43
46 Body * CreateSoftBody(const SoftBodyCreationSettings &inSettings);
47
51 Body * CreateBodyWithID(const BodyID &inBodyID, const BodyCreationSettings &inSettings);
52
54 Body * CreateSoftBodyWithID(const BodyID &inBodyID, const SoftBodyCreationSettings &inSettings);
55
59 Body * CreateBodyWithoutID(const BodyCreationSettings &inSettings) const;
60
62 Body * CreateSoftBodyWithoutID(const SoftBodyCreationSettings &inSettings) const;
63
66 void DestroyBodyWithoutID(Body *inBody) const;
67
70 bool AssignBodyID(Body *ioBody);
71
74 bool AssignBodyID(Body *ioBody, const BodyID &inBodyID);
75
77 Body * UnassignBodyID(const BodyID &inBodyID);
78
84 void UnassignBodyIDs(const BodyID *inBodyIDs, int inNumber, Body **outBodies);
85
87 void DestroyBody(const BodyID &inBodyID);
88
90 void DestroyBodies(const BodyID *inBodyIDs, int inNumber);
91
96 void AddBody(const BodyID &inBodyID, EActivation inActivationMode);
97
99 void RemoveBody(const BodyID &inBodyID);
100
102 bool IsAdded(const BodyID &inBodyID) const;
103
106 BodyID CreateAndAddBody(const BodyCreationSettings &inSettings, EActivation inActivationMode);
107
110 BodyID CreateAndAddSoftBody(const SoftBodyCreationSettings &inSettings, EActivation inActivationMode);
111
113 using AddState = void *;
114
118 AddState AddBodiesPrepare(BodyID *ioBodies, int inNumber);
119 void AddBodiesFinalize(BodyID *ioBodies, int inNumber, AddState inAddState, EActivation inActivationMode);
120 void AddBodiesAbort(BodyID *ioBodies, int inNumber, AddState inAddState);
121 void RemoveBodies(BodyID *ioBodies, int inNumber);
123
126 void ActivateBody(const BodyID &inBodyID);
127 void ActivateBodies(const BodyID *inBodyIDs, int inNumber);
128 void ActivateBodiesInAABox(const AABox &inBox, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter);
129 void DeactivateBody(const BodyID &inBodyID);
130 void DeactivateBodies(const BodyID *inBodyIDs, int inNumber);
131 bool IsActive(const BodyID &inBodyID) const;
133
135 TwoBodyConstraint * CreateConstraint(const TwoBodyConstraintSettings *inSettings, const BodyID &inBodyID1, const BodyID &inBodyID2);
136
138 void ActivateConstraint(const TwoBodyConstraint *inConstraint);
139
142
144 RefConst<Shape> GetShape(const BodyID &inBodyID) const;
145
151 void SetShape(const BodyID &inBodyID, const Shape *inShape, bool inUpdateMassProperties, EActivation inActivationMode) const;
152
158 void NotifyShapeChanged(const BodyID &inBodyID, Vec3Arg inPreviousCenterOfMass, bool inUpdateMassProperties, EActivation inActivationMode) const;
160
163 void SetObjectLayer(const BodyID &inBodyID, ObjectLayer inLayer);
164 ObjectLayer GetObjectLayer(const BodyID &inBodyID) const;
166
169 void SetPositionAndRotation(const BodyID &inBodyID, RVec3Arg inPosition, QuatArg inRotation, EActivation inActivationMode);
170 void SetPositionAndRotationWhenChanged(const BodyID &inBodyID, RVec3Arg inPosition, QuatArg inRotation, EActivation inActivationMode);
171 void GetPositionAndRotation(const BodyID &inBodyID, RVec3 &outPosition, Quat &outRotation) const;
172 void SetPosition(const BodyID &inBodyID, RVec3Arg inPosition, EActivation inActivationMode);
173 RVec3 GetPosition(const BodyID &inBodyID) const;
174 RVec3 GetCenterOfMassPosition(const BodyID &inBodyID) const;
175 void SetRotation(const BodyID &inBodyID, QuatArg inRotation, EActivation inActivationMode);
176 Quat GetRotation(const BodyID &inBodyID) const;
177 RMat44 GetWorldTransform(const BodyID &inBodyID) const;
178 RMat44 GetCenterOfMassTransform(const BodyID &inBodyID) const;
180
182 void MoveKinematic(const BodyID &inBodyID, RVec3Arg inTargetPosition, QuatArg inTargetRotation, float inDeltaTime);
183
186 void SetLinearAndAngularVelocity(const BodyID &inBodyID, Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity);
187 void GetLinearAndAngularVelocity(const BodyID &inBodyID, Vec3 &outLinearVelocity, Vec3 &outAngularVelocity) const;
188 void SetLinearVelocity(const BodyID &inBodyID, Vec3Arg inLinearVelocity);
189 Vec3 GetLinearVelocity(const BodyID &inBodyID) const;
190 void AddLinearVelocity(const BodyID &inBodyID, Vec3Arg inLinearVelocity);
191 void AddLinearAndAngularVelocity(const BodyID &inBodyID, Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity);
192 void SetAngularVelocity(const BodyID &inBodyID, Vec3Arg inAngularVelocity);
193 Vec3 GetAngularVelocity(const BodyID &inBodyID) const;
194 Vec3 GetPointVelocity(const BodyID &inBodyID, RVec3Arg inPoint) const;
195
198 void SetPositionRotationAndVelocity(const BodyID &inBodyID, RVec3Arg inPosition, QuatArg inRotation, Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity);
199
202 void AddForce(const BodyID &inBodyID, Vec3Arg inForce);
203 void AddForce(const BodyID &inBodyID, Vec3Arg inForce, RVec3Arg inPoint);
204 void AddTorque(const BodyID &inBodyID, Vec3Arg inTorque);
205 void AddForceAndTorque(const BodyID &inBodyID, Vec3Arg inForce, Vec3Arg inTorque);
207
210 void AddImpulse(const BodyID &inBodyID, Vec3Arg inImpulse);
211 void AddImpulse(const BodyID &inBodyID, Vec3Arg inImpulse, RVec3Arg inPoint);
212 void AddAngularImpulse(const BodyID &inBodyID, Vec3Arg inAngularImpulse);
214
217 EBodyType GetBodyType(const BodyID &inBodyID) const;
219
222 void SetMotionType(const BodyID &inBodyID, EMotionType inMotionType, EActivation inActivationMode);
223 EMotionType GetMotionType(const BodyID &inBodyID) const;
225
228 void SetMotionQuality(const BodyID &inBodyID, EMotionQuality inMotionQuality);
229 EMotionQuality GetMotionQuality(const BodyID &inBodyID) const;
231
233 Mat44 GetInverseInertia(const BodyID &inBodyID) const;
234
237 void SetRestitution(const BodyID &inBodyID, float inRestitution);
238 float GetRestitution(const BodyID &inBodyID) const;
240
243 void SetFriction(const BodyID &inBodyID, float inFriction);
244 float GetFriction(const BodyID &inBodyID) const;
246
249 void SetGravityFactor(const BodyID &inBodyID, float inGravityFactor);
250 float GetGravityFactor(const BodyID &inBodyID) const;
252
255 void SetUseManifoldReduction(const BodyID &inBodyID, bool inUseReduction);
256 bool GetUseManifoldReduction(const BodyID &inBodyID) const;
258
260 TransformedShape GetTransformedShape(const BodyID &inBodyID) const;
261
263 uint64 GetUserData(const BodyID &inBodyID) const;
264 void SetUserData(const BodyID &inBodyID, uint64 inUserData) const;
265
267 const PhysicsMaterial * GetMaterial(const BodyID &inBodyID, const SubShapeID &inSubShapeID) const;
268
270 void InvalidateContactCache(const BodyID &inBodyID);
271
272private:
273 BodyLockInterface * mBodyLockInterface = nullptr;
274 BodyManager * mBodyManager = nullptr;
275 BroadPhase * mBroadPhase = nullptr;
276};
277
EBodyType
Type of body.
Definition: BodyType.h:11
#define JPH_EXPORT
Definition: Core.h:227
std::uint64_t uint64
Definition: Core.h:443
#define JPH_NAMESPACE_END
Definition: Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
EActivation
Enum used by AddBody to determine if the body needs to be initially active.
Definition: EActivation.h:11
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
uint16 ObjectLayer
Definition: ObjectLayer.h:16
Axis aligned box.
Definition: AABox.h:16
Settings for constructing a rigid body.
Definition: BodyCreationSettings.h:31
Definition: Body.h:35
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition: BodyID.h:13
Definition: BodyInterface.h:35
void Init(BodyLockInterface &inBodyLockInterface, BodyManager &inBodyManager, BroadPhase &inBroadPhase)
Initialize the interface (should only be called by PhysicsSystem)
Definition: BodyInterface.h:38
void * AddState
Broadphase add state handle, used to keep track of a batch while adding to the broadphase.
Definition: BodyInterface.h:113
Base class interface for locking a body. Usually you will use BodyLockRead / BodyLockWrite / BodyLock...
Definition: BodyLockInterface.h:17
Class that contains all bodies.
Definition: BodyManager.h:32
Used to do coarse collision detection operations to quickly prune out bodies that will not collide.
Definition: BroadPhase.h:26
Filter class for broadphase layers.
Definition: BroadPhaseLayer.h:94
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition: Mat44.h:13
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition: NonCopyable.h:11
Filter class for object layers.
Definition: ObjectLayer.h:28
Definition: PhysicsMaterial.h:23
Definition: Quat.h:33
Definition: Reference.h:151
Base class for all shapes (collision volume of a body). Defines a virtual interface for collision det...
Definition: Shape.h:178
Definition: SoftBodyCreationSettings.h:18
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
Base class for all constraints that involve 2 bodies. Body1 is usually considered the parent,...
Definition: TwoBodyConstraint.h:27
Base class for settings for all constraints that involve 2 bodies.
Definition: TwoBodyConstraint.h:16
Definition: Vec3.h:16