Package org.mt4j.util.math

Examples of org.mt4j.util.math.Vertex


         //System.out.println(((double[]) vertexData).length);
//         /*
         double[] pointer;
            if (vertexData instanceof double[]){
              pointer = (double[]) vertexData;
              Vertex v = new Vertex();
             
              if (pointer.length >= 7){
//                gl.glColor4dv(pointer, 3);
//                v.setR((float) pointer[3]);
//                v.setG((float) pointer[4]);
//                v.setB((float) pointer[5]);
               
                v.setR((float) pointer[3]*255); //FIXME wirklich *255 interpolaten?
                v.setG((float) pointer[4]*255);
                v.setB((float) pointer[5]*255);
              }
//              gl.glVertex3dv(pointer, 0);  //TODO
            
              v.x = (float) pointer[0];
              v.y = (float) pointer[1];
View Full Code Here


        hull.add(hull.get(0).getCopy());
       
        Vertex[] newVerts = new Vertex[hull.size()];
        for (int i = 0; i < hull.size(); i++) {
          Vector3D vec = hull.get(i);
          newVerts[i] = new Vertex(vec);
        }
       
//        Vertex[] newVerts = (Vertex[])hull.toArray(new Vertex[hull.size()]);
//        System.out.println("Hull vertices: ");
        for (Vertex v : newVerts){
View Full Code Here

       * @param windingRule the winding rule
       */
      private void tesselateContour(Vertex[] contour, int windingRule){
        glu.gluTessBeginContour(tesselator);
        for(int i = 0; i < contour.length; i++) {
          Vertex v = contour[i];
          double[] pv = {v.x,v.y,v.z, v.getR()/255.0,v.getG()/255.0,v.getB()/255.0,v.getA()/255.0}; //{v.x,v.y,v.z};
          glu.gluTessVertex(tesselator, pv, 0, pv);
        }
        glu.gluTessEndContour(tesselator);
      }
View Full Code Here

    //Create vertex structure for creation of decomposition polygon (use the translated vertices)
    float xArr[] = new float[physicsVertices.length];
    float yArr[] = new float[physicsVertices.length];
    for (int i = 0; i < physicsVertices.length; i++) {
      Vertex v = physicsVertices[i];
      xArr[i] = v.x;
      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);

    //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
View Full Code Here

    //Create vertex structure for creation of decomposition polygon (use the translated vertices)
    float xArr[] = new float[bodyVerts.length];
    float yArr[] = new float[bodyVerts.length];
    for (int i = 0; i < bodyVerts.length; i++) {
      Vertex v = bodyVerts[i];
      xArr[i] = v.x;
      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);

    //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
View Full Code Here

   * @param width the width
   * @param height the height
   * @param pApplet the applet
   */
  public MTRectangle(float width, float height, PApplet pApplet) {
    this(new Vertex(0,0,0,0,0),width,height,pApplet);
  }
View Full Code Here

   * @param width the width
   * @param height the height
   * @param pApplet the applet
   */
  public MTRectangle(float x, float y, float width, float height, PApplet pApplet) {
    this(new Vertex(x,y,0,0,0),width,height,pApplet);
  }
View Full Code Here

   * @param width the width
   * @param height the height
   * @param pApplet the applet
   */
  public MTRectangle(float x, float y, float z, float width, float height, PApplet pApplet) {
    this(new Vertex(x,y,z,0,0),width,height,pApplet);
  }
View Full Code Here

   * @param height the height
   * @param pApplet the applet
   */
  public MTRectangle(Vertex upperLeft, float width, float height, PApplet pApplet) {
    super(new Vertex[]{
        new Vertex(upperLeft.x,      upperLeft.y,     upperLeft.z, 0, 0),
        new Vertex(upperLeft.x+width,   upperLeft.y,     upperLeft.z, 1, 0),
        new Vertex(upperLeft.x+width,   upperLeft.y+height, upperLeft.z, 1, 1),
        new Vertex(upperLeft.x,      upperLeft.y+height,  upperLeft.z, 0, 1),
        new Vertex(upperLeft.x,      upperLeft.y,    upperLeft.z, 0, 0)},
        pApplet);
   
    this.setName("unnamed rectangle");
    //
    this.setBoundsBehaviour(AbstractShape.BOUNDS_ONLY_CHECK);
View Full Code Here

    case CENTER:
      super.setPositionGlobal(position);
      break;
    case LOWER_LEFT:{
      Vertex[] vertices = this.getVerticesGlobal();
      Vertex lowerLeft = new Vertex(vertices[3]);
      this.translateGlobal(position.getSubtracted(lowerLeft));
    }break;
    case LOWER_RIGHT:{
      Vertex[] vertices = this.getVerticesGlobal();
      Vertex v = new Vertex(vertices[2]);
      this.translateGlobal(position.getSubtracted(v));
    }break;
    case UPPER_LEFT:{
      Vertex[] vertices = this.getVerticesGlobal();
      Vertex upperLeft = new Vertex(vertices[0]);
      this.translateGlobal(position.getSubtracted(upperLeft));
    }break;
    default:
      break;
    }
View Full Code Here

TOP

Related Classes of org.mt4j.util.math.Vertex

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.