MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / warmstart

Method warmstart

src/systems/SolveSliderJointSystem.cpp:242–319  ·  view source on GitHub ↗

Warm start the constraint (apply the previous impulse at the beginning of the step)

Source from the content-addressed store, hash-verified

240
241// Warm start the constraint (apply the previous impulse at the beginning of the step)
242void SolveSliderJointSystem::warmstart() {
243
244 // For each joint component
245 const uint32 nbJoints = mSliderJointComponents.getNbEnabledComponents();
246 for (uint32 i=0; i < nbJoints; i++) {
247
248 const Entity jointEntity = mSliderJointComponents.mJointEntities[i];
249 const uint32 jointIndex = mJointComponents.getEntityIndex(jointEntity);
250
251 // Get the bodies entities
252 const Entity body1Entity = mJointComponents.mBody1Entities[jointIndex];
253 const Entity body2Entity = mJointComponents.mBody2Entities[jointIndex];
254
255 const uint32 componentIndexBody1 = mRigidBodyComponents.getEntityIndex(body1Entity);
256 const uint32 componentIndexBody2 = mRigidBodyComponents.getEntityIndex(body2Entity);
257
258 // Get the velocities
259 Vector3& v1 = mRigidBodyComponents.mConstrainedLinearVelocities[componentIndexBody1];
260 Vector3& v2 = mRigidBodyComponents.mConstrainedLinearVelocities[componentIndexBody2];
261 Vector3& w1 = mRigidBodyComponents.mConstrainedAngularVelocities[componentIndexBody1];
262 Vector3& w2 = mRigidBodyComponents.mConstrainedAngularVelocities[componentIndexBody2];
263
264 // Get the inverse mass and inverse inertia tensors of the bodies
265 const decimal inverseMassBody1 = mRigidBodyComponents.mInverseMasses[componentIndexBody1];
266 const decimal inverseMassBody2 = mRigidBodyComponents.mInverseMasses[componentIndexBody2];
267
268 const Vector3& n1 = mSliderJointComponents.mN1[i];
269 const Vector3& n2 = mSliderJointComponents.mN2[i];
270
271 // Compute the impulse P=J^T * lambda for the lower and upper limits constraints of body 1
272 decimal impulseLimits = mSliderJointComponents.mImpulseUpperLimit[i] - mSliderJointComponents.mImpulseLowerLimit[i];
273 Vector3 linearImpulseLimits = impulseLimits * mSliderJointComponents.mSliderAxisWorld[i];
274
275 // Compute the impulse P=J^T * lambda for the motor constraint of body 1
276 Vector3 impulseMotor = mSliderJointComponents.mImpulseMotor[i] * mSliderJointComponents.mSliderAxisWorld[i];
277
278 const Vector2& impulseTranslation = mSliderJointComponents.mImpulseTranslation[i];
279 const Vector3& impulseRotation = mSliderJointComponents.mImpulseRotation[i];
280
281 // Compute the impulse P=J^T * lambda for the 2 translation constraints of body 1
282 Vector3 linearImpulseBody1 = -n1 * impulseTranslation.x - n2 * impulseTranslation.y;
283 Vector3 angularImpulseBody1 = -mSliderJointComponents.mR1PlusUCrossN1[i] * impulseTranslation.x -
284 mSliderJointComponents.mR1PlusUCrossN2[i] * impulseTranslation.y;
285
286 // Compute the impulse P=J^T * lambda for the 3 rotation constraints of body 1
287 angularImpulseBody1 += -impulseRotation;
288
289 // Compute the impulse P=J^T * lambda for the lower and upper limits constraints of body 1
290 linearImpulseBody1 += linearImpulseLimits;
291 angularImpulseBody1 += impulseLimits * mSliderJointComponents.mR1PlusUCrossSliderAxis[i];
292
293 // Compute the impulse P=J^T * lambda for the motor constraint of body 1
294 linearImpulseBody1 += impulseMotor;
295
296 // Apply the impulse to the body 1
297 v1 += inverseMassBody1 * mRigidBodyComponents.mLinearLockAxisFactors[componentIndexBody1] * linearImpulseBody1;
298 w1 += mRigidBodyComponents.mAngularLockAxisFactors[componentIndexBody1] * (mSliderJointComponents.mI1[i] * angularImpulseBody1);
299

Callers

nothing calls this directly

Calls 2

getEntityIndexMethod · 0.80

Tested by

no test coverage detected