Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. void RigidBody::integrate(real duration)
  2. {
  3. ///<BodyIntegrateBase
  4.     if (!isAwake) return;
  5.  
  6. ///>BodyIntegrate10
  7. ///>LastUpdateAcceleration
  8.     // Calculate linear acceleration from force inputs.
  9.     lastFrameAcceleration = acceleration;
  10.     lastFrameAcceleration.addScaledVector(forceAccum, inverseMass);
  11. ///<LastUpdateAcceleration
  12.  
  13.     // Calculate angular acceleration from torque inputs.
  14.     Vector3 angularAcceleration =
  15.         inverseInertiaTensorWorld.transform(torqueAccum);
  16.  
  17.     // Adjust velocities
  18.     // Update linear velocity from both acceleration and impulse.
  19.     velocity.addScaledVector(lastFrameAcceleration, duration);
  20.  
  21.     // Update angular velocity from both acceleration and impulse.
  22.     rotation.addScaledVector(angularAcceleration, duration);
  23.  
  24.     // Impose drag.
  25.     velocity *= real_pow(linearDamping, duration);
  26.     rotation *= real_pow(angularDamping, duration);
  27.  
  28.     // Adjust positions
  29.     // Update linear position.
  30.     position.addScaledVector(velocity, duration);
  31.  
  32.     // Update angular position.
  33.     orientation.addScaledVector(rotation, duration);
  34.  
  35.     // Impose drag.
  36.     velocity *= real_pow(linearDamping, duration);
  37.     rotation *= real_pow(angularDamping, duration);
  38.  
  39.     // Normalise the orientation, and update the matrices with the new
  40.     // position and orientation
  41.     calculateDerivedData();
  42.  
  43. ///>ClearAccumulators
  44.     // Clear accumulators.
  45.     clearAccumulators();
  46. ///<ClearAccumulators
  47. ///<BodyIntegrate10
  48.  
  49.     // Update the kinetic energy store, and possibly put the body to
  50.     // sleep.
  51.     if (canSleep) {
  52.         real currentMotion = velocity.scalarProduct(velocity) +
  53.             rotation.scalarProduct(rotation);
  54.  
  55.         real bias = real_pow(0.5, duration);
  56.         motion = bias*motion + (1-bias)*currentMotion;
  57.  
  58.         if (motion < sleepEpsilon) setAwake(false);
  59.         else if (motion > 10 * sleepEpsilon) motion = 10 * sleepEpsilon;
  60.     }
  61. ///>BodyIntegrateBase
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement