Package org.jbox2d.collision.shapes

Examples of org.jbox2d.collision.shapes.PolygonShape


   * @param color
   */
  private Rectangle(int contentPower,ShapesController controller, Point p,double angle,double width,double height,CssColor color){
    super(contentPower,controller, p, width, height, angle, color);
    if(this.isVerified()){
      PolygonShape shape=new PolygonShape();
      FixtureDef fixtureDef=new FixtureDef();
     
      shape.setAsBox(CoordinateConverter.scalerPixelsToWorld(width/2), CoordinateConverter.scalerPixelsToWorld(height/2));
     
      fixtureDef.shape=shape;
      fixtureDef.friction=0.6f;
      fixtureDef.density=1.2f;
      fixtureDef.restitution=0.6f;
View Full Code Here


  protected StaticLine(int contentPower,boolean beControlled,Point p1,Point p2, CssColor color){
    super(contentPower,beControlled, p1, p2, color);
    if(isVerified()){
      Vector rpA=position.delta(pointA);
      Vector rpB=position.delta(pointB);
      PolygonShape lineP=new PolygonShape();
      lineP.setAsEdge(CoordinateConverter.vectorPixelToWorld(rpA), CoordinateConverter.vectorPixelToWorld(rpB));
      fixture=body.createFixture(lineP, 0f);
      aabb=fixture.getAABB();
     
    }
  }
View Full Code Here

    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

   * @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

   * @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

            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

            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

    {
      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

      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

    {

      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

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.