Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
SwingTwistConstraintPart Class Reference

#include <SwingTwistConstraintPart.h>

Public Member Functions

void SetSwingType (ESwingType inSwingType)
 Override the swing type.
 
ESwingType GetSwingType () const
 Get the swing type for this part.
 
void SetLimits (float inTwistMinAngle, float inTwistMaxAngle, float inSwingYMinAngle, float inSwingYMaxAngle, float inSwingZMinAngle, float inSwingZMaxAngle)
 Set limits for this constraint (see description above for parameters)
 
void ClampSwingTwist (Quat &ioSwing, Quat &ioTwist, uint &outClampedAxis) const
 Clamp twist and swing against the constraint limits, returns which parts were clamped (everything assumed in constraint space)
 
void CalculateConstraintProperties (const Body &inBody1, const Body &inBody2, QuatArg inConstraintRotation, QuatArg inConstraintToWorld)
 
void Deactivate ()
 Deactivate this constraint.
 
bool IsActive () const
 Check if constraint is active.
 
void WarmStart (Body &ioBody1, Body &ioBody2, float inWarmStartImpulseRatio)
 Must be called from the WarmStartVelocityConstraint call to apply the previous frame's impulses.
 
bool SolveVelocityConstraint (Body &ioBody1, Body &ioBody2)
 Iteratively update the velocity constraint. Makes sure d/dt C(...) = 0, where C is the constraint equation.
 
bool SolvePositionConstraint (Body &ioBody1, Body &ioBody2, QuatArg inConstraintRotation, QuatArg inConstraintToBody1, QuatArg inConstraintToBody2, float inBaumgarte) const
 
float GetTotalSwingYLambda () const
 Return lagrange multiplier for swing.
 
float GetTotalSwingZLambda () const
 
float GetTotalTwistLambda () const
 Return lagrange multiplier for twist.
 
void SaveState (StateRecorder &inStream) const
 Save state of this constraint part.
 
void RestoreState (StateRecorder &inStream)
 Restore state of this constraint part.
 

Static Public Member Functions

static JPH_INLINE bool sDistanceToMinShorter (float inDeltaMin, float inDeltaMax)
 Helper function to determine if we're clamped against the min or max limit.
 

Static Public Attributes

static constexpr uint cClampedTwistMin = 1 << 0
 Flags to indicate which axis got clamped by ClampSwingTwist.
 
static constexpr uint cClampedTwistMax = 1 << 1
 
static constexpr uint cClampedSwingYMin = 1 << 2
 
static constexpr uint cClampedSwingYMax = 1 << 3
 
static constexpr uint cClampedSwingZMin = 1 << 4
 
static constexpr uint cClampedSwingZMax = 1 << 5
 

Detailed Description

Quaternion based constraint that decomposes the rotation in constraint space in swing and twist: q = q_swing * q_twist where q_swing.x = 0 and where q_twist.y = q_twist.z = 0

  • Rotation around the twist (x-axis) is within [inTwistMinAngle, inTwistMaxAngle].
  • Rotation around the swing axis (y and z axis) are limited to an ellipsoid in quaternion space formed by the equation:

(q_swing.y / sin(inSwingYHalfAngle / 2))^2 + (q_swing.z / sin(inSwingZHalfAngle / 2))^2 <= 1

Which roughly corresponds to an elliptic cone shape with major axis (inSwingYHalfAngle, inSwingZHalfAngle).

In case inSwingYHalfAngle = 0, the rotation around Y will be constrained to 0 and the rotation around Z will be constrained between [-inSwingZHalfAngle, inSwingZHalfAngle]. Vice versa if inSwingZHalfAngle = 0.

Member Function Documentation

◆ CalculateConstraintProperties()

void SwingTwistConstraintPart::CalculateConstraintProperties ( const Body inBody1,
const Body inBody2,
QuatArg  inConstraintRotation,
QuatArg  inConstraintToWorld 
)
inline

Calculate properties used during the functions below

Parameters
inBody1The first body that this constraint is attached to
inBody2The second body that this constraint is attached to
inConstraintRotationThe current rotation of the constraint in constraint space
inConstraintToWorldRotates from constraint space into world space

◆ ClampSwingTwist()

void SwingTwistConstraintPart::ClampSwingTwist ( Quat ioSwing,
Quat ioTwist,
uint outClampedAxis 
) const
inline

