28 float mMaxStrength = 100.0f;
35 float mPredictiveContactDistance = 0.1f;
36 uint mMaxCollisionIterations = 5;
37 uint mMaxConstraintIterations = 15;
38 float mMinTimeRemaining = 1.0e-4f;
39 float mCollisionTolerance = 1.0e-3f;
40 float mCharacterPadding = 0.02f;
42 float mHitReductionCosMaxAngle = 0.999f;
43 float mPenetrationRecoverySpeed = 1.0f;
139 void SetMass(
float inMass) { mMass = inMass; }
174 Vec3 CancelVelocityTowardsSteepSlopes(
Vec3Arg inDesiredVelocity)
const;
191 bool CanWalkStairs(
Vec3Arg inLinearVelocity)
const;
222 Vec3 mStickToFloorStepDown { 0, -0.5f, 0 };
223 Vec3 mWalkStairsStepUp { 0, 0.4f, 0 };
224 float mWalkStairsMinStepForward { 0.02f };
225 float mWalkStairsStepForwardTest { 0.15f };
249 void UpdateGroundVelocity();
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;
277 virtual void SaveState(
StateRecorder &inStream)
const override;
280#ifdef JPH_DEBUG_RENDERER
281 static inline bool sDrawConstraints =
false;
282 static inline bool sDrawWalkStairs =
false;
283 static inline bool sDrawStickToFloor =
false;
304 bool mHadCollision =
false;
305 bool mWasDiscarded =
false;
306 bool mCanPushCharacter =
true;
317 struct ContactOrderingPredicate
319 inline bool operator () (
const Contact &inLHS,
const Contact &inRHS)
const
321 if (inLHS.mBodyB != inRHS.mBodyB)
322 return inLHS.mBodyB < inRHS.mBodyB;
324 return inLHS.mSubShapeIDB.GetValue() < inRHS.mSubShapeIDB.GetValue();
329 struct IgnoredContact
331 IgnoredContact() =
default;
332 IgnoredContact(
const BodyID &inBodyID,
const SubShapeID &inSubShapeID) : mBodyID(inBodyID), mSubShapeID(inSubShapeID) { }
338 using IgnoredContactList = std::vector<IgnoredContact, STLTempAllocator<IgnoredContact>>;
345 float mProjectedVelocity;
346 Vec3 mLinearVelocity;
348 bool mIsSteepSlope =
false;
351 using ConstraintList = std::vector<Constraint, STLTempAllocator<Constraint>>;
357 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) { }
365 TempContactList & mContacts;
367 float mHitReductionCosMaxAngle;
368 bool mMaxHitsExceeded =
false;
375 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) { }
384 const IgnoredContactList & mIgnoredContacts;
389 template <
class taCollector>
394 #ifdef JPH_DEBUG_RENDERER
395 ,
bool inDrawConstraints =
false
400 bool ValidateContact(
const Contact &inContact)
const;
406 void RemoveConflictingContacts(TempContactList &ioContacts, IgnoredContactList &outIgnoredContacts)
const;
409 void DetermineConstraints(TempContactList &inContacts,
float inDeltaTime, ConstraintList &outConstraints)
const;
412 void SolveConstraints(
Vec3Arg inVelocity,
float inDeltaTime,
float inTimeRemaining, ConstraintList &ioConstraints, IgnoredContactList &ioIgnoredContacts,
float &outTimeSimulated,
Vec3 &outDisplacement,
TempAllocator &inAllocator
413 #ifdef JPH_DEBUG_RENDERER
414 ,
bool inDrawConstraints =
false
419 void GetAdjustedBodyVelocity(
const Body& inBody,
Vec3 &outLinearVelocity,
Vec3 &outAngularVelocity)
const;
424 Vec3 CalculateCharacterGroundVelocity(
RVec3Arg inCenterOfMass,
Vec3Arg inLinearVelocity,
Vec3Arg inAngularVelocity,
float inDeltaTime)
const;
427 bool HandleContact(
Vec3Arg inVelocity,
Constraint &ioConstraint,
float inDeltaTime)
const;
433 void StoreActiveContacts(
const TempContactList &inContacts,
TempAllocator &inAllocator);
436 void UpdateSupportingContact(
bool inSkipContactVelocityCheck,
TempAllocator &inAllocator);
452 float mPredictiveContactDistance;
453 uint mMaxCollisionIterations;
454 uint mMaxConstraintIterations;
455 float mMinTimeRemaining;
456 float mCollisionTolerance;
457 float mCharacterPadding;
459 float mHitReductionCosMaxAngle;
460 float mPenetrationRecoverySpeed;
481 ContactList mActiveContacts;
484 float mLastDeltaTime = 1.0f / 60.0f;
487 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.
#define JPH_EXPORT
Definition Core.h:214
std::uint64_t uint64
Definition Core.h:430
unsigned int uint
Definition Core.h:426
#define JPH_NAMESPACE_END
Definition Core.h:354
#define JPH_NAMESPACE_BEGIN
Definition Core.h:348
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:51
Base class for configuration of a character.
Definition CharacterBase.h:21
Definition CharacterVirtual.h:96
float GetMass() const
Character mass (kg)
Definition CharacterVirtual.h:138
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
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
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
Array< Contact > ContactList
Definition CharacterVirtual.h:310
void SetMass(float inMass)
Definition CharacterVirtual.h:139
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
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
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
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
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:103
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:896
JPH_INLINE Mat44 PreTranslated(Vec3Arg inTranslation) const
Pre multiply by translation matrix: result = this * Mat44::sTranslation(inTranslation)
Definition Mat44.inl:891
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:103
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:174
virtual Vec3 GetCenterOfMass() const
All shapes are centered around their center of mass. This function returns the center of mass positio...
Definition Shape.h:199
Definition StateRecorder.h:48
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