| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Core/Reference.h> |
| 8 |
#include <Jolt/Core/NonCopyable.h> |
| 9 |
#include <Jolt/Physics/Body/BodyID.h> |
| 10 |
#include <Jolt/Physics/Collision/Shape/Shape.h> |
| 11 |
#include <Jolt/Physics/Collision/Shape/SubShapeID.h> |
| 12 |
#include <Jolt/Physics/Collision/PhysicsMaterial.h> |
| 13 |
|
| 14 |
JPH_NAMESPACE_BEGIN |
| 15 |
|
| 16 |
class PhysicsSystem; |
| 17 |
class StateRecorder; |
| 18 |
|
| 19 |
|
| 20 |
class JPH_EXPORT CharacterBaseSettings : public RefTarget<CharacterBaseSettings> |
| 21 |
{ |
| 22 |
public: |
| 23 |
JPH_OVERRIDE_NEW_DELETE |
| 24 |
|
| 25 |
|
| 26 |
CharacterBaseSettings() = default; |
| 27 |
CharacterBaseSettings(const CharacterBaseSettings &) = default; |
| 28 |
CharacterBaseSettings & operator = (const CharacterBaseSettings &) = default; |
| 29 |
|
| 30 |
|
| 31 |
virtual ~CharacterBaseSettings() = default; |
| 32 |
|
| 33 |
|
| 34 |
Vec3 mUp = Vec3::sAxisY(); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
Plane mSupportingVolume { Vec3::sAxisY(), -1.0e10f }; |
| 40 |
|
| 41 |
|
| 42 |
float mMaxSlopeAngle = DegreesToRadians(50.0f); |
| 43 |
|
| 44 |
|
| 45 |
bool mEnhancedInternalEdgeRemoval = false; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
RefConst<Shape> mShape; |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
class JPH_EXPORT CharacterBase : public RefTarget<CharacterBase>, public NonCopyable |
| 54 |
{ |
| 55 |
public: |
| 56 |
JPH_OVERRIDE_NEW_DELETE |
| 57 |
|
| 58 |
|
| 59 |
CharacterBase(const CharacterBaseSettings *inSettings, PhysicsSystem *inSystem); |
| 60 |
|
| 61 |
|
| 62 |
virtual ~CharacterBase() = default; |
| 63 |
|
| 64 |
|
| 65 |
void SetMaxSlopeAngle(float inMaxSlopeAngle) { mCosMaxSlopeAngle = Cos(inMaxSlopeAngle); } |
| 66 |
float GetCosMaxSlopeAngle() const { return mCosMaxSlopeAngle; } |
| 67 |
|
| 68 |
|
| 69 |
void SetUp(Vec3Arg inUp) { mUp = inUp; } |
| 70 |
Vec3 GetUp() const { return mUp; } |
| 71 |
|
| 72 |
|
| 73 |
bool IsSlopeTooSteep(Vec3Arg inNormal) const |
| 74 |
{ |
| 75 |
|
| 76 |
|
| 77 |
return mCosMaxSlopeAngle < cNoMaxSlopeAngle && inNormal.Dot(mUp) < mCosMaxSlopeAngle; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
const Shape * GetShape() const { return mShape; } |
| 82 |
|
| 83 |
enum class EGroundState |
| 84 |
{ |
| 85 |
OnGround, |
| 86 |
OnSteepGround, |
| 87 |
NotSupported, |
| 88 |
InAir, |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
static const char * sToString(EGroundState inState); |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
EGroundState GetGroundState() const { return mGroundState; } |
| 98 |
|
| 99 |
|
| 100 |
bool IsSupported() const { return mGroundState == EGroundState::OnGround || mGroundState == EGroundState::OnSteepGround; } |
| 101 |
|
| 102 |
|
| 103 |
RVec3 GetGroundPosition() const { return mGroundPosition; } |
| 104 |
|
| 105 |
|
| 106 |
Vec3 GetGroundNormal() const { return mGroundNormal; } |
| 107 |
|
| 108 |
|
| 109 |
Vec3 GetGroundVelocity() const { return mGroundVelocity; } |
| 110 |
|
| 111 |
|
| 112 |
const PhysicsMaterial * GetGroundMaterial() const { return mGroundMaterial; } |
| 113 |
|
| 114 |
|
| 115 |
BodyID GetGroundBodyID() const { return mGroundBodyID; } |
| 116 |
|
| 117 |
|
| 118 |
SubShapeID GetGroundSubShapeID() const { return mGroundBodySubShapeID; } |
| 119 |
|
| 120 |
|
| 121 |
uint64 GetGroundUserData() const { return mGroundUserData; } |
| 122 |
|
| 123 |
|
| 124 |
virtual void SaveState(StateRecorder &inStream) const; |
| 125 |
virtual void RestoreState(StateRecorder &inStream); |
| 126 |
|
| 127 |
protected: |
| 128 |
|
| 129 |
PhysicsSystem * mSystem; |
| 130 |
|
| 131 |
|
| 132 |
RefConst<Shape> mShape; |
| 133 |
|
| 134 |
|
| 135 |
Vec3 mUp; |
| 136 |
|
| 137 |
|
| 138 |
Plane mSupportingVolume; |
| 139 |
|
| 140 |
|
| 141 |
static constexpr float cNoMaxSlopeAngle = 0.9999f; |
| 142 |
|
| 143 |
|
| 144 |
float mCosMaxSlopeAngle; |
| 145 |
|
| 146 |
|
| 147 |
EGroundState mGroundState = EGroundState::InAir; |
| 148 |
BodyID mGroundBodyID; |
| 149 |
SubShapeID mGroundBodySubShapeID; |
| 150 |
RVec3 mGroundPosition = RVec3::sZero(); |
| 151 |
Vec3 mGroundNormal = Vec3::sZero(); |
| 152 |
Vec3 mGroundVelocity = Vec3::sZero(); |
| 153 |
RefConst<PhysicsMaterial> mGroundMaterial = PhysicsMaterial::sDefault; |
| 154 |
uint64 mGroundUserData = 0; |
| 155 |
}; |
| 156 |
|
| 157 |
JPH_NAMESPACE_END |