public void solveCollision(TimeStep step) { final AABB aabb = temp; final Vec2 lowerBound = aabb.lowerBound; final Vec2 upperBound = aabb.upperBound; lowerBound.x = Float.MAX_VALUE; lowerBound.y = Float.MAX_VALUE; upperBound.x = -Float.MAX_VALUE; upperBound.y = -Float.MAX_VALUE; for (int i = 0; i < m_count; i++) { final Vec2 v = m_velocityBuffer.data[i]; final Vec2 p1 = m_positionBuffer.data[i]; final float p1x = p1.x; final float p1y = p1.y; final float p2x = p1x + step.dt * v.x; final float p2y = p1y + step.dt * v.y; final float bx = p1x < p2x ? p1x : p2x; final float by = p1y < p2y ? p1y : p2y; lowerBound.x = lowerBound.x < bx ? lowerBound.x : bx; lowerBound.y = lowerBound.y < by ? lowerBound.y : by; final float b1x = p1x > p2x ? p1x : p2x; final float b1y = p1y > p2y ? p1y : p2y; upperBound.x = upperBound.x > b1x ? upperBound.x : b1x; upperBound.y = upperBound.y > b1y ? upperBound.y : b1y; } sccallback.step = step; sccallback.system = this; m_world.queryAABB(sccallback, aabb); }
public int destroyParticlesInShape(Shape shape, Transform xf, boolean callDestructionListener) { dpcallback.init(this, shape, xf, callDestructionListener); shape.computeAABB(temp, xf, 0); m_world.queryAABB(dpcallback, temp); return dpcallback.destroyed; }
public void QueryAABB (final QueryCallback callback, float lowerX, float lowerY, float upperX, float upperY) { // FIXME pool QueryCallback? aabb.lowerBound.set(lowerX, lowerY); aabb.upperBound.set(upperX, upperY); world.queryAABB(new org.jbox2d.callbacks.QueryCallback() { @Override public boolean reportFixture (org.jbox2d.dynamics.Fixture f) { Fixture fixture = fixtures.get(f); return callback.reportFixture(fixture); } }, aabb); }
public void updateBodyContacts() { final AABB aabb = temp; aabb.lowerBound.x = Float.MAX_VALUE; aabb.lowerBound.y = Float.MAX_VALUE; aabb.upperBound.x = -Float.MAX_VALUE; aabb.upperBound.y = -Float.MAX_VALUE; for (int i = 0; i < m_count; i++) { Vec2 p = m_positionBuffer.data[i]; Vec2.minToOut(aabb.lowerBound, p, aabb.lowerBound); Vec2.maxToOut(aabb.upperBound, p, aabb.upperBound); } aabb.lowerBound.x -= m_particleDiameter; aabb.lowerBound.y -= m_particleDiameter; aabb.upperBound.x += m_particleDiameter; aabb.upperBound.y += m_particleDiameter; m_bodyContactCount = 0; ubccallback.system = this; m_world.queryAABB(ubccallback, aabb); }
public void solveCollision(TimeStep step) { final AABB aabb = temp; final Vec2 lowerBound = aabb.lowerBound; final Vec2 upperBound = aabb.upperBound; lowerBound.x = Float.MAX_VALUE; lowerBound.y = Float.MAX_VALUE; upperBound.x = -Float.MAX_VALUE; upperBound.y = -Float.MAX_VALUE; for (int i = 0; i < m_count; i++) { final Vec2 v = m_velocityBuffer.data[i]; final Vec2 p1 = m_positionBuffer.data[i]; final float p1x = p1.x; final float p1y = p1.y; final float p2x = p1x + step.dt * v.x; final float p2y = p1y + step.dt * v.y; final float bx = p1x < p2x ? p1x : p2x; final float by = p1y < p2y ? p1y : p2y; lowerBound.x = lowerBound.x < bx ? lowerBound.x : bx; lowerBound.y = lowerBound.y < by ? lowerBound.y : by; final float b1x = p1x > p2x ? p1x : p2x; final float b1y = p1y > p2y ? p1y : p2y; upperBound.x = upperBound.x > b1x ? upperBound.x : b1x; upperBound.y = upperBound.y > b1y ? upperBound.y : b1y; } sccallback.step = step; sccallback.system = this; m_world.queryAABB(sccallback, aabb); }
public int destroyParticlesInShape(Shape shape, Transform xf, boolean callDestructionListener) { dpcallback.init(this, shape, xf, callDestructionListener); shape.computeAABB(temp, xf, 0); m_world.queryAABB(dpcallback, temp); return dpcallback.destroyed; }
public void updateBodyContacts() { final AABB aabb = temp; aabb.lowerBound.x = Float.MAX_VALUE; aabb.lowerBound.y = Float.MAX_VALUE; aabb.upperBound.x = -Float.MAX_VALUE; aabb.upperBound.y = -Float.MAX_VALUE; for (int i = 0; i < m_count; i++) { Vec2 p = m_positionBuffer.data[i]; Vec2.minToOut(aabb.lowerBound, p, aabb.lowerBound); Vec2.maxToOut(aabb.upperBound, p, aabb.upperBound); } aabb.lowerBound.x -= m_particleDiameter; aabb.lowerBound.y -= m_particleDiameter; aabb.upperBound.x += m_particleDiameter; aabb.upperBound.y += m_particleDiameter; m_bodyContactCount = 0; ubccallback.system = this; m_world.queryAABB(ubccallback, aabb); }
private void spawnMouseJoint(Vec2 p) { if (mouseJoint != null) { return; } queryAABB.lowerBound.set(p.x - .001f, p.y - .001f); queryAABB.upperBound.set(p.x + .001f, p.y + .001f); callback.point.set(p); callback.fixture = null; m_world.queryAABB(callback, queryAABB); if (callback.fixture != null) { Body body = callback.fixture.getBody(); MouseJointDef def = new MouseJointDef(); def.bodyA = groundBody; def.bodyB = body; def.collideConnected = true; def.target.set(p); def.maxForce = 1000f * body.getMass(); mouseJoint = (MouseJoint) m_world.createJoint(def); body.setAwake(true); } }
public void solveCollision(TimeStep step) { final AABB aabb = temp; final Vec2 lowerBound = aabb.lowerBound; final Vec2 upperBound = aabb.upperBound; lowerBound.x = Float.MAX_VALUE; lowerBound.y = Float.MAX_VALUE; upperBound.x = -Float.MAX_VALUE; upperBound.y = -Float.MAX_VALUE; for (int i = 0; i < m_count; i++) { final Vec2 v = m_velocityBuffer.data[i]; final Vec2 p1 = m_positionBuffer.data[i]; final float p1x = p1.x; final float p1y = p1.y; final float p2x = p1x + step.dt * v.x; final float p2y = p1y + step.dt * v.y; final float bx = p1x < p2x ? p1x : p2x; final float by = p1y < p2y ? p1y : p2y; lowerBound.x = lowerBound.x < bx ? lowerBound.x : bx; lowerBound.y = lowerBound.y < by ? lowerBound.y : by; final float b1x = p1x > p2x ? p1x : p2x; final float b1y = p1y > p2y ? p1y : p2y; upperBound.x = upperBound.x > b1x ? upperBound.x : b1x; upperBound.y = upperBound.y > b1y ? upperBound.y : b1y; } sccallback.step = step; sccallback.system = this; m_world.queryAABB(sccallback, aabb); }
public void solveCollision(TimeStep step) { final AABB aabb = temp; final Vec2 lowerBound = aabb.lowerBound; final Vec2 upperBound = aabb.upperBound; lowerBound.x = Float.MAX_VALUE; lowerBound.y = Float.MAX_VALUE; upperBound.x = -Float.MAX_VALUE; upperBound.y = -Float.MAX_VALUE; for (int i = 0; i < m_count; i++) { final Vec2 v = m_velocityBuffer.data[i]; final Vec2 p1 = m_positionBuffer.data[i]; final float p1x = p1.x; final float p1y = p1.y; final float p2x = p1x + step.dt * v.x; final float p2y = p1y + step.dt * v.y; final float bx = p1x < p2x ? p1x : p2x; final float by = p1y < p2y ? p1y : p2y; lowerBound.x = lowerBound.x < bx ? lowerBound.x : bx; lowerBound.y = lowerBound.y < by ? lowerBound.y : by; final float b1x = p1x > p2x ? p1x : p2x; final float b1y = p1y > p2y ? p1y : p2y; upperBound.x = upperBound.x > b1x ? upperBound.x : b1x; upperBound.y = upperBound.y > b1y ? upperBound.y : b1y; } sccallback.step = step; sccallback.system = this; m_world.queryAABB(sccallback, aabb); }
/** * @see org.jbox2d.testbed.framework.TestbedTest#step(org.jbox2d.testbed.framework.TestbedSettings) */ @Override public void step(TestbedSettings settings) { super.step(settings); PolyShapesCallback callback = new PolyShapesCallback(getWorld().getPool()); callback.m_circle.m_radius = 2.0f; callback.m_circle.m_p.set(0.0f, 2.1f); callback.m_transform.setIdentity(); callback.debugDraw = getDebugDraw(); AABB aabb = new AABB(); callback.m_circle.computeAABB(aabb, callback.m_transform, 0); getWorld().queryAABB(callback, aabb); Color3f color = new Color3f(0.4f, 0.7f, 0.8f); getDebugDraw().drawCircle(callback.m_circle.m_p, callback.m_circle.m_radius, color); addTextLine("Press 1-5 to drop stuff"); addTextLine("Press 'a' to (de)activate some bodies"); addTextLine("Press 'd' to destroy a body"); addTextLine("Up to 30 bodies in the target circle are highlighted"); }
public int destroyParticlesInShape(Shape shape, Transform xf, boolean callDestructionListener) { dpcallback.init(this, shape, xf, callDestructionListener); shape.computeAABB(temp, xf, 0); m_world.queryAABB(dpcallback, temp); return dpcallback.destroyed; }
public int destroyParticlesInShape(Shape shape, Transform xf, boolean callDestructionListener) { dpcallback.init(this, shape, xf, callDestructionListener); shape.computeAABB(temp, xf, 0); m_world.queryAABB(dpcallback, temp); return dpcallback.destroyed; }
public void updateBodyContacts() { final AABB aabb = temp; aabb.lowerBound.x = Float.MAX_VALUE; aabb.lowerBound.y = Float.MAX_VALUE; aabb.upperBound.x = -Float.MAX_VALUE; aabb.upperBound.y = -Float.MAX_VALUE; for (int i = 0; i < m_count; i++) { Vec2 p = m_positionBuffer.data[i]; Vec2.minToOut(aabb.lowerBound, p, aabb.lowerBound); Vec2.maxToOut(aabb.upperBound, p, aabb.upperBound); } aabb.lowerBound.x -= m_particleDiameter; aabb.lowerBound.y -= m_particleDiameter; aabb.upperBound.x += m_particleDiameter; aabb.upperBound.y += m_particleDiameter; m_bodyContactCount = 0; ubccallback.system = this; m_world.queryAABB(ubccallback, aabb); }
public void updateBodyContacts() { final AABB aabb = temp; aabb.lowerBound.x = Float.MAX_VALUE; aabb.lowerBound.y = Float.MAX_VALUE; aabb.upperBound.x = -Float.MAX_VALUE; aabb.upperBound.y = -Float.MAX_VALUE; for (int i = 0; i < m_count; i++) { Vec2 p = m_positionBuffer.data[i]; Vec2.minToOut(aabb.lowerBound, p, aabb.lowerBound); Vec2.maxToOut(aabb.upperBound, p, aabb.upperBound); } aabb.lowerBound.x -= m_particleDiameter; aabb.lowerBound.y -= m_particleDiameter; aabb.upperBound.x += m_particleDiameter; aabb.upperBound.y += m_particleDiameter; m_bodyContactCount = 0; ubccallback.system = this; m_world.queryAABB(ubccallback, aabb); }
pcallback.init(m_world, pshape, mouseTracerVelocity); pshape.computeAABB(paabb, identity, 0); m_world.queryAABB(pcallback, paabb);
/** * Called for mouse-down * * @param p */ public void mouseDown(Vec2 p) { mouseWorld.set(p); if (mouseJoint != null) { return; } queryAABB.lowerBound.set(p.x - .001f, p.y - .001f); queryAABB.upperBound.set(p.x + .001f, p.y + .001f); callback.point.set(p); callback.fixture = null; m_world.queryAABB(callback, queryAABB); if (callback.fixture != null) { Body body = callback.fixture.getBody(); MouseJointDef def = new MouseJointDef(); def.bodyA = groundBody; def.bodyB = body; def.target.set(p); def.maxForce = 1000f * body.getMass(); mouseJoint = (MouseJoint) m_world.createJoint(def); body.setAwake(true); } }
/** * @see org.jbox2d.testbed.framework.TestbedTest#step(org.jbox2d.testbed.framework.TestbedSettings) */ @Override public void step(TestbedSettings settings) { super.step(settings); PolyShapesCallback callback = new PolyShapesCallback(getWorld().getPool()); callback.m_circle.m_radius = 2.0f; callback.m_circle.m_p.set(0.0f, 2.1f); callback.m_transform.setIdentity(); callback.debugDraw = getDebugDraw(); AABB aabb = new AABB(); callback.m_circle.computeAABB(aabb, callback.m_transform, 0); getWorld().queryAABB(callback, aabb); Color3f color = new Color3f(0.4f, 0.7f, 0.8f); getDebugDraw().drawCircle(callback.m_circle.m_p, callback.m_circle.m_radius, color); addTextLine("Press 1-5 to drop stuff"); addTextLine("Press 'a' to (de)activate some bodies"); addTextLine("Press 'd' to destroy a body"); addTextLine("Up to 30 bodies in the target circle are highlighted"); }