Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Constraints/ContactConstraintManager.h
22316 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Core/StaticArray.h>7#include <Jolt/Core/LockFreeHashMap.h>8#include <Jolt/Physics/EPhysicsUpdateError.h>9#include <Jolt/Physics/Body/BodyPair.h>10#include <Jolt/Physics/Collision/Shape/SubShapeIDPair.h>11#include <Jolt/Physics/Collision/ManifoldBetweenTwoFaces.h>12#include <Jolt/Physics/Constraints/ConstraintPart/AxisConstraintPart.h>13#include <Jolt/Physics/Constraints/ConstraintPart/DualAxisConstraintPart.h>14#include <Jolt/Core/HashCombine.h>15#include <Jolt/Core/NonCopyable.h>1617JPH_SUPPRESS_WARNINGS_STD_BEGIN18#include <atomic>19JPH_SUPPRESS_WARNINGS_STD_END2021JPH_NAMESPACE_BEGIN2223struct PhysicsSettings;24class PhysicsUpdateContext;2526/// A contact constraint manager manages all contacts between two bodies27///28/// WARNING: This class is an internal part of PhysicsSystem, it has no functions that can be called by users of the library.29class JPH_EXPORT ContactConstraintManager : public NonCopyable30{31public:32JPH_OVERRIDE_NEW_DELETE3334/// Constructor35explicit ContactConstraintManager(const PhysicsSettings &inPhysicsSettings);36~ContactConstraintManager();3738/// Initialize the system.39/// @param inMaxBodyPairs Maximum amount of body pairs to process (anything else will fall through the world), this number should generally be much higher than the max amount of contact points as there will be lots of bodies close that are not actually touching40/// @param inMaxContactConstraints Maximum amount of contact constraints to process (anything else will fall through the world)41void Init(uint inMaxBodyPairs, uint inMaxContactConstraints);4243/// Listener that is notified whenever a contact point between two bodies is added/updated/removed44void SetContactListener(ContactListener *inListener) { mContactListener = inListener; }45ContactListener * GetContactListener() const { return mContactListener; }4647/// Callback function to combine the restitution or friction of two bodies48/// Note that when merging manifolds (when PhysicsSettings::mUseManifoldReduction is true) you will only get a callback for the merged manifold.49/// It is not possible in that case to get all sub shape ID pairs that were colliding, you'll get the first encountered pair.50using CombineFunction = float (*)(const Body &inBody1, const SubShapeID &inSubShapeID1, const Body &inBody2, const SubShapeID &inSubShapeID2);5152/// Set the function that combines the friction of two bodies and returns it53/// Default method is the geometric mean: sqrt(friction1 * friction2).54void SetCombineFriction(CombineFunction inCombineFriction) { mCombineFriction = inCombineFriction; }55CombineFunction GetCombineFriction() const { return mCombineFriction; }5657/// Set the function that combines the restitution of two bodies and returns it58/// Default method is max(restitution1, restitution1)59void SetCombineRestitution(CombineFunction inCombineRestitution) { mCombineRestitution = inCombineRestitution; }60CombineFunction GetCombineRestitution() const { return mCombineRestitution; }6162/// Get the max number of contact constraints that are allowed63uint32 GetMaxConstraints() const { return mMaxConstraints; }6465/// Check with the listener if inBody1 and inBody2 could collide, returns false if not66inline ValidateResult ValidateContactPoint(const Body &inBody1, const Body &inBody2, RVec3Arg inBaseOffset, const CollideShapeResult &inCollisionResult) const67{68if (mContactListener == nullptr)69return ValidateResult::AcceptAllContactsForThisBodyPair;7071return mContactListener->OnContactValidate(inBody1, inBody2, inBaseOffset, inCollisionResult);72}7374/// Sets up the constraint buffer. Should be called before starting collision detection.75void PrepareConstraintBuffer(PhysicsUpdateContext *inContext);7677/// Max 4 contact points are needed for a stable manifold78static const int MaxContactPoints = 4;7980/// Contacts are allocated in a lock free hash map81class ContactAllocator : public LFHMAllocatorContext82{83public:84using LFHMAllocatorContext::LFHMAllocatorContext;8586uint mNumBodyPairs = 0; ///< Total number of body pairs added using this allocator87uint mNumManifolds = 0; ///< Total number of manifolds added using this allocator88EPhysicsUpdateError mErrors = EPhysicsUpdateError::None; ///< Errors reported on this allocator89};9091/// Get a new allocator context for storing contacts. Note that you should call this once and then add multiple contacts using the context.92ContactAllocator GetContactAllocator() { return mCache[mCacheWriteIdx].GetContactAllocator(); }9394/// Check if the contact points from the previous frame are reusable and if so copy them.95/// When the cache was usable and the pair has been handled: outPairHandled = true.96/// When a contact constraint was produced: outConstraintCreated = true.97void GetContactsFromCache(ContactAllocator &ioContactAllocator, Body &inBody1, Body &inBody2, bool &outPairHandled, bool &outConstraintCreated);9899/// Handle used to keep track of the current body pair100using BodyPairHandle = void *;101102/// Create a handle for a colliding body pair so that contact constraints can be added between them.103/// Needs to be called once per body pair per frame before calling AddContactConstraint.104BodyPairHandle AddBodyPair(ContactAllocator &ioContactAllocator, const Body &inBody1, const Body &inBody2);105106/// Add a contact constraint for this frame.107///108/// @param ioContactAllocator The allocator that reserves memory for the contacts109/// @param inBodyPair The handle for the contact cache for this body pair110/// @param inBody1 The first body that is colliding111/// @param inBody2 The second body that is colliding112/// @param inManifold The manifold that describes the collision113/// @return true if a contact constraint was created (can be false in the case of a sensor)114///115/// This is using the approach described in 'Modeling and Solving Constraints' by Erin Catto presented at GDC 2009 (and later years with slight modifications).116/// We're using the formulas from slide 50 - 53 combined.117///118/// Euler velocity integration:119///120/// v1' = v1 + M^-1 P121///122/// Impulse:123///124/// P = J^T lambda125///126/// Constraint force:127///128/// lambda = -K^-1 J v1129///130/// Inverse effective mass:131///132/// K = J M^-1 J^T133///134/// Constraint equation (limits movement in 1 axis):135///136/// C = (p2 - p1) . n137///138/// Jacobian (for position constraint)139///140/// J = [-n, -r1 x n, n, r2 x n]141///142/// n = contact normal (pointing away from body 1).143/// p1, p2 = positions of collision on body 1 and 2.144/// r1, r2 = contact point relative to center of mass of body 1 and body 2 (r1 = p1 - x1, r2 = p2 - x2).145/// v1, v2 = (linear velocity, angular velocity): 6 vectors containing linear and angular velocity for body 1 and 2.146/// M = mass matrix, a diagonal matrix of the mass and inertia with diagonal [m1, I1, m2, I2].147bool AddContactConstraint(ContactAllocator &ioContactAllocator, BodyPairHandle inBodyPair, Body &inBody1, Body &inBody2, const ContactManifold &inManifold);148149/// Finalizes the contact cache, the contact cache that was generated during the calls to AddContactConstraint in this update150/// will be used from now on to read from. After finalizing the contact cache, the contact removed callbacks will be called.151/// inExpectedNumBodyPairs / inExpectedNumManifolds are the amount of body pairs / manifolds found in the previous step and is152/// used to determine the amount of buckets the contact cache hash map will use in the next update.153void FinalizeContactCacheAndCallContactPointRemovedCallbacks(uint inExpectedNumBodyPairs, uint inExpectedNumManifolds);154155/// Check if 2 bodies were in contact during the last simulation step. Since contacts are only detected between active bodies, at least one of the bodies must be active.156/// Uses the read collision cache to determine if 2 bodies are in contact.157bool WereBodiesInContact(const BodyID &inBody1ID, const BodyID &inBody2ID) const;158159/// Get the number of contact constraints that were found160uint32 GetNumConstraints() const { return min<uint32>(mNumConstraints, mMaxConstraints); }161162/// Sort contact constraints deterministically163void SortContacts(uint32 *inConstraintIdxBegin, uint32 *inConstraintIdxEnd) const;164165/// Get the affected bodies for a given constraint166inline void GetAffectedBodies(uint32 inConstraintIdx, const Body *&outBody1, const Body *&outBody2) const167{168const ContactConstraint &constraint = mConstraints[inConstraintIdx];169outBody1 = constraint.mBody1;170outBody2 = constraint.mBody2;171}172173/// Apply last frame's impulses as an initial guess for this frame's impulses174template <class MotionPropertiesCallback>175void WarmStartVelocityConstraints(const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd, float inWarmStartImpulseRatio, MotionPropertiesCallback &ioCallback);176177/// Solve velocity constraints, when almost nothing changes this should only apply very small impulses178/// since we're warm starting with the total impulse applied in the last frame above.179///180/// Friction wise we're using the Coulomb friction model which says that:181///182/// |F_T| <= mu |F_N|183///184/// Where F_T is the tangential force, F_N is the normal force and mu is the friction coefficient185///186/// In impulse terms this becomes:187///188/// |lambda_T| <= mu |lambda_N|189///190/// And the constraint that needs to be applied is exactly the same as a non penetration constraint191/// except that we use a tangent instead of a normal. The tangent should point in the direction of the192/// tangential velocity of the point:193///194/// J = [-T, -r1 x T, T, r2 x T]195///196/// Where T is the tangent.197///198/// See slide 42 and 43.199///200/// Restitution is implemented as a velocity bias (see slide 41):201///202/// b = e v_n^-203///204/// e = the restitution coefficient, v_n^- is the normal velocity prior to the collision205///206/// Restitution is only applied when v_n^- is large enough and the points are moving towards collision207bool SolveVelocityConstraints(const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd);208209/// Save back the lambdas to the contact cache for the next warm start210void StoreAppliedImpulses(const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd) const;211212/// Solve position constraints.213/// This is using the approach described in 'Modeling and Solving Constraints' by Erin Catto presented at GDC 2007.214/// On slide 78 it is suggested to split up the Baumgarte stabilization for positional drift so that it does not215/// actually add to the momentum. We combine an Euler velocity integrate + a position integrate and then discard the velocity216/// change.217///218/// Constraint force:219///220/// lambda = -K^-1 b221///222/// Baumgarte stabilization:223///224/// b = beta / dt C225///226/// beta = baumgarte stabilization factor.227/// dt = delta time.228bool SolvePositionConstraints(const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd);229230/// Recycle the constraint buffer. Should be called between collision simulation steps.231void RecycleConstraintBuffer();232233/// Terminate the constraint buffer. Should be called after simulation ends.234void FinishConstraintBuffer();235236/// Called by continuous collision detection to notify the contact listener that a contact was added237/// @param ioContactAllocator The allocator that reserves memory for the contacts238/// @param inBody1 The first body that is colliding239/// @param inBody2 The second body that is colliding240/// @param inManifold The manifold that describes the collision241/// @param outSettings The calculated contact settings (may be overridden by the contact listener)242void OnCCDContactAdded(ContactAllocator &ioContactAllocator, const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &outSettings);243244#ifdef JPH_DEBUG_RENDERER245// Drawing properties246static bool sDrawContactPoint;247static bool sDrawSupportingFaces;248static bool sDrawContactPointReduction;249static bool sDrawContactManifolds;250#endif // JPH_DEBUG_RENDERER251252/// Saving state for replay253void SaveState(StateRecorder &inStream, const StateRecorderFilter *inFilter) const;254255/// Restoring state for replay. Returns false when failed.256bool RestoreState(StateRecorder &inStream, const StateRecorderFilter *inFilter);257258private:259/// Local space contact point, used for caching impulses260class CachedContactPoint261{262public:263/// Saving / restoring state for replay264void SaveState(StateRecorder &inStream) const;265void RestoreState(StateRecorder &inStream);266267/// Local space positions on body 1 and 2.268/// Note: these values are read through sLoadFloat3Unsafe.269Float3 mPosition1;270Float3 mPosition2;271272/// Total applied impulse during the last update that it was used273float mNonPenetrationLambda;274Vector<2> mFrictionLambda;275};276277static_assert(sizeof(CachedContactPoint) == 36, "Unexpected size");278static_assert(alignof(CachedContactPoint) == 4, "Assuming 4 byte aligned");279280/// A single cached manifold281class CachedManifold282{283public:284/// Calculate size in bytes needed beyond the size of the class to store inNumContactPoints285static int sGetRequiredExtraSize(int inNumContactPoints) { return max(0, inNumContactPoints - 1) * sizeof(CachedContactPoint); }286287/// Calculate total class size needed for storing inNumContactPoints288static int sGetRequiredTotalSize(int inNumContactPoints) { return sizeof(CachedManifold) + sGetRequiredExtraSize(inNumContactPoints); }289290/// Saving / restoring state for replay291void SaveState(StateRecorder &inStream) const;292void RestoreState(StateRecorder &inStream);293294/// Handle to next cached contact points in ManifoldCache::mCachedManifolds for the same body pair295uint32 mNextWithSameBodyPair;296297/// Contact normal in the space of 2.298/// Note: this value is read through sLoadFloat3Unsafe.299Float3 mContactNormal;300301/// Flags for this cached manifold302enum class EFlags : uint16303{304ContactPersisted = 1, ///< If this cache entry was reused in the next simulation update305CCDContact = 2 ///< This is a cached manifold reported by continuous collision detection and was only used to create a contact callback306};307308/// @see EFlags309mutable atomic<uint16> mFlags { 0 };310311/// Number of contact points in the array below312uint16 mNumContactPoints;313314/// Contact points that this manifold consists of315CachedContactPoint mContactPoints[1];316};317318static_assert(sizeof(CachedManifold) == 56, "This structure is expect to not contain any waste due to alignment");319static_assert(alignof(CachedManifold) == 4, "Assuming 4 byte aligned");320321/// Define a map that maps SubShapeIDPair -> manifold322using ManifoldMap = LockFreeHashMap<SubShapeIDPair, CachedManifold>;323using MKeyValue = ManifoldMap::KeyValue;324using MKVAndCreated = std::pair<MKeyValue *, bool>;325326/// Start of list of contact points for a particular pair of bodies327class CachedBodyPair328{329public:330/// Saving / restoring state for replay331void SaveState(StateRecorder &inStream) const;332void RestoreState(StateRecorder &inStream);333334/// Local space position difference from Body A to Body B.335/// Note: this value is read through sLoadFloat3Unsafe336Float3 mDeltaPosition;337338/// Local space rotation difference from Body A to Body B, fourth component of quaternion is not stored but is guaranteed >= 0.339/// Note: this value is read through sLoadFloat3Unsafe340Float3 mDeltaRotation;341342/// Handle to first manifold in ManifoldCache::mCachedManifolds343uint32 mFirstCachedManifold;344};345346static_assert(sizeof(CachedBodyPair) == 28, "Unexpected size");347static_assert(alignof(CachedBodyPair) == 4, "Assuming 4 byte aligned");348349/// Define a map that maps BodyPair -> CachedBodyPair350using BodyPairMap = LockFreeHashMap<BodyPair, CachedBodyPair>;351using BPKeyValue = BodyPairMap::KeyValue;352353/// Holds all caches that are needed to quickly find cached body pairs / manifolds354class ManifoldCache355{356public:357/// Initialize the cache358void Init(uint inMaxBodyPairs, uint inMaxContactConstraints, uint inCachedManifoldsSize);359360/// Reset all entries from the cache361void Clear();362363/// Prepare cache before creating new contacts.364/// inExpectedNumBodyPairs / inExpectedNumManifolds are the amount of body pairs / manifolds found in the previous step and is used to determine the amount of buckets the contact cache hash map will use.365void Prepare(uint inExpectedNumBodyPairs, uint inExpectedNumManifolds);366367/// Get a new allocator context for storing contacts. Note that you should call this once and then add multiple contacts using the context.368ContactAllocator GetContactAllocator() { return ContactAllocator(mAllocator, cAllocatorBlockSize); }369370/// Find / create cached entry for SubShapeIDPair -> CachedManifold371const MKeyValue * Find(const SubShapeIDPair &inKey, uint64 inKeyHash) const;372MKeyValue * Create(ContactAllocator &ioContactAllocator, const SubShapeIDPair &inKey, uint64 inKeyHash, int inNumContactPoints);373MKVAndCreated FindOrCreate(ContactAllocator &ioContactAllocator, const SubShapeIDPair &inKey, uint64 inKeyHash, int inNumContactPoints);374uint32 ToHandle(const MKeyValue *inKeyValue) const;375const MKeyValue * FromHandle(uint32 inHandle) const;376377/// Find / create entry for BodyPair -> CachedBodyPair378const BPKeyValue * Find(const BodyPair &inKey, uint64 inKeyHash) const;379BPKeyValue * Create(ContactAllocator &ioContactAllocator, const BodyPair &inKey, uint64 inKeyHash);380void GetAllBodyPairsSorted(Array<const BPKeyValue *> &outAll) const;381void GetAllManifoldsSorted(const CachedBodyPair &inBodyPair, Array<const MKeyValue *> &outAll) const;382void GetAllCCDManifoldsSorted(Array<const MKeyValue *> &outAll) const;383void ContactPointRemovedCallbacks(ContactListener *inListener);384385#ifdef JPH_ENABLE_ASSERTS386/// Get the amount of manifolds in the cache387uint GetNumManifolds() const { return mCachedManifolds.GetNumKeyValues(); }388389/// Get the amount of body pairs in the cache390uint GetNumBodyPairs() const { return mCachedBodyPairs.GetNumKeyValues(); }391392/// Before a cache is finalized you can only do Create(), after only Find() or Clear()393void Finalize();394#endif395396/// Saving / restoring state for replay397void SaveState(StateRecorder &inStream, const StateRecorderFilter *inFilter) const;398bool RestoreState(const ManifoldCache &inReadCache, StateRecorder &inStream, const StateRecorderFilter *inFilter);399400private:401/// Block size used when allocating new blocks in the contact cache402static constexpr uint32 cAllocatorBlockSize = 4096;403404/// Allocator used by both mCachedManifolds and mCachedBodyPairs, this makes it more likely that a body pair and its manifolds are close in memory405LFHMAllocator mAllocator;406407/// Simple hash map for SubShapeIDPair -> CachedManifold408ManifoldMap mCachedManifolds { mAllocator };409410/// Simple hash map for BodyPair -> CachedBodyPair411BodyPairMap mCachedBodyPairs { mAllocator };412413#ifdef JPH_ENABLE_ASSERTS414bool mIsFinalized = false; ///< Marks if this buffer is complete415#endif416};417418ManifoldCache mCache[2]; ///< We have one cache to read from and one to write to419int mCacheWriteIdx = 0; ///< Which cache we're currently writing to420421/// World space contact point, used for solving penetrations422class WorldContactPoint423{424public:425/// Calculate constraint properties below426void CalculateNonPenetrationConstraintProperties(const Body &inBody1, float inInvMass1, float inInvInertiaScale1, const Body &inBody2, float inInvMass2, float inInvInertiaScale2, RVec3Arg inWorldSpacePosition1, RVec3Arg inWorldSpacePosition2, Vec3Arg inWorldSpaceNormal);427428template <EMotionType Type1, EMotionType Type2>429JPH_INLINE void TemplatedCalculateFrictionAndNonPenetrationConstraintProperties(float inDeltaTime, Vec3Arg inGravity, const Body &inBody1, const Body &inBody2, float inInvM1, float inInvM2, Mat44Arg inInvI1, Mat44Arg inInvI2, RVec3Arg inWorldSpacePosition1, RVec3Arg inWorldSpacePosition2, Vec3Arg inWorldSpaceNormal, Vec3Arg inWorldSpaceTangent1, Vec3Arg inWorldSpaceTangent2, const ContactSettings &inSettings, float inMinVelocityForRestitution);430431/// The constraint parts432AxisConstraintPart mNonPenetrationConstraint;433AxisConstraintPart mFrictionConstraint1;434AxisConstraintPart mFrictionConstraint2;435436/// Contact cache437CachedContactPoint * mContactPoint;438};439440using WorldContactPoints = StaticArray<WorldContactPoint, MaxContactPoints>;441442/// Contact constraint class, used for solving penetrations443class ContactConstraint444{445public:446#ifdef JPH_DEBUG_RENDERER447/// Draw the state of the contact constraint448void Draw(DebugRenderer *inRenderer, ColorArg inManifoldColor) const;449#endif // JPH_DEBUG_RENDERER450451/// Convert the world space normal to a Vec3452JPH_INLINE Vec3 GetWorldSpaceNormal() const453{454return Vec3::sLoadFloat3Unsafe(mWorldSpaceNormal);455}456457/// Get the tangents for this contact constraint458JPH_INLINE void GetTangents(Vec3 &outTangent1, Vec3 &outTangent2) const459{460Vec3 ws_normal = GetWorldSpaceNormal();461outTangent1 = ws_normal.GetNormalizedPerpendicular();462outTangent2 = ws_normal.Cross(outTangent1);463}464465Body * mBody1;466Body * mBody2;467uint64 mSortKey;468Float3 mWorldSpaceNormal;469float mCombinedFriction;470float mInvMass1;471float mInvInertiaScale1;472float mInvMass2;473float mInvInertiaScale2;474WorldContactPoints mContactPoints;475};476477public:478/// The maximum value that can be passed to Init for inMaxContactConstraints. Note you should really use a lower value, using this value will cost a lot of memory!479static constexpr uint cMaxContactConstraintsLimit = ~uint(0) / sizeof(ContactConstraint);480481/// The maximum value that can be passed to Init for inMaxBodyPairs. Note you should really use a lower value, using this value will cost a lot of memory!482static constexpr uint cMaxBodyPairsLimit = ~uint(0) / sizeof(BodyPairMap::KeyValue);483484private:485/// Internal helper function to calculate the friction and non-penetration constraint properties. Templated to the motion type to reduce the amount of branches and calculations.486template <EMotionType Type1, EMotionType Type2>487JPH_INLINE void TemplatedCalculateFrictionAndNonPenetrationConstraintProperties(ContactConstraint &ioConstraint, const ContactSettings &inSettings, float inDeltaTime, Vec3Arg inGravity, RMat44Arg inTransformBody1, RMat44Arg inTransformBody2, const Body &inBody1, const Body &inBody2);488489/// Internal helper function to calculate the friction and non-penetration constraint properties.490inline void CalculateFrictionAndNonPenetrationConstraintProperties(ContactConstraint &ioConstraint, const ContactSettings &inSettings, float inDeltaTime, Vec3Arg inGravity, RMat44Arg inTransformBody1, RMat44Arg inTransformBody2, const Body &inBody1, const Body &inBody2);491492/// Internal helper function to add a contact constraint. Templated to the motion type to reduce the amount of branches and calculations.493template <EMotionType Type1, EMotionType Type2>494bool TemplatedAddContactConstraint(ContactAllocator &ioContactAllocator, BodyPairHandle inBodyPairHandle, Body &inBody1, Body &inBody2, const ContactManifold &inManifold);495496/// Internal helper function to warm start contact constraint. Templated to the motion type to reduce the amount of branches and calculations.497template <EMotionType Type1, EMotionType Type2>498JPH_INLINE static void sWarmStartConstraint(ContactConstraint &ioConstraint, MotionProperties *ioMotionProperties1, MotionProperties *ioMotionProperties2, float inWarmStartImpulseRatio);499500/// Internal helper function to solve a single contact constraint. Templated to the motion type to reduce the amount of branches and calculations.501template <EMotionType Type1, EMotionType Type2>502JPH_INLINE static bool sSolveVelocityConstraint(ContactConstraint &ioConstraint, MotionProperties *ioMotionProperties1, MotionProperties *ioMotionProperties2);503504/// The main physics settings instance505const PhysicsSettings & mPhysicsSettings;506507/// Listener that is notified whenever a contact point between two bodies is added/updated/removed508ContactListener * mContactListener = nullptr;509510/// Functions that are used to combine friction and restitution of 2 bodies511CombineFunction mCombineFriction = [](const Body &inBody1, const SubShapeID &, const Body &inBody2, const SubShapeID &) { return sqrt(inBody1.GetFriction() * inBody2.GetFriction()); };512CombineFunction mCombineRestitution = [](const Body &inBody1, const SubShapeID &, const Body &inBody2, const SubShapeID &) { return max(inBody1.GetRestitution(), inBody2.GetRestitution()); };513514/// The constraints that were added this frame515ContactConstraint * mConstraints = nullptr;516uint32 mMaxConstraints = 0;517atomic<uint32> mNumConstraints { 0 };518519/// Context used for this physics update520PhysicsUpdateContext * mUpdateContext;521};522523JPH_NAMESPACE_END524525526