use of com.almasb.fxgl.physics.box2d.collision.broadphase.BroadPhase in project FXGL by AlmasB.
the class Fixture method refilter.
/**
* Call this if you want to establish collision that was previously disabled by
* ContactFilter::ShouldCollide.
*/
public void refilter() {
// Flag associated contacts for filtering.
ContactEdge edge = 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 = body.getWorld();
if (world == null) {
return;
}
// Touch each proxy so that new pairs may be created
BroadPhase broadPhase = world.getContactManager().broadPhase;
for (int i = 0; i < proxyCount; ++i) {
broadPhase.touchProxy(proxies[i].proxyId);
}
}
use of com.almasb.fxgl.physics.box2d.collision.broadphase.BroadPhase in project FXGL by AlmasB.
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 void setTransform(Vec2 position, float angle) {
world.assertNotLocked();
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 = world.getContactManager().broadPhase;
for (Fixture f : fixtures) {
f.synchronize(broadPhase, m_xf, m_xf);
}
}
use of com.almasb.fxgl.physics.box2d.collision.broadphase.BroadPhase in project FXGL by AlmasB.
the class Body method setType.
/**
* Set the type of this body.
* This may alter the mass and velocity.
*
* @param type body type
*/
public void setType(BodyType type) {
world.assertNotLocked();
if (this.type == type) {
return;
}
this.type = type;
resetMassData();
if (this.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;
destroyAttachedContacts();
// Touch the proxies so that new contacts will be created (when appropriate)
BroadPhase broadPhase = world.getContactManager().broadPhase;
for (Fixture f : fixtures) {
int proxyCount = f.getProxyCount();
for (int i = 0; i < proxyCount; ++i) {
broadPhase.touchProxy(f.getProxyId(i));
}
}
}
use of com.almasb.fxgl.physics.box2d.collision.broadphase.BroadPhase in project FXGL by AlmasB.
the class Body method destroyFixture.
/**
* 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.
* Note: this function is locked during callbacks.
*
* @param fixture the fixture to be removed
*/
public void destroyFixture(Fixture fixture) {
world.assertNotLocked();
assert (fixture.getBody() == this);
assert (fixtures.size() > 0);
assert fixtures.contains(fixture);
fixtures.remove(fixture);
// Destroy any contacts associated with the fixture.
ContactEdge edge = m_contactList;
while (edge != null) {
Contact c = edge.contact;
edge = edge.next;
Fixture fixtureA = c.getFixtureA();
Fixture fixtureB = c.getFixtureB();
if (fixture == fixtureA || fixture == fixtureB) {
// This destroys the contact and removes it from this body's contact list.
world.getContactManager().destroy(c);
}
}
if ((m_flags & e_activeFlag) == e_activeFlag) {
BroadPhase broadPhase = world.getContactManager().broadPhase;
fixture.destroyProxies(broadPhase);
}
fixture.destroy();
resetMassData();
}
use of com.almasb.fxgl.physics.box2d.collision.broadphase.BroadPhase in project FXGL by AlmasB.
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.
* Note: This function is locked during callbacks.
*
* @param def the fixture definition
*/
public Fixture createFixture(FixtureDef def) {
world.assertNotLocked();
Fixture fixture = new Fixture(this, def);
if ((m_flags & e_activeFlag) == e_activeFlag) {
BroadPhase broadPhase = world.getContactManager().broadPhase;
fixture.createProxies(broadPhase, m_xf);
}
fixtures.add(fixture);
// Adjust mass properties if needed.
if (fixture.getDensity() > 0) {
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.
world.notifyNewFixture();
return fixture;
}
Aggregations