Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void RigidBody::integrate(real duration)
- {
- ///<BodyIntegrateBase
- if (!isAwake) return;
- ///>BodyIntegrate10
- ///>LastUpdateAcceleration
- // Calculate linear acceleration from force inputs.
- lastFrameAcceleration = acceleration;
- lastFrameAcceleration.addScaledVector(forceAccum, inverseMass);
- ///<LastUpdateAcceleration
- // Calculate angular acceleration from torque inputs.
- Vector3 angularAcceleration =
- inverseInertiaTensorWorld.transform(torqueAccum);
- // Adjust velocities
- // Update linear velocity from both acceleration and impulse.
- velocity.addScaledVector(lastFrameAcceleration, duration);
- // Update angular velocity from both acceleration and impulse.
- rotation.addScaledVector(angularAcceleration, duration);
- // Impose drag.
- velocity *= real_pow(linearDamping, duration);
- rotation *= real_pow(angularDamping, duration);
- // Adjust positions
- // Update linear position.
- position.addScaledVector(velocity, duration);
- // Update angular position.
- orientation.addScaledVector(rotation, duration);
- // Impose drag.
- velocity *= real_pow(linearDamping, duration);
- rotation *= real_pow(angularDamping, duration);
- // Normalise the orientation, and update the matrices with the new
- // position and orientation
- calculateDerivedData();
- ///>ClearAccumulators
- // Clear accumulators.
- clearAccumulators();
- ///<ClearAccumulators
- ///<BodyIntegrate10
- // Update the kinetic energy store, and possibly put the body to
- // sleep.
- if (canSleep) {
- real currentMotion = velocity.scalarProduct(velocity) +
- rotation.scalarProduct(rotation);
- real bias = real_pow(0.5, duration);
- motion = bias*motion + (1-bias)*currentMotion;
- if (motion < sleepEpsilon) setAwake(false);
- else if (motion > 10 * sleepEpsilon) motion = 10 * sleepEpsilon;
- }
- ///>BodyIntegrateBase
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement