update method

Vector2 update(
  1. double dt,
  2. Vector2 to
)

Implementation

Vector2 update(double dt, Vector2 to) {
  final Vector2 targetVel = (to - posPrev) / dt;

  posPrev.setFrom(to);

  // stability clamp
  final double k2Stable = max(k2, 1.1 * (dt * dt / 4 + dt * k1 / 2));

  // integrate position
  pos += vel * dt;

  // acceleration
  final Vector2 acc = (to + targetVel * k3 - pos - vel * k1);

  // integrate velocity
  vel += (acc * dt) / k2Stable;

  return pos;
}