collide method

void collide()

This is the top level collision call for the time step. Here all the narrow phase collision is processed for the world contact list.

Implementation

void collide() {
  final contactRemovals = <Contact>[];
  // Update awake contacts.
  for (final c in contacts) {
    final fixtureA = c.fixtureA;
    final fixtureB = c.fixtureB;
    final indexA = c.indexA;
    final indexB = c.indexB;
    final bodyA = fixtureA.body;
    final bodyB = fixtureB.body;

    // is this contact flagged for filtering?
    if ((c.flags & Contact.filterFlag) == Contact.filterFlag) {
      // Should these bodies collide?
      if (!bodyB.shouldCollide(bodyA)) {
        contactRemovals.add(c);
        continue;
      }

      // Check user filtering.
      if (contactFilter?.shouldCollide(fixtureA, fixtureB) == false) {
        contactRemovals.add(c);
        continue;
      }

      // Clear the filtering flag.
      c.flags &= ~Contact.filterFlag;
    }

    final activeA = bodyA.isAwake && bodyA.bodyType != BodyType.static;
    final activeB = bodyB.isAwake && bodyB.bodyType != BodyType.static;

    // At least one body must be awake and it must be dynamic or kinematic.
    if (activeA == false && activeB == false) {
      continue;
    }

    final proxyIdA = fixtureA.proxies[indexA].proxyId;
    final proxyIdB = fixtureB.proxies[indexB].proxyId;

    // Here we destroy contacts that cease to overlap in the broad-phase.
    if (!broadPhase.testOverlap(proxyIdA, proxyIdB)) {
      contactRemovals.add(c);
      continue;
    }

    // The contact persists.
    c.update(contactListener);
  }
  contactRemovals.forEach(destroy);
}