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

#include <AxisConstraintPart.h>

Public Member Functions

template<EMotionType Type1, EMotionType Type2>
JPH_INLINE void TemplatedCalculateConstraintProperties (float inInvMass1, Mat44Arg inInvI1, Vec3Arg inR1PlusU, float inInvMass2, Mat44Arg inInvI2, Vec3Arg inR2, Vec3Arg inWorldSpaceAxis, float inBias=0.0f)
 Templated form of CalculateConstraintProperties with the motion types baked in. More...
 
void CalculateConstraintProperties (const Body &inBody1, Vec3Arg inR1PlusU, const Body &inBody2, Vec3Arg inR2, Vec3Arg inWorldSpaceAxis, float inBias=0.0f)
 
void CalculateConstraintPropertiesWithMassOverride (const Body &inBody1, float inInvMass1, float inInvInertiaScale1, Vec3Arg inR1PlusU, const Body &inBody2, float inInvMass2, float inInvInertiaScale2, Vec3Arg inR2, Vec3Arg inWorldSpaceAxis, float inBias=0.0f)
 
void CalculateConstraintPropertiesWithFrequencyAndDamping (float inDeltaTime, const Body &inBody1, Vec3Arg inR1PlusU, const Body &inBody2, Vec3Arg inR2, Vec3Arg inWorldSpaceAxis, float inBias, float inC, float inFrequency, float inDamping)
 
void CalculateConstraintPropertiesWithStiffnessAndDamping (float inDeltaTime, const Body &inBody1, Vec3Arg inR1PlusU, const Body &inBody2, Vec3Arg inR2, Vec3Arg inWorldSpaceAxis, float inBias, float inC, float inStiffness, float inDamping)
 
void CalculateConstraintPropertiesWithSettings (float inDeltaTime, const Body &inBody1, Vec3Arg inR1PlusU, const Body &inBody2, Vec3Arg inR2, Vec3Arg inWorldSpaceAxis, float inBias, float inC, const SpringSettings &inSpringSettings)
 Selects one of the above functions based on the spring settings. More...
 
void Deactivate ()
 Deactivate this constraint. More...
 
bool IsActive () const
 Check if constraint is active. More...
 
template<EMotionType Type1, EMotionType Type2>
void TemplatedWarmStart (MotionProperties *ioMotionProperties1, float inInvMass1, MotionProperties *ioMotionProperties2, float inInvMass2, Vec3Arg inWorldSpaceAxis, float inWarmStartImpulseRatio)
 Templated form of WarmStart with the motion types baked in. More...
 
void WarmStart (Body &ioBody1, Body &ioBody2, Vec3Arg inWorldSpaceAxis, float inWarmStartImpulseRatio)
 
template<EMotionType Type1, EMotionType Type2>
JPH_INLINE float TemplatedSolveVelocityConstraintGetTotalLambda (const MotionProperties *ioMotionProperties1, const MotionProperties *ioMotionProperties2, Vec3Arg inWorldSpaceAxis) const
 Templated form of SolveVelocityConstraint with the motion types baked in, part 1: get the total lambda. More...
 
template<EMotionType Type1, EMotionType Type2>
JPH_INLINE bool TemplatedSolveVelocityConstraintApplyLambda (MotionProperties *ioMotionProperties1, float inInvMass1, MotionProperties *ioMotionProperties2, float inInvMass2, Vec3Arg inWorldSpaceAxis, float inTotalLambda)
 Templated form of SolveVelocityConstraint with the motion types baked in, part 2: apply new lambda. More...
 
template<EMotionType Type1, EMotionType Type2>
bool TemplatedSolveVelocityConstraint (MotionProperties *ioMotionProperties1, float inInvMass1, MotionProperties *ioMotionProperties2, float inInvMass2, Vec3Arg inWorldSpaceAxis, float inMinLambda, float inMaxLambda)
 Templated form of SolveVelocityConstraint with the motion types baked in. More...
 
bool SolveVelocityConstraint (Body &ioBody1, Body &ioBody2, Vec3Arg inWorldSpaceAxis, float inMinLambda, float inMaxLambda)
 
bool SolveVelocityConstraintWithMassOverride (Body &ioBody1, float inInvMass1, Body &ioBody2, float inInvMass2, Vec3Arg inWorldSpaceAxis, float inMinLambda, float inMaxLambda)
 
