Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
Constraint Class Referenceabstract

Base class for all physics constraints. A constraint removes one or more degrees of freedom for a rigid body. More...

#include <Constraint.h>

Inheritance diagram for Constraint:
RefTarget< Constraint > NonCopyable TwoBodyConstraint VehicleConstraint ConeConstraint DistanceConstraint FixedConstraint GearConstraint HingeConstraint PathConstraint PointConstraint PulleyConstraint RackAndPinionConstraint SixDOFConstraint SliderConstraint SwingTwistConstraint

Public Member Functions

JPH_OVERRIDE_NEW_DELETE Constraint (const ConstraintSettings &inSettings)
 Constructor. More...
 
virtual ~Constraint ()=default
 Virtual destructor. More...
 
virtual EConstraintType GetType () const
 Get the type of a constraint. More...
 
virtual EConstraintSubType GetSubType () const =0
 Get the sub type of a constraint. More...
 
uint32 GetConstraintPriority () const
 
void SetConstraintPriority (uint32 inPriority)
 
void SetNumVelocityStepsOverride (uint inN)
 Used only when the constraint is active. Override for the number of solver velocity iterations to run, 0 means use the default in PhysicsSettings::mNumVelocitySteps. The number of iterations to use is the max of all contacts and constraints in the island. More...
 
uint GetNumVelocityStepsOverride () const
 
void SetNumPositionStepsOverride (uint inN)
 Used only when the constraint is active. Override for the number of solver position iterations to run, 0 means use the default in PhysicsSettings::mNumPositionSteps. The number of iterations to use is the max of all contacts and constraints in the island. More...
 
uint GetNumPositionStepsOverride () const
 
void SetEnabled (bool inEnabled)
 
bool GetEnabled () const
 Test if a constraint is enabled. More...
 
uint64 GetUserData () const
 Access to the user data, can be used for anything by the application. More...
 
void SetUserData (uint64 inUserData)
 
virtual void NotifyShapeChanged (const BodyID &inBodyID, Vec3Arg inDeltaCOM)=0
 
virtual void ResetWarmStart ()=0
 
virtual void BuildIslands (uint32 inConstraintIndex, IslandBuilder &ioBuilder, BodyManager &inBodyManager)=0
 Link bodies that are connected by this constraint in the island builder. More...
 
virtual uint BuildIslandSplits (LargeIslandSplitter &ioSplitter) const =0
 Link bodies that are connected by this constraint in the same split. Returns the split index. More...
 
virtual void DrawConstraint (DebugRenderer *inRenderer) const =0
 
virtual void DrawConstraintLimits (DebugRenderer *inRenderer) const
 
virtual void DrawConstraintReferenceFrame (DebugRenderer *inRenderer) const
 
float GetDrawConstraintSize () const
 Size of constraint when drawing it through the debug renderer. More...
 
void SetDrawConstraintSize (float inSize)
 
virtual void SaveState (StateRecorder &inStream) const
 Saving state for replay. More...
 
virtual void RestoreState (StateRecorder &inStream)
 Restoring state for replay. More...
 
virtual Ref< ConstraintSettingsGetConstraintSettings () const =0
 Debug function to convert a constraint to its settings, note that this will not save to which bodies the constraint is connected to. More...
 
Solver interface
virtual bool IsActive () const
 
virtual void SetupVelocityConstraint (float inDeltaTime)=0
 
virtual void WarmStartVelocityConstraint (float inWarmStartImpulseRatio)=0
 
virtual bool SolveVelocityConstraint (float inDeltaTime)=0
 
virtual bool SolvePositionConstraint (float inDeltaTime, float inBaumgarte)=0
 
- Public Member Functions inherited from RefTarget< Constraint >
 RefTarget ()=default
 Constructor. More...
 
 RefTarget (const RefTarget &)
 
 ~RefTarget ()
 assert no one is referencing us More...
 
void SetEmbedded () const
 
RefTargetoperator= (const RefTarget &)
 Assignment operator. More...
 
uint32 GetRefCount () const
 Get current refcount of this object. More...
 
void AddRef () const
 Add or release a reference to this object. More...
 
