65 Vec3 impulse = inN1 * inLambda[0] + inN2 * inLambda[1];
85 inline void CalculateLagrangeMultiplier(
const Body &inBody1,
const Body &inBody2,
Vec3Arg inN1,
Vec3Arg inN2,
Vec2 &outLambda)
const
94 outLambda = mEffectiveMass * jv;
106 mR1PlusUxN1 = inR1PlusU.
Cross(inN1);
107 mR1PlusUxN2 = inR1PlusU.
Cross(inN2);
108 mR2xN1 = inR2.
Cross(inN1);
109 mR2xN2 = inR2.
Cross(inN2);
112 Mat22 inv_effective_mass;
117 mInvI1_R1PlusUxN1 = inv_i1.
Multiply3x3(mR1PlusUxN1);
118 mInvI1_R1PlusUxN2 = inv_i1.
Multiply3x3(mR1PlusUxN2);
120 inv_effective_mass(0, 0) = mp1->
GetInverseMass() + mR1PlusUxN1.
Dot(mInvI1_R1PlusUxN1);
121 inv_effective_mass(0, 1) = mR1PlusUxN1.
Dot(mInvI1_R1PlusUxN2);
122 inv_effective_mass(1, 0) = mR1PlusUxN2.
Dot(mInvI1_R1PlusUxN1);
123 inv_effective_mass(1, 1) = mp1->
GetInverseMass() + mR1PlusUxN2.
Dot(mInvI1_R1PlusUxN2);
141 inv_effective_mass(0, 1) += mR2xN1.
Dot(mInvI2_R2xN2);
142 inv_effective_mass(1, 0) += mR2xN2.
Dot(mInvI2_R2xN1);
151 if (!mEffectiveMass.
SetInversed(inv_effective_mass))
168 return !mEffectiveMass.
IsZero();
175 mTotalLambda *= inWarmStartImpulseRatio;
176 ApplyVelocityStep(ioBody1, ioBody2, inN1, inN2, mTotalLambda);
184 CalculateLagrangeMultiplier(ioBody1, ioBody2, inN1, inN2, lambda);
187 mTotalLambda += lambda;
189 return ApplyVelocityStep(ioBody1, ioBody2, inN1, inN2, lambda);
197 c[0] = inU.
Dot(inN1);
198 c[1] = inU.
Dot(inN2);
206 Vec2 lambda = -inBaumgarte * (mEffectiveMass * c);
223 Vec3 impulse = inN1 * lambda[0] + inN2 * lambda[1];
227 ioBody1.
SubRotationStep(mInvI1_R1PlusUxN1 * lambda[0] + mInvI1_R1PlusUxN2 * lambda[1]);
232 ioBody2.
AddRotationStep(mInvI2_R2xN1 * lambda[0] + mInvI2_R2xN2 * lambda[1]);
243 mTotalLambda = inLambda;
255 inStream.
Write(mTotalLambda);
261 inStream.
Read(mTotalLambda);
269 Vec3 mInvI1_R1PlusUxN1;
270 Vec3 mInvI1_R1PlusUxN2;
273 Mat22 mEffectiveMass;
#define JPH_IF_DEBUG(...)
Definition Core.h:354
#define JPH_NAMESPACE_END
Definition Core.h:240
#define JPH_NAMESPACE_BEGIN
Definition Core.h:234
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
const MotionProperties * GetMotionProperties() const
Access to the motion properties.
Definition Body.h:205
bool IsDynamic() const
Check if this body is dynamic, which means that it moves and forces can act on it.
Definition Body.h:56
void AddRotationStep(Vec3Arg inAngularVelocityTimesDeltaTime)
Update rotation using an Euler step (using during position integrate & constraint solving)
Definition Body.inl:75
void SubPositionStep(Vec3Arg inLinearVelocityTimesDeltaTime)
Definition Body.h:237
Vec3 GetLinearVelocity() const
Get world space linear velocity of the center of mass (unit: m/s)
Definition Body.h:109
void SubRotationStep(Vec3Arg inAngularVelocityTimesDeltaTime)
Definition Body.inl:93
Vec3 GetAngularVelocity() const
Get world space angular velocity of the center of mass (unit: rad/s)
Definition Body.h:118
void AddPositionStep(Vec3Arg inLinearVelocityTimesDeltaTime)
Update position using an Euler step (used during position integrate & constraint solving)
Definition Body.h:236
Definition DualAxisConstraintPart.h:46
bool SolveVelocityConstraint(Body &ioBody1, Body &ioBody2, Vec3Arg inN1, Vec3Arg inN2)
Definition DualAxisConstraintPart.h:181
void RestoreState(StateRecorder &inStream)
Restore state of this constraint part.
Definition DualAxisConstraintPart.h:259
Matrix< 2, 2 > Mat22
Definition DualAxisConstraintPart.h:49
void WarmStart(Body &ioBody1, Body &ioBody2, Vec3Arg inN1, Vec3Arg inN2, float inWarmStartImpulseRatio)
Definition DualAxisConstraintPart.h:173
bool SolvePositionConstraint(Body &ioBody1, Body &ioBody2, Vec3Arg inU, Vec3Arg inN1, Vec3Arg inN2, float inBaumgarte) const
Definition DualAxisConstraintPart.h:194
Vector< 2 > Vec2
Definition DualAxisConstraintPart.h:48
void SaveState(StateRecorder &inStream) const
Save state of this constraint part.
Definition DualAxisConstraintPart.h:253
const Vec2 & GetTotalLambda() const
Return lagrange multiplier.
Definition DualAxisConstraintPart.h:247
void SetTotalLambda(const Vec2 &inLambda)
Override total lagrange multiplier, can be used to set the initial value for warm starting.
Definition DualAxisConstraintPart.h:241
bool IsActive() const
Check if constraint is active.
Definition DualAxisConstraintPart.h:166
void Deactivate()
Deactivate this constraint.
Definition DualAxisConstraintPart.h:159
void CalculateConstraintProperties(const Body &inBody1, Mat44Arg inRotation1, Vec3Arg inR1PlusU, const Body &inBody2, Mat44Arg inRotation2, Vec3Arg inR2, Vec3Arg inN1, Vec3Arg inN2)
Definition DualAxisConstraintPart.h:100
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition Mat44.h:13
JPH_INLINE Vec3 Multiply3x3(Vec3Arg inV) const
Multiply vector by only 3x3 part of the matrix.
Definition Mat44.inl:307
static Matrix sZero()
Definition Matrix.h:32
bool SetInversed(const Matrix &inM)
Inverse matrix.
Definition Matrix.h:200
void SetZero()
Zero matrix.
Definition Matrix.h:26
bool IsZero() const
Check if this matrix consists of all zeros.
Definition Matrix.h:35
The Body class only keeps track of state for static bodies, the MotionProperties class keeps the addi...
Definition MotionProperties.h:20
void AddLinearVelocityStep(Vec3Arg inLinearVelocityChange)
Definition MotionProperties.h:126
void SubLinearVelocityStep(Vec3Arg inLinearVelocityChange)
Definition MotionProperties.h:127
float GetInverseMass() const
Get inverse mass (1 / mass). Should only be called on a dynamic object (static or kinematic bodies ha...
Definition MotionProperties.h:80
void SubAngularVelocityStep(Vec3Arg inAngularVelocityChange)
Definition MotionProperties.h:129
Mat44 GetInverseInertiaForRotation(Mat44Arg inRotation) const
Get inverse inertia matrix ( ) for a given object rotation (translation will be ignored)....
Definition MotionProperties.inl:81
void AddAngularVelocityStep(Vec3Arg inAngularVelocityChange)
Definition MotionProperties.h:128
Definition StateRecorder.h:15
void Read(T &outT)
Read a primitive (e.g. float, int, etc.) from the binary stream.
Definition StreamIn.h:27
void Write(const T &inT)
Write a primitive (e.g. float, int, etc.) to the binary stream.
Definition StreamOut.h:24
JPH_INLINE float Dot(Vec3Arg inV2) const
Dot product.
Definition Vec3.inl:637
JPH_INLINE Vec3 Cross(Vec3Arg inV2) const
Cross product.
Definition Vec3.inl:582
JPH_INLINE bool IsNormalized(float inTolerance=1.0e-6f) const
Test if vector is normalized.
Definition Vec3.inl:737
static JPH_INLINE Vec3 sNaN()
Vector with all NaN's.
Definition Vec3.inl:129
void SetZero()
Vector with all zeros.
Definition Vector.h:22
bool IsZero() const
Test if vector consists of all zeros.
Definition Vector.h:69
static Vector sZero()
Definition Vector.h:28