Package org.mt4j.util.math

Examples of org.mt4j.util.math.Vertex


  public static List<Vertex> triangulateEarClips(List<Vertex> vertices){
    org.jbox2d.util.nonconvex.Triangle[] tri = getEarClipTriangles(vertices);
    List<Vertex> tris = new ArrayList<Vertex>();
    for (int i = 0; i < tri.length; i++) {
      org.jbox2d.util.nonconvex.Triangle triangle = tri[i];
      tris.add(new Vertex(triangle.x[0], triangle.y[0],0));
      tris.add(new Vertex(triangle.x[1], triangle.y[1],0));
      tris.add(new Vertex(triangle.x[2], triangle.y[2],0));
    }
    return tris;
  }
View Full Code Here


//          new Vertex(v[1].x,   - innerPaddingTop,     v[1].z, v[1].getTexCoordU(), v[1].getTexCoordV(), v[1].getR(), v[1].getG(), v[1].getB(), v[1].getA()),
//          new Vertex(v[2].x,   - innerPaddingTop + height + (2 * innerPaddingTop),   v[2].z, v[2].getTexCoordU(), v[2].getTexCoordV(), v[2].getR(), v[2].getG(), v[2].getB(), v[2].getA()),
//          new Vertex(v[3].x,  - innerPaddingTop + height + (2 * innerPaddingTop),  v[3].z, v[3].getTexCoordU(), v[3].getTexCoordV(), v[3].getR(), v[3].getG(), v[3].getB(), v[3].getA()),
//          new Vertex(v[4].x,  - innerPaddingTop,      v[4].z, v[4].getTexCoordU(), v[4].getTexCoordV(), v[4].getR(), v[4].getG(), v[4].getB(), v[4].getA()),
         
          new Vertex(v[0].x,  0,                 v[0].z, v[0].getTexCoordU(), v[0].getTexCoordV(), v[0].getR(), v[0].getG(), v[0].getB(), v[0].getA()),
          new Vertex(v[1].x,   0,                 v[1].z, v[1].getTexCoordU(), v[1].getTexCoordV(), v[1].getR(), v[1].getG(), v[1].getB(), v[1].getA()),
          new Vertex(v[2].x,   height + (2 * innerPaddingTop), v[2].z, v[2].getTexCoordU(), v[2].getTexCoordV(), v[2].getR(), v[2].getG(), v[2].getB(), v[2].getA()),
          new Vertex(v[3].x,  height + (2 * innerPaddingTop),  v[3].z, v[3].getTexCoordU(), v[3].getTexCoordV(), v[3].getR(), v[3].getG(), v[3].getB(), v[3].getA()),
          new Vertex(v[4].x,  0,                v[4].z, v[4].getTexCoordU(), v[4].getTexCoordV(), v[4].getR(), v[4].getG(), v[4].getB(), v[4].getA()),
      });
      break;
    case MODE_WRAP:
      super.setHeightLocal(height);
      //if in MODE_WRAP also reset the size of the CLIP SHAPE!
View Full Code Here

//            new Vertex(v[0].x+width,   - innerPaddingTop,     v[1].z, v[1].getTexCoordU(), v[1].getTexCoordV(), v[1].getR(), v[1].getG(), v[1].getB(), v[1].getA()),
//            new Vertex(v[0].x+width,   - innerPaddingTop + height + (2 * innerPaddingTop), v[2].getTexCoordV(), v[2].getR(), v[2].getG(), v[2].getB(), v[2].getA()),
//            new Vertex(v[3].x,      - innerPaddingTop + height + (2 * innerPaddingTop),  v[3].z, v[3].getTexCoordU(), v[3].getTexCoordV(), v[3].getR(), v[3].getG(), v[3].getB(), v[3].getA()),
//            new Vertex(v[4].x,      - innerPaddingTop,      v[4].z, v[4].getTexCoordU(), v[4].getTexCoordV(), v[4].getR(), v[4].getG(), v[4].getB(), v[4].getA()),
           
            new Vertex(v[0].x,      0,                 v[0].z, v[0].getTexCoordU(), v[0].getTexCoordV(), v[0].getR(), v[0].getG(), v[0].getB(), v[0].getA()),
            new Vertex(v[0].x+width,   0,                 v[1].z, v[1].getTexCoordU(), v[1].getTexCoordV(), v[1].getR(), v[1].getG(), v[1].getB(), v[1].getA()),
            new Vertex(v[0].x+width,   height + (2 * innerPaddingTop), v[2].getTexCoordV(), v[2].getR(), v[2].getG(), v[2].getB(), v[2].getA()),
            new Vertex(v[3].x,      height + (2 * innerPaddingTop),  v[3].z, v[3].getTexCoordU(), v[3].getTexCoordV(), v[3].getR(), v[3].getG(), v[3].getB(), v[3].getA()),
            new Vertex(v[4].x,      0,                v[4].z, v[4].getTexCoordU(), v[4].getTexCoordV(), v[4].getR(), v[4].getG(), v[4].getB(), v[4].getA()),
        });
        break;
      case MODE_WRAP:
        super.setSizeLocal(width, height);
        //if in MODE_WRAP also reset the size of the CLIP SHAPE!
View Full Code Here

    GLTexture tex = fbo.addNewTexture();
   
    //Invert y texture coord (FBO texture is flipped)
    Vertex[] v = this.getVerticesLocal();
    for (int i = 0; i < v.length; i++) {
      Vertex vertex = v[i];
      if (vertex.getTexCoordV() == 1.0f){
        vertex.setTexCoordV(0.0f);
      }else if (vertex.getTexCoordV() == 0.0f){
        vertex.setTexCoordV(1.0f);
      }
    }
    this.setVertices(v);
   
    //Apply the texture to this component