Clamp twist and swing against the constraint limits, returns which parts were clamped (everything assumed in constraint space)

◆ Deactivate()

void SwingTwistConstraintPart::Deactivate ( )
inline

Deactivate this constraint.

◆ GetSwingType()

ESwingType SwingTwistConstraintPart::GetSwingType ( ) const
inline

Get the swing type for this part.

◆ GetTotalSwingYLambda()

float SwingTwistConstraintPart::GetTotalSwingYLambda ( ) const
inline

Return lagrange multiplier for swing.

◆ GetTotalSwingZLambda()

float SwingTwistConstraintPart::GetTotalSwingZLambda ( ) const
inline

◆ GetTotalTwistLambda()

float SwingTwistConstraintPart::GetTotalTwistLambda ( ) const
inline

Return lagrange multiplier for twist.

◆ IsActive()

bool SwingTwistConstraintPart::IsActive ( ) const
inline

Check if constraint is active.

◆ RestoreState()

void SwingTwistConstraintPart::RestoreState ( StateRecorder inStream)
inline

Restore state of this constraint part.

◆ SaveState()

void SwingTwistConstraintPart::SaveState ( StateRecorder inStream) const
inline

Save state of this constraint part.

◆ sDistanceToMinShorter()

static JPH_INLINE bool SwingTwistConstraintPart::sDistanceToMinShorter ( float  inDeltaMin,
float  inDeltaMax 
)
inlinestatic

Helper function to determine if we're clamped against the min or max limit.

◆ SetLimits()

void SwingTwistConstraintPart::SetLimits ( float  inTwistMinAngle,
float  inTwistMaxAngle,
float  inSwingYMinAngle,
float  inSwingYMaxAngle,
float  inSwingZMinAngle,
float  inSwingZMaxAngle 
)
inline

Set limits for this constraint (see description above for parameters)

◆ SetSwingType()

void SwingTwistConstraintPart::SetSwingType ( ESwingType  inSwingType)
inline

Override the swing type.

◆ SolvePositionConstraint()

bool SwingTwistConstraintPart::SolvePositionConstraint ( Body ioBody1,
Body ioBody2,
QuatArg  inConstraintRotation,
QuatArg  inConstraintToBody1,
QuatArg  inConstraintToBody2,
float  inBaumgarte 
) const
inline

Iteratively update the position constraint. Makes sure C(...) = 0.

Parameters
ioBody1The first body that this constraint is attached to
ioBody2The second body that this constraint is attached to
inConstraintRotationThe current rotation of the constraint in constraint space
inConstraintToBody1,inConstraintToBody2Rotates from constraint space to body 1/2 space
inBaumgarteBaumgarte constant (fraction of the error to correct)

◆ SolveVelocityConstraint()

bool SwingTwistConstraintPart::SolveVelocityConstraint ( Body ioBody1,
Body ioBody2 
)
inline

Iteratively update the velocity constraint. Makes sure d/dt C(...) = 0, where C is the constraint equation.

◆ WarmStart()

void SwingTwistConstraintPart::WarmStart ( Body ioBody1,
Body ioBody2,
float  inWarmStartImpulseRatio 
)
inline

Must be called from the WarmStartVelocityConstraint call to apply the previous frame's impulses.

Member Data Documentation

◆ cClampedSwingYMax

constexpr uint SwingTwistConstraintPart::cClampedSwingYMax = 1 << 3
staticconstexpr

◆ cClampedSwingYMin

constexpr uint SwingTwistConstraintPart::cClampedSwingYMin = 1 << 2
staticconstexpr

◆ cClampedSwingZMax

constexpr uint SwingTwistConstraintPart::cClampedSwingZMax = 1 << 5
staticconstexpr

◆ cClampedSwingZMin

constexpr uint SwingTwistConstraintPart::cClampedSwingZMin = 1 << 4
staticconstexpr

◆ cClampedTwistMax

constexpr uint SwingTwistConstraintPart::cClampedTwistMax = 1 << 1
staticconstexpr

◆ cClampedTwistMin

constexpr uint SwingTwistConstraintPart::cClampedTwistMin = 1 << 0
staticconstexpr

Flags to indicate which axis got clamped by ClampSwingTwist.


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