stepDt method

void stepDt(
  1. double dt
)

Take a time step. This performs collision detection, integration, and constraint solution.

dt should be the amount of time (in seconds) that has passed since the last step.

Implementation

void stepDt(double dt) {
  _stepTimer.reset();
  _tempTimer.reset();
  // If new fixtures were added, we need to find the new contacts.
  if ((flags & newFixture) == newFixture) {
    contactManager.findNewContacts();
    flags &= ~newFixture;
  }

  flags |= locked;

  _step.dt = dt;
  _step.velocityIterations = settings.velocityIterations;
  _step.positionIterations = settings.positionIterations;
  if (dt > 0.0) {
    _step.invDt = 1.0 / dt;
  } else {
    _step.invDt = 0.0;
  }

  _step.dtRatio = _invDt0 * dt;

  _step.warmStarting = _warmStarting;
  _profile.stepInit.record(_tempTimer.getMilliseconds());

  // Update contacts. This is where some contacts are destroyed.
  _tempTimer.reset();
  contactManager.collide();
  _profile.collide.record(_tempTimer.getMilliseconds());

  // Integrate velocities, solve velocity constraints, and integrate
  // positions.
  if (_stepComplete && _step.dt > 0.0) {
    _tempTimer.reset();
    particleSystem.solve(_step); // Particle Simulation
    _profile.solveParticleSystem.record(_tempTimer.getMilliseconds());
    _tempTimer.reset();
    solve(_step);
    _profile.solve.record(_tempTimer.getMilliseconds());
  }

  // Handle TOI events.
  if (_continuousPhysics && _step.dt > 0.0) {
    _tempTimer.reset();
    solveTOI(_step);
    _profile.solveTOI.record(_tempTimer.getMilliseconds());
  }

  if (_step.dt > 0.0) {
    _invDt0 = _step.invDt;
  }

  if ((flags & clearForcesBit) == clearForcesBit) {
    clearForces();
  }

  flags &= ~locked;

  _profile.step.record(_stepTimer.getMilliseconds());
}