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

#include <IndependentAxisConstraintPart.h>

Public Member Functions

void CalculateConstraintProperties (const Body &inBody1, const Body &inBody2, Vec3Arg inR1, Vec3Arg inN1, Vec3Arg inR2, Vec3Arg inN2, float inRatio)
 
void Deactivate ()
 Deactivate this constraint. More...
 
bool IsActive () const
 Check if constraint is active. More...
 
void WarmStart (Body &ioBody1, Body &ioBody2, Vec3Arg inN1, Vec3Arg inN2, float inRatio, float inWarmStartImpulseRatio)
 
bool SolveVelocityConstraint (Body &ioBody1, Body &ioBody2, Vec3Arg inN1, Vec3Arg inN2, float inRatio, float inMinLambda, float inMaxLambda)
 
float GetTotalLambda () const
 Return lagrange multiplier. More...
 
bool SolvePositionConstraint (Body &ioBody1, Body &ioBody2, Vec3Arg inN1, Vec3Arg inN2, float inRatio, float inC, float inBaumgarte) const
 
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 part to an AxisConstraintPart but both bodies have an independent axis on which the force is applied.

Constraint equation:

\[C = (x_1 + r_1 - f_1) . n_1 + r (x_2 + r_2 - f_2) \cdot n_2\]

Calculating the Jacobian:

\[dC/dt = (v_1 + w_1 \times r_1) \cdot n_1 + (x_1 + r_1 - f_1) \cdot d n_1/dt + r (v_2 + w_2 \times r_2) \cdot n_2 + r (x_2 + r_2 - f_2) \cdot d n_2/dt\]

Assuming that d n1/dt and d n2/dt are small this becomes:

\[(v_1 + w_1 \times r_1) \cdot n_1 + r (v_2 + w_2 \times r_2) \cdot n_2\]

\[= v_1 \cdot n_1 + r_1 \times n_1 \cdot w_1 + r v_2 \cdot n_2 + r r_2 \times n_2 \cdot w_2\]

Jacobian:

\[J = \begin{bmatrix}n_1 & r_1 \times n_1 & r n_2 & r r_2 \times n_2\end{bmatrix}\]

Effective mass:

\[K = m_1^{-1} + r_1 \times n_1 I_1^{-1} r_1 \times n_1 + r^2 m_2^{-1} + r^2 r_2 \times n_2 I_2^{-1} r_2 \times n_2\]

Used terms (here and below, everything in world space):
n1 = (x1 + r1 - f1) / |x1 + r1 - f1|, axis along which the force is applied for body 1
n2 = (x2 + r2 - f2) / |x2 + r2 - f2|, axis along which the force is applied for body 2
r = ratio how forces are applied between bodies.
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 IndependentAxisConstraintPart::CalculateConstraintProperties ( const Body inBody1,
const Body inBody2,
Vec3Arg  inR1,
Vec3Arg  inN1,
Vec3Arg  inR2,
Vec3Arg  inN2,
float  inRatio 
)
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
inR1The position on which the constraint operates on body 1 relative to COM
inN1The world space normal in which the constraint operates for body 1
inR2The position on which the constraint operates on body 1 relative to COM
inN2The world space normal in which the constraint operates for body 2
inRatioThe ratio how forces are applied between bodies

◆ Deactivate()

void IndependentAxisConstraintPart::Deactivate ( )
inline

Deactivate this constraint.

◆ GetTotalLambda()

float IndependentAxisConstraintPart::GetTotalLambda ( ) const
inline

Return lagrange multiplier.

◆ IsActive()

bool IndependentAxisConstraintPart::IsActive ( ) const
inline

Check if constraint is active.

◆ RestoreState()

void IndependentAxisConstraintPart::RestoreState ( StateRecorder inStream)
inline

Restore state of this constraint part.

◆ SaveState()

void IndependentAxisConstraintPart::SaveState ( StateRecorder inStream) const
inline

Save state of this constraint part.

◆ SolvePositionConstraint()

bool IndependentAxisConstraintPart::SolvePositionConstraint ( Body ioBody1,
Body ioBody2,
Vec3Arg  inN1,
Vec3Arg  inN2,
float  inRatio,
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
inN1The world space normal in which the constraint operates for body 1
inN2The world space normal in which the constraint operates for body 2
inRatioThe ratio how forces are applied between bodies
inCValue of the constraint equation (C)
inBaumgarteBaumgarte constant (fraction of the error to correct)

◆ SolveVelocityConstraint()

bool IndependentAxisConstraintPart::SolveVelocityConstraint ( Body ioBody1,
Body ioBody2,
Vec3Arg  inN1,
Vec3Arg  inN2,
float  inRatio,
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
inN1The world space normal in which the constraint operates for body 1
inN2The world space normal in which the constraint operates for body 2
inRatioThe ratio how forces are applied between bodies
inMinLambdaMinimum angular impulse to apply (N m s)
inMaxLambdaMaximum angular impulse to apply (N m s)

◆ WarmStart()

void IndependentAxisConstraintPart::WarmStart ( Body ioBody1,
Body ioBody2,
Vec3Arg  inN1,
Vec3Arg  inN2,
float  inRatio,
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
inN1The world space normal in which the constraint operates for body 1
inN2The world space normal in which the constraint operates for body 2
inRatioThe ratio how forces are applied between bodies
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: