2#ifdef StevEngine_PHYSICS
3#include "main/Component.hpp"
4#include "physics/Layers.hpp"
5#include "utilities/Vector3.hpp"
7#include "Jolt/Physics/Character/CharacterVirtual.h"
9#define CHARACTERBODY_TYPE "CharacterBody"
11namespace StevEngine::Physics {
55 virtual std::string
GetType()
const {
return CHARACTERBODY_TYPE; }
79 virtual void Update(
double deltaTime);
85 void ExtendedUpdate(
double deltaTime, JPH::CharacterVirtual::ExtendedUpdateSettings updateSettings = {});
103 JPH::Ref<JPH::Shape>
GetShape()
const {
return shape; }
106 JPH::CharacterVirtual* jphCharacter;
107 JPH::Ref<JPH::Shape> shape;
110 JPH::BodyFilter bodyFilter;
111 JPH::ShapeFilter shapeFilter;
115 bool IsSupported()
const {
return jphCharacter->IsSupported(); };
116 bool IsOnGround()
const {
return jphCharacter->GetGroundState() == JPH::CharacterBase::EGroundState::OnGround; };
117 float GetMass ()
const {
return jphCharacter->GetMass(); };
120 void SetMaxStrength (
float maxStrength) { jphCharacter->SetMaxStrength(maxStrength);
settings.mMaxStrength = maxStrength; };
121 float GetPenetrationRecoverySpeed ()
const {
return jphCharacter->GetPenetrationRecoverySpeed(); };
128 void SetMaxSlopeAngle (
float maxSlopeAngle) { jphCharacter->SetMaxSlopeAngle(maxSlopeAngle);
settings.mMaxSlopeAngle = maxSlopeAngle; };
Component()
Create new component.
Definition Component.cpp:11
uint GetMaxNumHits() const
Character padding.
Definition CharacterBody.hpp:124
void SetHitReductionCosMaxAngle(float cosMaxAngle)
Cos(angle) where angle is the maximum angle between two hits contact normals that are allowed to be m...
Definition CharacterBody.hpp:127
float GetMaxStrength() const
Set character mass (kg)
Definition CharacterBody.hpp:119
virtual std::string GetType() const
Get component type.
Definition CharacterBody.hpp:55
JPH::Ref< JPH::Shape > GetShape() const
Get Jolt Physics collision shape.
Definition CharacterBody.hpp:103
Utilities::Vector3 velocity
Character velocity.
Definition CharacterBody.hpp:49
virtual ~CharacterBody()
Clean up resources.
Definition CharacterBody.cpp:165
virtual Utilities::Stream Export(Utilities::StreamType type) const
Serialize component to a stream.
Definition CharacterBody.cpp:108
float GetCharacterPadding() const
Set how fast a penetration will be resolved, 0 = nothing is resolved, 1 = everything in one update.
Definition CharacterBody.hpp:123
LayerID layer
Physics layer.
Definition CharacterBody.hpp:100
void SetMaxSlopeAngle(float maxSlopeAngle)
Set Cos(angle) where angle is the maximum angle between two hits contact normals that are allowed to ...
Definition CharacterBody.hpp:128
void ExtendedUpdate(double deltaTime, JPH::CharacterVirtual::ExtendedUpdateSettings updateSettings={})
Extended physics transform update.
Definition CharacterBody.cpp:156
virtual void Deactivate()
Clean up when deactivated.
Definition CharacterBody.cpp:142
void SetPenetrationRecoverySpeed(float speed)
This value governs how fast a penetration will be resolved, 0 = nothing is resolved,...
Definition CharacterBody.hpp:122
bool IsSlopeTooSteep(Utilities::Vector3 normal) const
Set the maximum angle of slope that character can still walk on (radians)
Definition CharacterBody.hpp:129
void SetMass(float mass)
Get character mass (kg)
Definition CharacterBody.hpp:118
CharacterBody(CharacterSettings settings={}, LayerID layer=LayerManager::DEFAULT)
Create rigid body.
Definition CharacterBody.cpp:36
float GetHitReductionCosMaxAngle() const
Set max num hits to collect in order to avoid excess of contact points collection.
Definition CharacterBody.hpp:126
JPH::CharacterVirtualSettings settings
Jolt Physics Virtual Character Controller Settings.
Definition CharacterBody.hpp:99
virtual void Start()
Initialize component.
Definition CharacterBody.cpp:127
bool SetShape(JPH::Ref< JPH::Shape > shape, Utilities::Vector3 shapeOffset=0)
Set Jolt Physics collision shape.
Definition CharacterBody.cpp:70
float GetMass() const
Is character on the ground.
Definition CharacterBody.hpp:117
bool IsOnGround() const
Is character supported (by ground/wall)
Definition CharacterBody.hpp:116
void SetMaxStrength(float maxStrength)
Maximum force with which the character can push other bodies (N)
Definition CharacterBody.hpp:120
void SetMaxNumHits(uint maxHits)
Max num hits to collect in order to avoid excess of contact points collection.
Definition CharacterBody.hpp:125
static const bool unique
Only one per GameObject.
Definition CharacterBody.hpp:34
virtual void Update(double deltaTime)
Update transform from physics Adds gravity to the current velocity.
Definition CharacterBody.cpp:146
virtual bool RefreshShape()
Refresh combined collision shape Rebuilds shape from all attached colliders.
Definition CharacterBody.cpp:44
Stream for serialization of data.
Definition Stream.hpp:22
3D vector class
Definition Vector3.hpp:17
Definition CharacterBody.hpp:12
float minTimeRemaining
Early out condition: If this much time is left to simulate we are done.
Definition CharacterBody.hpp:18
uint32_t maxNumHits
Max num hits to collect in order to avoid excess of contact points collection.
Definition CharacterBody.hpp:21
float predictiveContactDistance
How far to scan outside of the shape for predictive contacts. A value of 0 will most likely cause the...
Definition CharacterBody.hpp:15
float maxStrength
Maximum force with which the character can push other bodies (N).
Definition CharacterBody.hpp:14
float collisionTolerance
How far we're willing to penetrate geometry.
Definition CharacterBody.hpp:19
uint32_t maxCollisionIterations
Max amount of collision loops.
Definition CharacterBody.hpp:16
float characterPadding
How far we try to stay away from the geometry, this ensures that the sweep will hit as little as poss...
Definition CharacterBody.hpp:20
float penetrationRecoverySpeed
This value governs how fast a penetration will be resolved, 0 = nothing is resolved,...
Definition CharacterBody.hpp:23
float hitReductionCosMaxAngle
Cos(angle) where angle is the maximum angle between two hits contact normals that are allowed to be m...
Definition CharacterBody.hpp:22
float mass
Character mass (kg)
Definition CharacterBody.hpp:13
uint32_t maxConstraintIterations
How often to try stepping in the constraint solving.
Definition CharacterBody.hpp:17