@Override public Shape clone() { ChainShape clone = new ChainShape(); clone.createChain(m_vertices, m_count); clone.m_prevVertex.set(m_prevVertex); clone.m_nextVertex.set(m_nextVertex); clone.m_hasPrevVertex = m_hasPrevVertex; clone.m_hasNextVertex = m_hasNextVertex; return clone; }
@Override public float computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut) { final EdgeShape edge = pool0; getChildEdge(edge, childIndex); return edge.computeDistanceToOut(xf, p, 0, normalOut); }
/** 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; }
vs[2] = new Vec2(7.0f, 8.0f); vs[3] = new Vec2(8.0f, 7.0f); ChainShape shape = new ChainShape(); shape.createChain(vs, 4); ground.createFixture(shape, 0.0f); vs[2] = new Vec2(1.0f, 5.0f); vs[3] = new Vec2(-1.0f, 5.0f); ChainShape shape = new ChainShape(); shape.createLoop(vs, 4); ground.createFixture(shape, 0.0f); vs[8] = new Vec2(-6.0f, 2.0f); vs[9] = new Vec2(-6.0f, 0.0f); ChainShape shape = new ChainShape(); shape.createLoop(vs, 10); ground.createFixture(shape, 0.0f);
@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); } }
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(); } }
/** Create a chain with isolated end vertices. * @param vertices an array of floats of alternating x, y coordinates. */ public void createChain (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.createChain(v, v.length); isLooped = false; }
public ChainShape () { super(new org.jbox2d.collision.shapes.ChainShape()); shape = (org.jbox2d.collision.shapes.ChainShape)super.shape; }
@Override public float getRadius () { return shape.getRadius(); }
@Override public void setRadius (float radius) { shape.setRadius(radius); }
vs[2] = new Vec2(7.0f, 8.0f); vs[3] = new Vec2(8.0f, 7.0f); ChainShape shape = new ChainShape(); shape.createChain(vs, 4); ground.createFixture(shape, 0.0f); vs[2] = new Vec2(1.0f, 5.0f); vs[3] = new Vec2(-1.0f, 5.0f); ChainShape shape = new ChainShape(); shape.createLoop(vs, 4); ground.createFixture(shape, 0.0f); vs[8] = new Vec2(-6.0f, 2.0f); vs[9] = new Vec2(-6.0f, 0.0f); ChainShape shape = new ChainShape(); shape.createLoop(vs, 10); ground.createFixture(shape, 0.0f);
ChainShape weird = new ChainShape(); weird.createLoop( new float[]{vertice1x, vertice1y, vertice2x, ...});
/** Create a chain with isolated end vertices. * @param vertices an array of vertices, these are copied */ public void createChain (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.createChain(v, v.length); isLooped = false; }
break; case CHAIN: { ChainShape chain = new ChainShape(); chain.m_count = s.getPointsCount(); chain.m_vertices = new Vec2[chain.m_count];
assert (0 <= index && index < m_count - 1); edge.setRadius(getRadius());
public ChainShape() { super(ShapeType.CHAIN); setRadius(JBoxSettings.polygonRadius); }
@Override public Shape clone() { ChainShape clone = new ChainShape(); clone.createChain(m_vertices, m_count); clone.m_prevVertex.set(m_prevVertex); clone.m_nextVertex.set(m_nextVertex); clone.m_hasPrevVertex = m_hasPrevVertex; clone.m_hasNextVertex = m_hasNextVertex; return clone; }
Body ground = m_world.createBody(bd); ChainShape shape = new ChainShape(); 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);
@Override public void evaluate(Manifold manifold, Transform xfA, Transform xfB) { ChainShape chain = (ChainShape) m_fixtureA.getShape(); chain.getChildEdge(edge, m_indexA); pool.getCollision().collideEdgeAndCircle(manifold, edge, xfA, (CircleShape) m_fixtureB.getShape(), xfB); } }
/** Create a chain with isolated end vertices. * @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 createChain (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.createChain(v, vertexCount); isLooped = false; }