Package org.jbox2d.collision.shapes

Examples of org.jbox2d.collision.shapes.PolygonShape


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

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

      body.createFixture(shape, 1.0f);
    }
  }
View Full Code Here


    {
      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);
      m_polygons[0] = new PolygonShape();
      m_polygons[0].set(vertices, 3);
    }

    {
      Vec2 vertices[] = new Vec2[3];
      vertices[0] = new Vec2(-0.1f, 0.0f);
      vertices[1] = new Vec2(0.1f, 0.0f);
      vertices[2] = new Vec2(0.0f, 1.5f);
      m_polygons[1] = new PolygonShape();
      m_polygons[1].set(vertices, 3);
    }

    {
      float w = 1.0f;
      float b = w / (2.0f + MathUtils.sqrt(2.0f));
      float s = MathUtils.sqrt(2.0f) * b;

      Vec2 vertices[] = new Vec2[8];
      vertices[0] = new Vec2(0.5f * s, 0.0f);
      vertices[1] = new Vec2(0.5f * w, b);
      vertices[2] = new Vec2(0.5f * w, b + s);
      vertices[3] = new Vec2(0.5f * s, w);
      vertices[4] = new Vec2(-0.5f * s, w);
      vertices[5] = new Vec2(-0.5f * w, b + s);
      vertices[6] = new Vec2(-0.5f * w, b);
      vertices[7] = new Vec2(-0.5f * s, 0.0f);

      m_polygons[2] = new PolygonShape();
      m_polygons[2].set(vertices, 8);
    }

    {
      m_polygons[3] = new PolygonShape();
      m_polygons[3].setAsBox(0.5f, 0.5f);
    }

    {
      m_circle = new CircleShape();
View Full Code Here

    }

    float xs[] = new float[] { 0.0f, -10.0f, -5.0f, 5.0f, 10.0f };

    for (int j = 0; j < e_columnCount; ++j) {
      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

    input.transformB = new Transform();
    {
      m_transformA = new Transform();
      m_transformA.setIdentity();
      m_transformA.p.set(0.0f, -0.2f);
      m_polygonA = new PolygonShape();
      m_polygonA.setAsBox(10.0f, 0.2f);
    }
   
    {
      m_positionB = new Vec2();
      m_positionB.set(12.017401f, 0.13678508f);
      m_angleB = -0.0109265f;
     
      m_transformB = new Transform();
      m_transformB.set(m_positionB, m_angleB);
     
      m_polygonB = new PolygonShape();
      m_polygonB.setAsBox(2.0f, 0.1f);
    }
    for (int i = 0; i < v.length; i++) {
      v[i] = new Vec2();
    }
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.5f);

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

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

    Vec2 vertices[] = new Vec2[3];
    vertices[0] = new Vec2(-1.0f, 0.0f);
    vertices[1] = new Vec2(1.0f, 0.0f);
    vertices[2] = new Vec2(0.0f, 2.0f);

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

    FixtureDef triangleShapeDef = new FixtureDef();
    triangleShapeDef.shape = polygon;
    triangleShapeDef.density = 1.0f;

    BodyDef triangleBodyDef = new BodyDef();
    triangleBodyDef.type = BodyType.DYNAMIC;
    triangleBodyDef.position.set(MathUtils.randomFloat(xLo, xHi), MathUtils.randomFloat(yLo, yHi));

    Body body1 = getWorld().createBody(triangleBodyDef);
    body1.createFixture(triangleShapeDef);

    // Large triangle (recycle definitions)
    vertices[0].mulLocal(2.0f);
    vertices[1].mulLocal(2.0f);
    vertices[2].mulLocal(2.0f);
    polygon.set(vertices, 3);

    triangleBodyDef.position.set(MathUtils.randomFloat(xLo, xHi), MathUtils.randomFloat(yLo, yHi));

    Body body2 = getWorld().createBody(triangleBodyDef);
    body2.createFixture(triangleShapeDef);

    // Small box
    polygon.setAsBox(1.0f, 0.5f);

    FixtureDef boxShapeDef = new FixtureDef();
    boxShapeDef.shape = polygon;
    boxShapeDef.density = 1.0f;

    BodyDef boxBodyDef = new BodyDef();
    boxBodyDef.type = BodyType.DYNAMIC;
    boxBodyDef.position.set(MathUtils.randomFloat(xLo, xHi), MathUtils.randomFloat(yLo, yHi));

    Body body3 = getWorld().createBody(boxBodyDef);
    body3.createFixture(boxShapeDef);

    // Large box (recycle definitions)
    polygon.setAsBox(2.0f, 1.0f);
    boxBodyDef.position.set(MathUtils.randomFloat(xLo, xHi), MathUtils.randomFloat(yLo, yHi));

    Body body4 = getWorld().createBody(boxBodyDef);
    body4.createFixture(boxShapeDef);
