Jolt Physics
A multi core friendly Game Physics Engine
|
#include <Character.h>
Public Member Functions | |
JPH_OVERRIDE_NEW_DELETE | Character (const CharacterSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, uint64 inUserData, PhysicsSystem *inSystem) |
virtual | ~Character () override |
Destructor. | |
void | AddToPhysicsSystem (EActivation inActivationMode=EActivation::Activate, bool inLockBodies=true) |
Add bodies and constraints to the system and optionally activate the bodies. | |
void | RemoveFromPhysicsSystem (bool inLockBodies=true) |
Remove bodies and constraints from the system. | |
void | Activate (bool inLockBodies=true) |
Wake up the character. | |
void | PostSimulation (float inMaxSeparationDistance, bool inLockBodies=true) |
void | SetLinearAndAngularVelocity (Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity, bool inLockBodies=true) |
Control the velocity of the character. | |
Vec3 | GetLinearVelocity (bool inLockBodies=true) const |
Get the linear velocity of the character (m / s) | |
void | SetLinearVelocity (Vec3Arg inLinearVelocity, bool inLockBodies=true) |
Set the linear velocity of the character (m / s) | |
void | AddLinearVelocity (Vec3Arg inLinearVelocity, bool inLockBodies=true) |
Add world space linear velocity to current velocity (m / s) | |
void | AddImpulse (Vec3Arg inImpulse, bool inLockBodies=true) |
Add impulse to the center of mass of the character. | |
BodyID | GetBodyID () const |
Get the body associated with this character. | |
void | GetPositionAndRotation (RVec3 &outPosition, Quat &outRotation, bool inLockBodies=true) const |
Get position / rotation of the body. | |
void | SetPositionAndRotation (RVec3Arg inPosition, QuatArg inRotation, EActivation inActivationMode=EActivation::Activate, bool inLockBodies=true) const |
Set the position / rotation of the body, optionally activating it. | |
RVec3 | GetPosition (bool inLockBodies=true) const |
Get the position of the character. | |
void | SetPosition (RVec3Arg inPostion, EActivation inActivationMode=EActivation::Activate, bool inLockBodies=true) |
Set the position of the character, optionally activating it. | |
Quat | GetRotation (bool inLockBodies=true) const |
Get the rotation of the character. | |
void | SetRotation (QuatArg inRotation, EActivation inActivationMode=EActivation::Activate, bool inLockBodies=true) |
Set the rotation of the character, optionally activating it. | |
RVec3 | GetCenterOfMassPosition (bool inLockBodies=true) const |
Position of the center of mass of the underlying rigid body. | |
RMat44 | GetWorldTransform (bool inLockBodies=true) const |
Calculate the world transform of the character. | |
ObjectLayer | GetLayer () const |
Get the layer of the character. | |
void | SetLayer (ObjectLayer inLayer, bool inLockBodies=true) |
Update the layer of the character. | |
bool | SetShape (const Shape *inShape, float inMaxPenetrationDepth, bool inLockBodies=true) |
TransformedShape | GetTransformedShape (bool inLockBodies=true) const |
Get the transformed shape that represents the volume of the character, can be used for collision checks. | |
void | CheckCollision (RVec3Arg inPosition, QuatArg inRotation, Vec3Arg inMovementDirection, float inMaxSeparationDistance, const Shape *inShape, RVec3Arg inBaseOffset, CollideShapeCollector &ioCollector, bool inLockBodies=true) const |
Get all contacts for the character at a particular location. | |
Public Member Functions inherited from CharacterBase | |
JPH_OVERRIDE_NEW_DELETE | CharacterBase (const CharacterBaseSettings *inSettings, PhysicsSystem *inSystem) |
Constructor. | |
virtual | ~CharacterBase ()=default |
Destructor. | |
void | SetMaxSlopeAngle (float inMaxSlopeAngle) |
Set the maximum angle of slope that character can still walk on (radians) | |
float | GetCosMaxSlopeAngle () const |
void | SetUp (Vec3Arg inUp) |
Set the up vector for the character. | |
Vec3 | GetUp () const |
bool | IsSlopeTooSteep (Vec3Arg inNormal) const |
Check if the normal of the ground surface is too steep to walk on. | |
const Shape * | GetShape () const |
Get the current shape that the character is using. | |
EGroundState | GetGroundState () const |
Current ground state. | |
bool | IsSupported () const |
Returns true if the player is supported by normal or steep ground. | |
RVec3 | GetGroundPosition () const |
Get the contact point with the ground. | |
Vec3 | GetGroundNormal () const |
Get the contact normal with the ground. | |
Vec3 | GetGroundVelocity () const |
Velocity in world space of ground. | |
const PhysicsMaterial * | GetGroundMaterial () const |
Material that the character is standing on. | |
BodyID | GetGroundBodyID () const |
BodyID of the object the character is standing on. Note may have been removed! | |
SubShapeID | GetGroundSubShapeID () const |
Sub part of the body that we're standing on. | |
uint64 | GetGroundUserData () const |
User data value of the body that we're standing on. | |
virtual void | SaveState (StateRecorder &inStream) const |
virtual void | RestoreState (StateRecorder &inStream) |
Public Member Functions inherited from RefTarget< CharacterBase > | |
RefTarget ()=default | |
Constructor. | |
RefTarget (const RefTarget &) | |
~RefTarget () | |
assert no one is referencing us | |
void | SetEmbedded () const |
RefTarget & | operator= (const RefTarget &) |
Assignment operator. | |
uint32 | GetRefCount () const |
Get current refcount of this object. | |
void | AddRef () const |
Add or release a reference to this object. | |
void | Release () const |
Public Member Functions inherited from NonCopyable | |
NonCopyable ()=default | |
NonCopyable (const NonCopyable &)=delete | |
void | operator= (const NonCopyable &)=delete |
Additional Inherited Members | |
Public Types inherited from CharacterBase | |
enum class | EGroundState { OnGround , OnSteepGround , NotSupported , InAir } |
Static Public Member Functions inherited from CharacterBase | |
static const char * | sToString (EGroundState inState) |
Debug function to convert enum values to string. | |
Static Public Member Functions inherited from RefTarget< CharacterBase > | |
static int | sInternalGetRefCountOffset () |
INTERNAL HELPER FUNCTION USED BY SERIALIZATION. | |
Protected Attributes inherited from CharacterBase | |
PhysicsSystem * | mSystem |
RefConst< Shape > | mShape |
Vec3 | mUp |
Plane | mSupportingVolume |
float | mCosMaxSlopeAngle |
EGroundState | mGroundState = EGroundState::InAir |
BodyID | mGroundBodyID |
SubShapeID | mGroundBodySubShapeID |
RVec3 | mGroundPosition = RVec3::sZero() |
Vec3 | mGroundNormal = Vec3::sZero() |
Vec3 | mGroundVelocity = Vec3::sZero() |
RefConst< PhysicsMaterial > | mGroundMaterial = PhysicsMaterial::sDefault |
uint64 | mGroundUserData = 0 |
Protected Attributes inherited from RefTarget< CharacterBase > | |
atomic< uint32 > | mRefCount |
Current reference count. | |
Static Protected Attributes inherited from CharacterBase | |
static constexpr float | cNoMaxSlopeAngle = 0.9999f |
Static Protected Attributes inherited from RefTarget< CharacterBase > | |
static constexpr uint32 | cEmbedded |
A large value that gets added to the refcount to mark the object as embedded. | |
Runtime character object. This object usually represents the player or a humanoid AI. It uses a single rigid body, usually with a capsule shape to simulate movement and collision for the character. The character is a keyframed object, the application controls it by setting the velocity.
Character::Character | ( | const CharacterSettings * | inSettings, |
RVec3Arg | inPosition, | ||
QuatArg | inRotation, | ||
uint64 | inUserData, | ||
PhysicsSystem * | inSystem | ||
) |
Constructor
inSettings | The settings for the character |
inPosition | Initial position for the character |
inRotation | Initial rotation for the character (usually only around Y) |
inUserData | Application specific value |
inSystem | Physics system that this character will be added to later |
|
overridevirtual |
Destructor.
void Character::Activate | ( | bool | inLockBodies = true | ) |
Wake up the character.
void Character::AddImpulse | ( | Vec3Arg | inImpulse, |
bool | inLockBodies = true |
||
) |
Add impulse to the center of mass of the character.
void Character::AddLinearVelocity | ( | Vec3Arg | inLinearVelocity, |
bool | inLockBodies = true |
||
) |
Add world space linear velocity to current velocity (m / s)
void Character::AddToPhysicsSystem | ( | EActivation | inActivationMode = EActivation::Activate , |
bool | inLockBodies = true |
||
) |
Add bodies and constraints to the system and optionally activate the bodies.
void Character::CheckCollision | ( | RVec3Arg | inPosition, |
QuatArg | inRotation, | ||
Vec3Arg | inMovementDirection, | ||
float | inMaxSeparationDistance, | ||
const Shape * | inShape, | ||
RVec3Arg | inBaseOffset, | ||
CollideShapeCollector & | ioCollector, | ||
bool | inLockBodies = true |
||
) | const |
Get all contacts for the character at a particular location.
inPosition | Position to test. |
inRotation | Rotation at which to test the shape. |
inMovementDirection | A hint in which direction the character is moving, will be used to calculate a proper normal. |
inMaxSeparationDistance | How much distance around the character you want to report contacts in (can be 0 to match the character exactly). |
inShape | Shape to test collision with. |
inBaseOffset | All hit results will be returned relative to this offset, can be zero to get results in world position, but when you're testing far from the origin you get better precision by picking a position that's closer e.g. GetPosition() since floats are most accurate near the origin |
ioCollector | Collision collector that receives the collision results. |
inLockBodies | If the collision query should use the locking body interface (true) or the non locking body interface (false) |
|
inline |
Get the body associated with this character.
RVec3 Character::GetCenterOfMassPosition | ( | bool | inLockBodies = true | ) | const |
Position of the center of mass of the underlying rigid body.
|
inline |
Get the layer of the character.
Vec3 Character::GetLinearVelocity | ( | bool | inLockBodies = true | ) | const |
Get the linear velocity of the character (m / s)
RVec3 Character::GetPosition | ( | bool | inLockBodies = true | ) | const |
Get the position of the character.
void Character::GetPositionAndRotation | ( | RVec3 & | outPosition, |
Quat & | outRotation, | ||
bool | inLockBodies = true |
||
) | const |
Get position / rotation of the body.
Quat Character::GetRotation | ( | bool | inLockBodies = true | ) | const |
Get the rotation of the character.
TransformedShape Character::GetTransformedShape | ( | bool | inLockBodies = true | ) | const |
Get the transformed shape that represents the volume of the character, can be used for collision checks.
RMat44 Character::GetWorldTransform | ( | bool | inLockBodies = true | ) | const |
Calculate the world transform of the character.
void Character::PostSimulation | ( | float | inMaxSeparationDistance, |
bool | inLockBodies = true |
||
) |
Needs to be called after every PhysicsSystem::Update
inMaxSeparationDistance | Max distance between the floor and the character to still consider the character standing on the floor |
inLockBodies | If the collision query should use the locking body interface (true) or the non locking body interface (false) |
void Character::RemoveFromPhysicsSystem | ( | bool | inLockBodies = true | ) |
Remove bodies and constraints from the system.
void Character::SetLayer | ( | ObjectLayer | inLayer, |
bool | inLockBodies = true |
||
) |
Update the layer of the character.
void Character::SetLinearAndAngularVelocity | ( | Vec3Arg | inLinearVelocity, |
Vec3Arg | inAngularVelocity, | ||
bool | inLockBodies = true |
||
) |
Control the velocity of the character.
void Character::SetLinearVelocity | ( | Vec3Arg | inLinearVelocity, |
bool | inLockBodies = true |
||
) |
Set the linear velocity of the character (m / s)
void Character::SetPosition | ( | RVec3Arg | inPostion, |
EActivation | inActivationMode = EActivation::Activate , |
||
bool | inLockBodies = true |
||
) |
Set the position of the character, optionally activating it.
void Character::SetPositionAndRotation | ( | RVec3Arg | inPosition, |
QuatArg | inRotation, | ||
EActivation | inActivationMode = EActivation::Activate , |
||
bool | inLockBodies = true |
||
) | const |
Set the position / rotation of the body, optionally activating it.
void Character::SetRotation | ( | QuatArg | inRotation, |
EActivation | inActivationMode = EActivation::Activate , |
||
bool | inLockBodies = true |
||
) |
Set the rotation of the character, optionally activating it.
bool Character::SetShape | ( | const Shape * | inShape, |
float | inMaxPenetrationDepth, | ||
bool | inLockBodies = true |
||
) |
Switch the shape of the character (e.g. for stance). When inMaxPenetrationDepth is not FLT_MAX, it checks if the new shape collides before switching shape. Returns true if the switch succeeded.