void Release () const
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Protected Member Functions

void ToConstraintSettings (ConstraintSettings &outSettings) const
 Helper function to copy settings back to constraint settings for this base class. More...
 

Protected Attributes

float mDrawConstraintSize
 Size of constraint when drawing it through the debug renderer. More...
 
- Protected Attributes inherited from RefTarget< Constraint >
atomic< uint32mRefCount
 Current reference count. More...
 

Friends

class ConstraintManager
 

Additional Inherited Members

- Static Public Member Functions inherited from RefTarget< Constraint >
static int sInternalGetRefCountOffset ()
 INTERNAL HELPER FUNCTION USED BY SERIALIZATION. More...
 
- Static Protected Attributes inherited from RefTarget< Constraint >
static constexpr uint32 cEmbedded
 A large value that gets added to the refcount to mark the object as embedded. More...
 

Detailed Description

Base class for all physics constraints. A constraint removes one or more degrees of freedom for a rigid body.

Constructor & Destructor Documentation

◆ Constraint()

JPH_OVERRIDE_NEW_DELETE Constraint::Constraint ( const ConstraintSettings inSettings)
inlineexplicit

Constructor.

◆ ~Constraint()

virtual Constraint::~Constraint ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ BuildIslands()

virtual void Constraint::BuildIslands ( uint32  inConstraintIndex,
IslandBuilder ioBuilder,
BodyManager inBodyManager 
)
pure virtual

Link bodies that are connected by this constraint in the island builder.

Implemented in TwoBodyConstraint, and VehicleConstraint.

◆ BuildIslandSplits()

virtual uint Constraint::BuildIslandSplits ( LargeIslandSplitter ioSplitter) const
pure virtual

Link bodies that are connected by this constraint in the same split. Returns the split index.

Implemented in TwoBodyConstraint, and VehicleConstraint.

◆ DrawConstraint()

◆ DrawConstraintLimits()

virtual void Constraint::DrawConstraintLimits ( DebugRenderer inRenderer) const
inlinevirtual

◆ DrawConstraintReferenceFrame()

virtual void Constraint::DrawConstraintReferenceFrame ( DebugRenderer inRenderer) const
inlinevirtual

Reimplemented in TwoBodyConstraint.

◆ GetConstraintPriority()

uint32 Constraint::GetConstraintPriority ( ) const
inline

Priority of the constraint when solving. Higher numbers have are more likely to be solved correctly. Note that if you want a deterministic simulation and you cannot guarantee the order in which constraints are added/removed, you can make the priority for all constraints unique to get a deterministic ordering.

◆ GetConstraintSettings()

virtual Ref< ConstraintSettings > Constraint::GetConstraintSettings ( ) const
pure virtual

Debug function to convert a constraint to its settings, note that this will not save to which bodies the constraint is connected to.

Implemented in ConeConstraint, DistanceConstraint, FixedConstraint, GearConstraint, HingeConstraint, PathConstraint, PointConstraint, PulleyConstraint, RackAndPinionConstraint, SixDOFConstraint, SliderConstraint, SwingTwistConstraint, and VehicleConstraint.

◆ GetDrawConstraintSize()

float Constraint::GetDrawConstraintSize ( ) const
inline

Size of constraint when drawing it through the debug renderer.

◆ GetEnabled()

bool Constraint::GetEnabled ( ) const
inline

Test if a constraint is enabled.

◆ GetNumPositionStepsOverride()

uint Constraint::GetNumPositionStepsOverride ( ) const
inline

◆ GetNumVelocityStepsOverride()

uint Constraint::GetNumVelocityStepsOverride ( ) const
inline

◆ GetSubType()

◆ GetType()

virtual EConstraintType Constraint::GetType ( ) const
inlinevirtual

Get the type of a constraint.

Reimplemented in TwoBodyConstraint.

◆ GetUserData()

uint64 Constraint::GetUserData ( ) const
inline

Access to the user data, can be used for anything by the application.

◆ IsActive()

virtual bool Constraint::IsActive ( ) const
inlinevirtual

◆ NotifyShapeChanged()

