Package org.jbox2d.dynamics

Examples of org.jbox2d.dynamics.BodyDef


  }

  public Body deserializeBody(World argWorld, PbBody argBody) {
    PbBody b = argBody;

    BodyDef bd = new BodyDef();
    bd.position.set(pbToVec(b.getPosition()));
    bd.angle = b.getAngle();
    bd.linearDamping = b.getLinearDamping();
    bd.angularDamping = b.getAngularDamping();
    bd.gravityScale = b.getGravityScale();
View Full Code Here


    if (deserialized) {
      return;
    }
    // Ground body
    {
      BodyDef bd = new BodyDef();
      Body ground = getWorld().createBody(bd);

      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-20.0f, 0.0f), new Vec2(20.0f, 0.0f));
      ground.createFixture(shape, 0.0f);
    }

    // Collinear edges
    // This shows the problematic case where a box shape can hit
    // an internal vertex.
    {
      BodyDef bd = new BodyDef();
      Body ground = getWorld().createBody(bd);

      EdgeShape shape = new EdgeShape();
      shape.m_radius = 0.0f;
      shape.set(new Vec2(-8.0f, 1.0f), new Vec2(-6.0f, 1.0f));
      ground.createFixture(shape, 0.0f);
      shape.set(new Vec2(-6.0f, 1.0f), new Vec2(-4.0f, 1.0f));
      ground.createFixture(shape, 0.0f);
      shape.set(new Vec2(-4.0f, 1.0f), new Vec2(-2.0f, 1.0f));
      ground.createFixture(shape, 0.0f);
    }

    // Chain shape
    {
      BodyDef bd = new BodyDef();
      bd.angle = 0.25f * MathUtils.PI;
      Body ground = getWorld().createBody(bd);

      Vec2[] vs = new Vec2[4];
      vs[0] = new Vec2(5.0f, 7.0f);
      vs[1] = new Vec2(6.0f, 8.0f);
      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);
    }

    // Square tiles. This shows that adjacency shapes may
    // have non-smooth collision. There is no solution
    // to this problem.
    {
      BodyDef bd = new BodyDef();
      Body ground = getWorld().createBody(bd);

      PolygonShape shape = new PolygonShape();
      shape.setAsBox(1.0f, 1.0f, new Vec2(4.0f, 3.0f), 0.0f);
      ground.createFixture(shape, 0.0f);
      shape.setAsBox(1.0f, 1.0f, new Vec2(6.0f, 3.0f), 0.0f);
      ground.createFixture(shape, 0.0f);
      shape.setAsBox(1.0f, 1.0f, new Vec2(8.0f, 3.0f), 0.0f);
      ground.createFixture(shape, 0.0f);
    }

    // Square made from an edge loop. Collision should be smooth.
    {
      BodyDef bd = new BodyDef();
      Body ground = m_world.createBody(bd);

      Vec2[] vs = new Vec2[4];
      vs[0] = new Vec2(-1.0f, 3.0f);
      vs[1] = new Vec2(1.0f, 3.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);
    }

    // Edge loop. Collision should be smooth.
    {
      BodyDef bd = new BodyDef();
      bd.position.set(-10.0f, 4.0f);
      Body ground = getWorld().createBody(bd);

      Vec2[] vs = new Vec2[10];
      vs[0] = new Vec2(0.0f, 0.0f);
      vs[1] = new Vec2(6.0f, 0.0f);
      vs[2] = new Vec2(6.0f, 2.0f);
      vs[3] = new Vec2(4.0f, 1.0f);
      vs[4] = new Vec2(2.0f, 2.0f);
      vs[5] = new Vec2(0.0f, 2.0f);
      vs[6] = new Vec2(-2.0f, 2.0f);
      vs[7] = new Vec2(-4.0f, 3.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);
    }

    // Square character 1
    {
      BodyDef bd = new BodyDef();
      bd.position.set(-3.0f, 8.0f);
      bd.type = BodyType.DYNAMIC;
      bd.fixedRotation = true;
      bd.allowSleep = false;

      Body body = getWorld().createBody(bd);

      PolygonShape shape = new PolygonShape();
      shape.setAsBox(0.5f, 0.5f);

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 20.0f;
      body.createFixture(fd);
    }

    // Square character 2
    {
      BodyDef bd = new BodyDef();
      bd.position.set(-5.0f, 5.0f);
      bd.type = BodyType.DYNAMIC;
      bd.fixedRotation = true;
      bd.allowSleep = false;

      Body body = getWorld().createBody(bd);

      PolygonShape shape = new PolygonShape();
      shape.setAsBox(0.25f, 0.25f);

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 20.0f;
      body.createFixture(fd);
    }

    // Hexagon character
    {
      BodyDef bd = new BodyDef();
      bd.position.set(-5.0f, 8.0f);
      bd.type = BodyType.DYNAMIC;
      bd.fixedRotation = true;
      bd.allowSleep = false;

      Body body = getWorld().createBody(bd);

      float angle = 0.0f;
      float delta = MathUtils.PI / 3.0f;
      Vec2 vertices[] = new Vec2[6];
      for (int i = 0; i < 6; ++i) {
        vertices[i] = new Vec2(0.5f * MathUtils.cos(angle), 0.5f * MathUtils.sin(angle));
        angle += delta;
      }

      PolygonShape shape = new PolygonShape();
      shape.set(vertices, 6);

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 20.0f;
      body.createFixture(fd);
    }

    // Circle character
    {
      BodyDef bd = new BodyDef();
      bd.position.set(3.0f, 5.0f);
      bd.type = BodyType.DYNAMIC;
      bd.fixedRotation = true;
      bd.allowSleep = false;

      Body body = getWorld().createBody(bd);

      CircleShape shape = new CircleShape();
      shape.m_radius = 0.5f;

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 20.0f;
      body.createFixture(fd);
    }

    // Circle character
    {
      BodyDef bd = new BodyDef();
      bd.position.set(-7.0f, 6.0f);
      bd.type = BodyType.DYNAMIC;
      bd.allowSleep = false;

      m_character = getWorld().createBody(bd);
View Full Code Here

  Fixture m_fixture2;

  @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();
View Full Code Here

  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);

