Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
CharacterBase.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
15
16class PhysicsSystem;
17class StateRecorder;
18
51
53class JPH_EXPORT CharacterBase : public RefTarget<CharacterBase>, public NonCopyable
54{
55public:
57
59 CharacterBase(const CharacterBaseSettings *inSettings, PhysicsSystem *inSystem);
60
62 virtual ~CharacterBase() = default;
63
65 void SetMaxSlopeAngle(float inMaxSlopeAngle) { mCosMaxSlopeAngle = Cos(inMaxSlopeAngle); }
66 float GetCosMaxSlopeAngle() const { return mCosMaxSlopeAngle; }
67
69 void SetUp(Vec3Arg inUp) { mUp = inUp; }
70 Vec3 GetUp() const { return mUp; }
71
73 bool IsSlopeTooSteep(Vec3Arg inNormal) const
74 {
75 // If cos max slope angle is close to one the system is turned off,
76 // otherwise check the angle between the up and normal vector
78 }
79
81 const Shape * GetShape() const { return mShape; }
82
83 enum class EGroundState
84 {
85 OnGround,
86 OnSteepGround,
87 NotSupported,
88 InAir,
89 };
90
92 static const char * sToString(EGroundState inState);
93
95
98
101
104
107
110
113
116
119
122
123 // Saving / restoring state for replay
124 virtual void SaveState(StateRecorder &inStream) const;
125 virtual void RestoreState(StateRecorder &inStream);
126
127protected:
128 // Cached physics system
130
131 // The shape that the body currently has
133
134 // The character's world space up axis
136
137 // Every contact behind this plane can support the character
139
140 // Beyond this value there is no max slope
141 static constexpr float cNoMaxSlopeAngle = 0.9999f;
142
143 // Cosine of the maximum angle of slope that character can still walk on
145
146 // Ground properties
155};
156
#define JPH_EXPORT
Definition Core.h:275
std::uint64_t uint64
Definition Core.h:504
#define JPH_NAMESPACE_END
Definition Core.h:425
#define JPH_NAMESPACE_BEGIN
Definition Core.h:419
JPH_INLINE constexpr float DegreesToRadians(float inV)
Convert a value from degrees to radians.
Definition Math.h:16
const Vec3 Vec3Arg
Definition MathTypes.h:19
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:50
Vec3 RVec3
Definition Real.h:29
JPH_INLINE float Cos(float inX)
Cosine of x (input in radians).
Definition Trigonometry.h:20
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition BodyID.h:13
void SetMaxSlopeAngle(float inMaxSlopeAngle)
Set the maximum angle of slope that character can still walk on (radians).
Definition CharacterBase.h:65
RVec3 GetGroundPosition() const
Get the contact point with the ground.
Definition CharacterBase.h:103
EGroundState mGroundState
Definition CharacterBase.h:147
RefConst< PhysicsMaterial > mGroundMaterial
Definition CharacterBase.h:153
Vec3 GetUp() const
Definition CharacterBase.h:70
SubShapeID GetGroundSubShapeID() const
Sub part of the body that we're standing on.
Definition CharacterBase.h:118
RVec3 mGroundPosition
Definition CharacterBase.h:150
static constexpr float cNoMaxSlopeAngle
Definition CharacterBase.h:141
Vec3 mGroundNormal
Definition CharacterBase.h:151
void SetUp(Vec3Arg inUp)
Set the up vector for the character.
Definition CharacterBase.h:69
RefConst< Shape > mShape
Definition CharacterBase.h:132
virtual ~CharacterBase()=default
Destructor.
Vec3 mUp
Definition CharacterBase.h:135
Vec3 GetGroundVelocity() const
Velocity in world space of ground.
Definition CharacterBase.h:109
bool IsSupported() const
Returns true if the player is supported by normal or steep ground.
Definition CharacterBase.h:100
EGroundState
Definition CharacterBase.h:84
@ OnGround
Character is on the ground and can move freely.
Definition CharacterBase.h:85
@ OnSteepGround
Character is on a slope that is too steep and can't climb up any further. The caller should start app...
Definition CharacterBase.h:86
@ InAir
Character is in the air and is not touching anything.
Definition CharacterBase.h:88
bool IsSlopeTooSteep(Vec3Arg inNormal) const
Check if the normal of the ground surface is too steep to walk on.
Definition CharacterBase.h:73
BodyID mGroundBodyID
Definition CharacterBase.h:148
float mCosMaxSlopeAngle
Definition CharacterBase.h:144
float GetCosMaxSlopeAngle() const
Definition CharacterBase.h:66
BodyID GetGroundBodyID() const
BodyID of the object the character is standing on. Note may have been removed!
Definition CharacterBase.h:115
EGroundState GetGroundState() const
Current ground state.
Definition CharacterBase.h:97
const PhysicsMaterial * GetGroundMaterial() const
Material that the character is standing on.
Definition CharacterBase.h:112
PhysicsSystem * mSystem
Definition CharacterBase.h:129
uint64 mGroundUserData
Definition CharacterBase.h:154
Vec3 mGroundVelocity
Definition CharacterBase.h:152
Vec3 GetGroundNormal() const
Get the contact normal with the ground.
Definition CharacterBase.h:106
JPH_OVERRIDE_NEW_DELETE CharacterBase(const CharacterBaseSettings *inSettings, PhysicsSystem *inSystem)
Constructor.
Definition CharacterBase.cpp:12
uint64 GetGroundUserData() const
User data value of the body that we're standing on.
Definition CharacterBase.h:121
Plane mSupportingVolume
Definition CharacterBase.h:138
SubShapeID mGroundBodySubShapeID
Definition CharacterBase.h:149
const Shape * GetShape() const
Get the current shape that the character is using.
Definition CharacterBase.h:81
Base class for configuration of a character.
Definition CharacterBase.h:21
bool mEnhancedInternalEdgeRemoval
Set to indicate that extra effort should be made to try to remove ghost contacts (collisions with int...
Definition CharacterBase.h:45
Plane mSupportingVolume
Definition CharacterBase.h:39
float mMaxSlopeAngle
Maximum angle of slope that character can still walk on (radians).
Definition CharacterBase.h:42
Vec3 mUp
Vector indicating the up direction of the character.
Definition CharacterBase.h:34
virtual ~CharacterBaseSettings()=default
Virtual destructor.
CharacterBaseSettings(const CharacterBaseSettings &)=default
RefConst< Shape > mShape
Definition CharacterBase.h:49
JPH_OVERRIDE_NEW_DELETE CharacterBaseSettings()=default
Constructor.
NonCopyable()=default
Definition PhysicsMaterial.h:23
static RefConst< PhysicsMaterial > sDefault
Default material that is used when a shape has no materials defined.
Definition PhysicsMaterial.h:32
Definition PhysicsSystem.h:30
An infinite plane described by the formula X . Normal + Constant = 0.
Definition Plane.h:11
Definition Reference.h:163
RefTarget & operator=(const RefTarget &)
Assignment operator.
Definition Reference.h:48
Base class for all shapes (collision volume of a body). Defines a virtual interface for collision det...
Definition Shape.h:186
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 Vec3.h:17
JPH_INLINE float Dot(Vec3Arg inV2) const
Dot product.
Definition Vec3.inl:650
static JPH_INLINE Vec3 sAxisY()
Definition Vec3.h:57
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:103