Package org.jbox2d.dynamics

Examples of org.jbox2d.dynamics.BodyDef


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

View Full Code Here


    Vec2 center = body1.getWorldCenter();

    body1.destroyFixture(m_piece2);
    m_piece2 = null;

    BodyDef bd = new BodyDef();
    bd.type = BodyType.DYNAMIC;
    bd.position = body1.getPosition();
    bd.angle = body1.getAngle();

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

      getGroundBody().createFixture(shape, 0.0f);
    }

    // Platform
    {
      BodyDef bd = new BodyDef();
      bd.position.set(-5.0f, 5.0f);
      Body body = getWorld().createBody(bd);

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

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.friction = 0.8f;
      m_platform = body.createFixture(fd);
    }

    // Boxes
    for (int i = 0; i < 5; ++i) {
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.position.set(-10.0f + 2.0f * i, 7.0f);
      Body body = m_world.createBody(bd);

      PolygonShape shape = new PolygonShape();
View Full Code Here

      pd.shape = shape;
      m_world.createParticleGroup(pd);
    }

    {
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      Body body = m_world.createBody(bd);
      CircleShape shape = new CircleShape();
      shape.m_p.set(0, 80);
      shape.m_radius = 5;
View Full Code Here

    for (int i = 0; i < m_bodies.length; i++) {
      m_bodies[i] = null;
    }
    // Ground body
    {
      BodyDef bd = new BodyDef();
      Body ground = getWorld().createBody(bd);

      float x1 = -20.0f;
      float y1 = 2.0f * MathUtils.cos(x1 / 10.0f * MathUtils.PI);
      for (int i = 0; i < 80; ++i) {
View Full Code Here

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

      return;
    }

    Body ground = null;
    {
      BodyDef bd = new BodyDef();
      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);
    }

    {
      PolygonShape shape = new PolygonShape();
      shape.setAsBox(0.6f, 0.125f);

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 20.0f;
      fd.friction = 0.2f;

      RevoluteJointDef jd = new RevoluteJointDef();
      jd.collideConnected = false;

      final float y = 25.0f;
      Body prevBody = ground;
      for (int i = 0; i < 30; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(0.5f + i, y);
        Body body = getWorld().createBody(bd);
        body.createFixture(fd);
View Full Code Here

    if (deserialized) {
      return;
    }
    Body ground = null;
    {
      BodyDef bd = new BodyDef();
      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);
    }

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

      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.position.set(-10.0f, 10.0f);
      bd.angle = 0.5f * MathUtils.PI;
      bd.allowSleep = false;
      Body body = getWorld().createBody(bd);
View Full Code Here

    m_zeta = 0.7f;
    m_speed = 50.0f;

    Body ground = null;
    {
      BodyDef bd = new BodyDef();
      ground = m_world.createBody(bd);

      EdgeShape shape = new EdgeShape();

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 0.0f;
      fd.friction = 0.6f;

      shape.set(new Vec2(-20.0f, 0.0f), new Vec2(20.0f, 0.0f));
      ground.createFixture(fd);

      float hs[] = {0.25f, 1.0f, 4.0f, 0.0f, 0.0f, -1.0f, -2.0f, -2.0f, -1.25f, 0.0f};

      float x = 20.0f, y1 = 0.0f, dx = 5.0f;

      for (int i = 0; i < 10; ++i) {
        float y2 = hs[i];
        shape.set(new Vec2(x, y1), new Vec2(x + dx, y2));
        ground.createFixture(fd);
        y1 = y2;
        x += dx;
      }

      for (int i = 0; i < 10; ++i) {
        float y2 = hs[i];
        shape.set(new Vec2(x, y1), new Vec2(x + dx, y2));
        ground.createFixture(fd);
        y1 = y2;
        x += dx;
      }

      shape.set(new Vec2(x, 0.0f), new Vec2(x + 40.0f, 0.0f));
      ground.createFixture(fd);

      x += 80.0f;
      shape.set(new Vec2(x, 0.0f), new Vec2(x + 40.0f, 0.0f));
      ground.createFixture(fd);

      x += 40.0f;
      shape.set(new Vec2(x, 0.0f), new Vec2(x + 10.0f, 5.0f));
      ground.createFixture(fd);

      x += 20.0f;
      shape.set(new Vec2(x, 0.0f), new Vec2(x + 40.0f, 0.0f));
      ground.createFixture(fd);

      x += 40.0f;
      shape.set(new Vec2(x, 0.0f), new Vec2(x, 20.0f));
      ground.createFixture(fd);
    }

    // Teeter
    {
      BodyDef bd = new BodyDef();
      bd.position.set(140.0f, 1.0f);
      bd.type = BodyType.DYNAMIC;
      Body body = m_world.createBody(bd);

      PolygonShape box = new PolygonShape();
      box.setAsBox(10.0f, 0.25f);
      body.createFixture(box, 1.0f);

      RevoluteJointDef jd = new RevoluteJointDef();
      jd.initialize(ground, body, body.getPosition());
      jd.lowerAngle = -8.0f * MathUtils.PI / 180.0f;
      jd.upperAngle = 8.0f * MathUtils.PI / 180.0f;
      jd.enableLimit = true;
      m_world.createJoint(jd);

      body.applyAngularImpulse(100.0f);
    }

    // Bridge
    {
      int N = 20;
      PolygonShape shape = new PolygonShape();
      shape.setAsBox(1.0f, 0.125f);

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 1.0f;
      fd.friction = 0.6f;

      RevoluteJointDef jd = new RevoluteJointDef();

      Body prevBody = ground;
      for (int i = 0; i < N; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(161.0f + 2.0f * i, -0.125f);
        Body body = m_world.createBody(bd);
        body.createFixture(fd);

        Vec2 anchor = new Vec2(160.0f + 2.0f * i, -0.125f);
        jd.initialize(prevBody, body, anchor);
        m_world.createJoint(jd);

        prevBody = body;
      }

      Vec2 anchor = new Vec2(160.0f + 2.0f * N, -0.125f);
      jd.initialize(prevBody, ground, anchor);
      m_world.createJoint(jd);
    }

    // Boxes
    {
      PolygonShape box = new PolygonShape();
      box.setAsBox(0.5f, 0.5f);

      Body body = null;
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;

      bd.position.set(230.0f, 0.5f);
      body = m_world.createBody(bd);
      body.createFixture(box, 0.5f);

      bd.position.set(230.0f, 1.5f);
      body = m_world.createBody(bd);
      body.createFixture(box, 0.5f);

      bd.position.set(230.0f, 2.5f);
      body = m_world.createBody(bd);
      body.createFixture(box, 0.5f);

      bd.position.set(230.0f, 3.5f);
      body = m_world.createBody(bd);
      body.createFixture(box, 0.5f);

      bd.position.set(230.0f, 4.5f);
      body = m_world.createBody(bd);
      body.createFixture(box, 0.5f);
    }

    // Car
    {
      PolygonShape chassis = new PolygonShape();
      Vec2 vertices[] = new Vec2[8];
      vertices[0] = new Vec2(-1.5f, -0.5f);
      vertices[1] = new Vec2(1.5f, -0.5f);
      vertices[2] = new Vec2(1.5f, 0.0f);
      vertices[3] = new Vec2(0.0f, 0.9f);
      vertices[4] = new Vec2(-1.15f, 0.9f);
      vertices[5] = new Vec2(-1.5f, 0.2f);
      chassis.set(vertices, 6);

      CircleShape circle = new CircleShape();
      circle.m_radius = 0.4f;

      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.position.set(0.0f, 1.0f);
      m_car = m_world.createBody(bd);
      m_car.createFixture(chassis, 1.0f);

View Full Code Here

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