67 Vec3 impulse = inN1 * inLambda[0] + inN2 * inLambda[1];
87 inline void CalculateLagrangeMultiplier(
const Body &inBody1,
const Body &inBody2,
Vec3Arg inN1,
Vec3Arg inN2,
Vec2 &outLambda)
const
96 outLambda = mEffectiveMass * jv;
108 mR1PlusUxN1 = inR1PlusU.
Cross(inN1);
109 mR1PlusUxN2 = inR1PlusU.
Cross(inN2);
110 mR2xN1 = inR2.
Cross(inN1);
111 mR2xN2 = inR2.
Cross(inN2);
114 Mat22 inv_effective_mass;
119 mInvI1_R1PlusUxN1 = inv_i1.
Multiply3x3(mR1PlusUxN1);
120 mInvI1_R1PlusUxN2 = inv_i1.
Multiply3x3(mR1PlusUxN2);
122 inv_effective_mass(0, 0) = mp1->
GetInverseMass() + mR1PlusUxN1.
Dot(mInvI1_R1PlusUxN1);
123 inv_effective_mass(0, 1) = mR1PlusUxN1.
Dot(mInvI1_R1PlusUxN2);
124 inv_effective_mass(1, 0) = mR1PlusUxN2.
Dot(mInvI1_R1PlusUxN1);
125 inv_effective_mass(1, 1) = mp1->
GetInverseMass() + mR1PlusUxN2.
Dot(mInvI1_R1PlusUxN2);
143 inv_effective_mass(0, 1) += mR2xN1.
Dot(mInvI2_R2xN2);
144 inv_effective_mass(1, 0) += mR2xN2.
Dot(mInvI2_R2xN1);
153 if (!mEffectiveMass.
SetInversed(inv_effective_mass))
167 return !mEffectiveMass.
IsZero();
174 mTotalLambda *= inWarmStartImpulseRatio;
175 ApplyVelocityStep(ioBody1, ioBody2, inN1, inN2, mTotalLambda);
183 CalculateLagrangeMultiplier(ioBody1, ioBody2, inN1, inN2, lambda);
186 mTotalLambda += lambda;
188 return ApplyVelocityStep(ioBody1, ioBody2, inN1, inN2, lambda);
196 c[0] = inU.
Dot(inN1);
197 c[1] = inU.
Dot(inN2);
205 Vec2 lambda = -inBaumgarte * (mEffectiveMass * c);
222 Vec3 impulse = inN1 * lambda[0] + inN2 * lambda[1];
226 ioBody1.
SubRotationStep(mInvI1_R1PlusUxN1 * lambda[0] + mInvI1_R1PlusUxN2 * lambda[1]);
231 ioBody2.
AddRotationStep(mInvI2_R2xN1 * lambda[0] + mInvI2_R2xN2 * lambda[1]);
242 mTotalLambda = inLambda;
254 inStream.
Write(mTotalLambda);
260 inStream.
Read(mTotalLambda);
268 Vec3 mInvI1_R1PlusUxN1;
269 Vec3 mInvI1_R1PlusUxN2;
272 Mat22 mEffectiveMass;
#define JPH_IF_DEBUG(...)
Definition Core.h:510
#define JPH_NAMESPACE_END
Definition Core.h:379
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
const MotionProperties * GetMotionProperties() const
Access to the motion properties.
Definition Body.h:285
bool IsDynamic() const
Check if this body is dynamic, which means that it moves and forces can act on it.
Definition Body.h:63
void AddRotationStep(Vec3Arg inAngularVelocityTimesDeltaTime)
Update rotation using an Euler step (used during position integrate & constraint solving)
Definition Body.inl:81
void SubPositionStep(Vec3Arg inLinearVelocityTimesDeltaTime)
Definition Body.h:320
Vec3 GetLinearVelocity() const
Get world space linear velocity of the center of mass (unit: m/s)
Definition Body.h:146
void SubRotationStep(Vec3Arg inAngularVelocityTimesDeltaTime)
Definition Body.inl:100
Vec3 GetAngularVelocity() const
Get world space angular velocity of the center of mass (unit: rad/s)
Definition Body.h:157
void AddPositionStep(Vec3Arg inLinearVelocityTimesDeltaTime)
Update position using an Euler step (used during position integrate & constraint solving)
Definition Body.h:319
Definition DualAxisConstraintPart.h:48
bool SolveVelocityConstraint(Body &ioBody1, Body &ioBody2, Vec3Arg inN1, Vec3Arg inN2)
Definition DualAxisConstraintPart.h:180
void RestoreState(StateRecorder &inStream)
Restore state of this constraint part.
Definition DualAxisConstraintPart.h:258
Matrix< 2, 2 > Mat22
Definition DualAxisConstraintPart.h:51
void WarmStart(Body &ioBody1, Body &ioBody2, Vec3Arg inN1, Vec3Arg inN2, float inWarmStartImpulseRatio)
Definition DualAxisConstraintPart.h:172
bool SolvePositionConstraint(Body &ioBody1, Body &ioBody2, Vec3Arg inU, Vec3Arg inN1, Vec3Arg inN2, float inBaumgarte) const
Definition DualAxisConstraintPart.h:193
Vector< 2 > Vec2
Definition DualAxisConstraintPart.h:50
void SaveState(StateRecorder &inStream) const
Save state of this constraint part.
Definition DualAxisConstraintPart.h:252
const Vec2 & GetTotalLambda() const
Return lagrange multiplier.
Definition DualAxisConstraintPart.h:246
void SetTotalLambda(const Vec2 &inLambda)
Override total lagrange multiplier, can be used to set the initial value for warm starting.
Definition DualAxisConstraintPart.h:240
bool IsActive() const
Check if constraint is active.
Definition DualAxisConstraintPart.h:165
void Deactivate()
Deactivate this constraint.
Definition DualAxisConstraintPart.h:158
void CalculateConstraintProperties(const Body &inBody1, Mat44Arg inRotation1, Vec3Arg inR1PlusU, const Body &inBody2, Mat44Arg inRotation2, Vec3Arg inR2, Vec3Arg inN1, Vec3Arg inN2)
Definition DualAxisConstraintPart.h:102
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:316
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:29
void AddLinearVelocityStep(Vec3Arg inLinearVelocityChange)
Definition MotionProperties.h:195
void SubLinearVelocityStep(Vec3Arg inLinearVelocityChange)
Definition MotionProperties.h:196
float GetInverseMass() const
Get inverse mass (1 / mass). Should only be called on a dynamic object (static or kinematic bodies ha...
Definition MotionProperties.h:95
void SubAngularVelocityStep(Vec3Arg inAngularVelocityChange)
Definition MotionProperties.h:198
Mat44 GetInverseInertiaForRotation(Mat44Arg inRotation) const
Get inverse inertia matrix ( ) for a given object rotation (translation will be ignored)....
Definition MotionProperties.inl:69
void AddAngularVelocityStep(Vec3Arg inAngularVelocityChange)
Definition MotionProperties.h:197
Definition StateRecorder.h:105
void Read(T &outT)
Read a primitive (e.g. float, int, etc.) from the binary stream.
Definition StreamIn.h:29
void Write(const T &inT)
Write a primitive (e.g. float, int, etc.) to the binary stream.
Definition StreamOut.h:26
JPH_INLINE float Dot(Vec3Arg inV2) const
Dot product.
Definition Vec3.inl:649
JPH_INLINE Vec3 Cross(Vec3Arg inV2) const
Cross product.
Definition Vec3.inl:594
JPH_INLINE bool IsNormalized(float inTolerance=1.0e-6f) const
Test if vector is normalized.
Definition Vec3.inl:751
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