public void MoveAABB(AABB aabb) { Vec2 d = new Vec2(); d.x = MathUtils.randomFloat(rand, -0.5f, 0.5f); d.y = MathUtils.randomFloat(rand, -0.5f, 0.5f); // d.x = 2.0f; // d.y = 0.0f; aabb.lowerBound.addLocal(d); aabb.upperBound.addLocal(d); Vec2 c0 = aabb.lowerBound.add(aabb.upperBound).mulLocal(.5f); Vec2 min = new Vec2(); min.set(-worldExtent, 0.0f); Vec2 max = new Vec2(); max.set(worldExtent, 2.0f * worldExtent); Vec2 c = MathUtils.clamp(c0, min, max); aabb.lowerBound.addLocal(c.sub(c0)); aabb.upperBound.addLocal(c.sub(c0)); }
bd2.type = BodyType.DYNAMIC; bd1.position = m_offset; bd2.position = p4.add(m_offset); djd.frequencyHz = 10.0f; djd.initialize(body1, body2, p2.add(m_offset), p5.add(m_offset)); getWorld().createJoint(djd); djd.initialize(body1, body2, p3.add(m_offset), p4.add(m_offset)); getWorld().createJoint(djd); djd.initialize(body1, m_wheel, p3.add(m_offset), wheelAnchor.add(m_offset)); getWorld().createJoint(djd); djd.initialize(body2, m_wheel, p6.add(m_offset), wheelAnchor.add(m_offset)); getWorld().createJoint(djd); rjd.initialize(body2, m_chassis, p4.add(m_offset)); getWorld().createJoint(rjd);
@Override public void step(TestbedSettings settings) { boolean advanceRay = settings.pause == false || settings.singleStep; super.step(settings); addTextLine("Press 1-5 to drop stuff"); float L = 25.0f; Vec2 point1 = new Vec2(0.0f, 10.0f); Vec2 d = new Vec2(L * MathUtils.cos(m_angle), -L * MathUtils.abs(MathUtils.sin(m_angle))); Vec2 point2 = point1.add(d); callback.m_fixture = null; getWorld().raycast(callback, point1, point2); if (callback.m_fixture != null) { getDebugDraw().drawPoint(callback.m_point, 5.0f, new Color3f(0.4f, 0.9f, 0.4f)); getDebugDraw().drawSegment(point1, callback.m_point, new Color3f(0.8f, 0.8f, 0.8f)); Vec2 head = callback.m_normal.mul(.5f).addLocal(callback.m_point); getDebugDraw().drawSegment(callback.m_point, head, new Color3f(0.9f, 0.9f, 0.4f)); } else { getDebugDraw().drawSegment(point1, point2, new Color3f(0.8f, 0.8f, 0.8f)); } if (advanceRay) { m_angle += 0.25f * MathUtils.PI / 180.0f; } }
void Break() { // Create two bodies from one. Body body1 = m_piece1.getBody(); Vec2 center = body1.getWorldCenter(); body1.destroyFixture(m_piece2); m_piece2 = null; BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position = body1.getPosition(); bd.angle = body1.getAngle(); Body body2 = getWorld().createBody(bd); m_piece2 = body2.createFixture(m_shape2, 1.0f); // Compute consistent velocities for new bodies based on // cached velocity. Vec2 center1 = body1.getWorldCenter(); Vec2 center2 = body2.getWorldCenter(); Vec2 velocity1 = m_velocity.add(Vec2.cross(m_angularVelocity, center1.sub(center))); Vec2 velocity2 = m_velocity.add(Vec2.cross(m_angularVelocity, center2.sub(center))); body1.setAngularVelocity(m_angularVelocity); body1.setLinearVelocity(velocity1); body2.setAngularVelocity(m_angularVelocity); body2.setLinearVelocity(velocity2); }
@Override public synchronized void step(TestbedSettings settings) { super.step(settings); shape.set(m_points, m_count); addTextLine("Press g to generate a new random convex hull"); getDebugDraw().drawPolygon(shape.m_vertices, shape.m_count, color); for (int i = 0; i < m_count; ++i) { getDebugDraw().drawPoint(m_points[i], 2.0f, color2); getDebugDraw().drawString(m_points[i].add(new Vec2(0.05f, 0.05f)), i + "", Color3f.WHITE); } assert (shape.validate()); if (m_auto) { generate(); } }
public void MoveAABB(AABB aabb) { Vec2 d = new Vec2(); d.x = MathUtils.randomFloat(rand, -0.5f, 0.5f); d.y = MathUtils.randomFloat(rand, -0.5f, 0.5f); // d.x = 2.0f; // d.y = 0.0f; aabb.lowerBound.addLocal(d); aabb.upperBound.addLocal(d); Vec2 c0 = aabb.lowerBound.add(aabb.upperBound).mulLocal(.5f); Vec2 min = new Vec2(); min.set(-worldExtent, 0.0f); Vec2 max = new Vec2(); max.set(worldExtent, 2.0f * worldExtent); Vec2 c = MathUtils.clamp(c0, min, max); aabb.lowerBound.addLocal(c.sub(c0)); aabb.upperBound.addLocal(c.sub(c0)); }
@Override public void step(TestbedSettings settings) { super.step(settings); addTextLine("Use 'wasd' to move, 'e' and 's' drift."); if (getModel().getKeys()['w']) { Vec2 f = m_body.getWorldVector(new Vec2(0.0f, -30.0f)); Vec2 p = m_body.getWorldPoint(m_body.getLocalCenter().add(new Vec2(0.0f, 2.0f))); m_body.applyForce(f, p); } else if (getModel().getKeys()['q']) { Vec2 f = m_body.getWorldVector(new Vec2(0.0f, -30.0f)); Vec2 p = m_body.getWorldPoint(m_body.getLocalCenter().add(new Vec2(-.2f, 0f))); m_body.applyForce(f, p); } else if (getModel().getKeys()['e']) { Vec2 f = m_body.getWorldVector(new Vec2(0.0f, -30.0f)); Vec2 p = m_body.getWorldPoint(m_body.getLocalCenter().add(new Vec2(.2f, 0f))); m_body.applyForce(f, p); } else if (getModel().getKeys()['s']) { Vec2 f = m_body.getWorldVector(new Vec2(0.0f, 30.0f)); Vec2 p = m_body.getWorldCenter(); m_body.applyForce(f, p); } if (getModel().getKeys()['a']) { m_body.applyTorque(20.0f); } if (getModel().getKeys()['d']) { m_body.applyTorque(-20.0f); } }
@Override public void step(TestbedSettings settings) { boolean advanceRay = settings.pause == false || settings.singleStep; super.step(settings); addTextLine("Press 1-5 to drop stuff"); float L = 25.0f; Vec2 point1 = new Vec2(0.0f, 10.0f); Vec2 d = new Vec2(L * MathUtils.cos(m_angle), -L * MathUtils.abs(MathUtils.sin(m_angle))); Vec2 point2 = point1.add(d); callback.m_fixture = null; getWorld().raycast(callback, point1, point2); if (callback.m_fixture != null) { getDebugDraw().drawPoint(callback.m_point, 5.0f, new Color3f(0.4f, 0.9f, 0.4f)); getDebugDraw().drawSegment(point1, callback.m_point, new Color3f(0.8f, 0.8f, 0.8f)); Vec2 head = callback.m_normal.mul(.5f).addLocal(callback.m_point); getDebugDraw().drawSegment(callback.m_point, head, new Color3f(0.9f, 0.9f, 0.4f)); } else { getDebugDraw().drawSegment(point1, point2, new Color3f(0.8f, 0.8f, 0.8f)); } if (advanceRay) { m_angle += 0.25f * MathUtils.PI / 180.0f; } }
bd2.type = BodyType.DYNAMIC; bd1.position = m_offset; bd2.position = p4.add(m_offset); djd.frequencyHz = 10.0f; djd.initialize(body1, body2, p2.add(m_offset), p5.add(m_offset)); getWorld().createJoint(djd); djd.initialize(body1, body2, p3.add(m_offset), p4.add(m_offset)); getWorld().createJoint(djd); djd.initialize(body1, m_wheel, p3.add(m_offset), wheelAnchor.add(m_offset)); getWorld().createJoint(djd); djd.initialize(body2, m_wheel, p6.add(m_offset), wheelAnchor.add(m_offset)); getWorld().createJoint(djd); rjd.initialize(body2, m_chassis, p4.add(m_offset)); getWorld().createJoint(rjd);
void Break() { // Create two bodies from one. Body body1 = m_piece1.getBody(); Vec2 center = body1.getWorldCenter(); body1.destroyFixture(m_piece2); m_piece2 = null; BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position = body1.getPosition(); bd.angle = body1.getAngle(); Body body2 = getWorld().createBody(bd); m_piece2 = body2.createFixture(m_shape2, 1.0f); // Compute consistent velocities for new bodies based on // cached velocity. Vec2 center1 = body1.getWorldCenter(); Vec2 center2 = body2.getWorldCenter(); Vec2 velocity1 = m_velocity.add(Vec2.cross(m_angularVelocity, center1.sub(center))); Vec2 velocity2 = m_velocity.add(Vec2.cross(m_angularVelocity, center2.sub(center))); body1.setAngularVelocity(m_angularVelocity); body1.setLinearVelocity(velocity1); body2.setAngularVelocity(m_angularVelocity); body2.setLinearVelocity(velocity2); }
@Override public synchronized void step(TestbedSettings settings) { super.step(settings); shape.set(m_points, count); addTextLine("Press g to generate a new random convex hull"); getDebugDraw().drawPolygon(shape.m_vertices, shape.m_count, color); for (int i = 0; i < count; ++i) { getDebugDraw().drawPoint(m_points[i], 2.0f, color2); getDebugDraw().drawString(m_points[i].add(new Vec2(0.05f, 0.05f)), i + "", Color3f.WHITE); } assert (shape.validate()); if (m_auto) { generate(); } }
@Override public void step(TestbedSettings settings) { super.step(settings); addTextLine("Use 'wasd' to move, 'e' and 's' drift."); if (getModel().getKeys()['w']) { Vec2 f = m_body.getWorldVector(new Vec2(0.0f, -30.0f)); Vec2 p = m_body.getWorldPoint(m_body.getLocalCenter().add(new Vec2(0.0f, 2.0f))); m_body.applyForce(f, p); } else if (getModel().getKeys()['q']) { Vec2 f = m_body.getWorldVector(new Vec2(0.0f, -30.0f)); Vec2 p = m_body.getWorldPoint(m_body.getLocalCenter().add(new Vec2(-.2f, 0f))); m_body.applyForce(f, p); } else if (getModel().getKeys()['e']) { Vec2 f = m_body.getWorldVector(new Vec2(0.0f, -30.0f)); Vec2 p = m_body.getWorldPoint(m_body.getLocalCenter().add(new Vec2(.2f, 0f))); m_body.applyForce(f, p); } else if (getModel().getKeys()['s']) { Vec2 f = m_body.getWorldVector(new Vec2(0.0f, 30.0f)); Vec2 p = m_body.getWorldCenter(); m_body.applyForce(f, p); } if (getModel().getKeys()['a']) { m_body.applyTorque(20.0f); } if (getModel().getKeys()['d']) { m_body.applyTorque(-20.0f); } }