Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
SwingTwistConstraint Class Referencefinal

#include <SwingTwistConstraint.h>

Inheritance diagram for SwingTwistConstraint:
TwoBodyConstraint Constraint RefTarget< Constraint > NonCopyable

Public Member Functions

JPH_OVERRIDE_NEW_DELETE SwingTwistConstraint (Body &inBody1, Body &inBody2, const SwingTwistConstraintSettings &inSettings)
 Construct swing twist constraint. More...
 
Generic interface of a constraint
virtual EConstraintSubType GetSubType () const override
 Get the sub type of a constraint. More...
 
virtual void NotifyShapeChanged (const BodyID &inBodyID, Vec3Arg inDeltaCOM) override
 
virtual void SetupVelocityConstraint (float inDeltaTime) override
 
virtual void ResetWarmStart () override
 
virtual void WarmStartVelocityConstraint (float inWarmStartImpulseRatio) override
 
virtual bool SolveVelocityConstraint (float inDeltaTime) override
 
virtual bool SolvePositionConstraint (float inDeltaTime, float inBaumgarte) override
 
virtual void DrawConstraint (DebugRenderer *inRenderer) const override
 
virtual void DrawConstraintLimits (DebugRenderer *inRenderer) const override
 
virtual void SaveState (StateRecorder &inStream) const override
 Saving state for replay. More...
 
virtual void RestoreState (StateRecorder &inStream) override
 Restoring state for replay. More...
 
virtual Ref< ConstraintSettingsGetConstraintSettings () const override
 Debug function to convert a constraint to its settings, note that this will not save to which bodies the constraint is connected to. More...
 
virtual Mat44 GetConstraintToBody1Matrix () const override
 Calculates the transform that transforms from constraint space to body 1 space. The first column of the matrix is the primary constraint axis (e.g. the hinge axis / slider direction), second column the secondary etc. More...
 
virtual Mat44 GetConstraintToBody2Matrix () const override
 Calculates the transform that transforms from constraint space to body 2 space. The first column of the matrix is the primary constraint axis (e.g. the hinge axis / slider direction), second column the secondary etc. More...
 
Constraint reference frame
Vec3 GetLocalSpacePosition1 () const
 
Vec3 GetLocalSpacePosition2 () const
 
Quat GetConstraintToBody1 () const
 
Quat GetConstraintToBody2 () const
 
Constraint limits
float GetNormalHalfConeAngle () const
 
void SetNormalHalfConeAngle (float inAngle)
 
float GetPlaneHalfConeAngle () const
 
void SetPlaneHalfConeAngle (float inAngle)
 
float GetTwistMinAngle () const
 
void SetTwistMinAngle (float inAngle)
 
float GetTwistMaxAngle () const
 
void SetTwistMaxAngle (float inAngle)
 
Motor settings
const MotorSettingsGetSwingMotorSettings () const
 
MotorSettingsGetSwingMotorSettings ()
 
const MotorSettingsGetTwistMotorSettings () const
 
MotorSettingsGetTwistMotorSettings ()
 
Friction control
void SetMaxFrictionTorque (float inFrictionTorque)
 
float GetMaxFrictionTorque () const
 
Motor controls
void SetSwingMotorState (EMotorState inState)
 Controls if the motors are on or off. More...
 
EMotorState GetSwingMotorState () const
 
void SetTwistMotorState (EMotorState inState)
 
EMotorState GetTwistMotorState () const
 
void SetTargetAngularVelocityCS (Vec3Arg inAngularVelocity)
 Set the target angular velocity of body 2 in constraint space of body 2. More...
 
Vec3 GetTargetAngularVelocityCS () const
 
void SetTargetOrientationCS (QuatArg inOrientation)
 Set the target orientation in constraint space (drives constraint to: GetRotationInConstraintSpace() == inOrientation) More...
 
Quat GetTargetOrientationCS () const
 
void SetTargetOrientationBS (QuatArg inOrientation)
 
Quat GetRotationInConstraintSpace () const
 
- Public Member Functions inherited from TwoBodyConstraint
JPH_OVERRIDE_NEW_DELETE TwoBodyConstraint (Body &inBody1, Body &inBody2, const TwoBodyConstraintSettings &inSettings)
 Constructor. More...
 
virtual EConstraintType GetType () const override
 Get the type of a constraint. More...
 
virtual bool IsActive () const override
 Solver interface. More...
 
virtual void DrawConstraintReferenceFrame (DebugRenderer *inRenderer) const override
 
BodyGetBody1 () const
 Access to the connected bodies. More...
 
BodyGetBody2 () const
 
virtual Mat44 GetConstraintToBody1Matrix () const =0
 Calculates the transform that transforms from constraint space to body 1 space. The first column of the matrix is the primary constraint axis (e.g. the hinge axis / slider direction), second column the secondary etc. More...
 
virtual Mat44 GetConstraintToBody2Matrix () const =0
 Calculates the transform that transforms from constraint space to body 2 space. The first column of the matrix is the primary constraint axis (e.g. the hinge axis / slider direction), second column the secondary etc. More...
 
