Refine search
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); } }
assert (3 <= num && num <= Settings.maxPolygonVertices); if (num < 3) { setAsBox(1.0f, 1.0f); return; setAsBox(1.0f, 1.0f); return; Vec2 r = pool1.set(ps[ie]).subLocal(ps[hull[m]]); Vec2 v = pool2.set(ps[j]).subLocal(ps[hull[m]]); float c = Vec2.cross(r, v); if (c < 0.0f) { computeCentroidToOut(m_vertices, m_count, m_centroid);
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; } }
getWorld().setGravity(new Vec2(0.0f, 0.0f)); BodyDef bd = new BodyDef(); bd.position.set(0.0f, 20.0f); ground = getWorld().createBody(bd); FixtureDef sd = new FixtureDef(); sd.shape = shape; sd.density = 0.0f; shape.set(new Vec2(-20.0f, -20.0f), new Vec2(-20.0f, 20.0f)); ground.createFixture(sd); ground.createFixture(sd); ground.createFixture(sd); PolygonShape poly1 = new PolygonShape(); poly1.set(vertices, 3); PolygonShape poly2 = new PolygonShape(); poly2.set(vertices, 3); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.5f); BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC;
@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); } }
BodyDef bd = new BodyDef(); Body ground = getWorld().createBody(bd); shape.set(new Vec2(-50.0f, 0.0f), new Vec2(50.0f, 0.0f)); ground.createFixture(shape, 0.0f); ground.createFixture(shape, 0.0f); ground.createFixture(shape, 0.0f); shape.m_radius = 0.25f; BodyDef bd = new BodyDef(); Body body = getWorld().createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(2.5f, 1.0f); m_chassis = getWorld().createBody(bd); shape.m_radius = 1.6f; FixtureDef sd = new FixtureDef(); sd.density = 1.0f; sd.shape = shape;
PolygonShape shape = new PolygonShape(); Vec2[] vertices = new Vec2[] {new Vec2(-40, -10), new Vec2(40, -10), new Vec2(40, 0), new Vec2(-40, 0)}; shape.set(vertices, 4); ground.createFixture(shape, 0.0f); PolygonShape shape = new PolygonShape(); shape.set(vertices, 4); ground.createFixture(shape, 0.0f); PolygonShape shape = new PolygonShape(); shape.set(vertices, 4); ground.createFixture(shape, 0.0f); PolygonShape shape = new PolygonShape(); shape.setAsBox(20, 10, new Vec2(0, 10), 0); ParticleGroupDef pd = new ParticleGroupDef(); pd.flags = pd.flags; pd.shape = shape; m_world.createParticleGroup(pd); PolygonShape shape = new PolygonShape(); shape.setAsBox(1, 1, new Vec2(-10, 5), 0); PolygonShape shape = new PolygonShape(); shape.setAsBox(1, 1, new Vec2(10, 5), 0.5f);
fd2.density = 1.0f; PolygonShape poly1 = new PolygonShape(); PolygonShape poly2 = new PolygonShape(); vertices[1] = p2; vertices[2] = p3; poly1.set(vertices, 3); poly2.set(vertices, 3); } else { Vec2[] vertices = new Vec2[3]; vertices[1] = p3; vertices[2] = p2; poly1.set(vertices, 3); poly2.set(vertices, 3); fd2.shape = poly2; bd2.angularDamping = 10.0f; Body body1 = getWorld().createBody(bd1); Body body2 = getWorld().createBody(bd2); getWorld().createJoint(djd);
PolygonShape sd = new PolygonShape(); sd.setAsBox(50.0f, 10.0f); BodyDef bd = new BodyDef(); bd.position = new Vec2(0.0f, -10.0f); getWorld().createBody(bd).createFixture(sd, 0f); PolygonShape sd = new PolygonShape(); sd.setAsBox(.7f, .7f); FixtureDef fd = new FixtureDef(); fd.density = 35f; BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; fd.shape = sd; bd.bullet = true; bd.position = new Vec2(30f, 50f); Body b = getWorld().createBody(bd); b.createFixture(fd); b.setLinearVelocity(new Vec2(-25f, -25f)); b.setAngularVelocity(6.7f); bd.position = new Vec2(-30, 25f); b = getWorld().createBody(bd); b.createFixture(fd); b.setLinearVelocity(new Vec2(35f, -10f));
private void createBox(float posX, float posY, float boxW, float boxH) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.StaticBody; bodyDef.position.set(posX, posY); Body body = world.createBody(bodyDef); PolygonShape shape = new PolygonShape(); shape.setAsBox(boxW / 2.f, boxH / 2.f); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; fixtureDef.density = 1f; Fixture fixture = body.createFixture(fixtureDef); shape.dispose(); }
PolygonShape shape = new PolygonShape(); Vec2[] vertices = new Vec2[] {new Vec2(-40, -10), new Vec2(40, -10), new Vec2(40, 0), new Vec2(-40, 0)}; shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f); PolygonShape shape = new PolygonShape(); Vec2[] vertices = {new Vec2(-40, -1), new Vec2(-20, -1), new Vec2(-20, 20), new Vec2(-40, 30)}; shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f); PolygonShape shape = new PolygonShape(); Vec2[] vertices = {new Vec2(20, -1), new Vec2(40, -1), new Vec2(40, 30), new Vec2(20, 20)}; shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f); m_world.setParticleRadius(0.35f); m_world.setParticleDamping(0.2f); pd.flags = ParticleType.b2_waterParticle; pd.shape = shape; m_world.createParticleGroup(pd); BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; Body body = m_world.createBody(bd);
@Override public void drawDebug(PhysicsDebugCanvas aCanvas) { Body theBody = physicsWorld.getBodyList(); while (theBody != null) { float theRotatedAngle = theBody.getAngle(); Vec2 theBodyPosition = theBody.getPosition(); aCanvas.drawPosition(toPosition(theBodyPosition)); Fixture theFixture = theBody.getFixtureList(); while (theFixture != null) { Shape theShape = theFixture.getShape(); if (theShape.getType() == ShapeType.POLYGON) { PolygonShape thePolyShape = (PolygonShape) theShape; for (int i = 1; i < thePolyShape.getVertexCount(); i++) { aCanvas.drawLine( toPosition(thePolyShape.getVertex(i - 1), theBodyPosition, theRotatedAngle), toPosition(thePolyShape.getVertex(i), theBodyPosition, theRotatedAngle), theBody.isAwake()); toPosition(thePolyShape.getVertex(thePolyShape.getVertexCount() - 1), theBodyPosition, theRotatedAngle), toPosition(thePolyShape.getVertex(0), theBodyPosition, theRotatedAngle), theBody .isAwake());
private void createBridge(Vector2 vecFrom, Vector2 vecTo, Float thickness){ BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.StaticBody; bodyDef.position.set(vecFrom); Body tmpBody = Box2dGameWorld.getInstance().getWorldBox2D().createBody(bodyDef); PolygonShape shape = new PolygonShape(); shape.set( new Vector2[]{ new Vector2(0,0) ,new Vector2(vecTo.x-vecFrom.x,vecTo.y-vecFrom.y) ,new Vector2(vecTo.x-vecFrom.x,vecTo.y-vecFrom.y-thickness) ,new Vector2(0,0-thickness)}); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; fixtureDef.density = 1f; tmpBody.createFixture(fixtureDef); }
context.scale(100, 100); context.setLineWidth(0.01); for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) { Vec2 center = body.getPosition(); context.save(); context.translate(center.x, center.y); context.rotate(body.getAngle()); for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) { Shape shape = fixture.getShape(); } else if (shape.getType() == ShapeType.POLYGON) { PolygonShape poly = (PolygonShape) shape; Vec2[] vertices = poly.getVertices(); context.beginPath(); context.moveTo(vertices[0].x, vertices[0].y); for (int i = 1; i < poly.getVertexCount(); ++i) { context.lineTo(vertices[i].x, vertices[i].y);
public PolygonShape() { super(ShapeType.POLYGON); m_count = 0; m_vertices = new Vec2[Settings.maxPolygonVertices]; for (int i = 0; i < m_vertices.length; i++) { m_vertices[i] = new Vec2(); } m_normals = new Vec2[Settings.maxPolygonVertices]; for (int i = 0; i < m_normals.length; i++) { m_normals[i] = new Vec2(); } setRadius(Settings.polygonRadius); m_centroid.setZero(); }
PolygonShape shape = new PolygonShape(); Vec2[] vertices = new Vec2[] {new Vec2(-40, -20), new Vec2(40, -20), new Vec2(40, 0), new Vec2(-40, 0)}; shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f); PolygonShape shape = new PolygonShape(); Vec2[] vertices = new Vec2[] {new Vec2(-40, -20), new Vec2(-20, -20), new Vec2(-20, 60), new Vec2(-40, 60)}; shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f); PolygonShape shape = new PolygonShape(); new Vec2[] {new Vec2(20, -20), new Vec2(40, -20), new Vec2(40, 60), new Vec2(20, 60)}; shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f); PolygonShape shape = new PolygonShape(); Vec2[] vertices = new Vec2[] {new Vec2(-40, 40), new Vec2(40, 40), new Vec2(40, 60), new Vec2(-40, 60)}; shape.set(vertices, 4); getGroundBody().createFixture(shape, 0.0f); m_world.setParticleRadius(0.5f); m_lastGroup = null; m_drawing = true;
@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(); } }
for (int i = 0; i < bodyConf.meshData.length; i++) { BodyDef bodyDef = ...; Body body = world.createBody(bodyDef); PolygonShape polygonShape = new PolygonShape(); polygonShape.set(bodyConf.meshData[i]); fixtureDef.shape = polygonShape; body.createFixture(fixtureDef); polygonShape.dispose(); }
Vec2[] vertices = { new Vec2(0.0f, - 10.0f), new Vec2(+ 10.0f, + 10.0f), new Vec2(- 10.0f, + 10.0f) }; PolygonShape shape = new PolygonShape(); shape.set(vertices, vertices.length);