initVelocityConstraints method

  1. @override
void initVelocityConstraints(
  1. SolverData step
)
override

Implementation

@override
void initVelocityConstraints(SolverData step) {
  final velocities = step.velocities;
  final positions = step.positions;
  final d = List<Vector2>.generate(
    _bodies.length,
    (i) {
      final prev = (i == 0) ? _bodies.length - 1 : i - 1;
      final next = (i == _bodies.length - 1) ? 0 : i + 1;
      return positions[_bodies[next].islandIndex].c -
          positions[_bodies[prev].islandIndex].c;
    },
  );

  if (step.step.warmStarting) {
    _impulse *= step.step.dtRatio;
    for (var i = 0; i < _bodies.length; ++i) {
      velocities[_bodies[i].islandIndex].v.x +=
          _bodies[i].inverseMass * d[i].y * .5 * _impulse;
      velocities[_bodies[i].islandIndex].v.y +=
          _bodies[i].inverseMass * -d[i].x * .5 * _impulse;
    }
  } else {
    _impulse = 0.0;
  }
}