Search in sources :

Example 1 with BroadPhase

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

the class Body2D method updateFixtures.

/**
 * call this if shape changes
 */
protected final void updateFixtures(Consumer<Fixture> tx) {
    W.invoke(() -> {
        for (Fixture f = fixtures; f != null; f = f.next) {
            // destroy and re-create proxies
            // if ((m_flags & e_activeFlag) == e_activeFlag) {
            BroadPhase broadPhase = W.contactManager.broadPhase;
            f.destroyProxies(broadPhase);
            tx.accept(f);
            f.createProxies(broadPhase, this);
            // Adjust mass properties if needed.
            if (f.density > 0.0f) {
                resetMassData();
            }
        }
        synchronizeFixtures();
        synchronizeTransform();
    });
}
Also used : PolygonFixture(spacegraph.space2d.phys.fracture.PolygonFixture) BroadPhase(spacegraph.space2d.phys.collision.broadphase.BroadPhase)

Example 2 with BroadPhase

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

the class Body2D method setType.

/**
 * Set the type of this body. This may alter the mass and velocity.
 *
 * @param type
 */
public void setType(BodyType type) {
    if (this.type == type) {
        return;
    }
    this.type = type;
    resetMassData();
    if (this.type == BodyType.STATIC) {
        vel.setZero();
        velAngular = 0.0f;
        sweep.a0 = sweep.a;
        sweep.c0.set(sweep.c);
        synchronizeFixtures();
    }
    setAwake(true);
    force.setZero();
    torque = 0.0f;
    // Delete the attached contacts.
    ContactEdge ce = contacts;
    while (ce != null) {
        ContactEdge ce0 = ce;
        ce = ce.next;
        W.contactManager.destroy(ce0.contact);
    }
    contacts = null;
    // Touch the proxies so that new contacts will be created (when appropriate)
    BroadPhase broadPhase = W.contactManager.broadPhase;
    for (Fixture f = fixtures; f != null; f = f.next) {
        int proxyCount = f.m_proxyCount;
        for (int i = 0; i < proxyCount; ++i) {
            broadPhase.touchProxy(f.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)

Example 3 with BroadPhase

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

the class Body2D method setActive.

/**
 * Set the active state of the body. An inactive body is not simulated and cannot be collided with
 * or woken up. If you pass a flag of true, all fixtures will be added to the broad-phase. If you
 * pass a flag of false, all fixtures will be removed from the broad-phase and all contacts will
 * be destroyed. Fixtures and joints are otherwise unaffected. You may continue to create/destroy
 * fixtures and joints on inactive bodies. Fixtures on an inactive body are implicitly inactive
 * and will not participate in collisions, ray-casts, or queries. Joints connected to an inactive
 * body are implicitly inactive. An inactive body is still owned by a World object and remains in
 * the body list.
 *
 * @param flag
 */
void setActive(boolean flag) {
    if (flag == isActive()) {
        return;
    }
    W.invoke(() -> {
        if (flag) {
            flags |= e_activeFlag;
            // Create all proxies.
            BroadPhase broadPhase = W.contactManager.broadPhase;
            for (Fixture f = fixtures; f != null; f = f.next) {
                f.createProxies(broadPhase, this);
            }
        // Contacts are created the next time step.
        } else {
            flags &= ~e_activeFlag;
            // Destroy all proxies.
            BroadPhase broadPhase = W.contactManager.broadPhase;
            for (Fixture f = fixtures; f != null; f = f.next) {
                f.destroyProxies(broadPhase);
            }
            // Destroy the attached contacts.
            ContactEdge ce = contacts;
            while (ce != null) {
                ContactEdge ce0 = ce;
                ce = ce.next;
                W.contactManager.destroy(ce0.contact);
            }
            contacts = null;
        }
    });
}
Also used : PolygonFixture(spacegraph.space2d.phys.fracture.PolygonFixture) BroadPhase(spacegraph.space2d.phys.collision.broadphase.BroadPhase) ContactEdge(spacegraph.space2d.phys.dynamics.contacts.ContactEdge)

Example 4 with BroadPhase

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

the class Body2D method addFixture.

/**
 * Creates a fixture and attach it to this body. Use this function if you need to set some fixture
 * parameters, like friction. Otherwise you can create the fixture directly from a shape. If the
 * density is non-zero, this function automatically updates the mass of the body. Contacts are not
 * created until the next time step.
 *
 * @param def the fixture definition.
 * @warning This function is locked during callbacks.
 */
public final Fixture addFixture(FixtureDef def) {
    Fixture fixture = new Fixture();
    fixture.body = this;
    fixture.create(this, def);
    W.invoke(() -> {
        if ((flags & e_activeFlag) == e_activeFlag) {
            BroadPhase broadPhase = W.contactManager.broadPhase;
            fixture.createProxies(broadPhase, this);
        }
        fixture.next = fixtures;
        fixtures = fixture;
        ++fixtureCount;
        // Let the world know we have a new fixture. This will cause new contacts
        // to be created at the beginning of the next time step.
        W.flags |= Dynamics2D.NEW_FIXTURE;
        // Adjust mass properties if needed.
        if (fixture.density > 0.0f) {
            resetMassData();
        }
    });
    return fixture;
}
Also used : PolygonFixture(spacegraph.space2d.phys.fracture.PolygonFixture) BroadPhase(spacegraph.space2d.phys.collision.broadphase.BroadPhase)

Example 5 with BroadPhase

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

the class Body2D method setTransform.

/**
 * Set the position of the body's origin and rotation. This breaks any contacts and wakes the
 * other bodies. Manipulating a body's transform may cause non-physical behavior. Note: contacts
 * are updated on the next call to World.step().
 *
 * @param position the world position of the body's local origin.
 * @param angle    the world rotation in radians.
 */
public final boolean setTransform(Tuple2f position, float angle, float epsilon) {
    if (getPosition().equals(position, epsilon) && Util.equals(angle, getAngle(), epsilon))
        // no change
        return false;
    W.invoke(() -> {
        this.set(angle);
        pos.set(position);
        // m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
        Transform.mulToOutUnsafe(this, sweep.localCenter, sweep.c);
        sweep.a = angle;
        sweep.c0.set(sweep.c);
        sweep.a0 = sweep.a;
        BroadPhase broadPhase = W.contactManager.broadPhase;
        for (Fixture f = fixtures; f != null; f = f.next) f.synchronize(broadPhase, this, this);
    });
    return true;
}
Also used : PolygonFixture(spacegraph.space2d.phys.fracture.PolygonFixture) BroadPhase(spacegraph.space2d.phys.collision.broadphase.BroadPhase)

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