update method

void update (ContactListener listener)

Implementation

void update(ContactListener listener) {
  _oldManifold.set(_manifold);

  // Re-enable this contact.
  _flags |= ENABLED_FLAG;

  bool touching = false;
  bool wasTouching = (_flags & TOUCHING_FLAG) == TOUCHING_FLAG;

  bool sensorA = _fixtureA.isSensor();
  bool sensorB = _fixtureB.isSensor();
  bool sensor = sensorA || sensorB;

  Body bodyA = _fixtureA.getBody();
  Body bodyB = _fixtureB.getBody();
  Transform xfA = bodyA._transform;
  Transform xfB = bodyB._transform;
  // log.debug("TransformA: "+xfA);
  // log.debug("TransformB: "+xfB);

  if (sensor) {
    Shape shapeA = _fixtureA.getShape();
    Shape shapeB = _fixtureB.getShape();
    touching = _pool
        .getCollision()
        .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 (int i = 0; i < _manifold.pointCount; ++i) {
      ManifoldPoint mp2 = _manifold.points[i];
      mp2.normalImpulse = 0.0;
      mp2.tangentImpulse = 0.0;
      ContactID id2 = mp2.id;

      for (int j = 0; j < _oldManifold.pointCount; ++j) {
        ManifoldPoint 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 |= TOUCHING_FLAG;
  } else {
    _flags &= ~TOUCHING_FLAG;
  }

  if (listener == null) {
    return;
  }

  if (wasTouching == false && touching == true) {
    listener.beginContact(this);
  }

  if (wasTouching == true && touching == false) {
    listener.endContact(this);
  }

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