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 inDeltaTime, const MotionProperties *inMotionProperties1, Mat44Arg inInvI1, Vec3Arg inR1PlusU, const MotionProperties *inMotionProperties2, Mat44Arg inInvI2, Vec3Arg inR2, Vec3Arg inWorldSpaceAxis, float inBias=0.0f, float inC=0.0f, float inFrequency=0.0f, float inDamping=0.0f)
 Templated form of CalculateConstraintProperties with the motion types baked in.
 
void CalculateConstraintProperties (float inDeltaTime, const Body &inBody1, Vec3Arg inR1PlusU, const Body &inBody2, Vec3Arg inR2, Vec3Arg inWorldSpaceAxis, float inBias=0.0f, float inC=0.0f, float inFrequency=0.0f, float inDamping=0.0f)
 
void Deactivate ()
 Deactivate this constraint.
 
bool IsActive () const
 Check if constraint is active.
 
template<EMotionType Type1, EMotionType Type2>
void TemplatedWarmStart (MotionProperties *ioMotionProperties1, MotionProperties *ioMotionProperties2, Vec3Arg inWorldSpaceAxis, float inWarmStartImpulseRatio)
 Templated form of WarmStart with the motion types baked in.
 
void WarmStart (Body &ioBody1, Body &ioBody2, Vec3Arg inWorldSpaceAxis, float inWarmStartImpulseRatio)
 
template<EMotionType Type1, EMotionType Type2>
bool TemplatedSolveVelocityConstraint (MotionProperties *ioMotionProperties1, MotionProperties *ioMotionProperties2, Vec3Arg inWorldSpaceAxis, float inMinLambda, float inMaxLambda)
 Templated form of SolveVelocityConstraint with the motion types baked in.
 
bool SolveVelocityConstraint (Body &ioBody1, Body &ioBody2, Vec3Arg inWorldSpaceAxis, float inMinLambda, float inMaxLambda)
 
bool SolvePositionConstraint (Body &ioBody1, Body &ioBody2, 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.
 
float GetTotalLambda () const
 Return lagrange multiplier.
 
void SaveState (StateRecorder &inStream) const
 Save state of this constraint part.
 
void RestoreState (StateRecorder &inStream)
 Restore state of this constraint part.
 

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 ( float inDeltaTime,
const Body & inBody1,
Vec3Arg inR1PlusU,
const Body & inBody2,
Vec3Arg inR2,
Vec3Arg inWorldSpaceAxis,
float inBias = 0.0f,
float inC = 0.0f,
float inFrequency = 0.0f,
float inDamping = 0.0f )
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). Set to zero if you don't want to drive the constraint to zero with a spring.
inFrequencyOscillation frequency (Hz). Set to zero if you don't want to drive the constraint to zero with a spring.
inDampingDamping factor (0 = no damping, 1 = critical damping). Set to zero if you don't want to drive the constraint to zero with a spring.

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

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

◆ TemplatedCalculateConstraintProperties()

template<EMotionType Type1, EMotionType Type2>
JPH_INLINE void AxisConstraintPart::TemplatedCalculateConstraintProperties ( float inDeltaTime,
const MotionProperties * inMotionProperties1,
Mat44Arg inInvI1,
Vec3Arg inR1PlusU,
const MotionProperties * inMotionProperties2,
Mat44Arg inInvI2,
Vec3Arg inR2,
Vec3Arg inWorldSpaceAxis,
float inBias = 0.0f,
float inC = 0.0f,
float inFrequency = 0.0f,
float inDamping = 0.0f )
inline

Templated form of CalculateConstraintProperties with the motion types baked in.

◆ TemplatedSolveVelocityConstraint()

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

Templated form of SolveVelocityConstraint with the motion types baked in.

◆ TemplatedWarmStart()

template<EMotionType Type1, EMotionType Type2>
void AxisConstraintPart::TemplatedWarmStart ( MotionProperties * ioMotionProperties1,
MotionProperties * ioMotionProperties2,
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: