Search in sources :

Example 6 with BroadPhase

use of spacegraph.space2d.phys.collision.broadphase.BroadPhase in project narchy by automenta.

the class Body2D method removeFixture.

/**
 * Destroy a fixture. This removes the fixture from the broad-phase and destroys all contacts
 * associated with this fixture. This will automatically adjust the mass of the body if the body
 * is dynamic and the fixture has positive density. All fixtures attached to a body are implicitly
 * destroyed when the body is destroyed.
 *
 * @param fixture the fixture to be removed.
 * @warning This function is locked during callbacks.
 */
public final void removeFixture(Fixture fixture) {
    W.invoke(() -> {
        assert (fixture.body == this);
        // Remove the fixture from this body's singly linked list.
        assert (fixtureCount > 0);
        // W.invokeLater(() -> {
        Fixture node = fixtures;
        // java change
        Fixture last = null;
        boolean found = false;
        while (node != null) {
            if (node == fixture) {
                node = fixture.next;
                found = true;
                break;
            }
            last = node;
            node = node.next;
        }
        // You tried to remove a shape that is not attached to this body.
        assert (found);
        // java change, remove it from the list
        if (last == null) {
            fixtures = fixture.next;
        } else {
            last.next = fixture.next;
        }
        // Destroy any contacts associated with the fixture.
        ContactEdge edge = contacts;
        while (edge != null) {
            Contact c = edge.contact;
            edge = edge.next;
            Fixture fixtureA = c.aFixture;
            Fixture fixtureB = c.bFixture;
            if (fixture == fixtureA || fixture == fixtureB) {
                // This destroys the contact and removes it from
                // this body's contact list.
                W.contactManager.destroy(c);
            }
        }
        if ((flags & e_activeFlag) == e_activeFlag) {
            BroadPhase broadPhase = W.contactManager.broadPhase;
            fixture.destroyProxies(broadPhase);
        }
        fixture.destroy();
        fixture.body = null;
        fixture.next = null;
        --fixtureCount;
        // Reset the mass data.
        resetMassData();
    });
}
Also used : PolygonFixture(spacegraph.space2d.phys.fracture.PolygonFixture) BroadPhase(spacegraph.space2d.phys.collision.broadphase.BroadPhase) ContactEdge(spacegraph.space2d.phys.dynamics.contacts.ContactEdge) Contact(spacegraph.space2d.phys.dynamics.contacts.Contact)

Example 7 with BroadPhase

use of spacegraph.space2d.phys.collision.broadphase.BroadPhase in project narchy by automenta.

the class Fixture method refilter.

/**
 * Call this if you want to establish collision that was previously disabled by
 * ContactFilter::ShouldCollide.
 */
public void refilter() {
    if (body == null) {
        return;
    }
    // Flag associated contacts for filtering.
    ContactEdge edge = body.contacts();
    while (edge != null) {
        Contact contact = edge.contact;
        Fixture fixtureA = contact.aFixture;
        Fixture fixtureB = contact.bFixture;
        if (fixtureA == this || fixtureB == this) {
            contact.flagForFiltering();
        }
        edge = edge.next;
    }
    Dynamics2D world = body.W;
    if (world == null) {
        return;
    }
    // Touch each proxy so that new pairs may be created
    BroadPhase broadPhase = world.contactManager.broadPhase;
    for (int i = 0; i < m_proxyCount; ++i) {
        broadPhase.touchProxy(proxies[i].id);
    }
}
Also used : PolygonFixture(spacegraph.space2d.phys.fracture.PolygonFixture) BroadPhase(spacegraph.space2d.phys.collision.broadphase.BroadPhase) ContactEdge(spacegraph.space2d.phys.dynamics.contacts.ContactEdge) Contact(spacegraph.space2d.phys.dynamics.contacts.Contact)

Aggregations

BroadPhase (spacegraph.space2d.phys.collision.broadphase.BroadPhase)7 PolygonFixture (spacegraph.space2d.phys.fracture.PolygonFixture)7 ContactEdge (spacegraph.space2d.phys.dynamics.contacts.ContactEdge)4 Contact (spacegraph.space2d.phys.dynamics.contacts.Contact)2