View Full Code Here

        //Fill Vertices array
        for (int j = 0; j < m.vertices(); j++) {
          Vertex3ds vert = m.vertex(j);
         
          if (this.flipY){
            vertices[j] = new Vertex(vert.X, -vert.Y, vert.Z, -1,-1);
          }else{
            vertices[j] = new Vertex(vert.X, vert.Y, vert.Z, -1,-1);
          }
         
          if (m.texCoords()> j)
            textureCoords[j] = new float[]{m.texCoord(j).U, m.texCoord(j).V };
        }
View Full Code Here

      }
     
      for (int i = 0; i < faces.size(); i++) {
        AFace currentFace = faces.get(i);
       
        Vertex v0 = allFileVerts[currentFace.p0];
        Vertex v1 = allFileVerts[currentFace.p1];
        Vertex v2 = allFileVerts[currentFace.p2];
       
        if allTexCoords.length > currentFace.t0
          &&   allTexCoords.length > currentFace.t1
          &&   allTexCoords.length > currentFace.t2
        ){
          float[] texV0 = allTexCoords[currentFace.t0];
          float[] texV1 = allTexCoords[currentFace.t1];
          float[] texV2 = allTexCoords[currentFace.t2];
         
          //Etwas redundant immer wieder zu machen beim gleichen vertex..whatever
          v0.setTexCoordU(texV0[0]);
          v0.setTexCoordV(texV0[1]);
         
          v1.setTexCoordU(texV1[0]);
          v1.setTexCoordV(texV1[1]);
         
          v2.setTexCoordU(texV2[0]);
          v2.setTexCoordV(texV2[1]);
         
          //Check if there is a texture index in the hashtable at the faces texture pointer
          //if not, create a new index = the end of thexcoords list, and put the pointer into the hash
          //if yes, point the faces texture pointer to the pointer in the hash
         
View Full Code Here

      for (int i = 0; i < indices.length/3; i++) {
        int vertIndex0 = indices[i*3];
        int vertIndex1 = indices[i*3+1];
        int vertIndex2 = indices[i*3+2];
       
        Vertex v0 = vertices[vertIndex0];
        Vertex v1 = vertices[vertIndex1];
        Vertex v2 = vertices[vertIndex2];
       
        tris.add(new Triangle(v0, v1, v2, vertIndex0, vertIndex1, vertIndex2));
      }
    }else{
      //System.out.println("MTTriangleMesh object: \"" + this.getName() + "\" Debug-> Supplied geometry is NOT INDEXED");
      if (vertices.length % 3 != 0){
        System.err.println("WARNING: the vertices of the mesh geometry:\"" + this.getName() + "\" arent dividable by 3 => probably no TRIANGLES array provided!");
      }
     
      //geht nur bei vertices/3 = ganze zahl (vertices sind dreiecke!)
      for (int i = 0; i < vertices.length/3; i++) {
        int vertIndex0 = i*3;
        int vertIndex1 = i*3+1;
        int vertIndex2 = i*3+2;
       
        Vertex v0 = vertices[vertIndex0];
        Vertex v1 = vertices[vertIndex1];
        Vertex v2 = vertices[vertIndex2];
       
        tris.add(new Triangle(v0, v1, v2, vertIndex0, vertIndex1, vertIndex2));
      }
    }
    this.triangles = (Triangle[])tris.toArray(new Triangle[tris.size()]);
View Full Code Here

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

        drawingScene.setBrushScale((Float)p.getNewValue());
      }
    });
        //Add triangle in slider to indicate brush width
        MTPolygon p = new MTPolygon(new Vertex[]{
            new Vertex(2 + slider.getKnob().getWidthXY(TransformSpace.LOCAL), slider.getHeightXY(TransformSpace.LOCAL)/2f, 0),
            new Vertex(slider.getWidthXY(TransformSpace.LOCAL)-3, slider.getHeightXY(TransformSpace.LOCAL)/4f +2, 0),
            new Vertex(slider.getWidthXY(TransformSpace.LOCAL)-1, slider.getHeightXY(TransformSpace.LOCAL)/2f, 0),
            new Vertex(slider.getWidthXY(TransformSpace.LOCAL)-3, -slider.getHeightXY(TransformSpace.LOCAL)/4f -2 + slider.getHeightXY(TransformSpace.LOCAL), 0),
            new Vertex(2, slider.getHeightXY(TransformSpace.LOCAL)/2f, 0),
        }, pa);
        p.setFillColor(new MTColor(150,150,150, 150));
        p.setStrokeColor(new MTColor(160,160,160, 190));
        p.unregisterAllInputProcessors();
        p.setPickable(false);
View Full Code Here

//              new Vertex(newPos.getX(), newPos.getY()+0.1f, newPos.getZ()),
//              new Vertex(newPos.getX(), newPos.getY(), newPos.getZ())},
//          pa);
      polygon = new MTStencilPolygon(
          new Vertex[]{
              new Vertex(newPos.getX(), newPos.getY(), newPos.getZ()),
              new Vertex(newPos.getX()+0.1f, newPos.getY(), newPos.getZ()),
              new Vertex(newPos.getX(), newPos.getY()+0.1f, newPos.getZ()),
              new Vertex(newPos.getX(), newPos.getY(), newPos.getZ())},
          pa);
      polygon.setPickable(true);
      polygon.setNoStroke(false);
      polygon.setNoFill(false);
      polygon.setFillColor(new MTColor(100, 150, 250, 55));
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.