View Full Code Here

      fd.shape = circle_shape;

      Body ball = m_world.createBody(circle_bd);
      ball.createFixture(fd);

      PolygonShape polygon_shape = new PolygonShape();
      polygon_shape.setAsBox(10.0f, 0.2f, new Vec2(-10.0f, 0.0f), 0.0f);

      BodyDef polygon_bd = new BodyDef();
      polygon_bd.position.set(20.0f, 10.0f);
      polygon_bd.type = BodyType.DYNAMIC;
      polygon_bd.bullet = true;
      Body polygon_body = m_world.createBody(polygon_bd);
      polygon_body.createFixture(polygon_shape, 2.0f);

      RevoluteJointDef rjd = new RevoluteJointDef();
      rjd.initialize(ground, polygon_body, new Vec2(20.0f, 10.0f));
      rjd.lowerAngle = -0.25f * MathUtils.PI;
      rjd.upperAngle = 0.0f * MathUtils.PI;
      rjd.enableLimit = true;
      m_world.createJoint(rjd);
    }

    // Tests mass computation of a small object far from the origin
    {
      BodyDef bodyDef = new BodyDef();
      bodyDef.type = BodyType.DYNAMIC;
      Body body = m_world.createBody(bodyDef);

      PolygonShape polyShape = new PolygonShape();
      Vec2 verts[] = new Vec2[3];
      verts[0] = new Vec2(17.63f, 36.31f);
      verts[1] = new Vec2(17.52f, 36.69f);
      verts[2] = new Vec2(17.19f, 36.36f);
      polyShape.set(verts, 3);

      FixtureDef polyFixtureDef = new FixtureDef();
      polyFixtureDef.shape = polyShape;
      polyFixtureDef.density = 1;

View Full Code Here

    Body leftWall = null;
    Body rightWall = null;
    {
      // Ground
      PolygonShape sd = new PolygonShape();
      sd.setAsBox(50.0f, 10.0f);
      BodyDef bd = new BodyDef();
      bd.type = BodyType.STATIC;
      bd.position = new Vec2(0.0f, -10.0f);
      Body b = getWorld().createBody(bd);
      FixtureDef fd = new FixtureDef();
      fd.shape = sd;
      fd.friction = 1.0f;
      b.createFixture(fd);

      // Walls
      sd.setAsBox(3.0f, 50.0f);
      bd = new BodyDef();
      bd.position = new Vec2(45.0f, 25.0f);
      rightWall = getWorld().createBody(bd);
      rightWall.createFixture(sd, 0);
      bd.position = new Vec2(-45.0f, 25.0f);
      leftWall = getWorld().createBody(bd);
      leftWall.createFixture(sd, 0);

      // Corners
      bd = new BodyDef();
      sd.setAsBox(20.0f, 3.0f);
      bd.angle = (float) (-Math.PI / 4.0);
      bd.position = new Vec2(-35f, 8.0f);
      Body myBod = getWorld().createBody(bd);
      myBod.createFixture(sd, 0);
      bd.angle = (float) (Math.PI / 4.0);
      bd.position = new Vec2(35f, 8.0f);
      myBod = getWorld().createBody(bd);
      myBod.createFixture(sd, 0);

      // top
      sd.setAsBox(50.0f, 10.0f);
      bd.type = BodyType.STATIC;
      bd.angle = 0;
      bd.position = new Vec2(0.0f, 75.0f);
      b = getWorld().createBody(bd);
      fd.shape = sd;
View Full Code Here

        CircleShape c = (CircleShape) argShape;
        builder.setType(PbShapeType.CIRCLE);
        builder.setCenter(vecToPb(c.m_p));
        break;
      case POLYGON:
        PolygonShape p = (PolygonShape) argShape;
        builder.setType(PbShapeType.POLYGON);
        builder.setCentroid(vecToPb(p.m_centroid));
        for (int i = 0; i < p.m_count; i++) {
          builder.addPoints(vecToPb(p.m_vertices[i]));
          builder.addNormals(vecToPb(p.m_normals[i]));
View Full Code Here

    // Small triangle
    Vec2 vertices[] = new Vec2[3];
    vertices[0] = new Vec2(-1.0f, 0.0f);
    vertices[1] = new Vec2(1.0f, 0.0f);
    vertices[2] = new Vec2(0.0f, 2.0f);
    PolygonShape polygon = new PolygonShape();
    polygon.set(vertices, 3);

    FixtureDef triangleShapeDef = new FixtureDef();
    triangleShapeDef.shape = polygon;
    triangleShapeDef.density = 1.0f;

    triangleShapeDef.filter.groupIndex = k_smallGroup;
    triangleShapeDef.filter.categoryBits = k_triangleCategory;
    triangleShapeDef.filter.maskBits = k_triangleMask;

    BodyDef triangleBodyDef = new BodyDef();
    triangleBodyDef.type = BodyType.DYNAMIC;
    triangleBodyDef.position.set(-5.0f, 2.0f);

    Body body1 = getWorld().createBody(triangleBodyDef);
    body1.createFixture(triangleShapeDef);

    // Large triangle (recycle definitions)
    vertices[0].mulLocal(2.0f);
    vertices[1].mulLocal(2.0f);
    vertices[2].mulLocal(2.0f);
    polygon.set(vertices, 3);
    triangleShapeDef.filter.groupIndex = k_largeGroup;
    triangleBodyDef.position.set(-5.0f, 6.0f);
    triangleBodyDef.fixedRotation = true; // look at me!

    Body body2 = getWorld().createBody(triangleBodyDef);
    body2.createFixture(triangleShapeDef);

    {
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DYNAMIC;
      bd.position.set(-5.0f, 10.0f);
      Body body = getWorld().createBody(bd);

      PolygonShape p = new PolygonShape();
      p.setAsBox(0.5f, 1.0f);
      body.createFixture(p, 1.0f);

      PrismaticJointDef jd = new PrismaticJointDef();
      jd.bodyA = body2;
      jd.bodyB = body;
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.