Body createBox (BodyType type, float width, float height, float density) { BodyDef def = new BodyDef(); def.type = type; Body box = world.createBody(def); PolygonShape poly = new PolygonShape(); poly.setAsBox(width, height); box.createFixture(poly, density); poly.dispose(); return box; }
-0.7122401f, 0.110677004f, -0.6419276f, 0.13151026f, -0.49869835f, 0.08984375f, -0.3190109f}; PolygonShape shape = new PolygonShape(); shape.set(vertices); PolygonShape groundPoly = new PolygonShape(); groundPoly.setAsBox(50, 1); fixtureDef.filter.groupIndex = 0; groundBody.createFixture(fixtureDef); groundPoly.dispose();
} else if (fixture.getType() == Type.Polygon) { PolygonShape shape = (PolygonShape)fixture.getShape(); int vertexCount = shape.getVertexCount(); shape.getVertex(0, vertices[0]); lower.set(transform.mul(vertices[0])); upper.set(lower); for (int i = 1; i < vertexCount; i++) { shape.getVertex(i, vertices[i]); transform.mul(vertices[i]); lower.x = Math.min(lower.x, vertices[i].x);
Body body = world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(10.0f, 0.5f); Body body = world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.5f); body.createFixture(shape, 20.0f);
PolygonShape shape = new PolygonShape(); shape.set(vs); shape.dispose();
private Shape getPolygon(PolygonMapObject polygonObject) { PolygonShape polygon = new PolygonShape(); float[] vertices = polygonObject.getPolygon().getTransformedVertices(); float[] worldVertices = new float[vertices.length]; for (int i = 0; i < vertices.length; ++i) { worldVertices[i] = vertices[i] / units; } polygon.set(worldVertices); return polygon; }
/** Returns the shape of this fixture */ public Shape getShape () { if (shape == null) { org.jbox2d.collision.shapes.Shape shape2 = fixture.getShape(); ShapeType type = shape2.getType(); if (type == ShapeType.CHAIN) shape = new ChainShape((org.jbox2d.collision.shapes.ChainShape)shape2); if (type == ShapeType.CIRCLE) shape = new CircleShape((org.jbox2d.collision.shapes.CircleShape)shape2); if (type == ShapeType.EDGE) shape = new EdgeShape((org.jbox2d.collision.shapes.EdgeShape)shape2); if (type == ShapeType.POLYGON) shape = new PolygonShape((org.jbox2d.collision.shapes.PolygonShape)shape2); } return shape; }
/** Copy vertices from the given float array. 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) { set(vertices, 0, vertices.length); }
public void dispose () { bodyMap.clear(); shape.dispose(); }
PolygonShape shape = new PolygonShape(); shape.setAsBox(2, 5);
PolygonShape head = new PolygonShape(); Vector2[] vertice = new Vector2[4]; vertice[0] = new Vector2(-5, 8).scl(1 / MarioBros.PPM); vertice[2] = new Vector2(-3, 3).scl(1 / MarioBros.PPM); vertice[3] = new Vector2(3, 3).scl(1 / MarioBros.PPM); head.set(vertice);
/** Returns the shape of this fixture */ public Shape getShape () { if (shape == null) { long shapeAddr = jniGetShape(addr); if (shapeAddr == 0) throw new GdxRuntimeException("Null shape address!"); int type = Shape.jniGetType(shapeAddr); switch (type) { case 0: shape = new CircleShape(shapeAddr); break; case 1: shape = new EdgeShape(shapeAddr); break; case 2: shape = new PolygonShape(shapeAddr); break; case 3: shape = new ChainShape(shapeAddr); break; default: throw new GdxRuntimeException("Unknown shape type!"); } } return shape; }
public static Body createFixture(World world, FixtureDef fixtureDef, BodyType type, List<Vector2> nodes, Shape shape, short maskBits, short categoryBits, short groupIndex) { Vector2[][] verts = Clipper.polygonize(Polygonizer.BAYAZIT, nodes.toArray(new Vector2[nodes.size()])); if(verts == null){ Log.log("GDXPolygon.createFixture", "Can't create fixture(s),"+ " verts null. Did a vertex cross the line segment between"+ " two other vertices (e.g. hourglass)?"); return null; } BodyDef bd = new BodyDef(); bd.type = type; Body body = world.createBody(bd); for(Vector2[] vertSet : verts){ if(shape instanceof PolygonShape) ((PolygonShape)shape).set(vertSet); fixtureDef.shape = shape; Fixture fixture = body.createFixture(fixtureDef); setFilterData(fixture, maskBits, categoryBits, groupIndex); } return body; }
@Override public void dispose() { debugRenderer.dispose(); batch.dispose(); square.dispose(); circle.dispose(); world.dispose(); }
private void createBoxes () { // next we create 50 boxes at random locations above the ground // body. First we create a nice polygon representing a box 2 meters // wide and high. PolygonShape boxPoly = new PolygonShape(); boxPoly.setAsBox(1, 1); // next we create the 50 box bodies using the PolygonShape we just // defined. This process is similar to the one we used for the ground // body. Note that we reuse the polygon for each body fixture. for (int i = 0; i < 20; i++) { // Create the BodyDef, set a random position above the // ground and create a new body BodyDef boxBodyDef = new BodyDef(); boxBodyDef.type = BodyType.DynamicBody; boxBodyDef.position.x = -24 + (float)(Math.random() * 48); boxBodyDef.position.y = 10 + (float)(Math.random() * 100); Body boxBody = world.createBody(boxBodyDef); boxBody.createFixture(boxPoly, 1); // add the box to our list of boxes boxes.add(boxBody); } // we are done, all that's left is disposing the boxPoly boxPoly.dispose(); }
PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.125f); shape.dispose(); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.125f); shape.dispose(); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.125f); shape.dispose(); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.125f); shape.dispose(); vertices[2] = new Vector2(0, 1.5f); PolygonShape shape = new PolygonShape(); shape.set(vertices); body.createFixture(fd); shape.dispose();
PolygonShape shape = new PolygonShape(); shape.setAsBox(a, a);
PolygonShape head = new PolygonShape(); Vector2[] vertice = new Vector2[4]; vertice[0] = new Vector2(-5, 8).scl(1 / MarioBros.PPM); vertice[2] = new Vector2(-3, 3).scl(1 / MarioBros.PPM); vertice[3] = new Vector2(3, 3).scl(1 / MarioBros.PPM); head.set(vertice);
public Body createFixture(World world, FixtureDef fixtureDef, BodyType type) { return PhysicsHelper.createFixture(world, fixtureDef, type, nodes, new PolygonShape(), (short)-1, (short)1, (short)0); }
shape.set(polygon); FixtureDef fd = params == null ? DEFAULT_FIXTURE : params; fd.shape = shape;