139 void SetMass(
float inMass) { mMass = inMass; }
274 void CheckCollision(
RVec3Arg inPosition,
QuatArg inRotation,
Vec3Arg inMovementDirection,
float inMaxSeparationDistance,
const Shape *inShape,
RVec3Arg inBaseOffset,
CollideShapeCollector &ioCollector,
const BroadPhaseLayerFilter &inBroadPhaseLayerFilter,
const ObjectLayerFilter &inObjectLayerFilter,
const BodyFilter &inBodyFilter,
const ShapeFilter &inShapeFilter)
const;
280#ifdef JPH_DEBUG_RENDERER
317 struct IgnoredContact
319 IgnoredContact() =
default;
320 IgnoredContact(
const BodyID &inBodyID,
const SubShapeID &inSubShapeID) : mBodyID(inBodyID), mSubShapeID(inSubShapeID) { }
326 using IgnoredContactList = std::vector<IgnoredContact, STLTempAllocator<IgnoredContact>>;
333 float mProjectedVelocity;
334 Vec3 mLinearVelocity;
338 using ConstraintList = std::vector<Constraint, STLTempAllocator<Constraint>>;
344 ContactCollector(
PhysicsSystem *inSystem,
const CharacterVirtual *inCharacter,
uint inMaxHits,
float inHitReductionCosMaxAngle,
Vec3Arg inUp,
RVec3Arg inBaseOffset,
TempContactList &outContacts) : mBaseOffset(inBaseOffset), mUp(inUp), mSystem(inSystem), mCharacter(inCharacter), mContacts(outContacts), mMaxHits(inMaxHits), mHitReductionCosMaxAngle(inHitReductionCosMaxAngle) { }
354 float mHitReductionCosMaxAngle;
355 bool mMaxHitsExceeded =
false;
362 ContactCastCollector(
PhysicsSystem *inSystem,
const CharacterVirtual *inCharacter,
Vec3Arg inDisplacement,
Vec3Arg inUp,
const IgnoredContactList &inIgnoredContacts,
RVec3Arg inBaseOffset, Contact &outContact) : mBaseOffset(inBaseOffset), mDisplacement(inDisplacement), mUp(inUp), mSystem(inSystem), mCharacter(inCharacter), mIgnoredContacts(inIgnoredContacts), mContact(outContact) { }
371 const IgnoredContactList & mIgnoredContacts;
376 template <
class taCollector>
381 #ifdef JPH_DEBUG_RENDERER
382 ,
bool inDrawConstraints =
false
387 bool ValidateContact(
const Contact &inContact)
const;
393 void RemoveConflictingContacts(
TempContactList &ioContacts, IgnoredContactList &outIgnoredContacts)
const;
396 void DetermineConstraints(
TempContactList &inContacts, ConstraintList &outConstraints)
const;
399 void SolveConstraints(
Vec3Arg inVelocity,
float inDeltaTime,
float inTimeRemaining, ConstraintList &ioConstraints, IgnoredContactList &ioIgnoredContacts,
float &outTimeSimulated,
Vec3 &outDisplacement,
TempAllocator &inAllocator
400 #ifdef JPH_DEBUG_RENDERER
401 ,
bool inDrawConstraints =
false
406 void GetAdjustedBodyVelocity(
const Body& inBody,
Vec3 &outLinearVelocity,
Vec3 &outAngularVelocity)
const;
411 Vec3 CalculateCharacterGroundVelocity(
RVec3Arg inCenterOfMass,
Vec3Arg inLinearVelocity,
Vec3Arg inAngularVelocity,
float inDeltaTime)
const;
414 bool HandleContact(
Vec3Arg inVelocity,
Constraint &ioConstraint,
float inDeltaTime)
const;
423 void UpdateSupportingContact(
bool inSkipContactVelocityCheck,
TempAllocator &inAllocator);
439 float mPredictiveContactDistance;
440 uint mMaxCollisionIterations;
441 uint mMaxConstraintIterations;
442 float mMinTimeRemaining;
443 float mCollisionTolerance;
444 float mCharacterPadding;
446 float mHitReductionCosMaxAngle;
447 float mPenetrationRecoverySpeed;
471 float mLastDeltaTime = 1.0f / 60.0f;
474 mutable bool mMaxHitsExceeded =
false;
EBackFaceMode
How collision detection functions will treat back facing triangles.
Definition BackFaceMode.h:11
@ CollideWithBackFaces
Collide with back facing surfaces/triangles.
unsigned int uint
Definition Core.h:309
#define JPH_NAMESPACE_END
Definition Core.h:240
uint64_t uint64
Definition Core.h:313
#define JPH_NAMESPACE_BEGIN
Definition Core.h:234
constexpr float DegreesToRadians(float inV)
Convert a value from degrees to radians.
Definition Math.h:13
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:29
EMotionType
Motion type of a physics body.
Definition MotionType.h:11
std::vector< T, STLAllocator< T > > Array
Definition STLAllocator.h:81
JPH_INLINE float Cos(float inX)
Cosine of x (input in radians)
Definition Trigonometry.h:20
Class function to filter out bodies, returns true if test should collide with body.
Definition BodyFilter.h:16
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition BodyID.h:13
Filter class for broadphase layers.
Definition BroadPhaseLayer.h:89
Base class for character class.
Definition CharacterBase.h:46
RefConst< Shape > mShape
Definition CharacterBase.h:121
Vec3 mUp
Definition CharacterBase.h:124
Base class for configuration of a character.
Definition CharacterBase.h:21
Definition CharacterVirtual.h:96
void RefreshContacts(const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator)
This function can be used after a character has teleported to determine the new contacts with the wor...
Definition CharacterVirtual.cpp:1038
float GetMass() const
Character mass (kg)
Definition CharacterVirtual.h:138
Vec3 CancelVelocityTowardsSteepSlopes(Vec3Arg inDesiredVelocity) const
Definition CharacterVirtual.cpp:979
float GetPenetrationRecoverySpeed() const
This value governs how fast a penetration will be resolved, 0 = nothing is resolved,...
Definition CharacterVirtual.h:146
RVec3 GetPosition() const
Get the position of the character.
Definition CharacterVirtual.h:120
void SetLinearVelocity(Vec3Arg inLinearVelocity)
Set the linear velocity of the character (m / s)
Definition CharacterVirtual.h:117
const ContactList & GetActiveContacts() const
Access to the internal list of contacts that the character has found.
Definition CharacterVirtual.h:313
virtual void RestoreState(StateRecorder &inStream) override
Definition CharacterVirtual.cpp:1416
RMat44 GetWorldTransform() const
Calculate the world transform of the character.
Definition CharacterVirtual.h:132
std::vector< Contact, STLTempAllocator< Contact > > TempContactList
Definition CharacterVirtual.h:309
bool GetMaxHitsExceeded() const
Definition CharacterVirtual.h:164
virtual void SaveState(StateRecorder &inStream) const override
Definition CharacterVirtual.cpp:1395
void UpdateGroundVelocity()
Definition CharacterVirtual.cpp:1048
void SetMaxStrength(float inMaxStrength)
Definition CharacterVirtual.h:143
float GetCharacterPadding() const
Character padding.
Definition CharacterVirtual.h:150
void SetMaxNumHits(uint inMaxHits)
Definition CharacterVirtual.h:154
uint GetMaxNumHits() const
Max num hits to collect in order to avoid excess of contact points collection.
Definition CharacterVirtual.h:153
float GetMaxStrength() const
Maximum force with which the character can push other bodies (N)
Definition CharacterVirtual.h:142
void SetShapeOffset(Vec3Arg inShapeOffset)
Definition CharacterVirtual.h:168
bool WalkStairs(float inDeltaTime, Vec3Arg inStepUp, Vec3Arg inStepForward, Vec3Arg inStepForwardTest, Vec3Arg inStepDownExtra, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator)
Definition CharacterVirtual.cpp:1149
JPH_OVERRIDE_NEW_DELETE CharacterVirtual(const CharacterVirtualSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, PhysicsSystem *inSystem)
Definition CharacterVirtual.cpp:22
bool SetShape(const Shape *inShape, float inMaxPenetrationDepth, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator)
Definition CharacterVirtual.cpp:1095
Array< Contact > ContactList
Definition CharacterVirtual.h:310
void SetMass(float inMass)
Definition CharacterVirtual.h:139
bool StickToFloor(Vec3Arg inStepDown, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator)
Definition CharacterVirtual.cpp:1257
Vec3 GetLinearVelocity() const
Get the linear velocity of the character (m / s)
Definition CharacterVirtual.h:114
CharacterContactListener * GetListener() const
Get the current contact listener.
Definition CharacterVirtual.h:111
RMat44 GetCenterOfMassTransform() const
Calculates the transform for this character's center of mass.
Definition CharacterVirtual.h:135
static bool sDrawStickToFloor
Draw the state of the stick to floor algorithm.
Definition CharacterVirtual.h:283
static bool sDrawWalkStairs
Draw the state of the walk stairs algorithm.
Definition CharacterVirtual.h:282
void Update(float inDeltaTime, Vec3Arg inGravity, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator)
Definition CharacterVirtual.cpp:1006
static bool sDrawConstraints
Draw the current state of the constraints for iteration 0 when creating them.
Definition CharacterVirtual.h:281
void SetRotation(QuatArg inRotation)
Set the rotation of the character.
Definition CharacterVirtual.h:129
void SetHitReductionCosMaxAngle(float inCosMaxAngle)
Definition CharacterVirtual.h:158
Vec3 GetShapeOffset() const
An extra offset applied to the shape in local space. This allows applying an extra offset to the shap...
Definition CharacterVirtual.h:167
void SetPenetrationRecoverySpeed(float inSpeed)
Definition CharacterVirtual.h:147
void ExtendedUpdate(float inDeltaTime, Vec3Arg inGravity, const ExtendedUpdateSettings &inSettings, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator)
Definition CharacterVirtual.cpp:1282
void CheckCollision(RVec3Arg inPosition, QuatArg inRotation, Vec3Arg inMovementDirection, float inMaxSeparationDistance, const Shape *inShape, RVec3Arg inBaseOffset, CollideShapeCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter) const
Get all contacts for the character at a particular location.
Definition CharacterVirtual.cpp:218
float GetHitReductionCosMaxAngle() const
Cos(angle) where angle is the maximum angle between two hits contact normals that are allowed to be m...
Definition CharacterVirtual.h:157
void SetPosition(RVec3Arg inPosition)
Set the position of the character.
Definition CharacterVirtual.h:123
bool CanWalkStairs(Vec3Arg inLinearVelocity) const
Definition CharacterVirtual.cpp:1128
void SetListener(CharacterContactListener *inListener)
Set the contact listener.
Definition CharacterVirtual.h:108
Quat GetRotation() const
Get the rotation of the character.
Definition CharacterVirtual.h:126
Contains the configuration of a character.
Definition CharacterVirtual.h:20
uint mMaxConstraintIterations
How often to try stepping in the constraint solving.
Definition CharacterVirtual.h:37
uint mMaxCollisionIterations
Max amount of collision loops.
Definition CharacterVirtual.h:36
float mMinTimeRemaining
Early out condition: If this much time is left to simulate we are done.
Definition CharacterVirtual.h:38
float mPenetrationRecoverySpeed
This value governs how fast a penetration will be resolved, 0 = nothing is resolved,...
Definition CharacterVirtual.h:43
float mMaxStrength
Maximum force with which the character can push other bodies (N).
Definition CharacterVirtual.h:28
Vec3 mShapeOffset
An extra offset applied to the shape in local space. This allows applying an extra offset to the shap...
Definition CharacterVirtual.h:31
JPH_OVERRIDE_NEW_DELETE float mMass
Character mass (kg). Used to push down objects with gravity when the character is standing on top.
Definition CharacterVirtual.h:25
float mCharacterPadding
How far we try to stay away from the geometry, this ensures that the sweep will hit as little as poss...
Definition CharacterVirtual.h:40
float mCollisionTolerance
How far we're willing to penetrate geometry.
Definition CharacterVirtual.h:39
EBackFaceMode mBackFaceMode
When colliding with back faces, the character will not be able to move through back facing triangles....
Definition CharacterVirtual.h:34
float mHitReductionCosMaxAngle
Cos(angle) where angle is the maximum angle between two hits contact normals that are allowed to be m...
Definition CharacterVirtual.h:42
float mPredictiveContactDistance
How far to scan outside of the shape for predictive contacts. A value of 0 will most likely cause the...
Definition CharacterVirtual.h:35
uint mMaxNumHits
Max num hits to collect in order to avoid excess of contact points collection.
Definition CharacterVirtual.h:41
Class that contains all information of two colliding shapes.
Definition CollideShape.h:19
Virtual interface that allows collecting multiple collision results.
Definition CollisionCollector.h:45
Base class for all physics constraints. A constraint removes one or more degrees of freedom for a rig...
Definition Constraint.h:99
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition Mat44.h:13
JPH_INLINE Mat44 PostTranslated(Vec3Arg inTranslation) const
Post multiply by translation matrix: result = Mat44::sTranslation(inTranslation) * this (i....
Definition Mat44.inl:1168
JPH_INLINE Mat44 PreTranslated(Vec3Arg inTranslation) const
Pre multiply by translation matrix: result = this * Mat44::sTranslation(inTranslation)
Definition Mat44.inl:1163
static JPH_INLINE Mat44 sRotationTranslation(QuatArg inR, Vec3Arg inT)
Get matrix that rotates and translates.
Definition Mat44.inl:149
Filter class for object layers.
Definition ObjectLayer.h:28
Definition PhysicsMaterial.h:23
Definition PhysicsSystem.h:28
An infinite plane described by the formula X . Normal + Constant = 0.
Definition Plane.h:11
static JPH_INLINE Quat sIdentity()
Definition Quat.h:93
Result of a shape cast test.
Definition ShapeCast.h:111
Filter class.
Definition ShapeFilter.h:17
Base class for all shapes (collision volume of a body). Defines a virtual interface for collision det...
Definition Shape.h:170
virtual Vec3 GetCenterOfMass() const
All shapes are centered around their center of mass. This function returns the center of mass positio...
Definition Shape.h:195
Definition StateRecorder.h:15
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 TempAllocator.h:16
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:107
Settings struct with settings for ExtendedUpdate.
Definition CharacterVirtual.h:221
float mWalkStairsMinStepForward
See WalkStairs inStepForward parameter. Note that the parameter only indicates a magnitude,...
Definition CharacterVirtual.h:224
Vec3 mStickToFloorStepDown
See StickToFloor inStepDown parameter. Can be zero to turn off.
Definition CharacterVirtual.h:222
float mWalkStairsStepForwardTest
See WalkStairs inStepForwardTest parameter. Note that the parameter only indicates a magnitude,...
Definition CharacterVirtual.h:225
Vec3 mWalkStairsStepDownExtra
See WalkStairs inStepDownExtra.
Definition CharacterVirtual.h:227
float mWalkStairsCosAngleForwardContact
Cos(angle) where angle is the maximum angle between the ground normal in the horizontal plane and the...
Definition CharacterVirtual.h:226
Vec3 mWalkStairsStepUp
See WalkStairs inStepUp parameter. Can be zero to turn off.
Definition CharacterVirtual.h:223