public ContactManager(World argPool, BroadPhase broadPhase) { m_contactList = null; m_contactCount = 0; m_contactFilter = new ContactFilter(); m_contactListener = null; m_broadPhase = broadPhase; pool = argPool; }
/** Draws a circle with an axis */ public void drawCircle(Vec2 center, float radius, Vec2 axis, Color3f color) { drawCircle(center, radius, color); }
public void drawString(Vec2 pos, String s, Color3f color) { drawString(pos.x, pos.y, s, color); }
public void drawTree(DebugDraw argDraw, DynamicTreeNode node, int spot, int height) { node.aabb.getVertices(drawVecs); color.set(1, (height - spot) * 1f / height, (height - spot) * 1f / height); argDraw.drawPolygon(drawVecs, 4, color); argDraw.getViewportTranform().getWorldToScreen(node.aabb.upperBound, textVec); argDraw.drawString(textVec.x, textVec.y, node.id + "-" + (spot + 1) + "/" + height, color); if (node.child1 != null) { drawTree(argDraw, node.child1, spot + 1, height); } if (node.child2 != null) { drawTree(argDraw, node.child2, spot + 1, height); } } }
private void drawParticleSystem(ParticleSystem system) { boolean wireframe = (m_debugDraw.getFlags() & DebugDraw.e_wireframeDrawingBit) != 0; int particleCount = system.getParticleCount(); if (particleCount != 0) { float particleRadius = system.getParticleRadius(); Vec2[] positionBuffer = system.getParticlePositionBuffer(); ParticleColor[] colorBuffer = null; if (system.m_colorBuffer.data != null) { colorBuffer = system.getParticleColorBuffer(); } if (wireframe) { m_debugDraw.drawParticlesWireframe(positionBuffer, particleRadius, colorBuffer, particleCount); } else { m_debugDraw.drawParticles(positionBuffer, particleRadius, colorBuffer, particleCount); } } }
/** * Draw a closed polygon provided in CCW order. This implementation uses * {@link #drawSegment(Vec2, Vec2, Color3f)} to draw each side of the polygon. * * @param vertices * @param vertexCount * @param color */ public void drawPolygon(Vec2[] vertices, int vertexCount, Color3f color) { if (vertexCount == 1) { drawSegment(vertices[0], vertices[0], color); return; } for (int i = 0; i < vertexCount - 1; i += 1) { drawSegment(vertices[i], vertices[i + 1], color); } if (vertexCount > 2) { drawSegment(vertices[vertexCount - 1], vertices[0], color); } }
@Override public final void query(TreeCallback callback, AABB aabb) { assert(aabb.isValid()); nodeStackIndex = 0; nodeStack[nodeStackIndex++] = m_root; while (nodeStackIndex > 0) { DynamicTreeNode node = nodeStack[--nodeStackIndex]; if (node == null) { continue; } if (AABB.testOverlap(node.aabb, aabb)) { if (node.child1 == null) { boolean proceed = callback.treeCallback(node.id); if (!proceed) { return; } } else { if (nodeStack.length - nodeStackIndex - 2 <= 0) { DynamicTreeNode[] newBuffer = new DynamicTreeNode[nodeStack.length * 2]; System.arraycopy(nodeStack, 0, newBuffer, 0, nodeStack.length); nodeStack = newBuffer; } nodeStack[nodeStackIndex++] = node.child1; nodeStack[nodeStackIndex++] = node.child2; } } } }
public void report(ContactVelocityConstraint[] constraints) { if (m_listener == null) { return; } for (int i = 0; i < m_contactCount; ++i) { Contact c = m_contacts[i]; ContactVelocityConstraint vc = constraints[i]; impulse.count = vc.pointCount; for (int j = 0; j < vc.pointCount; ++j) { impulse.normalImpulses[j] = vc.points[j].normalImpulse; impulse.tangentImpulses[j] = vc.points[j].tangentImpulse; } m_listener.postSolve(c, impulse); } } }
public boolean treeCallback(int nodeId) { FixtureProxy proxy = (FixtureProxy) broadPhase.getUserData(nodeId); return callback.reportFixture(proxy.fixture); }
public void queryAABB(ParticleQueryCallback callback, final AABB aabb) { if (m_proxyCount == 0) { return; } final float lowerBoundX = aabb.lowerBound.x; final float lowerBoundY = aabb.lowerBound.y; final float upperBoundX = aabb.upperBound.x; final float upperBoundY = aabb.upperBound.y; int firstProxy = lowerBound(m_proxyBuffer, m_proxyCount, computeTag(m_inverseDiameter * lowerBoundX, m_inverseDiameter * lowerBoundY)); int lastProxy = upperBound(m_proxyBuffer, m_proxyCount, computeTag(m_inverseDiameter * upperBoundX, m_inverseDiameter * upperBoundY)); for (int proxy = firstProxy; proxy < lastProxy; ++proxy) { int i = m_proxyBuffer[proxy].index; final Vec2 p = m_positionBuffer.data[i]; if (lowerBoundX < p.x && p.x < upperBoundX && lowerBoundY < p.y && p.y < upperBoundY) { if (!callback.reportParticle(i)) { break; } } } }
callback.addPair(userDataA, userDataB); ++i;
public float raycastCallback(RayCastInput input, int nodeId) { Object userData = broadPhase.getUserData(nodeId); FixtureProxy proxy = (FixtureProxy) userData; Fixture fixture = proxy.fixture; int index = proxy.childIndex; boolean hit = fixture.raycast(output, input, index); if (hit) { float fraction = output.fraction; // Vec2 point = (1.0f - fraction) * input.p1 + fraction * input.p2; temp.set(input.p2).mulLocal(fraction); point.set(input.p1).mulLocal(1 - fraction).addLocal(temp); return callback.reportFixture(fixture, point, output.normal, fraction); } return input.maxFraction; }
m_contactListener.endContact(c);
point.x = point1.x + t * vx; point.y = point1.y + t * vy; float f = callback.reportParticle(i, point, n, t); fraction = MathUtils.min(fraction, f); if (fraction <= 0) {
void destroyParticleGroup(ParticleGroup group) { assert (m_groupCount > 0); assert (group != null); if (m_world.getParticleDestructionListener() != null) { m_world.getParticleDestructionListener().sayGoodbye(group); } for (int i = group.m_firstIndex; i < group.m_lastIndex; i++) { m_groupBuffer[i] = null; } if (group.m_prev != null) { group.m_prev.m_next = group.m_next; } if (group.m_next != null) { group.m_next.m_prev = group.m_prev; } if (group == m_groupList) { m_groupList = group.m_next; } --m_groupCount; }
je = je.next; if (m_destructionListener != null) { m_destructionListener.sayGoodbye(je0.joint); m_destructionListener.sayGoodbye(f0);
public void drawTree(DebugDraw argDraw, int node, int spot, int height) { AABB a = m_aabb[node]; a.getVertices(drawVecs); color.set(1, (height - spot) * 1f / height, (height - spot) * 1f / height); argDraw.drawPolygon(drawVecs, 4, color); argDraw.getViewportTranform().getWorldToScreen(a.upperBound, textVec); argDraw.drawString(textVec.x, textVec.y, node + "-" + (spot + 1) + "/" + height, color); int c1 = m_child1[node]; int c2 = m_child2[node]; if (c1 != NULL_NODE) { drawTree(argDraw, c1, spot + 1, height); } if (c2 != NULL_NODE) { drawTree(argDraw, c2, spot + 1, height); } } }
m_debugDraw.drawSegment(p1, p2, color); break; Vec2 s1 = pulley.getGroundAnchorA(); Vec2 s2 = pulley.getGroundAnchorB(); m_debugDraw.drawSegment(s1, p1, color); m_debugDraw.drawSegment(s2, p2, color); m_debugDraw.drawSegment(s1, s2, color); m_debugDraw.drawSegment(x1, p1, color); m_debugDraw.drawSegment(p1, p2, color); m_debugDraw.drawSegment(x2, p2, color);
/** Register a contact filter to provide specific control over collision. Otherwise the default filter is used * (b2_defaultFilter). The listener is owned by you and must remain in scope. */ public void setContactFilter (final ContactFilter filter) { if (filter != null) { world.setContactFilter(new org.jbox2d.callbacks.ContactFilter() { @Override public boolean shouldCollide (org.jbox2d.dynamics.Fixture fixtureA, org.jbox2d.dynamics.Fixture fixtureB) { return filter.shouldCollide(fixtures.get(fixtureA), fixtures.get(fixtureB)); } }); } else { world.setContactFilter(new org.jbox2d.callbacks.ContactFilter()); } }
@Override public final void query(TreeCallback callback, AABB aabb) { nodeStackIndex = 0; nodeStack[nodeStackIndex++] = m_root; while (nodeStackIndex > 0) { int node = nodeStack[--nodeStackIndex]; if (node == NULL_NODE) { continue; } if (AABB.testOverlap(m_aabb[node], aabb)) { int child1 = m_child1[node]; if (child1 == NULL_NODE) { boolean proceed = callback.treeCallback(node); if (!proceed) { return; } } else { if (nodeStack.length - nodeStackIndex - 2 <= 0) { nodeStack = BufferUtils.reallocateBuffer(nodeStack, nodeStack.length, nodeStack.length * 2); } nodeStack[nodeStackIndex++] = child1; nodeStack[nodeStackIndex++] = m_child2[node]; } } } }