update method

void update(
  1. ContactListener? listener
)

Implementation

void update(ContactListener? listener) {
  _oldManifold.set(manifold);

  // Re-enable this contact.
  flags |= enabledFlag;

  var touching = false;
  final wasTouching = (flags & touchingFlag) == touchingFlag;

  final sensorA = fixtureA.isSensor;
  final sensorB = fixtureB.isSensor;
  final sensor = sensorA || sensorB;

  final bodyA = fixtureA.body;
  final bodyB = fixtureB.body;
  final xfA = bodyA.transform;
  final xfB = bodyB.transform;

  if (sensor) {
    final shapeA = fixtureA.shape;
    final shapeB = fixtureB.shape;
    touching = World.collision.testOverlap(
      shapeA,
      indexA,
      shapeB,
      indexB,
      xfA,
      xfB,
    );

    // Sensors don't generate manifolds.
    manifold.pointCount = 0;
  } else {
    evaluate(manifold, xfA, xfB);
    touching = manifold.pointCount > 0;

    // Match old contact ids to new contact ids and copy the
    // stored impulses to warm start the solver.
    for (var i = 0; i < manifold.pointCount; ++i) {
      final mp2 = manifold.points[i];
      mp2.normalImpulse = 0.0;
      mp2.tangentImpulse = 0.0;
      final id2 = mp2.id;

      for (var j = 0; j < _oldManifold.pointCount; ++j) {
        final mp1 = _oldManifold.points[j];

        if (mp1.id.isEqual(id2)) {
          mp2.normalImpulse = mp1.normalImpulse;
          mp2.tangentImpulse = mp1.tangentImpulse;
          break;
        }
      }
    }

    if (touching != wasTouching) {
      bodyA.setAwake(true);
      bodyB.setAwake(true);
    }
  }

  if (touching) {
    flags |= touchingFlag;
  } else {
    flags &= ~touchingFlag;
  }

  if (listener == null) {
    return;
  }

  if (!wasTouching && touching) {
    listener.beginContact(this);
  }

  if (wasTouching && !touching) {
    listener.endContact(this);
  }

  if (!sensor && touching) {
    listener.preSolve(this, _oldManifold);
  }
}