bool SolvePositionConstraint (Body &ioBody1, Body &ioBody2, Vec3Arg inWorldSpaceAxis, float inC, float inBaumgarte) const
 
bool SolvePositionConstraintWithMassOverride (Body &ioBody1, float inInvMass1, Body &ioBody2, float inInvMass2, Vec3Arg inWorldSpaceAxis, float inC, float inBaumgarte) const
 
void SetTotalLambda (float inLambda)
 Override total lagrange multiplier, can be used to set the initial value for warm starting. More...
 
float GetTotalLambda () const
 Return lagrange multiplier. More...
 
void SaveState (StateRecorder &inStream) const
 Save state of this constraint part. More...
 
void RestoreState (StateRecorder &inStream)
 Restore state of this constraint part. More...
 

Detailed Description

Constraint that constrains motion along 1 axis

See also
"Constraints Derivation for Rigid Body Simulation in 3D" - Daniel Chappuis, section 2.1.1 (we're not using the approximation of eq 27 but instead add the U term as in eq 55)

Constraint equation (eq 25):

\[C = (p_2 - p_1) \cdot n\]

Jacobian (eq 28):

\[J = \begin{bmatrix} -n^T & (-(r_1 + u) \times n)^T & n^T & (r_2 \times n)^T \end{bmatrix}\]

Used terms (here and below, everything in world space):
n = constraint axis (normalized).
p1, p2 = constraint points.
r1 = p1 - x1.
r2 = p2 - x2.
u = x2 + r2 - x1 - r1 = p2 - p1.
x1, x2 = center of mass for the bodies.
v = [v1, w1, v2, w2].
v1, v2 = linear velocity of body 1 and 2.
w1, w2 = angular velocity of body 1 and 2.
M = mass matrix, a diagonal matrix of the mass and inertia with diagonal [m1, I1, m2, I2].
\(K^{-1} = \left( J M^{-1} J^T \right)^{-1}\) = effective mass.
b = velocity bias.
\(\beta\) = baumgarte constant.

Member Function Documentation

◆ CalculateConstraintProperties()

void AxisConstraintPart::CalculateConstraintProperties ( const Body inBody1,
Vec3Arg  inR1PlusU,
const Body inBody2,
Vec3Arg  inR2,
Vec3Arg  inWorldSpaceAxis,
float  inBias = 0.0f 
)
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
inR1PlusUSee equations above (r1 + u)
inR2See equations above (r2)
inWorldSpaceAxisAxis along which the constraint acts (normalized, pointing from body 1 to 2)
inBiasBias term (b) for the constraint impulse: lambda = J v + b

◆ CalculateConstraintPropertiesWithFrequencyAndDamping()

void AxisConstraintPart::CalculateConstraintPropertiesWithFrequencyAndDamping ( float  inDeltaTime,
const Body inBody1,
Vec3Arg  inR1PlusU,
const Body inBody2,
Vec3Arg  inR2,
Vec3Arg  inWorldSpaceAxis,
float  inBias,
float  inC,
float  inFrequency,
float  inDamping 
)
inline

Calculate properties used during the functions below

Parameters
inDeltaTimeTime step
inBody1The first body that this constraint is attached to
inBody2The second body that this constraint is attached to
inR1PlusUSee equations above (r1 + u)
inR2See equations above (r2)
inWorldSpaceAxisAxis along which the constraint acts (normalized, pointing from body 1 to 2)
inBiasBias term (b) for the constraint impulse: lambda = J v + b
inCValue of the constraint equation (C).
inFrequencyOscillation frequency (Hz).
inDampingDamping factor (0 = no damping, 1 = critical damping).

◆ CalculateConstraintPropertiesWithMassOverride()

void AxisConstraintPart::CalculateConstraintPropertiesWithMassOverride ( const Body inBody1,
float  inInvMass1,
float  inInvInertiaScale1,
Vec3Arg  inR1PlusU,
const Body inBody2,
float  inInvMass2,
float  inInvInertiaScale2,
Vec3Arg  inR2,
Vec3Arg  inWorldSpaceAxis,
float  inBias = 0.0f 
)
inline

Calculate properties used during the functions below, version that supports mass scaling

Parameters
inBody1The first body that this constraint is attached to
inBody2The second body that this constraint is attached to
inInvMass1The inverse mass of body 1 (only used when body 1 is dynamic)
inInvMass2The inverse mass of body 2 (only used when body 2 is dynamic)
inInvInertiaScale1Scale factor for the inverse inertia of body 1
inInvInertiaScale2Scale factor for the inverse inertia of body 2
inR1PlusUSee equations above (r1 + u)
inR2See equations above (r2)
inWorldSpaceAxisAxis along which the constraint acts (normalized, pointing from body 1 to 2)
inBiasBias term (b) for the constraint impulse: lambda = J v + b

◆ CalculateConstraintPropertiesWithSettings()

void AxisConstraintPart::CalculateConstraintPropertiesWithSettings ( float  inDeltaTime,
const Body inBody1,
Vec3Arg  inR1PlusU,
const Body inBody2,
Vec3Arg  inR2,
Vec3Arg  inWorldSpaceAxis,
float  inBias,
float  inC,
const SpringSettings inSpringSettings 
)
inline

Selects one of the above functions based on the spring settings.

◆ CalculateConstraintPropertiesWithStiffnessAndDamping()

void AxisConstraintPart::CalculateConstraintPropertiesWithStiffnessAndDamping ( float  inDeltaTime,
const Body inBody1,
Vec3Arg  inR1PlusU,
const Body inBody2,
Vec3Arg  inR2,
Vec3Arg  inWorldSpaceAxis,
float  inBias,
float  inC,
float  inStiffness,
float  inDamping 
)
inline

Calculate properties used during the functions below

Parameters
inDeltaTimeTime step
inBody1The first body that this constraint is attached to
inBody2The second body that this constraint is attached to
inR1PlusUSee equations above (r1 + u)
inR2See equations above (r2)
inWorldSpaceAxisAxis along which the constraint acts (normalized, pointing from body 1 to 2)
inBiasBias term (b) for the constraint impulse: lambda = J v + b
inCValue of the constraint equation (C).
inStiffnessSpring stiffness k.
inDampingSpring damping coefficient c.

◆ Deactivate()

void AxisConstraintPart::Deactivate ( )
inline

Deactivate this constraint.

◆ GetTotalLambda()

float AxisConstraintPart::GetTotalLambda ( ) const
inline

Return lagrange multiplier.

◆ IsActive()

bool AxisConstraintPart::IsActive ( ) const
inline

Check if constraint is active.

◆ RestoreState()

void AxisConstraintPart::RestoreState ( StateRecorder inStream)
inline

Restore state of this constraint part.

◆ SaveState()

void AxisConstraintPart::SaveState ( StateRecorder inStream) const
inline

Save state of this constraint part.

◆ SetTotalLambda()

void AxisConstraintPart::SetTotalLambda ( float  inLambda)
inline

Override total lagrange multiplier, can be used to set the initial value for warm starting.

◆ SolvePositionConstraint()

bool AxisConstraintPart::SolvePositionConstraint ( Body ioBody1,
Body ioBody2,
Vec3Arg  inWorldSpaceAxis,
float  inC,
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
inWorldSpaceAxisAxis along which the constraint acts (normalized)
inCValue of the constraint equation (C)
inBaumgarteBaumgarte constant (fraction of the error to correct)

◆ SolvePositionConstraintWithMassOverride()

bool AxisConstraintPart::SolvePositionConstraintWithMassOverride ( Body ioBody1,
float  inInvMass1,
Body ioBody2,
float  inInvMass2,
Vec3Arg  inWorldSpaceAxis,
float  inC,
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
inInvMass1The inverse mass of body 1 (only used when body 1 is dynamic)
inInvMass2The inverse mass of body 2 (only used when body 2 is dynamic)
inWorldSpaceAxisAxis along which the constraint acts (normalized)
inCValue of the constraint equation (C)
inBaumgarteBaumgarte constant (fraction of the error to correct)

◆ SolveVelocityConstraint()

bool AxisConstraintPart::SolveVelocityConstraint ( Body ioBody1,
Body ioBody2,
Vec3Arg  inWorldSpaceAxis,
float  inMinLambda,
float  inMaxLambda 
)
inline

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

Parameters
ioBody1The first body that this constraint is attached to
ioBody2The second body that this constraint is attached to
inWorldSpaceAxisAxis along which the constraint acts (normalized)
inMinLambdaMinimum value of constraint impulse to apply (N s)
inMaxLambdaMaximum value of constraint impulse to apply (N s)

◆ SolveVelocityConstraintWithMassOverride()

bool AxisConstraintPart::SolveVelocityConstraintWithMassOverride ( Body ioBody1,
float  inInvMass1,
Body ioBody2,
float  inInvMass2,
Vec3Arg  inWorldSpaceAxis,
float  inMinLambda,
float  inMaxLambda 
)
inline

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

Parameters
ioBody1The first body that this constraint is attached to
ioBody2The second body that this constraint is attached to
inInvMass1The inverse mass of body 1 (only used when body 1 is dynamic)
inInvMass2The inverse mass of body 2 (only used when body 2 is dynamic)
inWorldSpaceAxisAxis along which the constraint acts (normalized)
inMinLambdaMinimum value of constraint impulse to apply (N s)
inMaxLambdaMaximum value of constraint impulse to apply (N s)

◆ TemplatedCalculateConstraintProperties()

template<EMotionType Type1, EMotionType Type2>
JPH_INLINE void AxisConstraintPart::TemplatedCalculateConstraintProperties ( float  inInvMass1,
Mat44Arg  inInvI1,
Vec3Arg  inR1PlusU,
float  inInvMass2,
Mat44Arg  inInvI2,
Vec3Arg  inR2,
Vec3Arg  inWorldSpaceAxis,
float  inBias = 0.0f 
)
inline

Templated form of CalculateConstraintProperties with the motion types baked in.

◆ TemplatedSolveVelocityConstraint()

template<EMotionType Type1, EMotionType Type2>
bool AxisConstraintPart::TemplatedSolveVelocityConstraint ( MotionProperties ioMotionProperties1,
float  inInvMass1,
MotionProperties ioMotionProperties2,
float  inInvMass2,
Vec3Arg  inWorldSpaceAxis,
float  inMinLambda,
float  inMaxLambda 
)
inline

Templated form of SolveVelocityConstraint with the motion types baked in.

◆ TemplatedSolveVelocityConstraintApplyLambda()

template<EMotionType Type1, EMotionType Type2>
JPH_INLINE bool AxisConstraintPart::TemplatedSolveVelocityConstraintApplyLambda ( MotionProperties ioMotionProperties1,
float  inInvMass1,
MotionProperties ioMotionProperties2,
float  inInvMass2,
Vec3Arg  inWorldSpaceAxis,
float  inTotalLambda 
)
inline

Templated form of SolveVelocityConstraint with the motion types baked in, part 2: apply new lambda.

◆ TemplatedSolveVelocityConstraintGetTotalLambda()

template<EMotionType Type1, EMotionType Type2>
JPH_INLINE float AxisConstraintPart::TemplatedSolveVelocityConstraintGetTotalLambda ( const MotionProperties ioMotionProperties1,
const MotionProperties ioMotionProperties2,
Vec3Arg  inWorldSpaceAxis 
) const
inline

Templated form of SolveVelocityConstraint with the motion types baked in, part 1: get the total lambda.

◆ TemplatedWarmStart()

template<EMotionType Type1, EMotionType Type2>
void AxisConstraintPart::TemplatedWarmStart ( MotionProperties ioMotionProperties1,
float  inInvMass1,
MotionProperties ioMotionProperties2,
float  inInvMass2,
Vec3Arg  inWorldSpaceAxis,
float  inWarmStartImpulseRatio 
)
inline

Templated form of WarmStart with the motion types baked in.

◆ WarmStart()

void AxisConstraintPart::WarmStart ( Body ioBody1,
Body ioBody2,
Vec3Arg  inWorldSpaceAxis,
float  inWarmStartImpulseRatio 
)
inline

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

Parameters
ioBody1The first body that this constraint is attached to
ioBody2The second body that this constraint is attached to
inWorldSpaceAxisAxis along which the constraint acts (normalized)
inWarmStartImpulseRatioRatio of new step to old time step (dt_new / dt_old) for scaling the lagrange multiplier of the previous frame

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