Jolt Physics
A multi core friendly Game Physics Engine
|
#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. | |
bool | IsActive () const |
Check if constraint is active. | |
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. | |
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. | |
void | RestoreState (StateRecorder &inStream) |
Restore state of this constraint part. | |
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.
|
inline |
Calculate properties used during the functions below
inBody1 | The first body that this constraint is attached to |
inBody2 | The second body that this constraint is attached to |
inR1 | The position on which the constraint operates on body 1 relative to COM |
inN1 | The world space normal in which the constraint operates for body 1 |
inR2 | The position on which the constraint operates on body 1 relative to COM |
inN2 | The world space normal in which the constraint operates for body 2 |
inRatio | The ratio how forces are applied between bodies |
|
inline |
Deactivate this constraint.
|
inline |
Return lagrange multiplier.
|
inline |
Check if constraint is active.
|
inline |
Restore state of this constraint part.
|
inline |
Save state of this constraint part.
|
inline |
Iteratively update the position constraint. Makes sure C(...) == 0.
ioBody1 | The first body that this constraint is attached to |
ioBody2 | The second body that this constraint is attached to |
inN1 | The world space normal in which the constraint operates for body 1 |
inN2 | The world space normal in which the constraint operates for body 2 |
inRatio | The ratio how forces are applied between bodies |
inC | Value of the constraint equation (C) |
inBaumgarte | Baumgarte constant (fraction of the error to correct) |
|
inline |
Iteratively update the velocity constraint. Makes sure d/dt C(...) = 0, where C is the constraint equation.
ioBody1 | The first body that this constraint is attached to |
ioBody2 | The second body that this constraint is attached to |
inN1 | The world space normal in which the constraint operates for body 1 |
inN2 | The world space normal in which the constraint operates for body 2 |
inRatio | The ratio how forces are applied between bodies |
inMinLambda | Minimum angular impulse to apply (N m s) |
inMaxLambda | Maximum angular impulse to apply (N m s) |
|
inline |
Must be called from the WarmStartVelocityConstraint call to apply the previous frame's impulses
ioBody1 | The first body that this constraint is attached to |
ioBody2 | The second body that this constraint is attached to |
inN1 | The world space normal in which the constraint operates for body 1 |
inN2 | The world space normal in which the constraint operates for body 2 |
inRatio | The ratio how forces are applied between bodies |
inWarmStartImpulseRatio | Ratio of new step to old time step (dt_new / dt_old) for scaling the lagrange multiplier of the previous frame |