Exemple #1
0
  public void destroy(final Contact c) {

    final Vec2 v1 = tlV1.get();
    final ContactPoint cp = tlCp.get();

    final Shape shape1 = c.getShape1();
    final Shape shape2 = c.getShape2();

    // Inform the user that this contact is ending.
    final int manifoldCount = c.getManifoldCount();
    if (manifoldCount > 0 && (m_world.m_contactListener != null)) {
      final Body b1 = shape1.getBody();
      final Body b2 = shape2.getBody();
      final List<Manifold> manifolds = c.getManifolds();
      cp.shape1 = c.getShape1();
      cp.shape2 = c.getShape2();
      cp.friction = c.m_friction;
      cp.restitution = c.m_restitution;
      for (int i = 0; i < manifoldCount; ++i) {
        final Manifold manifold = manifolds.get(i);
        cp.normal.set(manifold.normal);
        for (int j = 0; j < manifold.pointCount; ++j) {

          final ManifoldPoint mp = manifold.points[j];
          b1.getWorldLocationToOut(mp.localPoint1, cp.position);
          b1.getLinearVelocityFromLocalPointToOut(mp.localPoint1, v1);
          // velocity isn't initialized in the contact point
          b2.getLinearVelocityFromLocalPointToOut(mp.localPoint2, cp.velocity);
          cp.velocity.subLocal(v1);
          cp.separation = mp.separation;
          cp.id.set(mp.id);
          m_world.m_contactListener.remove(cp);
        }
      }
    }

    // Remove from the world.
    if (c.m_prev != null) {
      c.m_prev.m_next = c.m_next;
    }

    if (c.m_next != null) {
      c.m_next.m_prev = c.m_prev;
    }

    if (c == m_world.m_contactList) {
      m_world.m_contactList = c.m_next;
    }

    final Body body1 = shape1.getBody();
    final Body body2 = shape2.getBody();

    // Remove from body 1
    if (c.m_node1.prev != null) {
      c.m_node1.prev.next = c.m_node1.next;
    }

    if (c.m_node1.next != null) {
      c.m_node1.next.prev = c.m_node1.prev;
    }

    if (c.m_node1 == body1.m_contactList) {
      body1.m_contactList = c.m_node1.next;
    }

    // Remove from body 2
    if (c.m_node2.prev != null) {
      c.m_node2.prev.next = c.m_node2.next;
    }

    if (c.m_node2.next != null) {
      c.m_node2.next.prev = c.m_node2.prev;
    }

    if (c.m_node2 == body2.m_contactList) {
      body2.m_contactList = c.m_node2.next;
    }

    // Call the factory.
    Contact.destroy(c);
    --m_world.m_contactCount;
  }