Examples of GluTrianglulator


Examples of org.mt4j.util.opengl.GluTrianglulator

    //Caluculate vertices from bezierinformation
    int segments = 10;
    List<Vertex[]> bezierContours = ToolsGeometry.createVertexArrFromBezierVertexArrays(contours, segments);
   
    //Triangulate bezier contours
    GluTrianglulator triangulator = new GluTrianglulator(pApplet);
    List<Vertex> tris = triangulator.tesselate(bezierContours);
    //Set new geometry info with triangulated vertices
    super.setGeometryInfo(new GeometryInfo(pApplet, tris.toArray(new Vertex[tris.size()])));
    //Set Mesh outlines
    this.setOutlineContours(bezierContours);
    //Delete triangulator (C++ object)
    triangulator.deleteTess();
//    */
   
    this.setPickable(false);
  }
 
View Full Code Here

Examples of org.mt4j.util.opengl.GluTrianglulator

 
 
  public void setVertices(List<Vertex[]> contours, int windingRule) {
    this.setOutlineContours(contours);
   
    GluTrianglulator triangulator = new GluTrianglulator(getRenderer());
    List<Vertex> tris = triangulator.tesselate(contours, windingRule);
    triangulator.deleteTess();
   
    super.setVertices(tris.toArray(new Vertex[tris.size()]));
  }
View Full Code Here

Examples of org.mt4j.util.opengl.GluTrianglulator

  public void setVertices(Vertex[] vertices) {
    List<Vertex[]> contours = new ArrayList<Vertex[]>();
    contours.add(vertices);
    this.setOutlineContours(contours);
   
    GluTrianglulator triangulator = new GluTrianglulator(getRenderer());
    Vertex[] tris = triangulator.tesselate(vertices);
    triangulator.deleteTess();
   
    super.setVertices(tris);
  }
View Full Code Here

Examples of org.mt4j.util.opengl.GluTrianglulator

      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);
      }
      body.setMassFromShapes();
      //performance hit!?
      //theBody.setBullet(true);
      body.setUserData(this);
      this.setUserData("box2d", body);
      triangulator.deleteTess();
    }
   

  }
View Full Code Here

Examples of org.mt4j.util.opengl.GluTrianglulator

      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);
      }
      body.setMassFromShapes();
      //FIXME TEST - performance hit!?
      //theBody.setBullet(true);
      body.setUserData(this);
      this.setUserData("box2d", body);
      triangulator.deleteTess();
    }
  }
View Full Code Here

Examples of org.mt4j.util.opengl.GluTrianglulator

   */
  private AbstractShape createComplexPoly(ArrayList<Vertex[]> contours, int windingRule) {
    int segments = 10;
    List<Vertex[]> bezierContours = ToolsGeometry.createVertexArrFromBezierVertexArrays(contours, segments);
   
    GluTrianglulator triangulator = new GluTrianglulator(pa);
   
//    MTTriangleMesh mesh = triangulator.toTriangleMesh(bezierContours, windingRule);
   
    triangulator.tesselate(bezierContours, windingRule);
    List<Vertex> tris = triangulator.getTriList();
    Vertex[] verts = tris.toArray(new Vertex[tris.size()]);
    GeometryInfo geom = new GeometryInfo(pa, verts);
   
//    MTTriangleMesh mesh = new MTTriangleMesh(pa, geom);
    MTTriangleMesh mesh = new SVGMesh(pa, geom);
   
    //TODO put outline contourse in own class SVGMesh!
    //not belonging in general mesh class
    mesh.setOutlineContours(bezierContours);
   
    triangulator.deleteTess(); //Delete triangulator (C++ object)
    return mesh;
  }
View Full Code Here

Examples of org.mt4j.util.opengl.GluTrianglulator

  }
 
 
  public static List<Vertex> triangulateGLU(MTApplication app, List<Vertex> vertices){
    System.err.println("Trying glu triangulation..");
    GluTrianglulator triangulator = new GluTrianglulator(app);
    Vertex[] vertexArray = vertices.toArray(new Vertex[vertices.size()]);
    List<Vertex> triVerts = triangulator.tesselate(vertexArray, GLU.GLU_TESS_WINDING_NONZERO);
    return triVerts;
  }
View Full Code Here

Examples of org.mt4j.util.opengl.GluTrianglulator

   
    Vertex.scaleVectorArray(vertices, Vector3D.ZERO_VECTOR, 1f/worldScale, 1f/worldScale, 1);
   
    position.scaleLocal(1f/worldScale); //FIXME REALLY?
   
      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));
   
    this.translate(position);
    Vector3D realBodyCenter = this.getCenterPointGlobal(); //FIXME geht nur if detached from world //rename futurebodycenter?
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.