51 JPH_INLINE
bool ApplyVelocityStep(
Body &ioBody1,
Body &ioBody2,
const Vec2 &inLambda)
const
63 Vec3 impulse = mB2xA1 * inLambda[0] + mC2xA1 * inLambda[1];
82 mA1 = inWorldSpaceHingeAxis1;
83 Vec3 a2 = inWorldSpaceHingeAxis2;
84 float dot = mA1.
Dot(a2);
88 Vec3 perp = a2 - dot * mA1;
96 a2 = (0.99f * perp.
Normalized() + 0.01f * mA1).Normalized();
104 mB2xA1 = mB2.
Cross(mA1);
105 mC2xA1 = mC2.
Cross(mA1);
108 Mat44 summed_inv_inertia = mInvI1 + mInvI2;
109 Mat22 inv_effective_mass;
110 inv_effective_mass(0, 0) = mB2xA1.
Dot(summed_inv_inertia.
Multiply3x3(mB2xA1));
111 inv_effective_mass(0, 1) = mB2xA1.
Dot(summed_inv_inertia.
Multiply3x3(mC2xA1));
112 inv_effective_mass(1, 0) = mC2xA1.
Dot(summed_inv_inertia.
Multiply3x3(mB2xA1));
113 inv_effective_mass(1, 1) = mC2xA1.
Dot(summed_inv_inertia.
Multiply3x3(mC2xA1));
114 if (!mEffectiveMass.
SetInversed(inv_effective_mass))
128 mTotalLambda *= inWarmStartImpulseRatio;
129 ApplyVelocityStep(ioBody1, ioBody2, mTotalLambda);
140 jv[0] = mB2xA1.
Dot(delta_ang);
141 jv[1] = mC2xA1.
Dot(delta_ang);
142 Vec2 lambda = mEffectiveMass * jv;
145 mTotalLambda += lambda;
147 return ApplyVelocityStep(ioBody1, ioBody2, lambda);
164 Vec2 lambda = -inBaumgarte * (mEffectiveMass * c);
181 Vec3 impulse = mB2xA1 * lambda[0] + mC2xA1 * lambda[1];
201 inStream.
Write(mTotalLambda);
207 inStream.
Read(mTotalLambda);
218 Mat22 mEffectiveMass;
#define JPH_NAMESPACE_END
Definition: Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
const MotionProperties * GetMotionProperties() const
Access to the motion properties.
Definition: Body.h:255
bool IsDynamic() const
Check if this body is dynamic, which means that it moves and forces can act on it.
Definition: Body.h:67
void AddRotationStep(Vec3Arg inAngularVelocityTimesDeltaTime)
Update rotation using an Euler step (using during position integrate & constraint solving)
Definition: Body.inl:81
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:159
Definition: HingeRotationConstraintPart.h:44
bool SolvePositionConstraint(Body &ioBody1, Body &ioBody2, float inBaumgarte) const
Iteratively update the position constraint. Makes sure C(...) = 0.
Definition: HingeRotationConstraintPart.h:151
void CalculateConstraintProperties(const Body &inBody1, Mat44Arg inRotation1, Vec3Arg inWorldSpaceHingeAxis1, const Body &inBody2, Mat44Arg inRotation2, Vec3Arg inWorldSpaceHingeAxis2)
Calculate properties used during the functions below.
Definition: HingeRotationConstraintPart.h:76
void Deactivate()
Deactivate this constraint.
Definition: HingeRotationConstraintPart.h:119
void SaveState(StateRecorder &inStream) const
Save state of this constraint part.
Definition: HingeRotationConstraintPart.h:199
void WarmStart(Body &ioBody1, Body &ioBody2, float inWarmStartImpulseRatio)
Must be called from the WarmStartVelocityConstraint call to apply the previous frame's impulses.
Definition: HingeRotationConstraintPart.h:126
const Vec2 & GetTotalLambda() const
Return lagrange multiplier.
Definition: HingeRotationConstraintPart.h:193
bool SolveVelocityConstraint(Body &ioBody1, Body &ioBody2)
Iteratively update the velocity constraint. Makes sure d/dt C(...) = 0, where C is the constraint equ...
Definition: HingeRotationConstraintPart.h:133
Matrix< 2, 2 > Mat22
Definition: HingeRotationConstraintPart.h:47
void RestoreState(StateRecorder &inStream)
Restore state of this constraint part.
Definition: HingeRotationConstraintPart.h:205
Vector< 2 > Vec2
Definition: HingeRotationConstraintPart.h:46
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition: Mat44.h:13
static JPH_INLINE Mat44 sZero()
Zero matrix.
Definition: Mat44.inl:30
JPH_INLINE Vec3 Multiply3x3(Vec3Arg inV) const
Multiply vector by only 3x3 part of the matrix.
Definition: Mat44.inl:316
bool SetInversed(const Matrix &inM)
Inverse matrix.
Definition: Matrix.h:200
void SetZero()
Zero matrix.
Definition: Matrix.h:26
void SubAngularVelocityStep(Vec3Arg inAngularVelocityChange)
Definition: MotionProperties.h:194
Mat44 GetInverseInertiaForRotation(Mat44Arg inRotation) const
Get inverse inertia matrix ( ) for a given object rotation (translation will be ignored)....
Definition: MotionProperties.inl:59
void AddAngularVelocityStep(Vec3Arg inAngularVelocityChange)
Definition: MotionProperties.h:193
Definition: StateRecorder.h:48
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:637
JPH_INLINE Vec3 Normalized() const
Normalize vector.
Definition: Vec3.inl:694
JPH_INLINE Vec3 Cross(Vec3Arg inV2) const
Cross product.
Definition: Vec3.inl:582
JPH_INLINE Vec3 GetNormalizedPerpendicular() const
Get normalized vector that is perpendicular to this vector.
Definition: Vec3.inl:812
JPH_INLINE bool IsNormalized(float inTolerance=1.0e-6f) const
Test if vector is normalized.
Definition: Vec3.inl:737
JPH_INLINE float LengthSq() const
Squared length of vector.
Definition: Vec3.inl:653
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