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() {
  // Update awake contacts.
  Contact c = contactList;
  while (c != null) {
    Fixture fixtureA = c.fixtureA;
    Fixture fixtureB = c.fixtureB;
    int indexA = c.getChildIndexA();
    int indexB = c.getChildIndexB();
    Body bodyA = fixtureA.getBody();
    Body bodyB = fixtureB.getBody();

    // is this contact flagged for filtering?
    if ((c._flags & Contact.FILTER_FLAG) == Contact.FILTER_FLAG) {
      // Should these bodies collide?
      if (bodyB.shouldCollide(bodyA) == false) {
        Contact cNuke = c;
        c = cNuke.getNext();
        destroy(cNuke);
        continue;
      }

      // Check user filtering.
      if (contactFilter != null &&
          contactFilter.shouldCollide(fixtureA, fixtureB) == false) {
        Contact cNuke = c;
        c = cNuke.getNext();
        destroy(cNuke);
        continue;
      }

      // Clear the filtering flag.
      c._flags &= ~Contact.FILTER_FLAG;
    }

    bool activeA = bodyA.isAwake() && bodyA._bodyType != BodyType.STATIC;
    bool 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) {
      c = c.getNext();
      continue;
    }

    int proxyIdA = fixtureA._proxies[indexA].proxyId;
    int proxyIdB = fixtureB._proxies[indexB].proxyId;
    bool overlap = broadPhase.testOverlap(proxyIdA, proxyIdB);

    // Here we destroy contacts that cease to overlap in the broad-phase.
    if (overlap == false) {
      Contact cNuke = c;
      c = cNuke.getNext();
      destroy(cNuke);
      continue;
    }

    // The contact persists.
    c.update(contactListener);
    c = c.getNext();
  }
}