/** Constructs a new polygon */ public PolygonShape () { super(new org.jbox2d.collision.shapes.PolygonShape()); shape = (org.jbox2d.collision.shapes.PolygonShape)super.shape; }
public final Shape clone() { PolygonShape shape = new PolygonShape(); shape.m_centroid.set(this.m_centroid); for (int i = 0; i < shape.m_normals.length; i++) { shape.m_normals[i].set(m_normals[i]); shape.m_vertices[i].set(m_vertices[i]); } shape.setRadius(this.getRadius()); shape.m_count = this.m_count; return shape; }
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); } }
public final Shape clone() { PolygonShape shape = new PolygonShape(); shape.m_centroid.set(this.m_centroid); for (int i = 0; i < shape.m_normals.length; i++) { shape.m_normals[i].set(m_normals[i]); shape.m_vertices[i].set(m_vertices[i]); } shape.setRadius(this.getRadius()); shape.m_count = this.m_count; return shape; }
@Override public synchronized void step(TestbedSettings settings) { super.step(settings); if (m_count < MAX_NUM) { BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position.set(0.0f, 10.0f); Body body = m_world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.125f, 0.125f); body.createFixture(shape, 1.0f); ++m_count; } }
public void makeDomino(float x, float y, boolean horizontal, World world) { PolygonShape sd = new PolygonShape(); sd.setAsBox(.5f * dwidth, .5f * dheight); FixtureDef fd = new FixtureDef(); fd.shape = sd; fd.density = ddensity; BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; fd.friction = dfriction; fd.restitution = 0.65f; bd.position = new Vec2(x, y); bd.angle = horizontal ? (float) (Math.PI / 2.0) : 0f; Body myBody = getWorld().createBody(bd); myBody.createFixture(fd); }
@Override public void initTest(boolean argDeserialized) { input.transformA = new Transform(); input.transformB = new Transform(); { m_transformA = new Transform(); m_transformA.setIdentity(); m_transformA.p.set(0.0f, -0.2f); m_polygonA = new PolygonShape(); m_polygonA.setAsBox(10.0f, 0.2f); } { m_positionB = new Vec2(); m_positionB.set(12.017401f, 0.13678508f); m_angleB = -0.0109265f; m_transformB = new Transform(); m_transformB.set(m_positionB, m_angleB); m_polygonB = new PolygonShape(); m_polygonB.setAsBox(2.0f, 0.1f); } for (int i = 0; i < v.length; i++) { v[i] = new Vec2(); } }
PolygonShape shape = new PolygonShape(); Vec2[] vertices = new Vec2[] {new Vec2(-40, -20), new Vec2(40, -20), new Vec2(40, 0), new Vec2(-40, 0)}; PolygonShape shape = new PolygonShape(); Vec2[] vertices = new Vec2[] {new Vec2(-40, -20), new Vec2(-20, -20), new Vec2(-20, 60), PolygonShape shape = new PolygonShape(); PolygonShape shape = new PolygonShape(); Vec2[] vertices = new Vec2[] {new Vec2(-40, 40), new Vec2(40, 40), new Vec2(40, 60), new Vec2(-40, 60)};
@Override public void initTest(boolean argDeserialized) { // Ground body { BodyDef bd = new BodyDef(); Body ground = getWorld().createBody(bd); EdgeShape shape = new EdgeShape(); shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); ground.createFixture(shape, 0.0f); } // Breakable dynamic body { BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position.set(0.0f, 40.0f); bd.angle = 0.25f * MathUtils.PI; m_body1 = getWorld().createBody(bd); m_shape1 = new PolygonShape(); m_shape1.setAsBox(0.5f, 0.5f, new Vec2(-0.5f, 0.0f), 0.0f); m_piece1 = m_body1.createFixture(m_shape1, 1.0f); m_shape2 = new PolygonShape(); m_shape2.setAsBox(0.5f, 0.5f, new Vec2(0.5f, 0.0f), 0.0f); m_piece2 = m_body1.createFixture(m_shape2, 1.0f); } m_break = false; m_broke = false; }
Body body = getWorld().createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(10.0f, 0.5f); Body body = m_world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.5f); body.createFixture(shape, 20.0f);
body.createFixture(shape, 0.0f); PolygonShape pshape = new PolygonShape(); pshape.setAsBox(0.2f, 1.0f, new Vec2(0.5f, 1.0f), 0.0f); body.createFixture(pshape, 0.0f); m_poly = new PolygonShape(); m_poly.setAsBox(2.0f, 0.1f); m_circle = new CircleShape();
body.createFixture(edge, 0.0f); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.2f, 1.0f, new Vec2(0.5f, 1.0f), 0.0f); body.createFixture(shape, 0.0f); bd.position.set(0.0f, 4.0f); PolygonShape box = new PolygonShape(); box.setAsBox(2.0f, 0.1f);
@Override public void initTest(boolean argDeserialized) { { BodyDef bd = new BodyDef(); Body ground = getWorld().createBody(bd); EdgeShape shape = new EdgeShape(); shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); ground.createFixture(shape, 0.0f); } BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position.set(0.0f, 10.0f); m_body = getWorld().createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(4.0f, 4.0f, new Vec2(0.0f, 0.0f), 0.0f); m_fixture1 = m_body.createFixture(shape, 10.0f); m_fixture2 = null; }
@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); } }
Body body = getWorld().createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(2.0f, 0.5f);
@Override public void initTest(boolean deserialized) { { BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.allowSleep = false; bd.position.set(0.0f, 10.0f); Body body = m_world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 10.0f, new Vec2(10.0f, 0.0f), 0.0f); body.createFixture(shape, 5.0f); shape.setAsBox(0.5f, 10.0f, new Vec2(-10.0f, 0.0f), 0.0f); body.createFixture(shape, 5.0f); shape.setAsBox(10.0f, 0.5f, new Vec2(0.0f, 10.0f), 0.0f); body.createFixture(shape, 5.0f); shape.setAsBox(10.0f, 0.5f, new Vec2(0.0f, -10.0f), 0.0f); body.createFixture(shape, 5.0f); RevoluteJointDef jd = new RevoluteJointDef(); jd.bodyA = getGroundBody(); jd.bodyB = body; jd.localAnchorA.set(0.0f, 10.0f); jd.localAnchorB.set(0.0f, 0.0f); jd.referenceAngle = 0.0f; jd.motorSpeed = 0.05f * MathUtils.PI; jd.maxMotorTorque = 1e8f; jd.enableMotor = true; m_joint = (RevoluteJoint) m_world.createJoint(jd); } m_count = 0; }
PolygonShape shape = new PolygonShape(); shape.setAsBox(0.6f, 0.125f);
PolygonShape shape = new PolygonShape(); shape.setAsBox(a, a);
PolygonShape shape = new PolygonShape(); shape.setAsBox(2.0f, 0.5f);
Body body = getWorld().createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(3.0f, 0.5f); m_platform = body.createFixture(shape, 0.0f);