/** * Erzeugt aus einem PolylineMapObject ein ChainShape. * * @param polyObject das MapObject * @return die entsprechende Form */ public static ChainShape createPolyline(PolylineMapObject polyObject) { float[] vertices = polyObject.getPolyline().getTransformedVertices(); Vector2[] worldVertices = new Vector2[vertices.length / 2]; for (int i = 0; i < vertices.length / 2; i++) { worldVertices[i] = new Vector2(); worldVertices[i].x = vertices[i * 2] * Physics.MPP; worldVertices[i].y = vertices[i * 2 + 1] * Physics.MPP; } ChainShape chain = new ChainShape(); chain.createChain(worldVertices); return chain; }
@Override protected Body createBody(final Box2DService box2d) { final BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.StaticBody; bodyDef.fixedRotation = true; final ChainShape shape = new ChainShape(); final float w = Box2DUtil.WIDTH * 2f / 5f, h = Box2DUtil.HEIGHT * 2f / 5f; shape.createLoop(new float[] { -w, -h, -w, h, w, h, w, -h }); final FixtureDef fixtureDef = new FixtureDef(); fixtureDef.restitution = 0.9f; fixtureDef.friction = 0.2f; fixtureDef.shape = shape; fixtureDef.filter.categoryBits = Box2DUtil.CAT_BOUNDS; fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK; final Body body = box2d.getWorld().createBody(bodyDef); body.createFixture(fixtureDef); return body; }
private static Shape getPolyline(PolylineMapObject object) { float[] vertices = object.getPolyline().getTransformedVertices(); Vector2[] worldVertices = new Vector2[vertices.length / 2]; for(int i = 0; i < vertices.length / 2; ++i){ Vector2 vector = new Vector2(); vector.x = vertices[i * 2]; vector.y = vertices[i * 2 + 1]; worldVertices[i] = Pixels.toMeters(new Vector2(vector)); } ChainShape shape = new ChainShape(); shape.createChain(worldVertices); return shape; }
public void create(){ init = true; bdef.type = BodyType.StaticBody; bdef.position.set(x, y); ChainShape cs = new ChainShape(); Vector2[] v = new Vector2[5]; v[0] = new Vector2(-TILE_SIZE / 2 / PPM, -TILE_SIZE / 2 / PPM); v[1] = new Vector2(-TILE_SIZE / 2 / PPM, TILE_SIZE / 2 / PPM); v[2] = new Vector2(TILE_SIZE / 2 / PPM, TILE_SIZE / 2 / PPM); v[3] = new Vector2(TILE_SIZE / 2 / PPM, -TILE_SIZE / 2 / PPM); v[4] = new Vector2(-Vars.TILE_SIZE / 2 / Vars.PPM, -Vars.TILE_SIZE / 2 / Vars.PPM); cs.createChain(v); fdef.friction = .25f; fdef.shape = cs; fdef.filter.categoryBits = Vars.BIT_GROUND; fdef.filter.maskBits = Vars.BIT_LAYER1 | Vars.BIT_PLAYER_LAYER | Vars.BIT_LAYER3 | Vars.BIT_BATTLE; fdef.isSensor = false; body = world.createBody(bdef); body.createFixture(fdef).setUserData("ground"); body.setUserData(this); }
private void createPhysicsWorld() { world = new World(new Vector2(0, 0), true); float halfWidth = viewportWidth / 2f; ChainShape chainShape = new ChainShape(); chainShape.createLoop(new Vector2[] { new Vector2(-halfWidth, 0f), new Vector2(halfWidth, 0f), new Vector2(halfWidth, viewportHeight), new Vector2(-halfWidth, viewportHeight) }); BodyDef chainBodyDef = new BodyDef(); chainBodyDef.type = BodyType.StaticBody; groundBody = world.createBody(chainBodyDef); groundBody.createFixture(chainShape, 0); chainShape.dispose(); createBoxes(); }
public Body createScreenBox(final Rectangle rect) { ChainShape shape = new ChainShape(); shape.createLoop(new Vector2[]{ new Vector2(rect.x, rect.y).scl(1 / Box2dObject.RADIO), new Vector2(rect.x + rect.width, rect.y).scl(1 / Box2dObject.RADIO), new Vector2(rect.x + rect.width, rect.y + rect.height).scl(1 / Box2dObject.RADIO), new Vector2(rect.x, rect.y + rect.height).scl(1 / Box2dObject.RADIO), }); final FixtureDef fixtureDef = new FixtureDef(); fixtureDef.isSensor = false; fixtureDef.shape = shape; BodyDef bodyDef = new BodyDef(); bodyDef.bullet = false; bodyDef.type = BodyType.StaticBody; bodyDef.linearDamping = 0f; Body body = PhysicalWorld.WORLD.createBody(bodyDef); body.createFixture(fixtureDef); shape.dispose(); return body; }
/** * Creates the shape. */ @Override public void createShape() { shape = new ChainShape(); fixtureDef.shape = shape; int length = _vertices.size; Vector2[] v = new Vector2[length]; for(int i = 0; i < length; i++) { v[i] = new Vector2(_vertices.get(i)[0]/B2FlxB.RATIO, _vertices.get(i)[1]/B2FlxB.RATIO); } if(_loop) ((ChainShape)shape).createLoop(v); else { ((ChainShape)shape).createChain(v); // Add ghost edges if(_prevVertex != null) ((ChainShape)shape).setPrevVertex(_prevVertex); if(_nextVertex != null) ((ChainShape)shape).setNextVertex(_nextVertex); } }
private static Shape getPolylineShape(MapObject object) { Polyline polyline = ((PolylineMapObject)object).getPolyline(); float[] vertices = polyline.getTransformedVertices(); for (int i = 0; i < vertices.length; i++) { vertices[i] *= MainCamera.getInstance().getTileMapScale(); } ChainShape shape = new ChainShape(); shape.createChain(vertices); return shape; }
@Override public void drawBorder(Border border, Batch batch, Color parentColor) { Shape shape = border.getShape(); if (shape instanceof ChainShape) { Graphics.drawChain(border.getVertexes(), new Color(0.1f, 1, 0.5f, 0.75f), 0.2f); } }
/** * Creates box2d bodies for all non-null tiles * in the specified layer and assigns the specified * category bits. * * @param layer the layer being read * @param bits category bits assigned to fixtures */ private void createBlocks(TiledMapTileLayer layer, short bits) { // tile size float ts = layer.getTileWidth(); // go through all cells in layer for (int row = 0; row < layer.getHeight(); row++) { for (int col = 0; col < layer.getWidth(); col++) { // get cell Cell cell = layer.getCell(col, row); // check that there is a cell if (cell == null) continue; if (cell.getTile() == null) continue; // create body from cell BodyDef bdef = new BodyDef(); bdef.type = BodyType.StaticBody; bdef.position.set((col + 0.5f) * ts / PPM, (row + 0.5f) * ts / PPM); ChainShape cs = new ChainShape(); Vector2[] v = new Vector2[3]; v[0] = new Vector2(-ts / 2 / PPM, -ts / 2 / PPM); v[1] = new Vector2(-ts / 2 / PPM, ts / 2 / PPM); v[2] = new Vector2(ts / 2 / PPM, ts / 2 / PPM); cs.createChain(v); FixtureDef fd = new FixtureDef(); fd.friction = 0; fd.shape = cs; fd.filter.categoryBits = bits; fd.filter.maskBits = B2DVars.BIT_PLAYER; world.createBody(bdef).createFixture(fd); cs.dispose(); } } }
public Bounds(World world) { BodyDef bodyDef = new BodyDef(); FixtureDef fixtureDef = new FixtureDef(); float groundPos = -2.5f; float topPos = 7.5f; // body definition bodyDef.type = BodyType.StaticBody; bodyDef.position.set(0, groundPos); // ground shape ChainShape groundShapeBottom = new ChainShape(); ChainShape groundShapeTop = new ChainShape(); /* groundShape.createChain(new Vector2[] {new Vector2(-10, groundPos), new Vector2(10,groundPos), new Vector2(10, 8.35f), new Vector2(-10,8.35f), new Vector2(-10,groundPos)}); */ groundShapeBottom.createChain(new Vector2[] {new Vector2(-10, groundPos), new Vector2(10,groundPos)}); groundShapeTop.createChain(new Vector2[] {new Vector2(-10, topPos), new Vector2(10,topPos)}); // fixture definition fixtureDef.shape = groundShapeBottom; body = world.createBody(bodyDef); fixture = body.createFixture(fixtureDef); // fixture definition fixtureDef.shape = groundShapeTop; body = world.createBody(bodyDef); fixture = body.createFixture(fixtureDef); groundShapeTop.dispose(); groundShapeBottom.dispose(); }
/** * * @param world * @param polylineObject * @param density * @param friction * @param restitution */ private void createPolyline(World world, PolylineMapObject polylineObject, float density, float friction, float restitution){ Polyline polyline = polylineObject.getPolyline(); ChainShape shape = new ChainShape(); float[] vertices = polyline.getTransformedVertices(); float[] worldVertices = new float[vertices.length]; for(int i = 0; i < vertices.length; i++){ worldVertices[i] = vertices[i] / SupaBox.PPM; } shape.createChain(worldVertices); BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.StaticBody; Body body = world.createBody(bodyDef); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; fixtureDef.density = density; fixtureDef.friction = friction; fixtureDef.restitution = restitution; body.createFixture(fixtureDef); shape.dispose(); }
private Shape getPolyline(PolylineMapObject polylineObject) { float[] vertices = polylineObject.getPolyline().getTransformedVertices(); Vector2[] worldVertices = new Vector2[vertices.length / 2]; for (int i = 0; i < vertices.length / 2; ++i) { worldVertices[i] = new Vector2(); worldVertices[i].x = vertices[i * 2] / GameWorld.units; worldVertices[i].y = vertices[i * 2 + 1] / GameWorld.units; } ChainShape chain = new ChainShape(); chain.createChain(worldVertices); return chain; }
private Shape getPolyline(PolylineMapObject polylineObject) { float[] vertices = polylineObject.getPolyline().getTransformedVertices(); Vector2[] worldVertices = new Vector2[vertices.length / 2]; for (int i = 0; i < vertices.length / 2; ++i) { worldVertices[i] = new Vector2(); worldVertices[i].x = vertices[i * 2] / units; worldVertices[i].y = vertices[i * 2 + 1] / units; } ChainShape chain = new ChainShape(); chain.createChain(worldVertices); return chain; }
public Bounds (World world, float hWidth, float hHeight) { bodyDef = new BodyDef(); bodyDef.type = BodyType.StaticBody; body = world.createBody(bodyDef); ChainShape shape = new ChainShape(); Vector2[] vertices = {new Vector2(-hWidth, -hHeight), new Vector2(-hWidth, hHeight), new Vector2(hWidth, hHeight), new Vector2(hWidth, -hHeight)}; shape.createLoop(vertices); body.createFixture(shape, 0); shape.dispose(); body.setUserData("bounds"); }
public Piece (float radius, BodyType type, boolean isComposite) { ChainShape shape = new ChainShape(); // ArrayList<Vector2> vectors = createArc(0, 0, radius, 180, 360, 0.07f, false); // vectors.add(new Vector2(vectors.get(vectors.size() - 1).x - 1, vectors.get(vectors.size() - 1).y)); // vectors.add(0, new Vector2(vectors.get(0).x+1, vectors.get(0).y)); // vectors.addAll(createArc(0, 0, radius-1, 0, -180, 0.07f, true)); // Vector2[] finalVectors = new Vector2[vectors.size()]; // ((ChainShape)shape).createLoop(vectors.toArray(finalVectors)); // vectors.clear(); // finalVectors = null; this.shape = shape; this.pos = new Vector2(); this.type = type; }
/** Chain Shape */ public Piece (BodyType type, Vector2... pos) { this.shape = new ChainShape(); ((ChainShape)this.shape).createLoop(pos); this.pos = null; this.type = type; }
public FixtureSerializer(RubeScene scene, Json json) { this.scene = scene; chainShapeSerializer = new ChainShapeSerializer(); json.setSerializer(PolygonShape.class, new PolygonShapeSerializer()); json.setSerializer(EdgeShape.class, new EdgeShapeSerializer()); json.setSerializer(CircleShape.class, new CircleShapeSerializer()); json.setSerializer(ChainShape.class, chainShapeSerializer); }
private Shape getPolyline(PolylineMapObject polylineObject) { float[] vertices = polylineObject.getPolyline().getVertices(); // Changed Vector2[] worldVertices = new Vector2[vertices.length / 2]; for (int i = 0; i < vertices.length / 2; ++i) { worldVertices[i] = new Vector2(); worldVertices[i].x = vertices[i * 2] * m_units; worldVertices[i].y = vertices[i * 2 + 1] * m_units; } ChainShape chain = new ChainShape(); chain.createChain(worldVertices); return chain; }
public static Body randomCircleBody(World world,Vector2 position,float dX,float dY,float minY,float maxY,int randomness){ //TODO: Should use a logger class here if (360%dX != 0) System.out.println("Creating random planet: dx must be multiple of 360"); assert(360%dX == 0); // must be multiple of 360 int steps = (int) (360 / dX)-1; Random rand = new Random(); float prevElevation = (minY + maxY) / 2; boolean randomModeToggle = false; ArrayList<Vector2> verts = new ArrayList<Vector2>(); for (int x = 1; x < steps; x++){ Vector2 h = new Vector2(); if (randomModeToggle) h.set(0,rand.nextFloat() * (maxY - minY) + minY); else h.set(0,getRandomElevation(prevElevation,dY,minY,maxY)); if (randomness!=0){ if (x%randomness == 0){ randomModeToggle = !randomModeToggle; } } prevElevation = h.y; h.rotate(x * dX); verts.add(h); } ChainShape shape = new ChainShape(); float[] fVerts = new float[verts.size() * 2]; for (int x=0; x < verts.size(); x++){ fVerts[x*2] = verts.get(x).x; fVerts[(x*2) + 1] = verts.get(x).y; } shape.createLoop(fVerts); FixtureDef fd = new FixtureDef(); fd.density = 10; fd.friction = 10; fd.restitution = 0f; fd.shape = shape; BodyDef bd = new BodyDef(); bd.type = BodyDef.BodyType.StaticBody; bd.position.set(position); Body body = world.createBody(bd); body.createFixture(fd); return body; }
public PhysixFixtureDef shapePolyline(List<Point> points) { ChainShape chainShape = new ChainShape(); chainShape.createChain(system.toBox2D(points)); this.shape = chainShape; return this; }
public static Shape createChainShape(Vector2[] vertices) { ChainShape chainShape = new ChainShape(); chainShape.createChain(vertices); return chainShape; }
public static float ComputeSubmergedArea(ChainShape shape, Vector2 normal, float offset, Transform xf, Vector2 c) { return 0; }
@SuppressWarnings("rawtypes") @Override public Fixture read(Json json, JsonValue jsonData, Class type) { if(body == null) return null; json.setIgnoreUnknownFields(true); FixtureDef defaults = RubeDefaults.Fixture.definition; FixtureDef def = new FixtureDef(); json.readFields(def, jsonData); def.friction = json.readValue("friction", float.class, defaults.friction, jsonData); def.density = json.readValue("density", float.class, defaults.density, jsonData); def.restitution = json.readValue("restitution", float.class, defaults.restitution, jsonData); def.isSensor = json.readValue("sensor", boolean.class, defaults.isSensor, jsonData); def.filter.maskBits = json.readValue("filter-maskBits", short.class, defaults.filter.maskBits, jsonData); def.filter.categoryBits = json.readValue("filter-categoryBits", short.class, defaults.filter.categoryBits, jsonData); def.filter.groupIndex = json.readValue("filter-groupIndex", short.class, defaults.filter.groupIndex, jsonData); CircleShape circle = json.readValue("circle", CircleShape.class, jsonData); if(circle != null) { def.shape = circle; } else { EdgeShape edge = json.readValue("edge", EdgeShape.class, jsonData); if(edge != null) { def.shape = edge; } else { chainShapeSerializer.setReadLoop(false); ChainShape chain = json.readValue("chain", ChainShape.class, jsonData); if(chain != null) { def.shape = chain; } else { chainShapeSerializer.setReadLoop(true); chain = json.readValue("loop", ChainShape.class, jsonData); if(chain != null) { def.shape = chain; } else { PolygonShape polygon = json.readValue("polygon", PolygonShape.class, jsonData); if(polygon != null) { def.shape = polygon; } else { edge = json.readValue("polygon", EdgeShape.class, jsonData); if(edge != null) { def.shape = edge; } } } } } } Fixture fixture = body.createFixture(def); def.shape.dispose(); scene.parseCustomProperties(json, fixture, jsonData); String name = json.readValue("name", String.class, jsonData); if (name != null) { scene.putNamed(name, fixture); } return fixture; }