Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
CharacterVirtual.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
13
15
17
20{
21public:
23
25 float mMass = 70.0f;
26
28 float mMaxStrength = 100.0f;
29
32
34 EBackFaceMode mBackFaceMode = EBackFaceMode::CollideWithBackFaces;
38 float mMinTimeRemaining = 1.0e-4f;
39 float mCollisionTolerance = 1.0e-3f;
40 float mCharacterPadding = 0.02f;
42 float mHitReductionCosMaxAngle = 0.999f;
44};
45
48{
49public:
50 bool mCanPushCharacter = true;
51 bool mCanReceiveImpulses = true;
52};
53
56{
57public:
59 virtual ~CharacterContactListener() = default;
60
63 virtual void OnAdjustBodyVelocity(const CharacterVirtual *inCharacter, const Body &inBody2, Vec3 &ioLinearVelocity, Vec3 &ioAngularVelocity) { /* Do nothing, the linear and angular velocity are already filled in */ }
64
66 virtual bool OnContactValidate(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2) { return true; }
67
75 virtual void OnContactAdded(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, CharacterContactSettings &ioSettings) { /* Default do nothing */ }
76
87 virtual void OnContactSolve(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, Vec3Arg inContactVelocity, const PhysicsMaterial *inContactMaterial, Vec3Arg inCharacterVelocity, Vec3 &ioNewCharacterVelocity) { /* Default do nothing */ }
88};
89
96{
97public:
99
105 CharacterVirtual(const CharacterVirtualSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, PhysicsSystem *inSystem);
106
108 void SetListener(CharacterContactListener *inListener) { mListener = inListener; }
109
111 CharacterContactListener * GetListener() const { return mListener; }
112
114 Vec3 GetLinearVelocity() const { return mLinearVelocity; }
115
117 void SetLinearVelocity(Vec3Arg inLinearVelocity) { mLinearVelocity = inLinearVelocity; }
118
120 RVec3 GetPosition() const { return mPosition; }
121
123 void SetPosition(RVec3Arg inPosition) { mPosition = inPosition; }
124
126 Quat GetRotation() const { return mRotation; }
127
129 void SetRotation(QuatArg inRotation) { mRotation = inRotation; }
130
132 RMat44 GetWorldTransform() const { return RMat44::sRotationTranslation(mRotation, mPosition); }
133
135 RMat44 GetCenterOfMassTransform() const { return GetCenterOfMassTransform(mPosition, mRotation, mShape); }
136
138 float GetMass() const { return mMass; }
139 void SetMass(float inMass) { mMass = inMass; }
140
142 float GetMaxStrength() const { return mMaxStrength; }
143 void SetMaxStrength(float inMaxStrength) { mMaxStrength = inMaxStrength; }
144
146 float GetPenetrationRecoverySpeed() const { return mPenetrationRecoverySpeed; }
147 void SetPenetrationRecoverySpeed(float inSpeed) { mPenetrationRecoverySpeed = inSpeed; }
148
150 float GetCharacterPadding() const { return mCharacterPadding; }
151
153 uint GetMaxNumHits() const { return mMaxNumHits; }
154 void SetMaxNumHits(uint inMaxHits) { mMaxNumHits = inMaxHits; }
155
157 float GetHitReductionCosMaxAngle() const { return mHitReductionCosMaxAngle; }
158 void SetHitReductionCosMaxAngle(float inCosMaxAngle) { mHitReductionCosMaxAngle = inCosMaxAngle; }
159
164 bool GetMaxHitsExceeded() const { return mMaxHitsExceeded; }
165
167 Vec3 GetShapeOffset() const { return mShapeOffset; }
168 void SetShapeOffset(Vec3Arg inShapeOffset) { mShapeOffset = inShapeOffset; }
169
174 Vec3 CancelVelocityTowardsSteepSlopes(Vec3Arg inDesiredVelocity) const;
175
186 void Update(float inDeltaTime, Vec3Arg inGravity, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator);
187
191 bool CanWalkStairs(Vec3Arg inLinearVelocity) const;
192
205 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);
206
217 bool StickToFloor(Vec3Arg inStepDown, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator);
218
221 {
222 Vec3 mStickToFloorStepDown { 0, -0.5f, 0 };
223 Vec3 mWalkStairsStepUp { 0, 0.4f, 0 };
228 };
229
242 void ExtendedUpdate(float inDeltaTime, Vec3Arg inGravity, const ExtendedUpdateSettings &inSettings, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator);
243
245 void RefreshContacts(const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator);
246
250
260 bool SetShape(const Shape *inShape, float inMaxPenetrationDepth, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator);
261
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;
275
276 // Saving / restoring state for replay
277 virtual void SaveState(StateRecorder &inStream) const override;
278 virtual void RestoreState(StateRecorder &inStream) override;
279
280#ifdef JPH_DEBUG_RENDERER
281 static inline bool sDrawConstraints = false;
282 static inline bool sDrawWalkStairs = false;
283 static inline bool sDrawStickToFloor = false;
284#endif
285
286 // Encapsulates a collision contact
287 struct Contact
288 {
289 // Saving / restoring state for replay
290 void SaveState(StateRecorder &inStream) const;
291 void RestoreState(StateRecorder &inStream);
292
297 float mDistance;
298 float mFraction;
304 bool mHadCollision = false;
305 bool mWasDiscarded = false;
306 bool mCanPushCharacter = true;
307 };
308
309 using TempContactList = std::vector<Contact, STLTempAllocator<Contact>>;
311
313 const ContactList & GetActiveContacts() const { return mActiveContacts; }
314
315private:
316 // A contact that needs to be ignored
317 struct IgnoredContact
318 {
319 IgnoredContact() = default;
320 IgnoredContact(const BodyID &inBodyID, const SubShapeID &inSubShapeID) : mBodyID(inBodyID), mSubShapeID(inSubShapeID) { }
321
322 BodyID mBodyID;
323 SubShapeID mSubShapeID;
324 };
325
326 using IgnoredContactList = std::vector<IgnoredContact, STLTempAllocator<IgnoredContact>>;
327
328 // A constraint that limits the movement of the character
329 struct Constraint
330 {
331 Contact * mContact;
332 float mTOI;
333 float mProjectedVelocity;
334 Vec3 mLinearVelocity;
335 Plane mPlane;
336 };
337
338 using ConstraintList = std::vector<Constraint, STLTempAllocator<Constraint>>;
339
340 // Collision collector that collects hits for CollideShape
341 class ContactCollector : public CollideShapeCollector
342 {
343 public:
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) { }
345
346 virtual void AddHit(const CollideShapeResult &inResult) override;
347
348 RVec3 mBaseOffset;
349 Vec3 mUp;
350 PhysicsSystem * mSystem;
351 const CharacterVirtual * mCharacter;
352 TempContactList & mContacts;
353 uint mMaxHits;
354 float mHitReductionCosMaxAngle;
355 bool mMaxHitsExceeded = false;
356 };
357
358 // A collision collector that collects hits for CastShape
359 class ContactCastCollector : public CastShapeCollector
360 {
361 public:
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) { }
363
364 virtual void AddHit(const ShapeCastResult &inResult) override;
365
366 RVec3 mBaseOffset;
367 Vec3 mDisplacement;
368 Vec3 mUp;
369 PhysicsSystem * mSystem;
370 const CharacterVirtual * mCharacter;
371 const IgnoredContactList & mIgnoredContacts;
372 Contact & mContact;
373 };
374
375 // Helper function to convert a Jolt collision result into a contact
376 template <class taCollector>
377 inline static void sFillContactProperties(const CharacterVirtual *inCharacter, Contact &outContact, const Body &inBody, Vec3Arg inUp, RVec3Arg inBaseOffset, const taCollector &inCollector, const CollideShapeResult &inResult);
378
379 // Move the shape from ioPosition and try to displace it by inVelocity * inDeltaTime, this will try to slide the shape along the world geometry
380 void MoveShape(RVec3 &ioPosition, Vec3Arg inVelocity, float inDeltaTime, ContactList *outActiveContacts, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator
381 #ifdef JPH_DEBUG_RENDERER
382 , bool inDrawConstraints = false
383 #endif // JPH_DEBUG_RENDERER
384 ) const;
385
386 // Ask the callback if inContact is a valid contact point
387 bool ValidateContact(const Contact &inContact) const;
388
389 // Tests the shape for collision around inPosition
390 void GetContactsAtPosition(RVec3Arg inPosition, Vec3Arg inMovementDirection, const Shape *inShape, TempContactList &outContacts, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter) const;
391
392 // Remove penetrating contacts with the same body that have conflicting normals, leaving these will make the character mover get stuck
393 void RemoveConflictingContacts(TempContactList &ioContacts, IgnoredContactList &outIgnoredContacts) const;
394
395 // Convert contacts into constraints. The character is assumed to start at the origin and the constraints are planes around the origin that confine the movement of the character.
396 void DetermineConstraints(TempContactList &inContacts, ConstraintList &outConstraints) const;
397
398 // Use the constraints to solve the displacement of the character. This will slide the character on the planes around the origin for as far as possible.
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
402 #endif // JPH_DEBUG_RENDERER
403 ) const;
404
405 // Get the velocity of a body adjusted by the contact listener
406 void GetAdjustedBodyVelocity(const Body& inBody, Vec3 &outLinearVelocity, Vec3 &outAngularVelocity) const;
407
408 // Calculate the ground velocity of the character assuming it's standing on an object with specified linear and angular velocity and with specified center of mass.
409 // Note that we don't just take the point velocity because a point on an object with angular velocity traces an arc,
410 // so if you just take point velocity * delta time you get an error that accumulates over time
411 Vec3 CalculateCharacterGroundVelocity(RVec3Arg inCenterOfMass, Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity, float inDeltaTime) const;
412
413 // Handle contact with physics object that we're colliding against
414 bool HandleContact(Vec3Arg inVelocity, Constraint &ioConstraint, float inDeltaTime) const;
415
416 // Does a swept test of the shape from inPosition with displacement inDisplacement, returns true if there was a collision
417 bool GetFirstContactForSweep(RVec3Arg inPosition, Vec3Arg inDisplacement, Contact &outContact, const IgnoredContactList &inIgnoredContacts, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter) const;
418
419 // Store contacts so that we have proper ground information
420 void StoreActiveContacts(const TempContactList &inContacts, TempAllocator &inAllocator);
421
422 // This function will determine which contacts are touching the character and will calculate the one that is supporting us
423 void UpdateSupportingContact(bool inSkipContactVelocityCheck, TempAllocator &inAllocator);
424
426 void MoveToContact(RVec3Arg inPosition, const Contact &inContact, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator);
427
428 // This function returns the actual center of mass of the shape, not corrected for the character padding
429 inline RMat44 GetCenterOfMassTransform(RVec3Arg inPosition, QuatArg inRotation, const Shape *inShape) const
430 {
431 return RMat44::sRotationTranslation(inRotation, inPosition).PreTranslated(mShapeOffset + inShape->GetCenterOfMass()).PostTranslated(mCharacterPadding * mUp);
432 }
433
434 // Our main listener for contacts
435 CharacterContactListener * mListener = nullptr;
436
437 // Movement settings
438 EBackFaceMode mBackFaceMode; // When colliding with back faces, the character will not be able to move through back facing triangles. Use this if you have triangles that need to collide on both sides.
439 float mPredictiveContactDistance; // How far to scan outside of the shape for predictive contacts. A value of 0 will most likely cause the character to get stuck as it properly calculate a sliding direction anymore. A value that's too high will cause ghost collisions.
440 uint mMaxCollisionIterations; // Max amount of collision loops
441 uint mMaxConstraintIterations; // How often to try stepping in the constraint solving
442 float mMinTimeRemaining; // Early out condition: If this much time is left to simulate we are done
443 float mCollisionTolerance; // How far we're willing to penetrate geometry
444 float mCharacterPadding; // How far we try to stay away from the geometry, this ensures that the sweep will hit as little as possible lowering the collision cost and reducing the risk of getting stuck
445 uint mMaxNumHits; // Max num hits to collect in order to avoid excess of contact points collection
446 float mHitReductionCosMaxAngle; // Cos(angle) where angle is the maximum angle between two hits contact normals that are allowed to be merged during hit reduction. Default is around 2.5 degrees. Set to -1 to turn off.
447 float mPenetrationRecoverySpeed; // This value governs how fast a penetration will be resolved, 0 = nothing is resolved, 1 = everything in one update
448
449 // Character mass (kg)
450 float mMass;
451
452 // Maximum force with which the character can push other bodies (N)
453 float mMaxStrength;
454
455 // An extra offset applied to the shape in local space. This allows applying an extra offset to the shape in local space.
456 Vec3 mShapeOffset = Vec3::sZero();
457
458 // Current position (of the base, not the center of mass)
459 RVec3 mPosition = RVec3::sZero();
460
461 // Current rotation (of the base, not of the center of mass)
462 Quat mRotation = Quat::sIdentity();
463
464 // Current linear velocity
465 Vec3 mLinearVelocity = Vec3::sZero();
466
467 // List of contacts that were active in the last frame
468 ContactList mActiveContacts;
469
470 // Remembers the delta time of the last update
471 float mLastDeltaTime = 1.0f / 60.0f;
472
473 // Remember if we exceeded the maximum number of hits and had to remove similar contacts
474 mutable bool mMaxHitsExceeded = false;
475};
476
EBackFaceMode
How collision detection functions will treat back facing triangles.
Definition: BackFaceMode.h:11
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
Definition: Body.h:33
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
This class receives callbacks when a virtual character hits something.
Definition: CharacterVirtual.h:56
virtual void OnContactAdded(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, CharacterContactSettings &ioSettings)
Definition: CharacterVirtual.h:75
virtual ~CharacterContactListener()=default
Destructor.
virtual bool OnContactValidate(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2)
Checks if a character can collide with specified body. Return true if the contact is valid.
Definition: CharacterVirtual.h:66
virtual void OnContactSolve(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, Vec3Arg inContactVelocity, const PhysicsMaterial *inContactMaterial, Vec3Arg inCharacterVelocity, Vec3 &ioNewCharacterVelocity)
Definition: CharacterVirtual.h:87
virtual void OnAdjustBodyVelocity(const CharacterVirtual *inCharacter, const Body &inBody2, Vec3 &ioLinearVelocity, Vec3 &ioAngularVelocity)
Definition: CharacterVirtual.h:63
This class contains settings that allow you to override the behavior of a character's collision respo...
Definition: CharacterVirtual.h:48
bool mCanPushCharacter
True when the object can push the virtual character.
Definition: CharacterVirtual.h:50
bool mCanReceiveImpulses
True when the virtual character can apply impulses (push) the body.
Definition: CharacterVirtual.h:51
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
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
std::vector< Contact, STLTempAllocator< Contact > > TempContactList
Definition: CharacterVirtual.h:309
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
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
virtual void AddHit(const ResultType &inResult)=0
This function will be called for every hit found, it's up to the application to decide how to store t...
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
Definition: Quat.h:33
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
Definition: Vec3.h:16
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition: Vec3.inl:107
Definition: CharacterVirtual.h:288
EMotionType mMotionTypeB
Motion type of B, used to determine the priority of the contact.
Definition: CharacterVirtual.h:301
Vec3 mContactNormal
Contact normal, pointing towards the character.
Definition: CharacterVirtual.h:295
const PhysicsMaterial * mMaterial
Material of B.
Definition: CharacterVirtual.h:303
bool mWasDiscarded
If the contact validate callback chose to discard this contact.
Definition: CharacterVirtual.h:305
float mFraction
Fraction along the path where this contact takes place.
Definition: CharacterVirtual.h:298
uint64 mUserData
User data of B.
Definition: CharacterVirtual.h:302
bool mHadCollision
If the character actually collided with the contact (can be false if a predictive contact never becom...
Definition: CharacterVirtual.h:304
void RestoreState(StateRecorder &inStream)
Definition: CharacterVirtual.cpp:1377
BodyID mBodyB
ID of body we're colliding with.
Definition: CharacterVirtual.h:299
SubShapeID mSubShapeIDB
Sub shape ID of body we're colliding with.
Definition: CharacterVirtual.h:300
Vec3 mLinearVelocity
Velocity of the contact point.
Definition: CharacterVirtual.h:294
bool mCanPushCharacter
When true, the velocity of the contact point can push the character.
Definition: CharacterVirtual.h:306
float mDistance
Distance to the contact <= 0 means that it is an actual contact, > 0 means predictive.
Definition: CharacterVirtual.h:297
Vec3 mSurfaceNormal
Surface normal of the contact.
Definition: CharacterVirtual.h:296
RVec3 mPosition
Position where the character makes contact.
Definition: CharacterVirtual.h:293
void SaveState(StateRecorder &inStream) const
Definition: CharacterVirtual.cpp:1360
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