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
31 Vec3 mShapeOffset = Vec3::sZero();
32
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;
41 uint mMaxNumHits = 256;
42 float mHitReductionCosMaxAngle = 0.999f;
43 float mPenetrationRecoverySpeed = 1.0f;
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
106 CharacterVirtual(const CharacterVirtualSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, uint64 inUserData, PhysicsSystem *inSystem);
107
109 CharacterVirtual(const CharacterVirtualSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, PhysicsSystem *inSystem) : CharacterVirtual(inSettings, inPosition, inRotation, 0, inSystem) { }
110
112 void SetListener(CharacterContactListener *inListener) { mListener = inListener; }
113
115 CharacterContactListener * GetListener() const { return mListener; }
116
118 Vec3 GetLinearVelocity() const { return mLinearVelocity; }
119
121 void SetLinearVelocity(Vec3Arg inLinearVelocity) { mLinearVelocity = inLinearVelocity; }
122
124 RVec3 GetPosition() const { return mPosition; }
125
127 void SetPosition(RVec3Arg inPosition) { mPosition = inPosition; }
128
130 Quat GetRotation() const { return mRotation; }
131
133 void SetRotation(QuatArg inRotation) { mRotation = inRotation; }
134
136 RMat44 GetWorldTransform() const { return RMat44::sRotationTranslation(mRotation, mPosition); }
137
139 RMat44 GetCenterOfMassTransform() const { return GetCenterOfMassTransform(mPosition, mRotation, mShape); }
140
142 float GetMass() const { return mMass; }
143 void SetMass(float inMass) { mMass = inMass; }
144
146 float GetMaxStrength() const { return mMaxStrength; }
147 void SetMaxStrength(float inMaxStrength) { mMaxStrength = inMaxStrength; }
148
150 float GetPenetrationRecoverySpeed() const { return mPenetrationRecoverySpeed; }
151 void SetPenetrationRecoverySpeed(float inSpeed) { mPenetrationRecoverySpeed = inSpeed; }
152
155 void SetEnhancedInternalEdgeRemoval(bool inApply) { mEnhancedInternalEdgeRemoval = inApply; }
156
158 float GetCharacterPadding() const { return mCharacterPadding; }
159
161 uint GetMaxNumHits() const { return mMaxNumHits; }
162 void SetMaxNumHits(uint inMaxHits) { mMaxNumHits = inMaxHits; }
163
165 float GetHitReductionCosMaxAngle() const { return mHitReductionCosMaxAngle; }
166 void SetHitReductionCosMaxAngle(float inCosMaxAngle) { mHitReductionCosMaxAngle = inCosMaxAngle; }
167
172 bool GetMaxHitsExceeded() const { return mMaxHitsExceeded; }
173
175 Vec3 GetShapeOffset() const { return mShapeOffset; }
176 void SetShapeOffset(Vec3Arg inShapeOffset) { mShapeOffset = inShapeOffset; }
177
179 uint64 GetUserData() const { return mUserData; }
180 void SetUserData(uint64 inUserData) { mUserData = inUserData; }
181
186 Vec3 CancelVelocityTowardsSteepSlopes(Vec3Arg inDesiredVelocity) const;
187
198 void Update(float inDeltaTime, Vec3Arg inGravity, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator);
199
203 bool CanWalkStairs(Vec3Arg inLinearVelocity) const;
204
217 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);
218
229 bool StickToFloor(Vec3Arg inStepDown, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator);
230
233 {
234 Vec3 mStickToFloorStepDown { 0, -0.5f, 0 };
235 Vec3 mWalkStairsStepUp { 0, 0.4f, 0 };
236 float mWalkStairsMinStepForward { 0.02f };
237 float mWalkStairsStepForwardTest { 0.15f };
238 float mWalkStairsCosAngleForwardContact { Cos(DegreesToRadians(75.0f)) };
239 Vec3 mWalkStairsStepDownExtra { Vec3::sZero() };
240 };
241
254 void ExtendedUpdate(float inDeltaTime, Vec3Arg inGravity, const ExtendedUpdateSettings &inSettings, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator);
255
257 void RefreshContacts(const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator);
258
261 void UpdateGroundVelocity();
262
272 bool SetShape(const Shape *inShape, float inMaxPenetrationDepth, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator);
273
286 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;
287
288 // Saving / restoring state for replay
289 virtual void SaveState(StateRecorder &inStream) const override;
290 virtual void RestoreState(StateRecorder &inStream) override;
291
292#ifdef JPH_DEBUG_RENDERER
293 static inline bool sDrawConstraints = false;
294 static inline bool sDrawWalkStairs = false;
295 static inline bool sDrawStickToFloor = false;
296#endif
297
298 // Encapsulates a collision contact
299 struct Contact
300 {
301 // Saving / restoring state for replay
302 void SaveState(StateRecorder &inStream) const;
303 void RestoreState(StateRecorder &inStream);
304
309 float mDistance;
310 float mFraction;
317 bool mHadCollision = false;
318 bool mWasDiscarded = false;
319 bool mCanPushCharacter = true;
320 };
321
324
326 const ContactList & GetActiveContacts() const { return mActiveContacts; }
327
328private:
329 // Sorting predicate for making contact order deterministic
330 struct ContactOrderingPredicate
331 {
332 inline bool operator () (const Contact &inLHS, const Contact &inRHS) const
333 {
334 if (inLHS.mBodyB != inRHS.mBodyB)
335 return inLHS.mBodyB < inRHS.mBodyB;
336
337 return inLHS.mSubShapeIDB.GetValue() < inRHS.mSubShapeIDB.GetValue();
338 }
339 };
340
341 // A contact that needs to be ignored
342 struct IgnoredContact
343 {
344 IgnoredContact() = default;
345 IgnoredContact(const BodyID &inBodyID, const SubShapeID &inSubShapeID) : mBodyID(inBodyID), mSubShapeID(inSubShapeID) { }
346
347 BodyID mBodyID;
348 SubShapeID mSubShapeID;
349 };
350
352
353 // A constraint that limits the movement of the character
354 struct Constraint
355 {
356 Contact * mContact;
357 float mTOI;
358 float mProjectedVelocity;
359 Vec3 mLinearVelocity;
360 Plane mPlane;
361 bool mIsSteepSlope = false;
362 };
363
365
366 // Collision collector that collects hits for CollideShape
367 class ContactCollector : public CollideShapeCollector
368 {
369 public:
370 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) { }
371
372 virtual void AddHit(const CollideShapeResult &inResult) override;
373
374 RVec3 mBaseOffset;
375 Vec3 mUp;
376 PhysicsSystem * mSystem;
377 const CharacterVirtual * mCharacter;
378 TempContactList & mContacts;
379 uint mMaxHits;
380 float mHitReductionCosMaxAngle;
381 bool mMaxHitsExceeded = false;
382 };
383
384 // A collision collector that collects hits for CastShape
385 class ContactCastCollector : public CastShapeCollector
386 {
387 public:
388 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) { }
389
390 virtual void AddHit(const ShapeCastResult &inResult) override;
391
392 RVec3 mBaseOffset;
393 Vec3 mDisplacement;
394 Vec3 mUp;
395 PhysicsSystem * mSystem;
396 const CharacterVirtual * mCharacter;
397 const IgnoredContactList & mIgnoredContacts;
398 Contact & mContact;
399 };
400
401 // Helper function to convert a Jolt collision result into a contact
402 template <class taCollector>
403 inline static void sFillContactProperties(const CharacterVirtual *inCharacter, Contact &outContact, const Body &inBody, Vec3Arg inUp, RVec3Arg inBaseOffset, const taCollector &inCollector, const CollideShapeResult &inResult);
404
405 // Move the shape from ioPosition and try to displace it by inVelocity * inDeltaTime, this will try to slide the shape along the world geometry
406 void MoveShape(RVec3 &ioPosition, Vec3Arg inVelocity, float inDeltaTime, ContactList *outActiveContacts, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator
407 #ifdef JPH_DEBUG_RENDERER
408 , bool inDrawConstraints = false
409 #endif // JPH_DEBUG_RENDERER
410 ) const;
411
412 // Ask the callback if inContact is a valid contact point
413 bool ValidateContact(const Contact &inContact) const;
414
415 // Tests the shape for collision around inPosition
416 void GetContactsAtPosition(RVec3Arg inPosition, Vec3Arg inMovementDirection, const Shape *inShape, TempContactList &outContacts, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter) const;
417
418 // Remove penetrating contacts with the same body that have conflicting normals, leaving these will make the character mover get stuck
419 void RemoveConflictingContacts(TempContactList &ioContacts, IgnoredContactList &outIgnoredContacts) const;
420
421 // 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.
422 void DetermineConstraints(TempContactList &inContacts, float inDeltaTime, ConstraintList &outConstraints) const;
423
424 // 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.
425 void SolveConstraints(Vec3Arg inVelocity, float inDeltaTime, float inTimeRemaining, ConstraintList &ioConstraints, IgnoredContactList &ioIgnoredContacts, float &outTimeSimulated, Vec3 &outDisplacement, TempAllocator &inAllocator
426 #ifdef JPH_DEBUG_RENDERER
427 , bool inDrawConstraints = false
428 #endif // JPH_DEBUG_RENDERER
429 ) const;
430
431 // Get the velocity of a body adjusted by the contact listener
432 void GetAdjustedBodyVelocity(const Body& inBody, Vec3 &outLinearVelocity, Vec3 &outAngularVelocity) const;
433
434 // 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.
435 // Note that we don't just take the point velocity because a point on an object with angular velocity traces an arc,
436 // so if you just take point velocity * delta time you get an error that accumulates over time
437 Vec3 CalculateCharacterGroundVelocity(RVec3Arg inCenterOfMass, Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity, float inDeltaTime) const;
438
439 // Handle contact with physics object that we're colliding against
440 bool HandleContact(Vec3Arg inVelocity, Constraint &ioConstraint, float inDeltaTime) const;
441
442 // Does a swept test of the shape from inPosition with displacement inDisplacement, returns true if there was a collision
443 bool GetFirstContactForSweep(RVec3Arg inPosition, Vec3Arg inDisplacement, Contact &outContact, const IgnoredContactList &inIgnoredContacts, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter) const;
444
445 // Store contacts so that we have proper ground information
446 void StoreActiveContacts(const TempContactList &inContacts, TempAllocator &inAllocator);
447
448 // This function will determine which contacts are touching the character and will calculate the one that is supporting us
449 void UpdateSupportingContact(bool inSkipContactVelocityCheck, TempAllocator &inAllocator);
450
452 void MoveToContact(RVec3Arg inPosition, const Contact &inContact, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter, TempAllocator &inAllocator);
453
454 // This function returns the actual center of mass of the shape, not corrected for the character padding
455 inline RMat44 GetCenterOfMassTransform(RVec3Arg inPosition, QuatArg inRotation, const Shape *inShape) const
456 {
457 return RMat44::sRotationTranslation(inRotation, inPosition).PreTranslated(mShapeOffset + inShape->GetCenterOfMass()).PostTranslated(mCharacterPadding * mUp);
458 }
459
460 // Our main listener for contacts
461 CharacterContactListener * mListener = nullptr;
462
463 // Movement settings
464 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.
465 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 cannot properly calculate a sliding direction anymore. A value that's too high will cause ghost collisions.
466 uint mMaxCollisionIterations; // Max amount of collision loops
467 uint mMaxConstraintIterations; // How often to try stepping in the constraint solving
468 float mMinTimeRemaining; // Early out condition: If this much time is left to simulate we are done
469 float mCollisionTolerance; // How far we're willing to penetrate geometry
470 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
471 uint mMaxNumHits; // Max num hits to collect in order to avoid excess of contact points collection
472 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.
473 float mPenetrationRecoverySpeed; // This value governs how fast a penetration will be resolved, 0 = nothing is resolved, 1 = everything in one update
474 bool mEnhancedInternalEdgeRemoval; // Set to indicate that extra effort should be made to try to remove ghost contacts (collisions with internal edges of a mesh). This is more expensive but makes bodies move smoother over a mesh with convex edges.
475
476 // Character mass (kg)
477 float mMass;
478
479 // Maximum force with which the character can push other bodies (N)
480 float mMaxStrength;
481
482 // An extra offset applied to the shape in local space. This allows applying an extra offset to the shape in local space.
483 Vec3 mShapeOffset = Vec3::sZero();
484
485 // Current position (of the base, not the center of mass)
486 RVec3 mPosition = RVec3::sZero();
487
488 // Current rotation (of the base, not of the center of mass)
489 Quat mRotation = Quat::sIdentity();
490
491 // Current linear velocity
492 Vec3 mLinearVelocity = Vec3::sZero();
493
494 // List of contacts that were active in the last frame
495 ContactList mActiveContacts;
496
497 // Remembers the delta time of the last update
498 float mLastDeltaTime = 1.0f / 60.0f;
499
500 // Remember if we exceeded the maximum number of hits and had to remove similar contacts
501 mutable bool mMaxHitsExceeded = false;
502
503 // User data, can be used for anything by the application
504 uint64 mUserData = 0;
505};
506
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:236
std::uint64_t uint64
Definition Core.h:452
unsigned int uint
Definition Core.h:448
#define JPH_NAMESPACE_END
Definition Core.h:377
#define JPH_NAMESPACE_BEGIN
Definition Core.h:371
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:31
EMotionType
Motion type of a physics body.
Definition MotionType.h:11
JPH_INLINE float Cos(float inX)
Cosine of x (input in radians)
Definition Trigonometry.h:20
Definition Array.h:36
Class function to filter out bodies, returns true if test should collide with body.
Definition BodyFilter.h:16
Definition Body.h:35
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
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 SetUserData(uint64 inUserData)
Definition CharacterVirtual.h:180
void SetEnhancedInternalEdgeRemoval(bool inApply)
Definition CharacterVirtual.h:155
float GetMass() const
Character mass (kg)
Definition CharacterVirtual.h:142
float GetPenetrationRecoverySpeed() const
This value governs how fast a penetration will be resolved, 0 = nothing is resolved,...
Definition CharacterVirtual.h:150
RVec3 GetPosition() const
Get the position of the character.
Definition CharacterVirtual.h:124
void SetLinearVelocity(Vec3Arg inLinearVelocity)
Set the linear velocity of the character (m / s)
Definition CharacterVirtual.h:121
const ContactList & GetActiveContacts() const
Access to the internal list of contacts that the character has found.
Definition CharacterVirtual.h:326
RMat44 GetWorldTransform() const
Calculate the world transform of the character.
Definition CharacterVirtual.h:136
bool GetMaxHitsExceeded() const
Definition CharacterVirtual.h:172
void SetMaxStrength(float inMaxStrength)
Definition CharacterVirtual.h:147
float GetCharacterPadding() const
Character padding.
Definition CharacterVirtual.h:158
void SetMaxNumHits(uint inMaxHits)
Definition CharacterVirtual.h:162
uint GetMaxNumHits() const
Max num hits to collect in order to avoid excess of contact points collection.
Definition CharacterVirtual.h:161
float GetMaxStrength() const
Maximum force with which the character can push other bodies (N)
Definition CharacterVirtual.h:146
void SetShapeOffset(Vec3Arg inShapeOffset)
Definition CharacterVirtual.h:176
void SetMass(float inMass)
Definition CharacterVirtual.h:143
bool GetEnhancedInternalEdgeRemoval() const
Set to indicate that extra effort should be made to try to remove ghost contacts (collisions with int...
Definition CharacterVirtual.h:154
Vec3 GetLinearVelocity() const
Get the linear velocity of the character (m / s)
Definition CharacterVirtual.h:118
CharacterContactListener * GetListener() const
Get the current contact listener.
Definition CharacterVirtual.h:115
RMat44 GetCenterOfMassTransform() const
Calculates the transform for this character's center of mass.
Definition CharacterVirtual.h:139
CharacterVirtual(const CharacterVirtualSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, PhysicsSystem *inSystem)
Constructor without user data.
Definition CharacterVirtual.h:109
void SetRotation(QuatArg inRotation)
Set the rotation of the character.
Definition CharacterVirtual.h:133
void SetHitReductionCosMaxAngle(float inCosMaxAngle)
Definition CharacterVirtual.h:166
uint64 GetUserData() const
Access to the user data, can be used for anything by the application.
Definition CharacterVirtual.h:179
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:175
void SetPenetrationRecoverySpeed(float inSpeed)
Definition CharacterVirtual.h:151
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:165
void SetPosition(RVec3Arg inPosition)
Set the position of the character.
Definition CharacterVirtual.h:127
void SetListener(CharacterContactListener *inListener)
Set the contact listener.
Definition CharacterVirtual.h:112
Quat GetRotation() const
Get the rotation of the character.
Definition CharacterVirtual.h:130
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: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
Filter class for object layers.
Definition ObjectLayer.h:28
Definition PhysicsMaterial.h:23
Definition PhysicsSystem.h:29
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: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:178
virtual Vec3 GetCenterOfMass() const
All shapes are centered around their center of mass. This function returns the center of mass positio...
Definition Shape.h:203
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
Definition Vec3.h:17
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:107
Definition CharacterVirtual.h:300
EMotionType mMotionTypeB
Motion type of B, used to determine the priority of the contact.
Definition CharacterVirtual.h:313
Vec3 mContactNormal
Contact normal, pointing towards the character.
Definition CharacterVirtual.h:307
const PhysicsMaterial * mMaterial
Material of B.
Definition CharacterVirtual.h:316
float mFraction
Fraction along the path where this contact takes place.
Definition CharacterVirtual.h:310
uint64 mUserData
User data of B.
Definition CharacterVirtual.h:315
BodyID mBodyB
ID of body we're colliding with.
Definition CharacterVirtual.h:311
SubShapeID mSubShapeIDB
Sub shape ID of body we're colliding with.
Definition CharacterVirtual.h:312
Vec3 mLinearVelocity
Velocity of the contact point.
Definition CharacterVirtual.h:306
float mDistance
Distance to the contact <= 0 means that it is an actual contact, > 0 means predictive.
Definition CharacterVirtual.h:309
Vec3 mSurfaceNormal
Surface normal of the contact.
Definition CharacterVirtual.h:308
RVec3 mPosition
Position where the character makes contact.
Definition CharacterVirtual.h:305
bool mIsSensorB
If B is a sensor.
Definition CharacterVirtual.h:314
Settings struct with settings for ExtendedUpdate.
Definition CharacterVirtual.h:233