Package org.jbox2d.collision.shapes

Examples of org.jbox2d.collision.shapes.PolygonShape


                    case Keyboard.KEY_C:
                        Vec2 bodyPosition = new Vec2(Mouse.getX(), Mouse.getY()).mul(0.5f).mul(1 / 30f);
                        BodyDef boxDef = new BodyDef();
                        boxDef.position.set(bodyPosition);
                        boxDef.type = BodyType.DYNAMIC;
                        PolygonShape boxShape = new PolygonShape();
                        boxShape.setAsBox(0.75f, 0.75f);
                        Body box = world.createBody(boxDef);
                        FixtureDef boxFixture = new FixtureDef();
                        boxFixture.density = 0.1f;
                        boxFixture.shape = boxShape;
                        box.createFixture(boxFixture);
View Full Code Here


    private static void setUpObjects() {
        BodyDef boxDef = new BodyDef();
        boxDef.position.set(320 / 30 / 2f, 240 / 30 / 2f);
        boxDef.type = BodyType.DYNAMIC;
        PolygonShape boxShape = new PolygonShape();
        boxShape.setAsBox(0.75f, 0.75f);
        Body box = world.createBody(boxDef);
        FixtureDef boxFixture = new FixtureDef();
        boxFixture.density = 0.1f;
        boxFixture.shape = boxShape;
        box.createFixture(boxFixture);
        bodies.add(box);

        BodyDef groundDef = new BodyDef();
        groundDef.position.set(0, 0);
        groundDef.type = BodyType.STATIC;
        PolygonShape groundShape = new PolygonShape();
        groundShape.setAsBox(1000, 0);
        Body ground = world.createBody(groundDef);
        FixtureDef groundFixture = new FixtureDef();
        groundFixture.density = 1;
        groundFixture.restitution = 0.3f;
        groundFixture.shape = groundShape;
        ground.createFixture(groundFixture);

        BodyDef leftWallDef = new BodyDef();
        leftWallDef.position.set(0, 0);
        leftWallDef.type = BodyType.STATIC;
        PolygonShape leftWallShape = new PolygonShape();
        leftWallShape.setAsBox(0, 1000);
        Body leftWall = world.createBody(leftWallDef);
        FixtureDef leftWallFixture = new FixtureDef();
        leftWallFixture.density = 1;
        leftWallFixture.restitution = 0.3f;
        leftWallFixture.shape = leftWallShape;
        leftWall.createFixture(leftWallFixture);

        BodyDef rightWallDef = new BodyDef();
        rightWallDef.position.set(320f / 30, 0);
        rightWallDef.type = BodyType.STATIC;
        PolygonShape rightWallShape = new PolygonShape();
        rightWallShape.setAsBox(0, 1000);
        Body rightWall = world.createBody(rightWallDef);
        FixtureDef rightWallFixture = new FixtureDef();
        rightWallFixture.density = 1;
        rightWallFixture.restitution = 0.3f;
        rightWallFixture.shape = rightWallShape;
        rightWall.createFixture(rightWallFixture);

        BodyDef topWallDef = new BodyDef();
        topWallDef.position.set(0, 240f / 30);
        topWallDef.type = BodyType.STATIC;
        PolygonShape topWallShape = new PolygonShape();
        topWallShape.setAsBox(1000, 0);
        Body topWall = world.createBody(topWallDef);
        FixtureDef topWallFixture = new FixtureDef();
        topWallFixture.density = 1;
        topWallFixture.restitution = 0.3f;
        topWallFixture.shape = topWallShape;
View Full Code Here

    private static void setUpObjects() {
        BodyDef boxDef = new BodyDef();
        boxDef.position.set(320 / 30 / 2, 240 / 30 / 2);
        boxDef.type = BodyType.DYNAMIC;
        PolygonShape boxShape = new PolygonShape();
        boxShape.setAsBox(0.75f, 0.75f);
        Body box = world.createBody(boxDef);
        FixtureDef boxFixture = new FixtureDef();
        boxFixture.density = 0.1f;
        boxFixture.shape = boxShape;
        box.createFixture(boxFixture);
        bodies.add(box);

        BodyDef groundDef = new BodyDef();
        groundDef.position.set(0, 0);
        groundDef.type = BodyType.STATIC;
        PolygonShape groundShape = new PolygonShape();
        groundShape.setAsBox(1000, 0);
        Body ground = world.createBody(groundDef);
        FixtureDef groundFixture = new FixtureDef();
        groundFixture.density = 1;
        groundFixture.restitution = 0.3f;
        groundFixture.shape = groundShape;
View Full Code Here

      double rCos15=radius*Math.cos(Math.PI/12);
      double hw=(radius*0.8+rSin15)/2;
     
      FixtureDef triFixD=new FixtureDef();
      FixtureDef recFixD=new FixtureDef();
      PolygonShape triShape=new PolygonShape();
      PolygonShape recShape=new PolygonShape();
     
      Vector[] verticesP=new Vector[]{new Vector(rSin15,rCos15),new Vector(radius,0),new Vector(rSin15,-rCos15)};
      Vec2[] verticesW=new Vec2[3];
      for(int i=0;i<3;i++){
        verticesW[i]=CoordinateConverter.vectorPixelToWorld(verticesP[i]);
      }
      triShape.set(verticesW, verticesW.length);
      recShape.setAsBox(CoordinateConverter.scalerPixelsToWorld(hw),
          CoordinateConverter.scalerPixelsToWorld(radius*0.6) ,
          CoordinateConverter.vectorPixelToWorld(new Vector(rSin15-hw,0)),0);
     
      triFixD.isSensor=true;
      recFixD.isSensor=true;
View Full Code Here

    if(isVerified()){
      this.vertices=vertices;
     
      this.body.setType(BodyType.DYNAMIC);
      this.body.setUserData(this);
      PolygonShape shape=new PolygonShape();
      FixtureDef fixtureDef=new FixtureDef();
     
      Vec2[] vs=new Vec2[vertices.length];
      for(int i=0;i<3;i++){
        vs[i]=CoordinateConverter.vectorPixelToWorld(vertices[i]);
      }
     
      shape.set(vs, 3);
     
      fixtureDef.shape=shape;
      fixtureDef.friction=0.8f;
      fixtureDef.density=3f;
      fixtureDef.restitution=0.3f;
View Full Code Here

    points=Point.getRotatedPoint(getPosition(), getAngle(),tlP,trP,crossP,bmP,blP,brP);
   
    Vec2 crossV=CoordinateConverter.vectorPixelToWorld(position.delta(crossP));
   
    BodyDef bodyD=new BodyDef();
    PolygonShape[] edges=new PolygonShape[]{new PolygonShape(),new PolygonShape(),new PolygonShape(),new PolygonShape()};
   
    bodyD.type=BodyType.STATIC;
    bodyD.angle=(float)-getAngle();
    bodyD.position.set(CoordinateConverter.coordPixelToWorld(getPosition()));
    this.body=creator.getWorld().getWorld().createBody(bodyD);
View Full Code Here

      this.body.setUserData(this);
      body.setBullet(true);
     
      FixtureDef fixD=new FixtureDef();
       
      PolygonShape lineP=new PolygonShape();
     
      this.hL=getWidth()/2;
       
      lineP.setAsBox(CoordinateConverter.scalerPixelsToWorld(getWidth())/2
          ,CoordinateConverter.scalerPixelsToWorld(1),new Vec2(),0);
           
      fixD.density=1.2f;
      fixD.shape=lineP;
      fixD.restitution=0.75f;
View Full Code Here

    seP.translate(getHeight(), getHeight());
    swP.translate(-getHeight(), getHeight());
    this.points=Point.getRotatedPoint(getPosition(),getAngle(),nwP,neP,seP,swP);
   
    BodyDef bodyD=new BodyDef();
    PolygonShape[] edges=new PolygonShape[]{new PolygonShape(),new PolygonShape(),new PolygonShape(),new PolygonShape()};
   
    bodyD.type=BodyType.STATIC;
    bodyD.angle=(float)-getAngle();
    bodyD.position.set(CoordinateConverter.coordPixelToWorld(getPosition()));
    this.body=creator.getWorld().getWorld().createBody(bodyD);
View Full Code Here

  private Polygon (int contentPower,ShapesController controller,Point p,double angle,Vector[] vertices,CssColor color){
    super(contentPower,controller, p, 0, 0, angle, color);
    if(this.isVerified()){
      this.vertices=vertices;
     
      PolygonShape shape=new PolygonShape();
      FixtureDef fixtureDef=new FixtureDef();
     
      Vec2[] vs=new Vec2[vertices.length];
      for(int i=0;i<vs.length;i++){
        vs[i]=CoordinateConverter.vectorPixelToWorld(vertices[i]);
      }
     
      shape.set(vs, vs.length);
     
      fixtureDef.shape=shape;
      fixtureDef.friction=0.7f;
      fixtureDef.density=1.5f;
      fixtureDef.restitution=0.6f;
View Full Code Here

      FixtureDef cirFixDA=new FixtureDef();
      FixtureDef cirFixDB=new FixtureDef();
     
      CircleShape cirShapeA=new CircleShape();
      CircleShape cirShapeB=new CircleShape();
      PolygonShape recShape=new PolygonShape();
     
      cirShapeA.m_radius=radius;
      cirShapeB.m_radius=radius;
      cirShapeA.m_p.set(CoordinateConverter.vectorPixelToWorld(position.delta(pointA)));
      cirShapeB.m_p.set(CoordinateConverter.vectorPixelToWorld(position.delta(pointB)));
      recShape.setAsBox(CoordinateConverter.scalerPixelsToWorld(getWidth()/2),radius, new Vec2(),(float)-getAngle());
     
      recFixD.isSensor=true;
      cirFixDA.isSensor=true;
      cirFixDB.isSensor=true;
     
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.