Examples of PolygonShape


Examples of org.jbox2d.collision.shapes.PolygonShape

    this.space=space;
    this.image=MEngine.getAssetManager().getSpriteSheet("volcano.png");
   
    BodyDef bodyDef=new BodyDef();
    bodyDef.position.set(CoordinateConverter.coordPixelsToWorld(p));
    PolygonShape shape=new PolygonShape();
    Vec2[] vertices={
        CoordinateConverter.vectorPixelsToWorld(new Vector(-250,75)),
        CoordinateConverter.vectorPixelsToWorld(new Vector(250,75)),
        CoordinateConverter.vectorPixelsToWorld(new Vector(CRATER_WIDTH/2,-75)),
        CoordinateConverter.vectorPixelsToWorld(new Vector(-CRATER_WIDTH/2,-75)),
       
       
    };
   
   
    body=space.getWorld().createBody(bodyDef);
   
    shape.set(vertices, vertices.length);
   
    aabb=CoordinateConverter.transformAABB(body.createFixture(shape, 0f).getAABB());
  }
View Full Code Here

Examples of org.jbox2d.collision.shapes.PolygonShape

   * @param friction The friction of the rectangle
   */
  public Rectangle(float width, float height, float density, float restitution, float friction) {
    super();
   
    def.shape = shape = new PolygonShape();
    shape.setAsBox(width / 2, height / 2);
    def.density = density;
    def.restitution = restitution;
    def.friction = friction;
   
View Full Code Here

Examples of org.jbox2d.collision.shapes.PolygonShape

   * @param friction
   *            The friction of the polygon
   */
  public Polygon(float density, float restitution, float friction) {
    super();
    def.shape = shape = new PolygonShape();
    def.density = density;
    def.restitution = restitution;
    def.friction = friction;
  }
View Full Code Here

Examples of org.jbox2d.collision.shapes.PolygonShape

            Vec2 oldSize = getSize().clone();
            Vec2 newPos =  new Vec2();
            Vec2 newSize = new Vec2();

            //  Common.info(1,"DOWN: oldPOS="+getPosition()+" oldSIZE="+getSize());
            PolygonShape newShape = new PolygonShape();

            //bodydef = new BodyDef();
            //level.delElement(this);
            if (isBending) {
                newPos = new Vec2(oldPos.x, oldPos.y + oldSize.y / 2f- standardSize.y / 2);
View Full Code Here

Examples of org.jbox2d.collision.shapes.PolygonShape

            Point center) {
        if (shape == null)
            return new Rectangle(center.x - 5, center.y - 5, 10, 10);
        if (shape.getType() == ShapeType.POLYGON) {
            java.awt.Polygon result = new java.awt.Polygon();
            PolygonShape pshape = (PolygonShape) shape;
            for (int i = 0; i < pshape.getVertexCount(); i++) {
                Vec2 v = pshape.getVertex(i);
                result.addPoint((int) (v.x * scale.x) + center.x,
                                (int) (v.y * scale.y) + center.y);
            }
            return result;
        }
View Full Code Here

Examples of org.jbox2d.collision.shapes.PolygonShape

    {
      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

Examples of org.jbox2d.collision.shapes.PolygonShape

      return;
    }

    Body ground = null;
    {
      PolygonShape sd = new PolygonShape();
      sd.setAsBox(50.0f, 0.4f);

      BodyDef bd = new BodyDef();
      bd.position.set(0.0f, 0.0f);
      ground = getWorld().createBody(bd);
      ground.createFixture(sd, 0f);

      sd.setAsBox(0.4f, 50.0f, new Vec2(-10.0f, 0.0f), 0.0f);
      ground.createFixture(sd, 0f);
      sd.setAsBox(0.4f, 50.0f, new Vec2(10.0f, 0.0f), 0.0f);
      ground.createFixture(sd, 0f);
    }

    ConstantVolumeJointDef cvjd = new ConstantVolumeJointDef();

    float cx = 0.0f;
    float cy = 10.0f;
    float rx = 5.0f;
    float ry = 5.0f;
    int nBodies = 20;
    float bodyRadius = 0.5f;
    for (int i = 0; i < nBodies; ++i) {
      float angle = MathUtils.map(i, 0, nBodies, 0, 2 * 3.1415f);
      BodyDef bd = new BodyDef();
      // bd.isBullet = true;
      bd.fixedRotation = true;

      float x = cx + rx * (float) Math.sin(angle);
      float y = cy + ry * (float) Math.cos(angle);
      bd.position.set(new Vec2(x, y));
      bd.type = BodyType.DYNAMIC;
      Body body = getWorld().createBody(bd);

      FixtureDef fd = new FixtureDef();
      CircleShape cd = new CircleShape();
      cd.m_radius = bodyRadius;
      fd.shape = cd;
      fd.density = 1.0f;
      body.createFixture(fd);
      cvjd.addBody(body);
    }

    cvjd.frequencyHz = 10.0f;
    cvjd.dampingRatio = 1.0f;
    cvjd.collideConnected = false;
    getWorld().createJoint(cvjd);

    BodyDef bd2 = new BodyDef();
    bd2.type = BodyType.DYNAMIC;
    PolygonShape psd = new PolygonShape();
    psd.setAsBox(3.0f, 1.5f, new Vec2(cx, cy + 15.0f), 0.0f);
    bd2.position = new Vec2(cx, cy + 15.0f);
    Body fallingBox = getWorld().createBody(bd2);
    fallingBox.createFixture(psd, 1.0f);
  }
View Full Code Here

Examples of org.jbox2d.collision.shapes.PolygonShape

    {

      BodyDef bd = new BodyDef();
      bd.position.set(0.0f, 0.0f);
      ground = getWorld().createBody(bd);
      PolygonShape shape = new PolygonShape();
      shape.setAsBox(5.0f, 0.5f);
      ground.createFixture(shape, 0);

      shape.setAsBox(1.0f, 0.2f, new Vec2(0.0f, 4.0f), -0.2f);
      ground.createFixture(shape, 0);
      shape.setAsBox(1.5f, 0.2f, new Vec2(-1.2f, 5.2f), -1.5f);
      ground.createFixture(shape, 0);
      shape.setAsBox(0.5f, 50.0f, new Vec2(5.0f, 0.0f), 0.0f);
      ground.createFixture(shape, 0);



      shape.setAsBox(0.5f, 3.0f, new Vec2(-8.0f, 0.0f), 0.0f);
      ground.createFixture(shape, 0);

      shape.setAsBox(2.0f, 0.1f, new Vec2(-6.0f, -2.8f), 0.1f);
      ground.createFixture(shape, 0);

      CircleShape cd = new CircleShape();
      cd.m_radius = 0.5f;
      cd.m_p.set(-0.5f, -4.0f);
      ground.createFixture(cd, 0);

    }

    liquid = new Body[nParticles];
    float massPerParticle = totalMass / nParticles;
    // PointDef pd = new PointDef();
    // pd.mass = massPerParticle;
    // pd.restitution = 0.0f;
    // pd.filter.groupIndex = -10;
    CircleShape pd = new CircleShape();
    FixtureDef fd = new FixtureDef();
    fd.shape = pd;
    fd.density = 1f;
    fd.filter.groupIndex = -10;
    pd.m_radius = .05f;
    fd.restitution = 0.4f;
    fd.friction = 0.0f;
    float cx = 0.0f;
    float cy = 25.0f;
    for (int i = 0; i < nParticles; ++i) {
      BodyDef bd = new BodyDef();
      bd.position =
          new Vec2(MathUtils.randomFloat(cx - boxWidth * .5f, cx + boxWidth * .5f),
              MathUtils.randomFloat(cy - boxHeight * .5f, cy + boxHeight * .5f));
      bd.fixedRotation = true;
      bd.type = BodyType.DYNAMIC;
      Body b = getWorld().createBody(bd);

      b.createFixture(fd).setUserData(LIQUID_INT);

      MassData md = new MassData();
      md.mass = massPerParticle;
      md.I = 1.0f;
      b.setMassData(md);
      b.setSleepingAllowed(false);
      liquid[i] = b;
    }

    PolygonShape polyDef = new PolygonShape();
    polyDef.setAsBox(MathUtils.randomFloat(0.3f, 0.7f), MathUtils.randomFloat(0.3f, 0.7f));
    BodyDef bodyDef = new BodyDef();
    bodyDef.position = new Vec2(0.0f, 25.0f);
    bodyDef.type = BodyType.DYNAMIC;
    bod = getWorld().createBody(bodyDef);
    bod.createFixture(polyDef, 1f);
View Full Code Here

Examples of org.jbox2d.collision.shapes.PolygonShape

      }
    }

    if (bod.getWorldCenter().y < -15.0f) {
      getWorld().destroyBody(bod);
      PolygonShape polyDef = new PolygonShape();
      polyDef.setAsBox(MathUtils.randomFloat(0.3f, 0.7f), MathUtils.randomFloat(0.3f, 0.7f));
      BodyDef bodyDef = new BodyDef();
      bodyDef.position = new Vec2(0.0f, 25.0f);
      bodyDef.type = BodyType.DYNAMIC;
      bod = getWorld().createBody(bodyDef);
      bod.createFixture(polyDef, 1f);
View Full Code Here

Examples of org.jbox2d.collision.shapes.PolygonShape

      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 = 5.0f;
      bd.linearDamping = 0.1f;

      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
TOP
Copyright © 2018 www.massapi.com. 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.