39 JPH_INLINE
bool ApplyVelocityStep(
Body &ioBody1,
Body &ioBody2,
float inLambda)
const
62 JPH_INLINE
float CalculateInverseEffectiveMass(
const Body &inBody1,
const Body &inBody2,
Vec3Arg inWorldSpaceAxis)
71 return inWorldSpaceAxis.
Dot(mInvI1_Axis + mInvI2_Axis);
83 float inv_effective_mass = CalculateInverseEffectiveMass(inBody1, inBody2, inWorldSpaceAxis);
85 if (inv_effective_mass == 0.0f)
89 mEffectiveMass = 1.0f / inv_effective_mass;
106 float inv_effective_mass = CalculateInverseEffectiveMass(inBody1, inBody2, inWorldSpaceAxis);
108 if (inv_effective_mass == 0.0f)
126 float inv_effective_mass = CalculateInverseEffectiveMass(inBody1, inBody2, inWorldSpaceAxis);
128 if (inv_effective_mass == 0.0f)
137 float inv_effective_mass = CalculateInverseEffectiveMass(inBody1, inBody2, inWorldSpaceAxis);
139 if (inv_effective_mass == 0.0f)
141 else if (inSpringSettings.
mMode == ESpringMode::FrequencyAndDamping)
150 mEffectiveMass = 0.0f;
157 return mEffectiveMass != 0.0f;
166 mTotalLambda *= inWarmStartImpulseRatio;
167 ApplyVelocityStep(ioBody1, ioBody2, mTotalLambda);
182 float new_lambda =
Clamp(mTotalLambda + lambda, inMinLambda, inMaxLambda);
183 lambda = new_lambda - mTotalLambda;
184 mTotalLambda = new_lambda;
186 return ApplyVelocityStep(ioBody1, ioBody2, lambda);
203 if (inC != 0.0f && !mSpringPart.
IsActive())
210 float lambda = -mEffectiveMass * inBaumgarte * inC;
240 inStream.
Write(mTotalLambda);
246 inStream.
Read(mTotalLambda);
252 float mEffectiveMass = 0.0f;
254 float mTotalLambda = 0.0f;
#define JPH_NAMESPACE_END
Definition: Core.h:378
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:372
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
JPH_INLINE constexpr T Clamp(T inV, T inMin, T inMax)
Clamp a value between two values.
Definition: Math.h:45
Definition: AngleConstraintPart.h:37
bool SolvePositionConstraint(Body &ioBody1, Body &ioBody2, float inC, float inBaumgarte) const
Definition: AngleConstraintPart.h:200
void CalculateConstraintPropertiesWithStiffnessAndDamping(float inDeltaTime, const Body &inBody1, const Body &inBody2, Vec3Arg inWorldSpaceAxis, float inBias, float inC, float inStiffness, float inDamping)
Definition: AngleConstraintPart.h:124
void Deactivate()
Deactivate this constraint.
Definition: AngleConstraintPart.h:148
bool IsActive() const
Check if constraint is active.
Definition: AngleConstraintPart.h:155
void CalculateConstraintProperties(const Body &inBody1, const Body &inBody2, Vec3Arg inWorldSpaceAxis, float inBias=0.0f)
Definition: AngleConstraintPart.h:81
void RestoreState(StateRecorder &inStream)
Restore state of this constraint part.
Definition: AngleConstraintPart.h:244
void WarmStart(Body &ioBody1, Body &ioBody2, float inWarmStartImpulseRatio)
Definition: AngleConstraintPart.h:164
bool SolveVelocityConstraint(Body &ioBody1, Body &ioBody2, Vec3Arg inWorldSpaceAxis, float inMinLambda, float inMaxLambda)
Definition: AngleConstraintPart.h:176
void SaveState(StateRecorder &inStream) const
Save state of this constraint part.
Definition: AngleConstraintPart.h:238
void CalculateConstraintPropertiesWithSettings(float inDeltaTime, const Body &inBody1, const Body &inBody2, Vec3Arg inWorldSpaceAxis, float inBias, float inC, const SpringSettings &inSpringSettings)
Selects one of the above functions based on the spring settings.
Definition: AngleConstraintPart.h:135
void CalculateConstraintPropertiesWithFrequencyAndDamping(float inDeltaTime, const Body &inBody1, const Body &inBody2, Vec3Arg inWorldSpaceAxis, float inBias, float inC, float inFrequency, float inDamping)
Definition: AngleConstraintPart.h:104
float GetTotalLambda() const
Return lagrange multiplier.
Definition: AngleConstraintPart.h:190
const MotionProperties * GetMotionProperties() const
Access to the motion properties.
Definition: Body.h:249
bool IsDynamic() const
Check if this body is dynamic, which means that it moves and forces can act on it.
Definition: Body.h:61
void AddRotationStep(Vec3Arg inAngularVelocityTimesDeltaTime)
Update rotation using an Euler step (using during position integrate & constraint solving)
Definition: Body.inl:81
Quat GetRotation() const
World space rotation of the body.
Definition: Body.h:231
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:153
void SubAngularVelocityStep(Vec3Arg inAngularVelocityChange)
Definition: MotionProperties.h:194
JPH_INLINE Vec3 MultiplyWorldSpaceInverseInertiaByVector(QuatArg inBodyRotation, Vec3Arg inV) const
Multiply a vector with the inverse world space inertia tensor ( ). Zero if object is static or kinema...
Definition: MotionProperties.inl:76
void AddAngularVelocityStep(Vec3Arg inAngularVelocityChange)
Definition: MotionProperties.h:193
Class used in other constraint parts to calculate the required bias factor in the lagrange multiplier...
Definition: SpringPart.h:14
void CalculateSpringPropertiesWithFrequencyAndDamping(float inDeltaTime, float inInvEffectiveMass, float inBias, float inC, float inFrequency, float inDamping, float &outEffectiveMass)
Definition: SpringPart.h:86
void CalculateSpringPropertiesWithStiffnessAndDamping(float inDeltaTime, float inInvEffectiveMass, float inBias, float inC, float inStiffness, float inDamping, float &outEffectiveMass)
Definition: SpringPart.h:116
float GetBias(float inTotalLambda) const
Get total bias b, including supplied bias and bias for spring: lambda = J v + b.
Definition: SpringPart.h:137
void CalculateSpringPropertiesWithBias(float inBias)
Definition: SpringPart.h:71
bool IsActive() const
Returns if this spring is active.
Definition: SpringPart.h:131
Settings for a linear or angular spring.
Definition: SpringSettings.h:23
float mStiffness
Definition: SpringSettings.h:60
float mDamping
Definition: SpringSettings.h:67
ESpringMode mMode
Definition: SpringSettings.h:44
float mFrequency
Definition: SpringSettings.h:51
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:645
JPH_INLINE bool IsNormalized(float inTolerance=1.0e-6f) const
Test if vector is normalized.
Definition: Vec3.inl:745
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition: Vec3.inl:107