Package org.jbox2d.collision.shapes

Examples of org.jbox2d.collision.shapes.PolygonShape


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

      PolygonShape box = new PolygonShape();
      box.setAsBox(0.5f, 5.0f);

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

      BodyDef bd1 = new BodyDef();
      bd1.type = BodyType.STATIC;
      bd1.position.set(10.0f, 9.0f);
      Body body1 = m_world.createBody(bd1);
      body1.createFixture(circle1, 5.0f);

      BodyDef bd2 = new BodyDef();
      bd2.type = BodyType.DYNAMIC;
      bd2.position.set(10.0f, 8.0f);
      Body body2 = m_world.createBody(bd2);
      body2.createFixture(box, 5.0f);

      BodyDef bd3 = new BodyDef();
      bd3.type = BodyType.DYNAMIC;
      bd3.position.set(10.0f, 6.0f);
      Body body3 = m_world.createBody(bd3);
      body3.createFixture(circle2, 5.0f);

      RevoluteJointDef jd1 = new RevoluteJointDef();
      jd1.initialize(body2, body1, bd1.position);
      Joint joint1 = m_world.createJoint(jd1);

      RevoluteJointDef jd2 = new RevoluteJointDef();
      jd2.initialize(body2, body3, bd3.position);
      Joint joint2 = m_world.createJoint(jd2);

      GearJointDef jd4 = new GearJointDef();
      jd4.bodyA = body1;
      jd4.bodyB = body3;
      jd4.joint1 = joint1;
      jd4.joint2 = joint2;
      jd4.ratio = circle2.m_radius / circle1.m_radius;
      m_world.createJoint(jd4);
    }

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

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

      PolygonShape box = new PolygonShape();
      box.setAsBox(0.5f, 5.0f);

      BodyDef bd1 = new BodyDef();
      bd1.type = BodyType.DYNAMIC;
      bd1.position.set(-3.0f, 12.0f);
      Body body1 = m_world.createBody(bd1);
View Full Code Here


      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;
      fd.friction = 0.2f;
      fd.filter.categoryBits = 0x0001;
      fd.filter.maskBits = 0xFFFF & ~0x0002;

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

      final int N = 10;
      final float y = 15.0f;
      m_ropeDef = new RopeJointDef();
      m_ropeDef.localAnchorA.set(0.0f, y);

      Body prevBody = ground;
      for (int i = 0; i < N; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(0.5f + 1.0f * i, y);
        if (i == N - 1) {
          shape.setAsBox(1.5f, 1.5f);
          fd.density = 100.0f;
          fd.filter.categoryBits = 0x0002;
          bd.position.set(1.0f * i, y);
          bd.angularDamping = 0.4f;
        }
View Full Code Here

      bd.type = BodyType.DYNAMIC;
      bd.allowSleep = false;
      bd.position.set(0.0f, 10.0f);
      Body body = m_world.createBody(bd);

      PolygonShape shape = new PolygonShape();
      shape.setAsBox(0.5f, 10.0f, new Vec2(10.0f, 0.0f), 0.0f);
      body.createFixture(shape, 5.0f);
      shape.setAsBox(0.5f, 10.0f, new Vec2(-10.0f, 0.0f), 0.0f);
      body.createFixture(shape, 5.0f);
      shape.setAsBox(10.0f, 0.5f, new Vec2(0.0f, 10.0f), 0.0f);
      body.createFixture(shape, 5.0f);
      shape.setAsBox(10.0f, 0.5f, new Vec2(0.0f, -10.0f), 0.0f);
      body.createFixture(shape, 5.0f);

      RevoluteJointDef jd = new RevoluteJointDef();
      jd.bodyA = getGroundBody();
      jd.bodyB = body;
View Full Code Here

      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.position.set(0.0f, 10.0f);
      Body body = m_world.createBody(bd);

      PolygonShape shape = new PolygonShape();
      shape.setAsBox(0.125f, 0.125f);
      body.createFixture(shape, 1.0f);

      ++m_count;
    }
  }
View Full Code Here

    }

    m_world.setParticleRadius(0.15f);
    {
      PolygonShape shape = new PolygonShape();
      shape.setAsBox(20, 4, new Vec2(0, 36), 0);
      ParticleGroupDef pd = new ParticleGroupDef();
      pd.flags = ParticleType.b2_tensileParticle | ParticleType.b2_viscousParticle;
      pd.shape = shape;
      m_world.createParticleGroup(pd);
    }

    {
      BodyDef bd = new BodyDef();
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-20, 32), new Vec2(-12, 32));
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-11, 32), new Vec2(20, 32));
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-12, 32), new Vec2(-12, 28));
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-11, 32), new Vec2(-11, 28));
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-16, 24), new Vec2(8, 20));
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(16, 16), new Vec2(-8, 12));
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-12, 8), new Vec2(-12, 0));
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-4, 8), new Vec2(-4, 0));
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(4, 8), new Vec2(4, 0));
      body.createFixture(shape, 0.1f);
    }

    {
      BodyDef bd = new BodyDef();
      Body body = m_world.createBody(bd);
      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(12, 8), new Vec2(12, 0));
      body.createFixture(shape, 0.1f);
    }
  }
View Full Code Here

      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(13.0f, 0.25f);

      BodyDef bd = new BodyDef();
      bd.position.set(-4.0f, 22.0f);
      bd.angle = -0.25f;

      Body ground = getWorld().createBody(bd);
      ground.createFixture(shape, 0.0f);
    }

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

      BodyDef bd = new BodyDef();
      bd.position.set(10.5f, 19.0f);

      Body ground = getWorld().createBody(bd);
      ground.createFixture(shape, 0.0f);
    }

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

      BodyDef bd = new BodyDef();
      bd.position.set(4.0f, 14.0f);
      bd.angle = 0.25f;

      Body ground = getWorld().createBody(bd);
      ground.createFixture(shape, 0.0f);
    }

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

      BodyDef bd = new BodyDef();
      bd.position.set(-10.5f, 11.0f);

      Body ground = getWorld().createBody(bd);
      ground.createFixture(shape, 0.0f);
    }

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

      BodyDef bd = new BodyDef();
      bd.position.set(-4.0f, 6.0f);
      bd.angle = -0.25f;

      Body ground = getWorld().createBody(bd);
      ground.createFixture(shape, 0.0f);
    }

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

      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 25.0f;
View Full Code Here

  public AbstractElement(Vec2 position, int category, int mask) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DYNAMIC;
    bodyDef.position = position;
   
    PolygonShape polygonShape = new PolygonShape();
    polygonShape.setAsBox(1.1f, 1.1f);
    polygonShape.m_radius = 1;

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = polygonShape;
    fixtureDef.density = 1;
View Full Code Here

      Shape shape;
      for (shape = body.getShapeList(); shape != null; shape = shape.getNext()) {
        switch (shape.getType()) {
        case POLYGON_SHAPE:
          app.beginShape();
          PolygonShape poly = (PolygonShape)shape;
          int count = poly.getVertexCount();
          Vec2[] verts = poly.getVertices();
          for(int i = 0; i < count; i++) {
            Vec2 vert = body.getWorldLocation(verts[i]);
            app.vertex(vert.x , vert.y );
          }
          app.endShape();
View Full Code Here

TOP

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

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.