public org.jbox2d.dynamics.FixtureDef toJBox2d () { org.jbox2d.dynamics.FixtureDef fd = new org.jbox2d.dynamics.FixtureDef(); fd.density = density; fd.filter = new org.jbox2d.dynamics.Filter(); fd.filter.categoryBits = filter.categoryBits; fd.filter.groupIndex = filter.groupIndex; fd.filter.maskBits = filter.maskBits; fd.friction = friction; fd.isSensor = isSensor; fd.restitution = restitution; fd.shape = shape.shape; return fd; } }
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); } }
private void initAxis() { BodyDef axisDef = new BodyDef(); axisDef.type = BodyType.STATIC; axisDef.position = new Vec2(3, 3); axis = world.createBody(axisDef); CircleShape axisShape = new CircleShape(); axisShape.setRadius(0.02f); axisShape.m_p.set(0, 0); FixtureDef axisFixture = new FixtureDef(); axisFixture.shape = axisShape; axis.createFixture(axisFixture); }
FixtureDef fixtureDef = new FixtureDef(); fixtureDef.friction = 0.3f; fixtureDef.restitution = 0.3f;
FixtureDef fd = new FixtureDef(); fd.shape = m_polygons[index]; fd.friction = 0.3f; m_bodies[m_bodyIndex].createFixture(fd); } else if (index < 5) { FixtureDef fd = new FixtureDef(); fd.shape = m_circle; fd.friction = 0.3f; FixtureDef fd = new FixtureDef(); fd.shape = m_edge; fd.friction = 0.3f;
public void createCircle() { float radius = 2.0f; CircleShape shape = new CircleShape(); shape.m_p.setZero(); shape.m_radius = radius; FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.density = 1.0f; fd.friction = 0.0f; Vec2 p = new Vec2((float)Math.random(), 3.0f + (float)Math.random()); BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position = p; //bd.allowSleep = false; Body body = getWorld().createBody(bd); body.createFixture(fd); }
void Create(int index) { BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; float x = MathUtils.randomFloat(-2.0f, 2.0f); bd.position.set(x, 10.0f); bd.angle = MathUtils.randomFloat(-MathUtils.PI, MathUtils.PI); if (index == 4) { bd.angularDamping = 0.02f; } m_bodies[m_bodyIndex] = getWorld().createBody(bd); if (index < 4) { FixtureDef fd = new FixtureDef(); fd.shape = m_polygons[index]; fd.density = 1.0f; fd.friction = 0.3f; m_bodies[m_bodyIndex].createFixture(fd); } else { FixtureDef fd = new FixtureDef(); fd.shape = m_circle; fd.density = 1.0f; fd.friction = 0.3f; m_bodies[m_bodyIndex].createFixture(fd); } m_bodyIndex = (m_bodyIndex + 1) % k_maxBodies; }
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); }
void Create(int index) { if (m_bodies[m_bodyIndex] != null) { getWorld().destroyBody(m_bodies[m_bodyIndex]); m_bodies[m_bodyIndex] = null; } BodyDef bd = new BodyDef(); float x = MathUtils.randomFloat(-10.0f, 10.0f); float y = MathUtils.randomFloat(10.0f, 20.0f); bd.position.set(x, y); bd.angle = MathUtils.randomFloat(-MathUtils.PI, MathUtils.PI); bd.type = BodyType.DYNAMIC; if (index == 4) { bd.angularDamping = 0.02f; } m_bodies[m_bodyIndex] = getWorld().createBody(bd); if (index < 4) { FixtureDef fd = new FixtureDef(); fd.shape = m_polygons[index]; fd.friction = 0.3f; fd.density = 20.0f; m_bodies[m_bodyIndex].createFixture(fd); } else { FixtureDef fd = new FixtureDef(); fd.shape = m_circle; fd.friction = 0.3f; fd.density = 20.0f; m_bodies[m_bodyIndex].createFixture(fd); } m_bodyIndex = (m_bodyIndex + 1) % e_maxBodies; }
FixtureDef fd = new FixtureDef(); PolygonShape sd = new PolygonShape(); sd.setAsBox(50.0f, 10.0f); FixtureDef fd = new FixtureDef(); PolygonShape sd = new PolygonShape(); sd.setAsBox(15.0f, 0.125f); FixtureDef fd = new FixtureDef(); PolygonShape sd = new PolygonShape(); sd.setAsBox(0.125f, 2f);
FixtureDef fd = new FixtureDef(); fd.shape = shape; getGroundBody().createFixture(fd); shape.setAsBox(2.0f, 0.5f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.friction = 0.6f;
@Override public void keyPressed(char argKeyChar, int argKeyCode) { switch (argKeyChar) { case ',': if (m_bullet != null) { getWorld().destroyBody(m_bullet); m_bullet = null; } { CircleShape shape = new CircleShape(); shape.m_radius = 0.25f; FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.density = 20.0f; fd.restitution = 0.05f; BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.bullet = true; bd.position.set(-31.0f, 5.0f); m_bullet = getWorld().createBody(bd); m_bullet.createFixture(fd); m_bullet.setLinearVelocity(new Vec2(400.0f, 0.0f)); } break; } }
public Fixture deserializeFixture(Body argBody, PbFixture argFixture) { PbFixture f = argFixture; FixtureDef fd = new FixtureDef(); fd.density = f.getDensity(); fd.filter.categoryBits = f.getFilter().getCategoryBits(); fd.filter.groupIndex = f.getFilter().getGroupIndex(); fd.filter.maskBits = f.getFilter().getMaskBits(); fd.friction = f.getFriction(); fd.isSensor = f.getSensor(); fd.restitution = f.getRestitution(); fd.shape = deserializeShape(f.getShape()); Fixture fixture = argBody.createFixture(fd); if (listener != null && f.hasTag()) { listener.processFixture(fixture, f.getTag()); } return fixture; }
@Override public void initTest(boolean deserialized) { if (deserialized) { return; } { 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); } { CircleShape shape = new CircleShape(); shape.m_radius = 1.0f; FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.density = 1.0f; float restitution[] = {0.0f, 0.1f, 0.3f, 0.5f, 0.75f, 0.9f, 1.0f}; for (int i = 0; i < 7; ++i) { BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position.set(-10.0f + 3.0f * i, 20.0f); Body body = getWorld().createBody(bd); fd.restitution = restitution[i]; body.createFixture(fd); } } }
private void launchBomb(Vec2 position, Vec2 velocity) { if (bomb != null) { m_world.destroyBody(bomb); bomb = null; } // todo optimize this BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position.set(position); bd.bullet = true; bomb = m_world.createBody(bd); bomb.setLinearVelocity(velocity); CircleShape circle = new CircleShape(); circle.m_radius = 0.3f; FixtureDef fd = new FixtureDef(); fd.shape = circle; fd.density = 20f; fd.restitution = 0; Vec2 minV = new Vec2(position); Vec2 maxV = new Vec2(position); minV.subLocal(new Vec2(.3f, .3f)); maxV.addLocal(new Vec2(.3f, .3f)); aabb.lowerBound.set(minV); aabb.upperBound.set(maxV); bomb.createFixture(fd); }
shape.m_p.set(0.0f, 10.0f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.isSensor = true;
shape.setAsBox(10.0f, 0.5f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.friction = 0.8f;
shape.setAsBox(0.5f, 0.5f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.density = 1.0f;
shape.setAsBox(0.6f, 0.125f); FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.density = 20.0f;
shape.m_radius = radius; FixtureDef fd = new FixtureDef(); fd.shape = shape; fd.density = 1.0f;