| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Body/BodyID.h> |
| 8 |
#include <Jolt/Physics/EActivation.h> |
| 9 |
#include <Jolt/Physics/Collision/ObjectLayer.h> |
| 10 |
#include <Jolt/Physics/Body/MotionType.h> |
| 11 |
#include <Jolt/Physics/Body/MotionQuality.h> |
| 12 |
#include <Jolt/Physics/Body/BodyType.h> |
| 13 |
#include <Jolt/Core/Reference.h> |
| 14 |
|
| 15 |
JPH_NAMESPACE_BEGIN |
| 16 |
|
| 17 |
class Body; |
| 18 |
class BodyCreationSettings; |
| 19 |
class SoftBodyCreationSettings; |
| 20 |
class BodyLockInterface; |
| 21 |
class BroadPhase; |
| 22 |
class BodyManager; |
| 23 |
class TransformedShape; |
| 24 |
class PhysicsMaterial; |
| 25 |
class SubShapeID; |
| 26 |
class Shape; |
| 27 |
class TwoBodyConstraintSettings; |
| 28 |
class TwoBodyConstraint; |
| 29 |
class BroadPhaseLayerFilter; |
| 30 |
class AABox; |
| 31 |
class CollisionGroup; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class JPH_EXPORT BodyInterface : public NonCopyable |
| 36 |
{ |
| 37 |
public: |
| 38 |
|
| 39 |
void Init(BodyLockInterface &inBodyLockInterface, BodyManager &inBodyManager, BroadPhase &inBroadPhase) { mBodyLockInterface = &inBodyLockInterface; mBodyManager = &inBodyManager; mBroadPhase = &inBroadPhase; } |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
Body * CreateBody(const BodyCreationSettings &inSettings); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
Body * CreateSoftBody(const SoftBodyCreationSettings &inSettings); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
Body * CreateBodyWithID(const BodyID &inBodyID, const BodyCreationSettings &inSettings); |
| 53 |
|
| 54 |
|
| 55 |
Body * CreateSoftBodyWithID(const BodyID &inBodyID, const SoftBodyCreationSettings &inSettings); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
Body * CreateBodyWithoutID(const BodyCreationSettings &inSettings) const; |
| 61 |
|
| 62 |
|
| 63 |
Body * CreateSoftBodyWithoutID(const SoftBodyCreationSettings &inSettings) const; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
void DestroyBodyWithoutID(Body *inBody) const; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
bool AssignBodyID(Body *ioBody); |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
bool AssignBodyID(Body *ioBody, const BodyID &inBodyID); |
| 76 |
|
| 77 |
|
| 78 |
Body * UnassignBodyID(const BodyID &inBodyID); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
void UnassignBodyIDs(const BodyID *inBodyIDs, int inNumber, Body **outBodies); |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
void DestroyBody(const BodyID &inBodyID); |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
void DestroyBodies(const BodyID *inBodyIDs, int inNumber); |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
void AddBody(const BodyID &inBodyID, EActivation inActivationMode); |
| 100 |
|
| 101 |
|
| 102 |
void RemoveBody(const BodyID &inBodyID); |
| 103 |
|
| 104 |
|
| 105 |
bool IsAdded(const BodyID &inBodyID) const; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
BodyID CreateAndAddBody(const BodyCreationSettings &inSettings, EActivation inActivationMode); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
BodyID CreateAndAddSoftBody(const SoftBodyCreationSettings &inSettings, EActivation inActivationMode); |
| 114 |
|
| 115 |
|
| 116 |
using AddState = void *; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
AddState AddBodiesPrepare(BodyID *ioBodies, int inNumber); |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
void AddBodiesFinalize(BodyID *ioBodies, int inNumber, AddState inAddState, EActivation inActivationMode); |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
void AddBodiesAbort(BodyID *ioBodies, int inNumber, AddState inAddState); |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
void RemoveBodies(BodyID *ioBodies, int inNumber); |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
void ActivateBody(const BodyID &inBodyID); |
| 143 |
void ActivateBodies(const BodyID *inBodyIDs, int inNumber); |
| 144 |
void ActivateBodiesInAABox(const AABox &inBox, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter); |
| 145 |
void DeactivateBody(const BodyID &inBodyID); |
| 146 |
void DeactivateBodies(const BodyID *inBodyIDs, int inNumber); |
| 147 |
bool IsActive(const BodyID &inBodyID) const; |
| 148 |
void ResetSleepTimer(const BodyID &inBodyID); |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
TwoBodyConstraint * CreateConstraint(const TwoBodyConstraintSettings *inSettings, const BodyID &inBodyID1, const BodyID &inBodyID2); |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
void ActivateConstraint(const TwoBodyConstraint *inConstraint); |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
RefConst<Shape> GetShape(const BodyID &inBodyID) const; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
void SetShape(const BodyID &inBodyID, const Shape *inShape, bool inUpdateMassProperties, EActivation inActivationMode) const; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
void NotifyShapeChanged(const BodyID &inBodyID, Vec3Arg inPreviousCenterOfMass, bool inUpdateMassProperties, EActivation inActivationMode) const; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
void SetObjectLayer(const BodyID &inBodyID, ObjectLayer inLayer); |
| 182 |
ObjectLayer GetObjectLayer(const BodyID &inBodyID) const; |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
void SetPositionAndRotation(const BodyID &inBodyID, RVec3Arg inPosition, QuatArg inRotation, EActivation inActivationMode); |
| 188 |
void SetPositionAndRotationWhenChanged(const BodyID &inBodyID, RVec3Arg inPosition, QuatArg inRotation, EActivation inActivationMode); |
| 189 |
void GetPositionAndRotation(const BodyID &inBodyID, RVec3 &outPosition, Quat &outRotation) const; |
| 190 |
void SetPosition(const BodyID &inBodyID, RVec3Arg inPosition, EActivation inActivationMode); |
| 191 |
RVec3 GetPosition(const BodyID &inBodyID) const; |
| 192 |
RVec3 GetCenterOfMassPosition(const BodyID &inBodyID) const; |
| 193 |
void SetRotation(const BodyID &inBodyID, QuatArg inRotation, EActivation inActivationMode); |
| 194 |
Quat GetRotation(const BodyID &inBodyID) const; |
| 195 |
RMat44 GetWorldTransform(const BodyID &inBodyID) const; |
| 196 |
RMat44 GetCenterOfMassTransform(const BodyID &inBodyID) const; |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
void MoveKinematic(const BodyID &inBodyID, RVec3Arg inTargetPosition, QuatArg inTargetRotation, float inDeltaTime); |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
void SetLinearAndAngularVelocity(const BodyID &inBodyID, Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity); |
| 205 |
void GetLinearAndAngularVelocity(const BodyID &inBodyID, Vec3 &outLinearVelocity, Vec3 &outAngularVelocity) const; |
| 206 |
void SetLinearVelocity(const BodyID &inBodyID, Vec3Arg inLinearVelocity); |
| 207 |
Vec3 GetLinearVelocity(const BodyID &inBodyID) const; |
| 208 |
void AddLinearVelocity(const BodyID &inBodyID, Vec3Arg inLinearVelocity); |
| 209 |
void AddLinearAndAngularVelocity(const BodyID &inBodyID, Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity); |
| 210 |
void SetAngularVelocity(const BodyID &inBodyID, Vec3Arg inAngularVelocity); |
| 211 |
Vec3 GetAngularVelocity(const BodyID &inBodyID) const; |
| 212 |
Vec3 GetPointVelocity(const BodyID &inBodyID, RVec3Arg inPoint) const; |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
void SetPositionRotationAndVelocity(const BodyID &inBodyID, RVec3Arg inPosition, QuatArg inRotation, Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity); |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
void AddForce(const BodyID &inBodyID, Vec3Arg inForce, EActivation inActivationMode = EActivation::Activate); |
| 221 |
void AddForce(const BodyID &inBodyID, Vec3Arg inForce, RVec3Arg inPoint, EActivation inActivationMode = EActivation::Activate); |
| 222 |
void AddTorque(const BodyID &inBodyID, Vec3Arg inTorque, EActivation inActivationMode = EActivation::Activate); |
| 223 |
void AddForceAndTorque(const BodyID &inBodyID, Vec3Arg inForce, Vec3Arg inTorque, EActivation inActivationMode = EActivation::Activate); |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
void AddImpulse(const BodyID &inBodyID, Vec3Arg inImpulse); |
| 229 |
void AddImpulse(const BodyID &inBodyID, Vec3Arg inImpulse, RVec3Arg inPoint); |
| 230 |
void AddAngularImpulse(const BodyID &inBodyID, Vec3Arg inAngularImpulse); |
| 231 |
bool ApplyBuoyancyImpulse(const BodyID &inBodyID, RVec3Arg inSurfacePosition, Vec3Arg inSurfaceNormal, float inBuoyancy, float inLinearDrag, float inAngularDrag, Vec3Arg inFluidVelocity, Vec3Arg inGravity, float inDeltaTime); |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
EBodyType GetBodyType(const BodyID &inBodyID) const; |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
void SetMotionType(const BodyID &inBodyID, EMotionType inMotionType, EActivation inActivationMode); |
| 242 |
EMotionType GetMotionType(const BodyID &inBodyID) const; |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
void SetMotionQuality(const BodyID &inBodyID, EMotionQuality inMotionQuality); |
| 248 |
EMotionQuality GetMotionQuality(const BodyID &inBodyID) const; |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
Mat44 GetInverseInertia(const BodyID &inBodyID) const; |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
void SetRestitution(const BodyID &inBodyID, float inRestitution); |
| 257 |
float GetRestitution(const BodyID &inBodyID) const; |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
void SetFriction(const BodyID &inBodyID, float inFriction); |
| 263 |
float GetFriction(const BodyID &inBodyID) const; |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
void SetGravityFactor(const BodyID &inBodyID, float inGravityFactor); |
| 269 |
float GetGravityFactor(const BodyID &inBodyID) const; |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
void SetMaxLinearVelocity(const BodyID &inBodyID, float inLinearVelocity); |
| 275 |
float GetMaxLinearVelocity(const BodyID &inBodyID) const; |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
void SetMaxAngularVelocity(const BodyID &inBodyID, float inAngularVelocity); |
| 281 |
float GetMaxAngularVelocity(const BodyID &inBodyID) const; |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
void SetUseManifoldReduction(const BodyID &inBodyID, bool inUseReduction); |
| 287 |
bool GetUseManifoldReduction(const BodyID &inBodyID) const; |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
void SetIsSensor(const BodyID &inBodyID, bool inIsSensor); |
| 293 |
bool IsSensor(const BodyID &inBodyID) const; |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
void SetCollisionGroup(const BodyID &inBodyID, const CollisionGroup &inCollisionGroup); |
| 299 |
const CollisionGroup & GetCollisionGroup(const BodyID &inBodyID) const; |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
TransformedShape GetTransformedShape(const BodyID &inBodyID) const; |
| 304 |
|
| 305 |
|
| 306 |
uint64 GetUserData(const BodyID &inBodyID) const; |
| 307 |
void SetUserData(const BodyID &inBodyID, uint64 inUserData) const; |
| 308 |
|
| 309 |
|
| 310 |
const PhysicsMaterial * GetMaterial(const BodyID &inBodyID, const SubShapeID &inSubShapeID) const; |
| 311 |
|
| 312 |
|
| 313 |
void InvalidateContactCache(const BodyID &inBodyID); |
| 314 |
|
| 315 |
private: |
| 316 |
|
| 317 |
JPH_INLINE void ActivateBodyInternal(Body &ioBody) const; |
| 318 |
|
| 319 |
BodyLockInterface * mBodyLockInterface = nullptr; |
| 320 |
BodyManager * mBodyManager = nullptr; |
| 321 |
BroadPhase * mBroadPhase = nullptr; |
| 322 |
}; |
| 323 |
|
| 324 |
JPH_NAMESPACE_END |