/** * Create a convex hull from the given array of points. The count must be in the range [3, * Settings.maxPolygonVertices]. * * @warning the points may be re-ordered, even if they form a convex polygon. * @warning collinear points are removed. */ public final void set(final Vec2[] vertices, final int count) { set(vertices, count, null, null); }
/** Copy vertices. This assumes the vertices define a convex polygon. It is assumed that the exterior is the the right of each * edge. */ public void set (Vector2[] vertices) { Vec2[] v = new org.jbox2d.common.Vec2[vertices.length]; for (int i = 0; i < v.length; i++) { v[i] = new Vec2(vertices[i].x, vertices[i].y); } shape.set(v, v.length); }
/** Copy vertices from the given float array, taking into account the offset and length. It is assumed the vertices are in x,y * order and define a convex polygon. It is assumed that the exterior is the the right of each edge. */ public void set (float[] vertices, int offset, int len) { Vec2[] v = new org.jbox2d.common.Vec2[len / 2]; for (int i = 0; i < v.length; i++) { v[i] = new Vec2(vertices[i * 2], vertices[i * 2 + 1]); } shape.set(v, v.length); }
private void initReel() { BodyDef reelDef = new BodyDef(); reelDef.type = BodyType.DYNAMIC; reelDef.position = new Vec2(3, 3); reel = world.createBody(reelDef); FixtureDef fixture = new FixtureDef(); fixture.friction = 0.5f; fixture.restitution = 0.4f; fixture.density = 1; int parts = 30; for (int i = 0; i < parts; ++i) { PolygonShape shape = new PolygonShape(); double angle1 = i / (double) parts * 2 * Math.PI; double x1 = 2.7 * Math.cos(angle1); double y1 = 2.7 * Math.sin(angle1); double angle2 = (i + 1) / (double) parts * 2 * Math.PI; double x2 = 2.7 * Math.cos(angle2); double y2 = 2.7 * Math.sin(angle2); double angle = (angle1 + angle2) / 2; double x = 0.01 * Math.cos(angle); double y = 0.01 * Math.sin(angle); shape.set(new Vec2[] { new Vec2((float) x1, (float) y1), new Vec2((float) x2, (float) y2), new Vec2((float) (x2 - x), (float) (y2 - y)), new Vec2((float) (x1 - x), (float) (y1 - y)) }, 4); fixture.shape = shape; reel.createFixture(fixture); } }
Vec2[] vertices = new Vec2[] {new Vec2(-40, -10), new Vec2(40, -10), new Vec2(40, 0), new Vec2(-40, 0)}; shape.set(vertices, 4); ground.createFixture(shape, 0.0f); Vec2[] vertices = new Vec2[] {new Vec2(-40, -1), new Vec2(-20, -1), new Vec2(-20, 20), new Vec2(-40, 30)}; shape.set(vertices, 4); ground.createFixture(shape, 0.0f); Vec2[] vertices = new Vec2[] {new Vec2(20, -1), new Vec2(40, -1), new Vec2(40, 30), new Vec2(20, 20)}; shape.set(vertices, 4); ground.createFixture(shape, 0.0f);
/** * Create a convex hull from the given array of points. The count must be in the range [3, * Settings.maxPolygonVertices]. * * @warning the points may be re-ordered, even if they form a convex polygon. * @warning collinear points are removed. */ public final void set(final Vec2[] vertices, final int count) { set(vertices, count, null, null); }
shape.set(vertices, 6);
Vec2[] vertices = new Vec2[] {new Vec2(-40, -20), new Vec2(40, -20), new Vec2(40, 0), new Vec2(-40, 0)}; shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f); new Vec2[] {new Vec2(-40, -20), new Vec2(-20, -20), new Vec2(-20, 60), new Vec2(-40, 60)}; shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f); shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f); Vec2[] vertices = new Vec2[] {new Vec2(-40, 40), new Vec2(40, 40), new Vec2(40, 60), new Vec2(-40, 60)}; shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f);
@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(); } }
Vec2[] vertices = new Vec2[] {new Vec2(-40, -10), new Vec2(40, -10), new Vec2(40, 0), new Vec2(-40, 0)}; shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f); Vec2[] vertices = {new Vec2(-40, -1), new Vec2(-20, -1), new Vec2(-20, 20), new Vec2(-40, 30)}; shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f); shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f);
shape.set(vertices, 3);
verts[1] = new Vec2(17.52f, 36.69f); verts[2] = new Vec2(17.19f, 36.36f); polyShape.set(verts, 3);