/** * 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; }
private void destroyFixtures() { for (Fixture f : getFixtures()) { if (world.getDestructionListener() != null) { world.getDestructionListener().onDestroy(f); } f.destroyProxies(world.getContactManager().broadPhase); f.destroy(); // jbox2dTODO djm recycle fixtures (here or in that destroy method) } getFixtures().clear(); }
private void pushContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); if (contact.m_manifold.pointCount > 0 && !fixtureA.isSensor() && !fixtureB.isSensor()) { fixtureA.getBody().setAwake(true); fixtureB.getBody().setAwake(true); } ShapeType type1 = fixtureA.getType(); ShapeType type2 = fixtureB.getType(); IDynamicStack<Contact> creator = contactStacks[type1.ordinal()][type2.ordinal()].creator; creator.push(contact); } }
/** initialization for pooling */ public void init(Fixture fA, int indexA, Fixture fB, int indexB) { m_flags = ENABLED_FLAG; m_fixtureA = fA; m_fixtureB = fB; m_indexA = indexA; m_indexB = indexB; m_manifold.pointCount = 0; m_prev = null; m_next = null; m_nodeA.contact = null; m_nodeA.prev = null; m_nodeA.next = null; m_nodeA.other = null; m_nodeB.contact = null; m_nodeB.prev = null; m_nodeB.next = null; m_nodeB.other = null; m_toiCount = 0; m_friction = mixFriction(fA.getFriction(), fB.getFriction()); m_restitution = mixRestitution(fA.getRestitution(), fB.getRestitution()); m_tangentSpeed = 0; }
@Override public boolean reportFixture(Fixture fixture) { if (fixture.isSensor()) { return true; final Shape shape = fixture.getShape(); Body body = fixture.getBody(); int childCount = shape.getChildCount(); for (int childIndex = 0; childIndex < childCount; childIndex++) { AABB aabb = fixture.getAABB(childIndex); final float aabblowerBoundx = aabb.lowerBound.x - system.m_particleDiameter; final float aabblowerBoundy = aabb.lowerBound.y - system.m_particleDiameter; input.p2.y = ap.y + step.dt * av.y; input.maxFraction = 1; if (fixture.raycast(output, input, childIndex)) { final Vec2 p = tempVec; p.x =
@Override public boolean reportFixture(Fixture fixture) { if (fixture.isSensor()) { return true; final Shape shape = fixture.getShape(); Body b = fixture.getBody(); Vec2 bp = b.getWorldCenter(); float bm = b.getMass(); int childCount = shape.getChildCount(); for (int childIndex = 0; childIndex < childCount; childIndex++) { AABB aabb = fixture.getAABB(childIndex); final float aabblowerBoundx = aabb.lowerBound.x - system.m_particleDiameter; final float aabblowerBoundy = aabb.lowerBound.y - system.m_particleDiameter; float d; final Vec2 n = tempVec; d = fixture.computeDistance(ap, childIndex, n); if (d < system.m_particleDiameter) { float invAm =
boolean sensorA = m_fixtureA.isSensor(); boolean sensorB = m_fixtureB.isSensor(); boolean sensor = sensorA || sensorB; Body bodyA = m_fixtureA.getBody(); Body bodyB = m_fixtureB.getBody(); Transform xfA = bodyA.getTransform(); Transform xfB = bodyB.getTransform(); Shape shapeA = m_fixtureA.getShape(); Shape shapeB = m_fixtureB.getShape(); touching = pool.getCollision().testOverlap(shapeA, m_indexA, shapeB, m_indexB, xfA, xfB);
world.assertNotLocked(); assert (fixture.getBody() == this); assert fixtures.contains(fixture); fixture.destroyProxies(broadPhase); fixture.destroy();
@Override public void endContact(Contact contact) { Entity e1 = contact.getFixtureA().getBody().getEntity(); Entity e2 = contact.getFixtureB().getBody().getEntity(); // check sensors first if (contact.getFixtureA().isSensor()) { notifySensorCollisionEnd(e1, e2, contact.getFixtureA().getHitBox()); return; } else if (contact.getFixtureB().isSensor()) { notifySensorCollisionEnd(e2, e1, contact.getFixtureB().getHitBox()); return; } if (!areCollidable(e1, e2)) return; CollisionHandler handler = getHandler(e1, e2); if (handler != null) { int pairIndex = getPairIndex(e1, e2); // collision registered, so remove it and put pair back to pool if (pairIndex != -1) { CollisionPair pair = collisions.get(pairIndex); collisions.removeIndex(pairIndex); pair.collisionEnd(); Pools.free(pair); } } }
@Override public void endContact(Contact contact) { Entity e1 = contact.getFixtureA().getBody().getEntity(); Entity e2 = contact.getFixtureB().getBody().getEntity(); // check sensors first if (contact.getFixtureA().isSensor()) { HitBox box = (HitBox) contact.getFixtureA().getUserData(); SensorCollisionHandler h = e1.getComponent(PhysicsComponent.class).getSensorHandlers().get(box); h.onCollisionEnd(e2); return; } else if (contact.getFixtureB().isSensor()) { HitBox box = (HitBox) contact.getFixtureB().getUserData(); SensorCollisionHandler h = e2.getComponent(PhysicsComponent.class).getSensorHandlers().get(box); h.onCollisionEnd(e1); return; } if (!areCollidable(e1, e2)) return; CollisionHandler handler = getHandler(e1, e2); if (handler != null) { int pairIndex = getPairIndex(e1, e2); // collision registered, so remove it and put pair back to pool if (pairIndex != -1) { CollisionPair pair = collisions.get(pairIndex); collisions.removeIndex(pairIndex); pair.collisionEnd(); Pools.free(pair); } } }
f.createProxies(broadPhase, m_xf); f.destroyProxies(broadPhase);
int indexA = c.getChildIndexA(); int indexB = c.getChildIndexB(); Body bodyA = fixtureA.getBody(); Body bodyB = fixtureB.getBody(); int proxyIdA = fixtureA.getProxyId(indexA); int proxyIdB = fixtureB.getProxyId(indexB); boolean overlap = broadPhase.testOverlap(proxyIdA, proxyIdB);
if (f.getDensity() == 0.0f) { continue; f.getMassData(massData); m_mass += massData.mass;
int indexB = proxyB.childIndex; Body bodyA = fixtureA.getBody(); Body bodyB = fixtureB.getBody(); indexA = c.getChildIndexA(); indexB = c.getChildIndexB(); bodyA = fixtureA.getBody(); bodyB = fixtureB.getBody(); if (!fixtureA.isSensor() && !fixtureB.isSensor()) { bodyA.setAwake(true); bodyB.setAwake(true);
public void resetFriction() { m_friction = mixFriction(m_fixtureA.getFriction(), m_fixtureB.getFriction()); }
/** * @warning for performance reasons this is only called when the AABBs begin to overlap. * @param fixtureA first fixture * @param fixtureB second fixture * @return true if contact calculations should be performed between these two shapes */ public boolean shouldCollide(Fixture fixtureA, Fixture fixtureB) { Filter filterA = fixtureA.getFilterData(); Filter filterB = fixtureB.getFilterData(); if (filterA.groupIndex == filterB.groupIndex && filterA.groupIndex != 0) { return filterA.groupIndex > 0; } return (filterA.maskBits & filterB.categoryBits) != 0 && (filterA.categoryBits & filterB.maskBits) != 0; } }
@Override public boolean reportFixture(Fixture fixture) { if (fixture.isSensor()) { return true; final Shape shape = fixture.getShape(); Body body = fixture.getBody(); int childCount = shape.getChildCount(); for (int childIndex = 0; childIndex < childCount; childIndex++) { AABB aabb = fixture.getAABB(childIndex); final float aabblowerBoundx = aabb.lowerBound.x - system.m_particleDiameter; final float aabblowerBoundy = aabb.lowerBound.y - system.m_particleDiameter; input.p2.y = ap.y + step.dt * av.y; input.maxFraction = 1; if (fixture.raycast(output, input, childIndex)) { final Vec2 p = tempVec; p.x =
@Override public boolean reportFixture(Fixture fixture) { if (fixture.isSensor()) { return true; final Shape shape = fixture.getShape(); Body b = fixture.getBody(); Vec2 bp = b.getWorldCenter(); float bm = b.getMass(); int childCount = shape.getChildCount(); for (int childIndex = 0; childIndex < childCount; childIndex++) { AABB aabb = fixture.getAABB(childIndex); final float aabblowerBoundx = aabb.lowerBound.x - system.m_particleDiameter; final float aabblowerBoundy = aabb.lowerBound.y - system.m_particleDiameter; float d; final Vec2 n = tempVec; d = fixture.computeDistance(ap, childIndex, n); if (d < system.m_particleDiameter) { float invAm =