virtual void BuildIslands (uint32 inConstraintIndex, IslandBuilder &ioBuilder, BodyManager &inBodyManager) override
 Link bodies that are connected by this constraint in the island builder. More...
 
virtual uint BuildIslandSplits (LargeIslandSplitter &ioSplitter) const override
 Link bodies that are connected by this constraint in the same split. Returns the split index. More...
 
- Public Member Functions inherited from Constraint
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...
 
- 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
 

Get Lagrange multiplier from last physics update (the linear/angular impulse applied to satisfy the constraint)

Vec3 GetTotalLambdaPosition () const
 
float GetTotalLambdaTwist () const
 
float GetTotalLambdaSwingY () const
 
float GetTotalLambdaSwingZ () const
 
Vec3 GetTotalLambdaMotor () const
 

Additional Inherited Members

- Static Public Member Functions inherited from RefTarget< Constraint >
static int sInternalGetRefCountOffset ()
 INTERNAL HELPER FUNCTION USED BY SERIALIZATION. More...
 
- Protected Member Functions inherited from Constraint
void ToConstraintSettings (ConstraintSettings &outSettings) const
 Helper function to copy settings back to constraint settings for this base class. More...
 
- Protected Attributes inherited from TwoBodyConstraint
BodymBody1
 The two bodies involved. More...
 
BodymBody2
 
- Protected Attributes inherited from Constraint
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...
 
- 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

A swing twist constraint is a specialized constraint for humanoid ragdolls that allows limited rotation only

See also
SwingTwistConstraintSettings for a description of the limits

Constructor & Destructor Documentation

◆ SwingTwistConstraint()

SwingTwistConstraint::SwingTwistConstraint ( Body inBody1,
Body inBody2,
const SwingTwistConstraintSettings inSettings 
)

Construct swing twist constraint.

Member Function Documentation

◆ DrawConstraint()

void SwingTwistConstraint::DrawConstraint ( DebugRenderer inRenderer) const
overridevirtual

Implements Constraint.

◆ DrawConstraintLimits()

void SwingTwistConstraint::DrawConstraintLimits ( DebugRenderer inRenderer) const
overridevirtual

Reimplemented from Constraint.

◆ GetConstraintSettings()

Ref< ConstraintSettings > SwingTwistConstraint::GetConstraintSettings ( ) const
overridevirtual

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

Implements Constraint.

◆ GetConstraintToBody1()

Quat SwingTwistConstraint::GetConstraintToBody1 ( ) const
inline

◆ GetConstraintToBody1Matrix()

virtual Mat44 SwingTwistConstraint::GetConstraintToBody1Matrix ( ) const
inlineoverridevirtual

Calculates the transform that transforms from constraint space to body 1 space. The first column of the matrix is the primary constraint axis (e.g. the hinge axis / slider direction), second column the secondary etc.

Implements TwoBodyConstraint.

◆ GetConstraintToBody2()

Quat SwingTwistConstraint::GetConstraintToBody2 ( ) const
inline

◆ GetConstraintToBody2Matrix()

virtual Mat44 SwingTwistConstraint::GetConstraintToBody2Matrix ( ) const
inlineoverridevirtual

Calculates the transform that transforms from constraint space to body 2 space. The first column of the matrix is the primary constraint axis (e.g. the hinge axis / slider direction), second column the secondary etc.

Implements TwoBodyConstraint.

◆ GetLocalSpacePosition1()

Vec3 SwingTwistConstraint::GetLocalSpacePosition1 ( ) const
inline

◆ GetLocalSpacePosition2()

Vec3 SwingTwistConstraint::GetLocalSpacePosition2 ( ) const
inline

◆ GetMaxFrictionTorque()

float SwingTwistConstraint::GetMaxFrictionTorque ( ) const
inline

◆ GetNormalHalfConeAngle()

float SwingTwistConstraint::GetNormalHalfConeAngle ( ) const
inline

◆ GetPlaneHalfConeAngle()

float SwingTwistConstraint::GetPlaneHalfConeAngle ( ) const
inline

◆ GetRotationInConstraintSpace()

Quat SwingTwistConstraint::GetRotationInConstraintSpace ( ) const

Get current rotation of constraint in constraint space. Solve: R2 * ConstraintToBody2 = R1 * ConstraintToBody1 * q for q.

◆ GetSubType()

virtual EConstraintSubType SwingTwistConstraint::GetSubType ( ) const
inlineoverridevirtual

Get the sub type of a constraint.

Implements Constraint.

◆ GetSwingMotorSettings() [1/2]

MotorSettings & SwingTwistConstraint::GetSwingMotorSettings ( )
inline

◆ GetSwingMotorSettings() [2/2]

const MotorSettings & SwingTwistConstraint::GetSwingMotorSettings ( ) const
inline

◆ GetSwingMotorState()

EMotorState SwingTwistConstraint::GetSwingMotorState ( ) const
inline