virtual void Constraint::NotifyShapeChanged ( const BodyID inBodyID,
Vec3Arg  inDeltaCOM 
)
pure virtual

Notify the constraint that the shape of a body has changed and that its center of mass has moved by inDeltaCOM. Bodies don't know which constraints are connected to them so the user is responsible for notifying the relevant constraints when a body changes.

Parameters
inBodyIDID of the body that has changed
inDeltaCOMThe delta of the center of mass of the body (shape->GetCenterOfMass() - shape_before_change->GetCenterOfMass())

Implemented in ConeConstraint, DistanceConstraint, FixedConstraint, GearConstraint, HingeConstraint, PathConstraint, PointConstraint, PulleyConstraint, RackAndPinionConstraint, SixDOFConstraint, SliderConstraint, SwingTwistConstraint, and VehicleConstraint.

◆ ResetWarmStart()

virtual void Constraint::ResetWarmStart ( )
pure virtual

Notify the system that the configuration of the bodies and/or constraint has changed enough so that the warm start impulses should not be applied the next frame. You can use this function for example when repositioning a ragdoll through Ragdoll::SetPose in such a way that the orientation of the bodies completely changes so that the previous frame impulses are no longer a good approximation of what the impulses will be in the next frame. Calling this function when there are no big changes will result in the constraints being much 'softer' than usual so they are more easily violated (e.g. a long chain of bodies might sag a bit if you call this every frame).

Implemented in ConeConstraint, DistanceConstraint, FixedConstraint, GearConstraint, HingeConstraint, PathConstraint, PointConstraint, PulleyConstraint, RackAndPinionConstraint, SixDOFConstraint, SliderConstraint, SwingTwistConstraint, and VehicleConstraint.

◆ RestoreState()

◆ SaveState()

◆ SetConstraintPriority()

void Constraint::SetConstraintPriority ( uint32  inPriority)
inline

◆ SetDrawConstraintSize()

void Constraint::SetDrawConstraintSize ( float  inSize)
inline

◆ SetEnabled()

void Constraint::SetEnabled ( bool  inEnabled)
inline

Enable / disable this constraint. This can e.g. be used to implement a breakable constraint by detecting that the constraint impulse (see e.g. PointConstraint::GetTotalLambdaPosition) went over a certain limit and then disabling the constraint. Note that although a disabled constraint will not affect the simulation in any way anymore, it does incur some processing overhead. Alternatively you can remove a constraint from the constraint manager (which may be more costly if you want to disable the constraint for a short while).

◆ SetNumPositionStepsOverride()

void Constraint::SetNumPositionStepsOverride ( uint  inN)
inline

Used only when the constraint is active. Override for the number of solver position iterations to run, 0 means use the default in PhysicsSettings::mNumPositionSteps. The number of iterations to use is the max of all contacts and constraints in the island.

◆ SetNumVelocityStepsOverride()

void Constraint::SetNumVelocityStepsOverride ( uint  inN)
inline

Used only when the constraint is active. Override for the number of solver velocity iterations to run, 0 means use the default in PhysicsSettings::mNumVelocitySteps. The number of iterations to use is the max of all contacts and constraints in the island.

◆ SetupVelocityConstraint()

◆ SetUserData()

void Constraint::SetUserData ( uint64  inUserData)
inline

◆ SolvePositionConstraint()

virtual bool Constraint::SolvePositionConstraint ( float  inDeltaTime,
float  inBaumgarte 
)
pure virtual

◆ SolveVelocityConstraint()

◆ ToConstraintSettings()

void Constraint::ToConstraintSettings ( ConstraintSettings outSettings) const
protected

Helper function to copy settings back to constraint settings for this base class.

◆ WarmStartVelocityConstraint()

virtual void Constraint::WarmStartVelocityConstraint ( float  inWarmStartImpulseRatio)
pure virtual

Friends And Related Function Documentation

◆ ConstraintManager

friend class ConstraintManager
friend

Member Data Documentation

◆ mDrawConstraintSize

float Constraint::mDrawConstraintSize
protected

Size of constraint when drawing it through the debug renderer.


The documentation for this class was generated from the following files: