/** Create a loop. This automatically adjusts connectivity. * @param vertices an array of floats of alternating x, y coordinates. * @param offset into the vertices array * @param length after offset (in floats, not float-pairs, so even number) */ public void createLoop (float[] vertices, int offset, int length) { final int vertexCount = length / 2; Vec2[] v = new Vec2[vertexCount]; for (int i = offset, vi = 0; vi < vertexCount; i += 2, vi++) { v[vi] = new Vec2(vertices[i], vertices[i + 1]); } shape.createLoop(v, vertexCount); isLooped = true; }
/** Create a loop. This automatically adjusts connectivity. * @param vertices an array of vertices, these are copied */ public void createLoop (Vector2[] vertices) { Vec2[] v = new Vec2[vertices.length]; for (int i = 0; i < vertices.length; i++) { v[i] = new Vec2(vertices[i].x, vertices[i].y); } shape.createLoop(v, v.length); isLooped = true; }
/** Create a loop. This automatically adjusts connectivity. * @param vertices an array of floats of alternating x, y coordinates. */ public void createLoop (float[] vertices) { Vec2[] v = new Vec2[vertices.length / 2]; for (int i = 0, vi = 0; i < vertices.length; i += 2, vi++) { v[vi] = new Vec2(vertices[i], vertices[i + 1]); } shape.createLoop(v, v.length); isLooped = true; }
@Override public void initTest(boolean deserialized) { { BodyDef bd = new BodyDef(); Body ground = m_world.createBody(bd); ChainShape shape = new ChainShape(); Vec2[] vertices = new Vec2[] {new Vec2(-20, 0), new Vec2(20, 0), new Vec2(20, 40), new Vec2(-20, 40)}; shape.createLoop(vertices, 4); ground.createFixture(shape, 0.0f); } m_world.setParticleRadius(0.15f); m_world.setParticleDamping(0.2f); { PolygonShape shape = new PolygonShape(); shape.setAsBox(8, 10, new Vec2(-12, 10.1f), 0); ParticleGroupDef pd = new ParticleGroupDef(); pd.shape = shape; m_world.createParticleGroup(pd); } }
ChainShape weird = new ChainShape(); weird.createLoop( new float[]{vertice1x, vertice1y, vertice2x, ...});
private void buildRoom() { Vector2[] roomCorners = new Vector2[]{new Vector2(0f, 0f), new Vector2(0f, ROOM_HEIGHT), new Vector2(ROOM_WIDTH, ROOM_HEIGHT), new Vector2(ROOM_WIDTH, 0f)}; ChainShape roomShape = new ChainShape(); try { roomShape.createLoop(roomCorners); BodyDef roomDef = new BodyDef(); roomDef.type = BodyDef.BodyType.StaticBody; Body room = world.createBody(roomDef); room.createFixture(roomShape, 0); } finally { roomShape.dispose(); } }
vs[3] = new Vec2(-1.0f, 5.0f); ChainShape shape = new ChainShape(); shape.createLoop(vs, 4); ground.createFixture(shape, 0.0f); vs[9] = new Vec2(-6.0f, 0.0f); ChainShape shape = new ChainShape(); shape.createLoop(vs, 10); ground.createFixture(shape, 0.0f);
final Vec2[] vertices = new Vec2[] {new Vec2(-20, 0), new Vec2(20, 0), new Vec2(20, 40), new Vec2(-20, 40)}; shape.createLoop(vertices, 4); ground.createFixture(shape, 0.0f);
vs[3] = new Vec2(-1.0f, 5.0f); ChainShape shape = new ChainShape(); shape.createLoop(vs, 4); ground.createFixture(shape, 0.0f); vs[9] = new Vec2(-6.0f, 0.0f); ChainShape shape = new ChainShape(); shape.createLoop(vs, 10); ground.createFixture(shape, 0.0f);