Package org.jbox2d.dynamics

Examples of org.jbox2d.dynamics.BodyDef


    FixtureDef wallFixture = new FixtureDef();
    wallFixture.shape = wallShape;
    wallFixture.density = 1;
    wallFixture.restitution = 0;
   
    BodyDef wallBodyDef = new BodyDef();
    wallBodyDef.type = BodyType.STATIC;
    wallBodyDef.position = position;
   
    World.WORLD.createBody(wallBodyDef).createFixture(wallFixture);
  }
View Full Code Here


  @Override
  public void setupWorld(World world) {
    this.world = world;
    Body ground = null;
    {
      BodyDef bd = new BodyDef();
      ground = world.createBody(bd);

      PolygonShape shape = new PolygonShape();
      shape.setAsBox(5.0f, 100.0f);
      bd = new BodyDef();
      bd.type = BodyType.STATIC;
      FixtureDef sides = new FixtureDef();
      sides.shape = shape;
      sides.density = 0;
      sides.friction = 0;
      sides.restitution = .8f;
      sides.filter.categoryBits = 4;
      sides.filter.maskBits = 2;

      bd.position.set(-10.01f, 50.0f);
      Body bod = world.createBody(bd);
      bod.createFixture(sides);
      bd.position.set(10.01f, 50.0f);
      bod = world.createBody(bd);
      bod.createFixture(sides);
    }

    // turney
    {
      CircleShape cd;
      FixtureDef fd = new FixtureDef();
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      int numPieces = 5;
      float radius = 4f;
      bd.position = new Vec2(0.0f, 25.0f);
      Body body = world.createBody(bd);
      for (int i = 0; i < numPieces; i++) {
        cd = new CircleShape();
        cd.m_radius = .5f;
        fd.shape = cd;
        fd.density = 25;
        fd.friction = .1f;
        fd.restitution = .9f;
        float xPos = radius * (float) Math.cos(2f * Math.PI * (i / (float) (numPieces)));
        float yPos = radius * (float) Math.sin(2f * Math.PI * (i / (float) (numPieces)));
        cd.m_p.set(xPos, yPos);

        body.createFixture(fd);
      }

      RevoluteJointDef rjd = new RevoluteJointDef();
      rjd.initialize(body, ground, body.getPosition());
      rjd.motorSpeed = MathUtils.PI;
      rjd.maxMotorTorque = 1000000.0f;
      rjd.enableMotor = true;
      world.createJoint(rjd);
    }

    {
      Body prevBody = ground;

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

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(0.0f, 7.0f);
        Body body = world.createBody(bd);
        body.createFixture(shape, 2.0f);

        RevoluteJointDef rjd = new RevoluteJointDef();
        rjd.initialize(prevBody, body, new Vec2(0.0f, 5.0f));
        rjd.motorSpeed = 1.0f * MathUtils.PI;
        rjd.maxMotorTorque = 20000;
        rjd.enableMotor = true;
        m_joint1 = (RevoluteJoint) world.createJoint(rjd);

        prevBody = body;
      }

      // Define follower.
      {
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(0.5f, 4.0f);

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(0.0f, 13.0f);
        Body body = world.createBody(bd);
        body.createFixture(shape, 2.0f);

        RevoluteJointDef rjd = new RevoluteJointDef();
        rjd.initialize(prevBody, body, new Vec2(0.0f, 9.0f));
        rjd.enableMotor = false;
        world.createJoint(rjd);

        prevBody = body;
      }

      // Define piston
      {
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(7f, 2f);

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(0.0f, 17.0f);
        Body body = world.createBody(bd);
        FixtureDef piston = new FixtureDef();
        piston.shape = shape;
        piston.density = 2;
        piston.filter.categoryBits = 1;
        piston.filter.maskBits = 2;
        body.createFixture(piston);

        RevoluteJointDef rjd = new RevoluteJointDef();
        rjd.initialize(prevBody, body, new Vec2(0.0f, 17.0f));
        world.createJoint(rjd);

        PrismaticJointDef pjd = new PrismaticJointDef();
        pjd.initialize(ground, body, new Vec2(0.0f, 17.0f), new Vec2(0.0f, 1.0f));

        pjd.maxMotorForce = 1000.0f;
        pjd.enableMotor = true;

        m_joint2 = (PrismaticJoint) world.createJoint(pjd);
      }

      // Create a payload
      {
        PolygonShape sd = new PolygonShape();
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        FixtureDef fixture = new FixtureDef();
        Body body;
        for (int i = 0; i < 100; ++i) {
          sd.setAsBox(0.4f, 0.3f);
View Full Code Here

  Bench2d() {
    Vec2 gravity = new Vec2(0, -10f);
    world = new World(gravity);

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

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


    {
      float a = .5f;
      PolygonShape shape = new PolygonShape();
      shape.setAsBox(a, a);

      Vec2 x = new Vec2(-7.0f, 0.75f);
      Vec2 y = new Vec2();
      Vec2 deltaX = new Vec2(0.5625f, 1f);
      Vec2 deltaY = new Vec2(1.125f, 0.0f);

      for (int i = 0; i < PYRAMID_SIZE; ++i){
        y.set(x);

        for (int j = i; j < PYRAMID_SIZE; ++j){
          BodyDef bd = new BodyDef();
          bd.type = BodyType.DYNAMIC;
          bd.position.set(y);
          Body body = world.createBody(bd);
          body.createFixture(shape, 5.0f);
                                        topBody = body;
View Full Code Here

    if (argDeserialized) {
      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.5f, 0.125f);

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

      WeldJointDef jd = new WeldJointDef();

      Body prevBody = ground;
      for (int i = 0; i < e_count; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(-14.5f + 1.0f * i, 5.0f);
        Body body = getWorld().createBody(bd);
        body.createFixture(fd);

        Vec2 anchor = new Vec2(-15.0f + 1.0f * i, 5.0f);
        jd.initialize(prevBody, body, anchor);
        getWorld().createJoint(jd);

        prevBody = body;
      }
    }

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

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

      WeldJointDef jd = new WeldJointDef();
      jd.frequencyHz = 5f;
      jd.dampingRatio = .7f;

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

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

        prevBody = body;
      }
    }

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

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

      WeldJointDef jd = new WeldJointDef();

      Body prevBody = ground;
      for (int i = 0; i < e_count; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(-4.5f + 1.0f * i, 5.0f);
        Body body = getWorld().createBody(bd);
        body.createFixture(fd);

        if (i > 0) {
          Vec2 anchor = new Vec2(-5.0f + 1.0f * i, 5.0f);
          jd.initialize(prevBody, body, anchor);
          getWorld().createJoint(jd);
        }

        prevBody = body;
      }
    }

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

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

      WeldJointDef jd = new WeldJointDef();
      jd.frequencyHz = 8f;
      jd.dampingRatio = .7f;

      Body prevBody = ground;
      for (int i = 0; i < e_count; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(5.5f + 1.0f * i, 10.0f);
        Body body = getWorld().createBody(bd);
        body.createFixture(fd);

        if (i > 0) {
          Vec2 anchor = new Vec2(5.0f + 1.0f * i, 10.0f);
          jd.initialize(prevBody, body, anchor);
          getWorld().createJoint(jd);
        }

        prevBody = body;
      }
    }

    for (int i = 0; i < 2; ++i) {
      Vec2 vertices[] = new Vec2[3];
      vertices[0] = new Vec2(-0.5f, 0.0f);
      vertices[1] = new Vec2(0.5f, 0.0f);
      vertices[2] = new Vec2(0.0f, 1.5f);

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

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

      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.position.set(-8.0f + 8.0f * i, 12.0f);
      Body body = getWorld().createBody(bd);
      body.createFixture(fd);
    }

    for (int i = 0; i < 2; ++i) {
      CircleShape shape = new CircleShape();
      shape.m_radius = 0.5f;

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

      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.position.set(-6.0f + 6.0f * i, 10.0f);
      Body body = getWorld().createBody(bd);
      body.createFixture(fd);
    }
View Full Code Here

  public void initTest(boolean argDeserialized) {
    if(argDeserialized){
      return;
    }
    {
      BodyDef bd = new BodyDef();
      Body ground = getWorld().createBody(bd);

      EdgeShape shape = new EdgeShape();

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

      // Left wall
      shape.set(new Vec2(-10.0f, 0.0f), new Vec2(-10.0f, 20.0f));
      ground.createFixture(shape, 0.0f);

      // Right wall
      shape.set(new Vec2(10.0f, 0.0f), new Vec2(10.0f, 20.0f));
      ground.createFixture(shape, 0.0f);

      // Roof
      shape.set(new Vec2(-10.0f, 20.0f), new Vec2(10.0f, 20.0f));
      ground.createFixture(shape, 0.0f);
    }

    float radius = 0.5f;
    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.1f;

    for (int j = 0; j < e_columnCount; ++j)
    {
      for (int i = 0; i < e_rowCount; ++i)
      {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(-10.0f + (2.1f * j + 1.0f + 0.01f * i) * radius, (2.0f * i + 1.0f) * radius);
        Body body = getWorld().createBody(bd);

        body.createFixture(fd);
View Full Code Here

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

  }

  @Override
  public void initTest(boolean argDeserialized) {
    {
      BodyDef bd = new BodyDef();
      bd.position.set(0.0f, 0.0f);
      Body body = getWorld().createBody(bd);

      EdgeShape shape = new EdgeShape();

      shape.set(new Vec2(-10.0f, 0.0f), new Vec2(10.0f, 0.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();
    m_circle.m_p.setZero();
    m_circle.m_radius = 0.5f;

    BodyDef bd = new BodyDef();
    bd.type = BodyType.DYNAMIC;
    bd.position.set(0.0f, 20.0f);

    m_body = getWorld().createBody(bd);
    currFixture = m_body.createFixture(m_poly, 1.0f);
View Full Code Here

      FixtureDef fd = new FixtureDef();
      PolygonShape sd = new PolygonShape();
      sd.setAsBox(50.0f, 10.0f);
      fd.shape = sd;

      BodyDef bd = new BodyDef();
      bd.position = new Vec2(0.0f, -10.0f);
      getWorld().createBody(bd).createFixture(fd);

    }

    { // Platforms
      for (int i = 0; i < 4; i++) {
        FixtureDef fd = new FixtureDef();
        PolygonShape sd = new PolygonShape();
        sd.setAsBox(15.0f, 0.125f);
        fd.shape = sd;

        BodyDef bd = new BodyDef();
        bd.position = new Vec2(0.0f, 5f + 5f * i);
        getWorld().createBody(bd).createFixture(fd);
      }
    }

    {
      FixtureDef fd = new FixtureDef();
      PolygonShape sd = new PolygonShape();
      sd.setAsBox(0.125f, 2f);
      fd.shape = sd;
      fd.density = 25.0f;

      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      float friction = .5f;
      int numPerRow = 25;

      for (int i = 0; i < 4; ++i) {
View Full Code Here

  }

  @Override
  public void initTest(boolean deserialized) {
    {
      BodyDef bd = new BodyDef();
      bd.position.set(0.0f, 0.0f);
      Body body = m_world.createBody(bd);

      EdgeShape edge = new EdgeShape();

      edge.set(new Vec2(-10.0f, 0.0f), new Vec2(10.0f, 0.0f));
      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);
    }

    {
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.position.set(0.0f, 4.0f);

      PolygonShape box = new PolygonShape();
      box.setAsBox(2.0f, 0.1f);
View Full Code Here

    if (deserialized) {
      return;
    }
    int count = 20;
    {
      BodyDef bd = new BodyDef();
      Body ground = getWorld().createBody(bd);

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

    }

    {
      float a = .5f;
      PolygonShape shape = new PolygonShape();
      shape.setAsBox(a, a);

      Vec2 x = new Vec2(-7.0f, 0.75f);
      Vec2 y = new Vec2();
      Vec2 deltaX = new Vec2(0.5625f, 1.25f);
      Vec2 deltaY = new Vec2(1.125f, 0.0f);

      for (int i = 0; i < count; ++i) {
        y.set(x);

        for (int j = i; j < count; ++j) {
          BodyDef bd = new BodyDef();
          bd.type = BodyType.DYNAMIC;
          bd.position.set(y);
          Body body = getWorld().createBody(bd);
          body.createFixture(shape, 5.0f);
          y.addLocal(deltaY);
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.