Package org.jbox2d.collision.shapes

Examples of org.jbox2d.collision.shapes.EdgeShape


    if(deserialized){
      return;
    }
    // Ground body
    {
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));

      FixtureDef sd = new FixtureDef();
      sd.shape = shape;
      sd.friction = 0.3f;
View Full Code Here


  boolean m_go;

  @Override
  public void initTest(boolean deserialized) {
    {
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-20.0f, 0.0f), new Vec2(20.0f, 0.0f));
      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      getGroundBody().createFixture(fd);
    }

    // Define motorized body
    {
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.position.set(0.0f, 8.0f);
      Body body = getWorld().createBody(bd);

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

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.friction = 0.6f;
      fd.density = 2.0f;
View Full Code Here

    {
      BodyDef bd = new BodyDef();
      bd.position.set(0.0f, 20.0f);
      ground = getWorld().createBody(bd);

      EdgeShape shape = new EdgeShape();

      FixtureDef sd = new FixtureDef();
      sd.shape = shape;
      sd.density = 0.0f;
      sd.restitution = k_restitution;

      // Left vertical
      shape.set(new Vec2(-20.0f, -20.0f), new Vec2(-20.0f, 20.0f));
      ground.createFixture(sd);

      // Right vertical
      shape.set(new Vec2(20.0f, -20.0f), new Vec2(20.0f, 20.0f));
      ground.createFixture(sd);

      // Top horizontal
      shape.set(new Vec2(-20.0f, 20.0f), new Vec2(20.0f, 20.0f));
      ground.createFixture(sd);

      // Bottom horizontal
      shape.set(new Vec2(-20.0f, -20.0f), new Vec2(20.0f, -20.0f));
      ground.createFixture(sd);
    }

    {
      Transform xf1 = new Transform();
      xf1.q.set(0.3524f * MathUtils.PI);
      Rot.mulToOutUnsafe(xf1.q, new Vec2(1.0f, 0.0f), xf1.p);

      Vec2 vertices[] = new Vec2[3];
      vertices[0] = Transform.mul(xf1, new Vec2(-1.0f, 0.0f));
      vertices[1] = Transform.mul(xf1, new Vec2(1.0f, 0.0f));
      vertices[2] = Transform.mul(xf1, new Vec2(0.0f, 0.5f));

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

      FixtureDef sd1 = new FixtureDef();
      sd1.shape = poly1;
      sd1.density = 4.0f;

      Transform xf2 = new Transform();
      xf2.q.set(-0.3524f * MathUtils.PI);
      Rot.mulToOut(xf2.q, new Vec2(-1.0f, 0.0f), xf2.p);

      vertices[0] = Transform.mul(xf2, new Vec2(-1.0f, 0.0f));
      vertices[1] = Transform.mul(xf2, new Vec2(1.0f, 0.0f));
      vertices[2] = Transform.mul(xf2, new Vec2(0.0f, 0.5f));

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

      FixtureDef sd2 = new FixtureDef();
      sd2.shape = poly2;
      sd2.density = 2.0f;

      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.angularDamping = 2.0f;
      bd.linearDamping = 0.5f;

      bd.position.set(0.0f, 2.0f);
      bd.angle = MathUtils.PI;
      bd.allowSleep = false;
      m_body = getWorld().createBody(bd);
      m_body.createFixture(sd1);
      m_body.createFixture(sd2);
    }

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

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 1.0f;
      fd.friction = 0.3f;
View Full Code Here

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

    {
      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 = getWorld().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 = 10000.0f;
        rjd.enableMotor = true;
        m_joint1 = (RevoluteJoint) getWorld().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 = getWorld().createBody(bd);
        body.createFixture(shape, 2.0f);

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

        prevBody = body;
      }

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

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.fixedRotation = true;
        bd.position.set(0.0f, 17.0f);
        Body body = getWorld().createBody(bd);
        body.createFixture(shape, 2.0f);

        RevoluteJointDef rjd = new RevoluteJointDef();
        rjd.initialize(prevBody, body, new Vec2(0.0f, 17.0f));
        getWorld().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 = false;

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

      // Create a payload
      {
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(1.5f, 1.5f);

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(0.0f, 23.0f);
        Body body = getWorld().createBody(bd);
View Full Code Here

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

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

      circle.m_p.set(-10.0f, y + b + L);
      ground.createFixture(circle, 0.0f);

      circle.m_p.set(10.0f, y + b + L);
      ground.createFixture(circle, 0.0f);
    }

    {

      PolygonShape shape = new PolygonShape();
      shape.setAsBox(a, b);

      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;

      bd.position.set(-10.0f, y);
View Full Code Here

          p.m_normals[i].set(pbToVec(s.getNormals(i)));
        }
        shape = p;
        break;
      case EDGE:
        EdgeShape edge = new EdgeShape();
        edge.m_vertex0.set(pbToVec(s.getV0()));
        edge.m_vertex1.set(pbToVec(s.getV1()));
        edge.m_vertex2.set(pbToVec(s.getV2()));
        edge.m_vertex3.set(pbToVec(s.getV3()));
        edge.m_hasVertex0 = s.getHas0();
View Full Code Here

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

  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();
    shape.setAsBox(4.0f, 4.0f, new Vec2(0.0f, 0.0f), 0.0f);
    m_fixture1 = m_body.createFixture(shape, 10.0f);

    m_fixture2 = null;
  }
View Full Code Here

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

    {
      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

TOP

Related Classes of org.jbox2d.collision.shapes.EdgeShape

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.