◆ GetTargetAngularVelocityCS()

Vec3 SwingTwistConstraint::GetTargetAngularVelocityCS ( ) const
inline

◆ GetTargetOrientationCS()

Quat SwingTwistConstraint::GetTargetOrientationCS ( ) const
inline

◆ GetTotalLambdaMotor()

Vec3 SwingTwistConstraint::GetTotalLambdaMotor ( ) const
inline

◆ GetTotalLambdaPosition()

Vec3 SwingTwistConstraint::GetTotalLambdaPosition ( ) const
inline

◆ GetTotalLambdaSwingY()

float SwingTwistConstraint::GetTotalLambdaSwingY ( ) const
inline

◆ GetTotalLambdaSwingZ()

float SwingTwistConstraint::GetTotalLambdaSwingZ ( ) const
inline

◆ GetTotalLambdaTwist()

float SwingTwistConstraint::GetTotalLambdaTwist ( ) const
inline

◆ GetTwistMaxAngle()

float SwingTwistConstraint::GetTwistMaxAngle ( ) const
inline

◆ GetTwistMinAngle()

float SwingTwistConstraint::GetTwistMinAngle ( ) const
inline

◆ GetTwistMotorSettings() [1/2]

MotorSettings & SwingTwistConstraint::GetTwistMotorSettings ( )
inline

◆ GetTwistMotorSettings() [2/2]

const MotorSettings & SwingTwistConstraint::GetTwistMotorSettings ( ) const
inline

◆ GetTwistMotorState()

EMotorState SwingTwistConstraint::GetTwistMotorState ( ) const
inline

◆ NotifyShapeChanged()

void SwingTwistConstraint::NotifyShapeChanged ( const BodyID inBodyID,
Vec3Arg  inDeltaCOM 
)
overridevirtual

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())

Implements Constraint.

◆ ResetWarmStart()

void SwingTwistConstraint::ResetWarmStart ( )
overridevirtual

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).

Implements Constraint.

◆ RestoreState()

void SwingTwistConstraint::RestoreState ( StateRecorder inStream)
overridevirtual

Restoring state for replay.

Reimplemented from Constraint.

◆ SaveState()

void SwingTwistConstraint::SaveState ( StateRecorder inStream) const
overridevirtual

Saving state for replay.

Reimplemented from Constraint.

◆ SetMaxFrictionTorque()

void SwingTwistConstraint::SetMaxFrictionTorque ( float  inFrictionTorque)
inline

◆ SetNormalHalfConeAngle()

void SwingTwistConstraint::SetNormalHalfConeAngle ( float  inAngle)
inline

◆ SetPlaneHalfConeAngle()

void SwingTwistConstraint::SetPlaneHalfConeAngle ( float  inAngle)
inline

◆ SetSwingMotorState()

void SwingTwistConstraint::SetSwingMotorState ( EMotorState  inState)

Controls if the motors are on or off.

◆ SetTargetAngularVelocityCS()

void SwingTwistConstraint::SetTargetAngularVelocityCS ( Vec3Arg  inAngularVelocity)
inline

Set the target angular velocity of body 2 in constraint space of body 2.

◆ SetTargetOrientationBS()

void SwingTwistConstraint::SetTargetOrientationBS ( QuatArg  inOrientation)
inline

Set the target orientation in body space (R2 = R1 * inOrientation, where R1 and R2 are the world space rotations for body 1 and 2). Solve: R2 * ConstraintToBody2 = R1 * ConstraintToBody1 * q (see SwingTwistConstraint::GetSwingTwist) and R2 = R1 * inOrientation for q.

◆ SetTargetOrientationCS()

void SwingTwistConstraint::SetTargetOrientationCS ( QuatArg  inOrientation)

Set the target orientation in constraint space (drives constraint to: GetRotationInConstraintSpace() == inOrientation)

◆ SetTwistMaxAngle()

void SwingTwistConstraint::SetTwistMaxAngle ( float  inAngle)
inline

◆ SetTwistMinAngle()

void SwingTwistConstraint::SetTwistMinAngle ( float  inAngle)
inline

◆ SetTwistMotorState()

void SwingTwistConstraint::SetTwistMotorState ( EMotorState  inState)

◆ SetupVelocityConstraint()

void SwingTwistConstraint::SetupVelocityConstraint ( float  inDeltaTime)
overridevirtual

Implements Constraint.

◆ SolvePositionConstraint()

bool SwingTwistConstraint::SolvePositionConstraint ( float  inDeltaTime,
float  inBaumgarte 
)
overridevirtual

Implements Constraint.

◆ SolveVelocityConstraint()

bool SwingTwistConstraint::SolveVelocityConstraint ( float  inDeltaTime)
overridevirtual

Implements Constraint.

◆ WarmStartVelocityConstraint()

void SwingTwistConstraint::WarmStartVelocityConstraint ( float  inWarmStartImpulseRatio)
overridevirtual

Implements Constraint.


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