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

#include <GearConstraintPart.h>

Public Member Functions

void CalculateConstraintProperties (const Body &inBody1, Vec3Arg inWorldSpaceHingeAxis1, const Body &inBody2, Vec3Arg inWorldSpaceHingeAxis2, float inRatio)
 
void Deactivate ()
 Deactivate this constraint. More...
 
bool IsActive () const
 Check if constraint is active. More...
 
void WarmStart (Body &ioBody1, Body &ioBody2, float inWarmStartImpulseRatio)
 
bool SolveVelocityConstraint (Body &ioBody1, Vec3Arg inWorldSpaceHingeAxis1, Body &ioBody2, Vec3Arg inWorldSpaceHingeAxis2, float inRatio)
 
float GetTotalLambda () const
 Return lagrange multiplier. More...
 
bool SolvePositionConstraint (Body &ioBody1, Body &ioBody2, 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 that constrains two rotations using a gear (rotating in opposite direction)

Constraint equation:

C = Rotation1(t) + r Rotation2(t)

Derivative:

d/dt C = 0 <=> w1 . a + r w2 . b = 0

Jacobian:

\[J = \begin{bmatrix}0 & a^T & 0 & r b^T\end{bmatrix}\]

Used terms (here and below, everything in world space):
a = axis around which body 1 rotates (normalized).
b = axis along which body 2 slides (normalized).
Rotation1(t) = rotation around a of body 1.
Rotation2(t) = rotation around b of body 2.
r = ratio between rotation for body 1 and 2.
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.
\(\beta\) = baumgarte constant.

Member Function Documentation

◆ CalculateConstraintProperties()

void GearConstraintPart::CalculateConstraintProperties ( const Body inBody1,
Vec3Arg  inWorldSpaceHingeAxis1,
const Body inBody2,
Vec3Arg  inWorldSpaceHingeAxis2,
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
inWorldSpaceHingeAxis1The axis around which body 1 rotates
inWorldSpaceHingeAxis2The axis around which body 2 rotates
inRatioThe ratio between rotation and translation

◆ Deactivate()

void GearConstraintPart::Deactivate ( )
inline

Deactivate this constraint.

◆ GetTotalLambda()

float GearConstraintPart::GetTotalLambda ( ) const
inline

Return lagrange multiplier.

◆ IsActive()

bool GearConstraintPart::IsActive ( ) const
inline

Check if constraint is active.

◆ RestoreState()

void GearConstraintPart::RestoreState ( StateRecorder inStream)
inline

Restore state of this constraint part.

◆ SaveState()

void GearConstraintPart::SaveState ( StateRecorder inStream) const
inline

Save state of this constraint part.

◆ SolvePositionConstraint()

bool GearConstraintPart::SolvePositionConstraint ( Body ioBody1,
Body ioBody2,
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
inCValue of the constraint equation (C)
inBaumgarteBaumgarte constant (fraction of the error to correct)

◆ SolveVelocityConstraint()

bool GearConstraintPart::SolveVelocityConstraint ( Body ioBody1,
Vec3Arg  inWorldSpaceHingeAxis1,
Body ioBody2,
Vec3Arg  inWorldSpaceHingeAxis2,
float  inRatio 
)
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
inWorldSpaceHingeAxis1The axis around which body 1 rotates
inWorldSpaceHingeAxis2The axis around which body 2 rotates
inRatioThe ratio between rotation and translation

◆ WarmStart()

void GearConstraintPart::WarmStart ( Body ioBody1,
Body ioBody2,
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
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: