30 float mMaxStrength = 100.0f;
37 float mPredictiveContactDistance = 0.1f;
38 uint mMaxCollisionIterations = 5;
39 uint mMaxConstraintIterations = 15;
40 float mMinTimeRemaining = 1.0e-4f;
41 float mCollisionTolerance = 1.0e-3f;
42 float mCharacterPadding = 0.02f;
44 float mHitReductionCosMaxAngle = 0.999f;
45 float mPenetrationRecoverySpeed = 1.0f;
211 inline RVec3 GetCenterOfMassPosition()
const {
return mPosition + (mRotation * (mShapeOffset + mShape->GetCenterOfMass()) + mCharacterPadding * mUp); }
221 void SetMass(
float inMass) { mMass = inMass; }
258 void SetUserData(
uint64 inUserData);
267 Vec3 CancelVelocityTowardsSteepSlopes(
Vec3Arg inDesiredVelocity)
const;
284 bool CanWalkStairs(
Vec3Arg inLinearVelocity)
const;
315 Vec3 mStickToFloorStepDown { 0, -0.5f, 0 };
316 Vec3 mWalkStairsStepUp { 0, 0.4f, 0 };
317 float mWalkStairsMinStepForward { 0.02f };
318 float mWalkStairsStepForwardTest { 0.15f };
342 void UpdateGroundVelocity();
356 void SetInnerBodyShape(
const Shape *inShape);
374 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;
377 virtual void SaveState(
StateRecorder &inStream)
const override;
380#ifdef JPH_DEBUG_RENDERER
381 static inline bool sDrawConstraints =
false;
382 static inline bool sDrawWalkStairs =
false;
383 static inline bool sDrawStickToFloor =
false;
409 bool mHadCollision =
false;
410 bool mWasDiscarded =
false;
411 bool mCanPushCharacter =
true;
424 if (c.mHadCollision && c.mBodyB == inBody)
433 if (c.mHadCollision && c.mCharacterB == inCharacter)
440 struct ContactOrderingPredicate
442 inline bool operator () (
const Contact &inLHS,
const Contact &inRHS)
const
444 if (inLHS.mBodyB != inRHS.mBodyB)
445 return inLHS.mBodyB < inRHS.mBodyB;
447 return inLHS.mSubShapeIDB.GetValue() < inRHS.mSubShapeIDB.GetValue();
452 struct IgnoredContact
454 IgnoredContact() =
default;
455 IgnoredContact(
const BodyID &inBodyID,
const SubShapeID &inSubShapeID) : mBodyID(inBodyID), mSubShapeID(inSubShapeID) { }
468 float mProjectedVelocity;
469 Vec3 mLinearVelocity;
471 bool mIsSteepSlope =
false;
480 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) { }
482 virtual void SetUserData(
uint64 inUserData)
override { mOtherCharacter =
reinterpret_cast<CharacterVirtual *
>(inUserData); }
491 TempContactList & mContacts;
493 float mHitReductionCosMaxAngle;
494 bool mMaxHitsExceeded =
false;
501 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) { }
503 virtual void SetUserData(
uint64 inUserData)
override { mOtherCharacter =
reinterpret_cast<CharacterVirtual *
>(inUserData); }
513 const IgnoredContactList & mIgnoredContacts;
518 template <
class taCollector>
524 #ifdef JPH_DEBUG_RENDERER
525 ,
bool inDrawConstraints =
false
530 bool ValidateContact(
const Contact &inContact)
const;
539 void RemoveConflictingContacts(TempContactList &ioContacts, IgnoredContactList &outIgnoredContacts)
const;
542 void DetermineConstraints(TempContactList &inContacts,
float inDeltaTime, ConstraintList &outConstraints)
const;
545 void SolveConstraints(
Vec3Arg inVelocity,
float inDeltaTime,
float inTimeRemaining, ConstraintList &ioConstraints, IgnoredContactList &ioIgnoredContacts,
float &outTimeSimulated,
Vec3 &outDisplacement,
TempAllocator &inAllocator
546 #ifdef JPH_DEBUG_RENDERER
547 ,
bool inDrawConstraints =
false
552 void GetAdjustedBodyVelocity(
const Body& inBody,
Vec3 &outLinearVelocity,
Vec3 &outAngularVelocity)
const;
557 Vec3 CalculateCharacterGroundVelocity(
RVec3Arg inCenterOfMass,
Vec3Arg inLinearVelocity,
Vec3Arg inAngularVelocity,
float inDeltaTime)
const;
560 bool HandleContact(
Vec3Arg inVelocity,
Constraint &ioConstraint,
float inDeltaTime)
const;
566 void StoreActiveContacts(
const TempContactList &inContacts,
TempAllocator &inAllocator);
569 void UpdateSupportingContact(
bool inSkipContactVelocityCheck,
TempAllocator &inAllocator);
581 inline RVec3 GetInnerBodyPosition()
const
583 return mPosition + (mRotation * mShapeOffset + mCharacterPadding *
mUp);
587 void UpdateInnerBodyTransform();
597 float mPredictiveContactDistance;
598 uint mMaxCollisionIterations;
599 uint mMaxConstraintIterations;
600 float mMinTimeRemaining;
601 float mCollisionTolerance;
602 float mCharacterPadding;
604 float mHitReductionCosMaxAngle;
605 float mPenetrationRecoverySpeed;
627 ContactList mActiveContacts;
630 float mLastDeltaTime = 1.0f / 60.0f;
633 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:271
std::uint64_t uint64
Definition Core.h:485
unsigned int uint
Definition Core.h:481
#define JPH_NAMESPACE_END
Definition Core.h:414
#define JPH_NAMESPACE_BEGIN
Definition Core.h:408
JPH_INLINE constexpr float DegreesToRadians(float inV)
Convert a value from degrees to radians.
Definition Math.h:16
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:31
EMotionType
Motion type of a physics body.
Definition MotionType.h:11
uint16 ObjectLayer
Definition ObjectLayer.h:16
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:94
Base class for character class.
Definition CharacterBase.h:54
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
Vec3 mUp
Vector indicating the up direction of the character.
Definition CharacterBase.h:34
Definition CharacterVirtual.h:165
void SetEnhancedInternalEdgeRemoval(bool inApply)
Definition CharacterVirtual.h:233
TransformedShape GetTransformedShape() const
Get the transformed shape that represents the volume of the character, can be used for collision chec...
Definition CharacterVirtual.h:359
float GetMass() const
Character mass (kg)
Definition CharacterVirtual.h:220
float GetPenetrationRecoverySpeed() const
This value governs how fast a penetration will be resolved, 0 = nothing is resolved,...
Definition CharacterVirtual.h:228
RVec3 GetPosition() const
Get the position of the character.
Definition CharacterVirtual.h:199
void SetLinearVelocity(Vec3Arg inLinearVelocity)
Set the linear velocity of the character (m / s)
Definition CharacterVirtual.h:196
const ContactList & GetActiveContacts() const
Access to the internal list of contacts that the character has found.
Definition CharacterVirtual.h:418
RMat44 GetWorldTransform() const
Calculate the world transform of the character.
Definition CharacterVirtual.h:214
void SetCharacterVsCharacterCollision(CharacterVsCharacterCollision *inCharacterVsCharacterCollision)
Set the character vs character collision interface.
Definition CharacterVirtual.h:190
RVec3 GetCenterOfMassPosition() const
Definition CharacterVirtual.h:211
bool GetMaxHitsExceeded() const
Definition CharacterVirtual.h:250
bool HasCollidedWith(const BodyID &inBody) const
Check if the character is currently in contact with or has collided with another body in the last tim...
Definition CharacterVirtual.h:421
void SetMaxStrength(float inMaxStrength)
Definition CharacterVirtual.h:225
float GetCharacterPadding() const
Character padding.
Definition CharacterVirtual.h:236
void SetMaxNumHits(uint inMaxHits)
Definition CharacterVirtual.h:240
uint GetMaxNumHits() const
Max num hits to collect in order to avoid excess of contact points collection.
Definition CharacterVirtual.h:239
float GetMaxStrength() const
Maximum force with which the character can push other bodies (N)
Definition CharacterVirtual.h:224
void SetShapeOffset(Vec3Arg inShapeOffset)
Definition CharacterVirtual.h:254
BodyID GetInnerBodyID() const
Optional inner rigid body that proxies the character in the world. Can be used to update body propert...
Definition CharacterVirtual.h:261
void SetMass(float inMass)
Definition CharacterVirtual.h:221
bool GetEnhancedInternalEdgeRemoval() const
Set to indicate that extra effort should be made to try to remove ghost contacts (collisions with int...
Definition CharacterVirtual.h:232
Vec3 GetLinearVelocity() const
Get the linear velocity of the character (m / s)
Definition CharacterVirtual.h:193
CharacterContactListener * GetListener() const
Get the current contact listener.
Definition CharacterVirtual.h:187
RMat44 GetCenterOfMassTransform() const
Calculates the transform for this character's center of mass.
Definition CharacterVirtual.h:217
CharacterVirtual(const CharacterVirtualSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, PhysicsSystem *inSystem)
Constructor without user data.
Definition CharacterVirtual.h:178
void SetRotation(QuatArg inRotation)
Set the rotation of the character.
Definition CharacterVirtual.h:208
void SetHitReductionCosMaxAngle(float inCosMaxAngle)
Definition CharacterVirtual.h:244
uint64 GetUserData() const
Access to the user data, can be used for anything by the application.
Definition CharacterVirtual.h:257
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:253
void SetPenetrationRecoverySpeed(float inSpeed)
Definition CharacterVirtual.h:229
bool HasCollidedWith(const CharacterVirtual *inCharacter) const
Check if the character is currently in contact with or has collided with another character in the las...
Definition CharacterVirtual.h:430
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:243
void SetPosition(RVec3Arg inPosition)
Set the position of the character.
Definition CharacterVirtual.h:202
void SetListener(CharacterContactListener *inListener)
Set the contact listener.
Definition CharacterVirtual.h:184
Quat GetRotation() const
Get the rotation of the character.
Definition CharacterVirtual.h:205
Contains the configuration of a character.
Definition CharacterVirtual.h:22
RefConst< Shape > mInnerBodyShape
Definition CharacterVirtual.h:51
Definition CharacterVirtual.h:119
virtual void CollideCharacter(const CharacterVirtual *inCharacter, RMat44Arg inCenterOfMassTransform, const CollideShapeSettings &inCollideShapeSettings, RVec3Arg inBaseOffset, CollideShapeCollector &ioCollector) const =0
virtual ~CharacterVsCharacterCollision()=default
virtual void CastCharacter(const CharacterVirtual *inCharacter, RMat44Arg inCenterOfMassTransform, Vec3Arg inDirection, const ShapeCastSettings &inShapeCastSettings, RVec3Arg inBaseOffset, CastShapeCollector &ioCollector) const =0
Definition CharacterVirtual.h:144
void Add(CharacterVirtual *inCharacter)
Add a character to the list of characters to check collision against.
Definition CharacterVirtual.h:147
Array< CharacterVirtual * > mCharacters
The list of characters to check collision against.
Definition CharacterVirtual.h:156
Class that contains all information of two colliding shapes.
Definition CollideShape.h:19
Settings to be passed with a collision query.
Definition CollideShape.h:94
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:903
JPH_INLINE Mat44 PreTranslated(Vec3Arg inTranslation) const
Pre multiply by translation matrix: result = this * Mat44::sTranslation(inTranslation)
Definition Mat44.inl:898
static JPH_INLINE Mat44 sRotationTranslation(QuatArg inR, Vec3Arg inT)
Get matrix that rotates and translates.
Definition Mat44.inl:149
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11
Filter class for object layers.
Definition ObjectLayer.h:28
Definition PhysicsMaterial.h:23
Definition PhysicsSystem.h:30
An infinite plane described by the formula X . Normal + Constant = 0.
Definition Plane.h:11
static JPH_INLINE Quat sIdentity()
Definition Quat.h:103
Definition Reference.h:163
Result of a shape cast test.
Definition ShapeCast.h:114
Settings to be passed with a shape cast.
Definition ShapeCast.h:92
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:186
virtual Vec3 GetCenterOfMass() const
All shapes are centered around their center of mass. This function returns the center of mass positio...
Definition Shape.h:211
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 TempAllocator.h:16
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:103
Settings struct with settings for ExtendedUpdate.
Definition CharacterVirtual.h:314