Search in sources :

Example 1 with BroadPhase

use of org.jbox2d.collision.broadphase.BroadPhase in project libgdx by libgdx.

the class Fixture method refilter.

/**
   * Call this if you want to establish collision that was previously disabled by
   * ContactFilter::ShouldCollide.
   */
public void refilter() {
    if (m_body == null) {
        return;
    }
    // Flag associated contacts for filtering.
    ContactEdge edge = m_body.getContactList();
    while (edge != null) {
        Contact contact = edge.contact;
        Fixture fixtureA = contact.getFixtureA();
        Fixture fixtureB = contact.getFixtureB();
        if (fixtureA == this || fixtureB == this) {
            contact.flagForFiltering();
        }
        edge = edge.next;
    }
    World world = m_body.getWorld();
    if (world == null) {
        return;
    }
    // Touch each proxy so that new pairs may be created
    BroadPhase broadPhase = world.m_contactManager.m_broadPhase;
    for (int i = 0; i < m_proxyCount; ++i) {
        broadPhase.touchProxy(m_proxies[i].proxyId);
    }
}
Also used : BroadPhase(org.jbox2d.collision.broadphase.BroadPhase) ContactEdge(org.jbox2d.dynamics.contacts.ContactEdge) Contact(org.jbox2d.dynamics.contacts.Contact)

Example 2 with BroadPhase

use of org.jbox2d.collision.broadphase.BroadPhase in project libgdx by libgdx.

the class Body method setType.

/**
   * Set the type of this body. This may alter the mass and velocity.
   * 
   * @param type
   */
public void setType(BodyType type) {
    assert (m_world.isLocked() == false);
    if (m_world.isLocked() == true) {
        return;
    }
    if (m_type == type) {
        return;
    }
    m_type = type;
    resetMassData();
    if (m_type == BodyType.STATIC) {
        m_linearVelocity.setZero();
        m_angularVelocity = 0.0f;
        m_sweep.a0 = m_sweep.a;
        m_sweep.c0.set(m_sweep.c);
        synchronizeFixtures();
    }
    setAwake(true);
    m_force.setZero();
    m_torque = 0.0f;
    // Delete the attached contacts.
    ContactEdge ce = m_contactList;
    while (ce != null) {
        ContactEdge ce0 = ce;
        ce = ce.next;
        m_world.m_contactManager.destroy(ce0.contact);
    }
    m_contactList = null;
    // Touch the proxies so that new contacts will be created (when appropriate)
    BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
    for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
        int proxyCount = f.m_proxyCount;
        for (int i = 0; i < proxyCount; ++i) {
            broadPhase.touchProxy(f.m_proxies[i].proxyId);
        }
    }
}
Also used : BroadPhase(org.jbox2d.collision.broadphase.BroadPhase) ContactEdge(org.jbox2d.dynamics.contacts.ContactEdge)

Example 3 with BroadPhase

use of org.jbox2d.collision.broadphase.BroadPhase in project libgdx by libgdx.

the class Body 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
   */
public void setActive(boolean flag) {
    assert (m_world.isLocked() == false);
    if (flag == isActive()) {
        return;
    }
    if (flag) {
        m_flags |= e_activeFlag;
        // Create all proxies.
        BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
        for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
            f.createProxies(broadPhase, m_xf);
        }
    // Contacts are created the next time step.
    } else {
        m_flags &= ~e_activeFlag;
        // Destroy all proxies.
        BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
        for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
            f.destroyProxies(broadPhase);
        }
        // Destroy the attached contacts.
        ContactEdge ce = m_contactList;
        while (ce != null) {
            ContactEdge ce0 = ce;
            ce = ce.next;
            m_world.m_contactManager.destroy(ce0.contact);
        }
        m_contactList = null;
    }
}
Also used : BroadPhase(org.jbox2d.collision.broadphase.BroadPhase) ContactEdge(org.jbox2d.dynamics.contacts.ContactEdge)

Example 4 with BroadPhase

use of org.jbox2d.collision.broadphase.BroadPhase in project libgdx by libgdx.

the class Body 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 void setTransform(Vec2 position, float angle) {
    assert (m_world.isLocked() == false);
    if (m_world.isLocked() == true) {
        return;
    }
    m_xf.q.set(angle);
    m_xf.p.set(position);
    // m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
    Transform.mulToOutUnsafe(m_xf, m_sweep.localCenter, m_sweep.c);
    m_sweep.a = angle;
    m_sweep.c0.set(m_sweep.c);
    m_sweep.a0 = m_sweep.a;
    BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
    for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
        f.synchronize(broadPhase, m_xf, m_xf);
    }
}
Also used : BroadPhase(org.jbox2d.collision.broadphase.BroadPhase)

Example 5 with BroadPhase

use of org.jbox2d.collision.broadphase.BroadPhase in project libgdx by libgdx.

the class Body method createFixture.

/**
   * 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 createFixture(FixtureDef def) {
    assert (m_world.isLocked() == false);
    if (m_world.isLocked() == true) {
        return null;
    }
    Fixture fixture = new Fixture();
    fixture.create(this, def);
    if ((m_flags & e_activeFlag) == e_activeFlag) {
        BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
        fixture.createProxies(broadPhase, m_xf);
    }
    fixture.m_next = m_fixtureList;
    m_fixtureList = fixture;
    ++m_fixtureCount;
    fixture.m_body = this;
    // Adjust mass properties if needed.
    if (fixture.m_density > 0.0f) {
        resetMassData();
    }
    // 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.
    m_world.m_flags |= World.NEW_FIXTURE;
    return fixture;
}
Also used : BroadPhase(org.jbox2d.collision.broadphase.BroadPhase)

Aggregations

BroadPhase (org.jbox2d.collision.broadphase.BroadPhase)6 ContactEdge (org.jbox2d.dynamics.contacts.ContactEdge)4 Contact (org.jbox2d.dynamics.contacts.Contact)2