Examples of PolygonDef


Examples of org.jbox2d.collision.PolygonDef

  }

  static ShapeDef translateShape(Shape shape, double elasticity) {
    if (shape instanceof Polygon) {
      Polygon poly = (Polygon) shape;
      PolygonDef def = new PolygonDef();
      // TODO Set def.density for realistic mass;
      def.restitution = (float) elasticity;
      for (int i = 0; i < poly.npoints; i++) {
        def.vertices.add(new Vec2(poly.xpoints[i], poly.ypoints[i]));
      }
View Full Code Here

Examples of org.jbox2d.collision.shapes.PolygonDef

//    dymBodyDef.position = new Vec2(pos.x, pos.y);
    dymBodyDef.position = new Vec2(scaledPos.x, scaledPos.y);//FIXME WORKS?
    this.bodyDefB4CreationCallback(dymBodyDef);
    this.body = world.createBody(dymBodyDef);
   
    PolygonDef dymShapeDef = new PolygonDef();
    dymShapeDef.setAsBox( (width/2f)/scale, (height/2f)/scale);
//    dymShapeDef.setAsBox( (width/2f), (height/2f));
    if (density != 0.0f){
      dymShapeDef.density     = density;
      dymShapeDef.friction     = friction;
      dymShapeDef.restitution   = restitution;
View Full Code Here

Examples of org.jbox2d.collision.shapes.PolygonDef

    //Create a polygon too see if its simple and eventually decompose it
    org.jbox2d.util.nonconvex.Polygon myPoly = new org.jbox2d.util.nonconvex.Polygon(xArr, yArr);

    //System.out.println("Polygon is simple! -> Using convex decomposition for physics shape and glu triangulated mesh for display!");
    PolygonDef pd = new PolygonDef();
    if (density != 0.0f){
      pd.density     = density;
      pd.friction   = friction;
      pd.restitution   = restituion;
    }

    //Create polygon body
    BodyDef dymBodyDef = new BodyDef();
    dymBodyDef.position = new Vec2(scaledPos.x, scaledPos.y);
    this.bodyDefB4CreationCallback(dymBodyDef);
    this.body = world.createBody(dymBodyDef);

    this.polyDefB4CreationCallback(pd); //FIXME TEST
   
    int success = org.jbox2d.util.nonconvex.Polygon.decomposeConvexAndAddTo(myPoly, body, pd);
    if (success != -1){
      System.out.println("-> Ear clipping SUCCESSFUL -> Using triangulated and polygonized shape for b2d.");
      body.setMassFromShapes();
      body.setUserData(this);
      this.setUserData("box2d", body);
      //Performance hit! but prevents object from sticking to another sometimes
//      theBody.setBullet(true);
    }else{
      System.out.println("-> Ear clipping had an ERROR - trying again by triangulating shape for b2d with GLU-Triangulator");
      GluTrianglulator triangulator = new GluTrianglulator(applet);
      List<Vertex> physicsTris = triangulator.tesselate(physicsVertices, GLU.GLU_TESS_WINDING_NONZERO);
      Vertex[] triangulatedBodyVerts = physicsTris.toArray(new Vertex[physicsTris.size()]);
      //System.out.println("GLU tris created: " + triangulatedBodyVerts.length);

      //Cap the max triangles - dont use anymore triangles for the physics body..
      int cap = 400;
      if (triangulatedBodyVerts.length > cap){
        //System.err.println("OVER cap! -> capping!");
        Vertex[] tmp = new Vertex[cap];
        System.arraycopy(triangulatedBodyVerts, 0, tmp, 0, cap);
        triangulatedBodyVerts = tmp;
      }

      //Create polygon body
      world.destroyBody(body);
      dymBodyDef = new BodyDef();
      dymBodyDef.position = new Vec2(scaledPos.x, scaledPos.y);
      this.bodyDefB4CreationCallback(dymBodyDef);
      body = world.createBody(dymBodyDef);
      for (int i = 0; i < triangulatedBodyVerts.length/3; i++) {
        //Create polygon definition
        PolygonDef polyDef = new PolygonDef();
        if (density != 0.0f){
          polyDef.density     = density;
          polyDef.friction     = friction;
          polyDef.restitution   = restituion;
        }
        //Add triangle vertices
        Vertex vertex1 = triangulatedBodyVerts[i*3];
        Vertex vertex2 = triangulatedBodyVerts[i*3+1];
        Vertex vertex3 = triangulatedBodyVerts[i*3+2];
        polyDef.addVertex(new Vec2(vertex1.x, vertex1.y));
        polyDef.addVertex(new Vec2(vertex2.x, vertex2.y));
        polyDef.addVertex(new Vec2(vertex3.x, vertex3.y));
       
        this.polyDefB4CreationCallback(pd); //FIXME TEST
       
        //Add poly to body
        body.createShape(polyDef);
View Full Code Here

Examples of org.jbox2d.collision.shapes.PolygonDef

    //Create a polygon too see if its simple and eventually decompose it
    org.jbox2d.util.nonconvex.Polygon myPoly = new org.jbox2d.util.nonconvex.Polygon(xArr, yArr);

    //System.out.println("Polygon is simple! -> Using convex decomposition for physics shape and glu triangulated mesh for display!");
    PolygonDef pd = new PolygonDef();
    if (density != 0.0f){
      pd.density     = density;
      pd.friction   = friction;
      pd.restitution   = restituion;
    }

    //Create polygon body
    BodyDef dymBodyDef = new BodyDef();
    dymBodyDef.position = new Vec2(scaledPos.x, scaledPos.y);
    this.bodyDefB4CreationCallback(dymBodyDef);
    this.body = world.createBody(dymBodyDef);
   
    this.polyDefB4CreationCallback(pd); //FIXME TEST
   
    int success = org.jbox2d.util.nonconvex.Polygon.decomposeConvexAndAddTo(myPoly, body, pd);
    if (success != -1){
      System.out.println("-> Ear clipping SUCCESSFUL -> Using triangulated and polygonized shape for b2d.");
      body.setMassFromShapes();
      body.setUserData(this);
      this.setUserData("box2d", body);
      //Performance hit! but prevents object from sticking to another sometimes
//      theBody.setBullet(true);
    }else{
      System.out.println("-> Ear clipping had an ERROR - trying again by triangulating shape for b2d with GLU-Triangulator");
      GluTrianglulator triangulator = new GluTrianglulator(this.getRenderer());
      List<Vertex> physicsTris = triangulator.tesselate(bodyVerts, GLU.GLU_TESS_WINDING_NONZERO);
      Vertex[] triangulatedBodyVerts = physicsTris.toArray(new Vertex[physicsTris.size()]);
      //System.out.println("GLU tris created: " + triangulatedBodyVerts.length);

      //Cap the max triangles - dont use anymore triangles for the physics body..
      int cap = 400;
      if (triangulatedBodyVerts.length > cap){
        //System.err.println("OVER cap! -> capping!");
        Vertex[] tmp = new Vertex[cap];
        System.arraycopy(triangulatedBodyVerts, 0, tmp, 0, cap);
        triangulatedBodyVerts = tmp;
      }

      //Create polygon body
      world.destroyBody(body);
      dymBodyDef = new BodyDef();
      dymBodyDef.position = new Vec2(scaledPos.x, scaledPos.y);
      this.bodyDefB4CreationCallback(dymBodyDef);
      body = world.createBody(dymBodyDef);
      for (int i = 0; i < triangulatedBodyVerts.length/3; i++) {
        //Create polygon definition
        PolygonDef polyDef = new PolygonDef();
        if (density != 0.0f){
          polyDef.density     = density;
          polyDef.friction     = friction;
          polyDef.restitution   = restituion;
        }
        //Add triangle vertices
        Vertex vertex1 = triangulatedBodyVerts[i*3];
        Vertex vertex2 = triangulatedBodyVerts[i*3+1];
        Vertex vertex3 = triangulatedBodyVerts[i*3+2];
        polyDef.addVertex(new Vec2(vertex1.x, vertex1.y));
        polyDef.addVertex(new Vec2(vertex2.x, vertex2.y));
        polyDef.addVertex(new Vec2(vertex3.x, vertex3.y));
       
        this.polyDefB4CreationCallback(polyDef); //FIXME TEST
        //Add poly to body
        body.createShape(polyDef);
      }
View Full Code Here

Examples of org.jbox2d.collision.shapes.PolygonDef

      yArr[i] = v.y;
    }
    //Create a polygon too see if its simple and eventually decompose it
    org.jbox2d.util.nonconvex.Polygon myPoly = new org.jbox2d.util.nonconvex.Polygon(xArr, yArr);
   
    PolygonDef pd = new PolygonDef();
      if (density != 0.0f){
        pd.density     = density;
        pd.friction   = friction;
        pd.restitution   = restituion;
    }
     
    //Create polygon body
    BodyDef dymBodyDef = new BodyDef();
//    dymBodyDef.position = new Vec2(position.x /worldScale, position.y /worldScale);
    dymBodyDef.position = new Vec2(position.x , position.y );
    this.bodyDefB4CreationCallback(dymBodyDef);
    this.body = world.createBody(dymBodyDef);
   
//      GluTrianglulator triangulator = new GluTrianglulator(applet);
//    List<Vertex> physicsTris = triangulator.tesselate(vertices, GLU.GLU_TESS_WINDING_NONZERO);
//    Vertex[] triangulatedBodyVerts = physicsTris.toArray(new Vertex[physicsTris.size()]);
//    triangulator.deleteTess();
   
//    //Set the triangulated vertices as the polygons (mesh's) vertices
//    this.setGeometryInfo(new GeometryInfo(applet, triangulatedBodyVerts));
   
    //Decompose poly and add verts to phys body if possible
      int success = org.jbox2d.util.nonconvex.Polygon.decomposeConvexAndAddTo(myPoly, this.body, pd);
     
      if (success != -1){
        System.out.println("-> Ear clipping SUCCESSFUL -> Using triangulated and polygonized shape for b2d.");
        this.body.setMassFromShapes();
        this.body.setUserData(this);
        this.setUserData("box2d", this.body); //TODO rename userData
      //Performance hit! but prevents object from sticking to another sometimes
//      theBody.setBullet(true);
      }else{
        System.out.println("-> Ear clipping had an ERROR - trying again by triangulating shape for b2d with GLU-Triangulator");
//        GluTrianglulator triangulator = new GluTrianglulator(app);
//        List<Vertex> physicsTris = triangulator.tesselate(bodyVerts, GLU.GLU_TESS_WINDING_NONZERO);
//        Vertex[] triangulatedBodyVerts = physicsTris.toArray(new Vertex[physicsTris.size()]);
        //System.out.println("GLU tris created: " + triangulatedBodyVerts.length);
       
        //Cap the max triangles - dont use anymore triangles for the physics body..
        int cap = 400;
        if (triangulatedBodyVerts.length > cap){
          //System.err.println("OVER cap! -> capping!");
          Vertex[] tmp = new Vertex[cap];
          System.arraycopy(triangulatedBodyVerts, 0, tmp, 0, cap);
          triangulatedBodyVerts = tmp;
        }
       
        //Create polygon body
        world.destroyBody(this.body);
        dymBodyDef = new BodyDef();
        dymBodyDef.position = new Vec2(position.x, position.y);
        this.bodyDefB4CreationCallback(dymBodyDef);
        this.body = world.createBody(dymBodyDef);
        for (int i = 0; i < triangulatedBodyVerts.length/3; i++) {
          //Create polygon definition
          PolygonDef polyDef = new PolygonDef();
          if (density != 0.0f){
            polyDef.density     = density;
            polyDef.friction     = friction;
            polyDef.restitution   = restituion;
          }
          this.polyDefB4CreationCallback(polyDef); //FIXME TEST
         
          //Add triangle vertices
          Vertex vertex1 = triangulatedBodyVerts[i*3];
          Vertex vertex2 = triangulatedBodyVerts[i*3+1];
          Vertex vertex3 = triangulatedBodyVerts[i*3+2];
          polyDef.addVertex(new Vec2(vertex1.x, vertex1.y));
          polyDef.addVertex(new Vec2(vertex2.x, vertex2.y));
          polyDef.addVertex(new Vec2(vertex3.x, vertex3.y));
          //Add poly to body
          this.body.createShape(polyDef);
        }
        this.body.setMassFromShapes();
        //FIXME TEST - performance hit!?
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.