View Full Code Here

    for (int i = 0; i < m_touching.length; i++) {
      m_touching[i] = new BoolWrapper();
    }

    {
      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 = 5.0f;
        shape.m_p.set(0.0f, 10.0f);

        FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        fd.isSensor = true;
        m_sensor = ground.createFixture(fd);
      }
    }

    {
      CircleShape shape = new CircleShape();
      shape.m_radius = 1.0f;

      for (int i = 0; i < e_count; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(-10.0f + 3.0f * i, 20.0f);
        bd.userData = m_touching[i];

        m_touching[i].tf = false;
View Full Code Here

  int flags = ParticleType.b2_tensileParticle;

  @Override
  public void initTest(boolean deserialized) {
    {
      BodyDef bd = new BodyDef();
      Body ground = m_world.createBody(bd);

      {
        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();
        Vec2[] vertices =
            new Vec2[] {new Vec2(-40, -1), new Vec2(-20, -1), new Vec2(-20, 20), new Vec2(-40, 30)};
        shape.set(vertices, 4);
        ground.createFixture(shape, 0.0f);
      }

      {
        PolygonShape shape = new PolygonShape();
        Vec2[] vertices =
            new Vec2[] {new Vec2(20, -1), new Vec2(40, -1), new Vec2(40, 30), new Vec2(20, 20)};
        shape.set(vertices, 4);
        ground.createFixture(shape, 0.0f);
      }
    }

    m_world.setParticleRadius(0.2f);
    {
      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);
    }

    {
      BodyDef bd = new BodyDef();
      bd.type = BodyType.KINEMATIC;
      Body body = m_world.createBody(bd);
      circle = body;
      CircleShape shape = new CircleShape();
      shape.m_p.set(0, 5);
      shape.m_radius = 1;
      body.createFixture(shape, 0.1f);
      body.setLinearVelocity(new Vec2(-6, 0.0f));
    }

    {
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      Body body = m_world.createBody(bd);
      PolygonShape shape = new PolygonShape();
      shape.setAsBox(1, 1, new Vec2(-10, 5), 0);
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      Body body = m_world.createBody(bd);
      PolygonShape shape = new PolygonShape();
      shape.setAsBox(1, 1, new Vec2(10, 5), 0.5f);
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(0, 20), new Vec2(1, 21));
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(3, 20), new Vec2(4, 21));
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-3, 21), new Vec2(-2, 20));
      body.createFixture(shape, 0.1f);
View Full Code Here

    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;
View Full Code Here

    { // Floor
      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);
    }

    {
      ddensity = 10f;
      // Make bullet
      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;
      fd.friction = 0f;
      fd.restitution = 0.85f;
      bd.bullet = true;
View Full Code Here

    m_motorOn = true;
    Vec2 pivot = new Vec2(0.0f, 0.8f);

    // Ground
    {
      BodyDef bd = new BodyDef();
      Body ground = getWorld().createBody(bd);

      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-50.0f, 0.0f), new Vec2(50.0f, 0.0f));
      ground.createFixture(shape, 0.0f);

      shape.set(new Vec2(-50.0f, 0.0f), new Vec2(-50.0f, 10.0f));
      ground.createFixture(shape, 0.0f);

      shape.set(new Vec2(50.0f, 0.0f), new Vec2(50.0f, 10.0f));
      ground.createFixture(shape, 0.0f);
    }

    // Balls
    for (int i = 0; i < 40; ++i) {
      CircleShape shape = new CircleShape();
      shape.m_radius = 0.25f;

      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.position.set(-40.0f + 2.0f * i, 0.5f);

      Body body = getWorld().createBody(bd);
      body.createFixture(shape, 1.0f);
    }

    // Chassis
    {
      PolygonShape shape = new PolygonShape();
      shape.setAsBox(2.5f, 1.0f);

      FixtureDef sd = new FixtureDef();
      sd.density = 1.0f;
      sd.shape = shape;
      sd.filter.groupIndex = -1;
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.position.set(pivot).addLocal(m_offset);
      m_chassis = getWorld().createBody(bd);
      m_chassis.createFixture(sd);
    }

    {
      CircleShape shape = new CircleShape();
      shape.m_radius = 1.6f;

      FixtureDef sd = new FixtureDef();
      sd.density = 1.0f;
      sd.shape = shape;
      sd.filter.groupIndex = -1;
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.position.set(pivot).addLocal(m_offset);
      m_wheel = getWorld().createBody(bd);
      m_wheel.createFixture(sd);
    }
View Full Code Here

    }

    fd1.shape = poly1;
    fd2.shape = poly2;

    BodyDef bd1 = new BodyDef(), bd2 = new BodyDef();
    bd1.type = BodyType.DYNAMIC;
    bd2.type = BodyType.DYNAMIC;
    bd1.position = m_offset;
    bd2.position = p4.add(m_offset);
View Full Code Here

TOP

Related Classes of org.jbox2d.dynamics.BodyDef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.