Package javax.vecmath

Examples of javax.vecmath.Vector2f


    // Create GeneralPaths
    HashMap<GeneralPath, List<Vector2f>> pathMap = new HashMap<GeneralPath, List<Vector2f>>();
    for(List<Vector2f> points: paths) {
      if(points.size() == 0) continue;
      GeneralPath path = new GeneralPath(GeneralPath.WIND_NON_ZERO);
      Vector2f last = points.get(points.size() -1);
      path.moveTo(last.x, last.y);
      for(Vector2f point: points) {
        path.lineTo(point.x, point.y);
      }
      pathMap.put(path, points);
View Full Code Here


      for(Vector2f vec: nonConvexPointsParallel) {
        Line prepost = nonConvexPointOutsideSegment.get(vec);
        List<Line> lines1 = segmentMap.get(prepost.getPoint(0));
        List<Line> lines2 = segmentMap.get(prepost.getPoint(1));
        for(Line line1: lines1) {
          Vector2f point1 = line1.getPoint(0);
          if(point1 == prepost.getPoint(0)) point1 = line1.getPoint(1);
         
          for(Line line2: lines2) {
            Vector2f point2 = line2.getPoint(0);
            if(point2 == prepost.getPoint(1)) point2 = line2.getPoint(1);
           
            if(point2 == point1) {
              if(getLine(vec, point1) == null) {
                addSegment(vec, point1);
              }
            }
          }
        }
      }
    }

    // If there are no cut-outs and no concave points the first point get connected to all but the one before and after
    if(nonConvexPoints.size() == 0 && shape.getCutOuts().size() == 0) {
      Vector2f point = shape.getOutline().get(1);
      for(int i = 3; i < shape.getOutline().size(); i++) {
        Vector2f point2 = shape.getOutline().get(i);
        addSegment(point, point2);
      }
    }

   
    // Build a list of all points for construction of triangles
    ArrayList<Vector2f> points = new ArrayList<Vector2f>();
    points.addAll(shape.getOutline());
    for(List<Vector2f> cutOut: shape.getCutOuts()) {
      points.addAll(cutOut);
    }
    ArrayList<Vector2f> insidePoints = new ArrayList<Vector2f>(points);
   
   
    // Testing: drawing
//    for(Line segment: segments) {
//      renderer.drawLine(segment.getPoint1().x, segment.getPoint1().y, segment.getPoint2().x, segment.getPoint2().y, 0.001f, new Color4f(1,1,1,1));
//    }
//    for(Vector2f point: points) {
//      renderer.drawPoint(point.x, point.y, 3f, new Color4f(1,1,1,1));
//    }
//    for(Vector2f point: nonConvexPoints) {
//      renderer.drawPoint(point.x, point.y, 6f, new Color4f(1,0,0,1));
//    }
//    for(Vector2f point: nonConvexPointsParallel) {
//      renderer.drawPoint(point.x, point.y, 6f, new Color4f(0,1,0,1));
//    }

   
    ArrayList<Triangle> triangles = new ArrayList<Triangle>();
   
    // create triangles with the calculated segments by processing each point
    while(points.size() > 0) {
      Vector2f point1 = points.get(points.size() - 1);
      Vector2f point2;
      Vector2f point3;
     
      // process each combination of segments starting at the current point
      List<Line> pointSegments = segmentMap.get(point1);
      for(Line line: pointSegments) {
       
View Full Code Here

        } else {
          i++;
        }
      }
      for(Vector2f vec: nonConvexPointsParallel) {
        Vector2f pre = nonConvexPointsParallelPredecessor.get(vec);
        int preindex = rolloverRange(points.indexOf(pre), points.size() -1);
        int postindex = rolloverRange(preindex + 1, points.size() -1);
       
        Vector2f post = points.get(postindex);
        nonConvexPointOutsideSegment.put(vec, new Line(pre, post));
      }
    }
   
    int max = points.size() - 1;
    List<Vector2f> aSide = new ArrayList<Vector2f>();
    List<Vector2f> bSide = new ArrayList<Vector2f>();
    float aSideAngle = 0f;
    float bSideAngle = 0f;
    boolean useASide = true;
    Vector2f angleVec1 = new Vector2f();
    Vector2f angleVec2 = new Vector2f();
    for(int i = 0; i < points.size(); i++) {
      int before = rolloverRange(i-1,max);
      int after = rolloverRange(i+1,max);
      int after2 = rolloverRange(i+2,max);

      Vector2f currentVec = points.get(i);
      angleVec1.set(points.get(before));
      angleVec2.set(points.get(after));
      angleVec1.sub(currentVec);
      angleVec2.sub(currentVec);
      float angle = angleVec2.angle(angleVec1);
View Full Code Here

    return false;
  }
 
  private void createSegments(List<Vector2f> points) {
    if(points.size() == 0) return;
    Vector2f last = points.get(points.size() - 1);
    for(Vector2f current: points) {
      addSegment(last, current);
//      System.out.println(last + "," + current);
      last = current;
    }
View Full Code Here

  public static void mapTexture(Area shape, Image texture, float x, float y, float rotationAngle, float scale) {
    float rad = (float)Math.toRadians(rotationAngle);
    for(int i = 0; i < shape.getTriangles().length; i++) {
      Triangle area = shape.getTriangles()[i];
      for(int j = 0; j < 3; j++) {
        Vector2f textureCoordinate = area.getTextureCoordinate(j);
        if(textureCoordinate == null) {
          textureCoordinate = new Vector2f();
          area.setTextureCoordinate(j, textureCoordinate);
        }
       
        // Get corresponding shape coordinate
        textureCoordinate.set(area.getPoint(j));
       
        // Rotate, scale, translate results in translation first, then scaling and then rotation
        Transformations.rotate(textureCoordinate, rad);
        textureCoordinate.scale(scale);
        textureCoordinate.x += x;
        textureCoordinate.y += y;
      }
    }
    shape.setTexture(texture);
View Full Code Here

  }
  public void drawLines(Line[] lines, boolean useColor) {
    if (lines == null) throw new IllegalArgumentException("lines must not be null");
      startPrimitive(Primitive.LINE, null);
    GL gl = drawable.getGL();
    Vector2f p;
    if(useColor) {
      Color4f c;
      for(int i = 0; i < lines.length; i++) {
        Line l = lines[i];
        if(l == null) continue;
View Full Code Here

  }
  public void drawTriangles(Triangle[] triangles, boolean useColors) {
    if (triangles == null) throw new IllegalArgumentException("triangles must not be null");
      startPrimitive(Primitive.LINE, null);
    GL gl = drawable.getGL();
    Vector2f p;
    if(useColors) {
      Color4f c;
      for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;
View Full Code Here

  public void fillTriangles(Triangle[] triangles, boolean useColors) {
    if (triangles == null) throw new IllegalArgumentException("triangles must not be null");
    GL gl = drawable.getGL();

    Vector2f p;
   
    startPrimitive(Primitive.TRIANGLE, null);

    if(useColors) {
      Color4f c = null;
View Full Code Here

  public void fillTriangles(Triangle[] triangles, boolean useColors, ch.blackspirit.graphics.Image image) {
    if (triangles == null) throw new IllegalArgumentException("triangles must not be null");
    if (image == null) throw new IllegalArgumentException("image must not be null");
    GL gl = drawable.getGL();

    Vector2f p;
    Image joglImage = null;

    joglImage = (Image)image;
    startPrimitive(Primitive.TEXTURED_TRIANGLE, joglImage);

    TextureCoords coords = joglImage.texture.getImageTexCoords();
   
    if(useColors) {
      Color4f c;
        for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;

        Vector2f tc1 = t.getTextureCoordinate(0);
        if (tc1 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
        Vector2f tc2 = t.getTextureCoordinate(1);
        if (tc2 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
        Vector2f tc3 = t.getTextureCoordinate(2);
        if (tc3 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
   
        p = t.getPoint(0);
        c = t.getColor(0);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
        float texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc1.x;
        float texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc1.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(1);
        c = t.getColor(1);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
        texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc2.x;
        texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc2.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
       
            p = t.getPoint(2);
        c = t.getColor(2);
        if(c == null) c = color;
        gl.glColor4f(c.x, c.y, c.z, c.w);
        texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc3.x;
        texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc3.y;
        gl.glTexCoord2f(texX, texY);
            gl.glVertex2f(p.x, p.y);
   
        }
    } else {
        for(int i = 0; i < triangles.length; i++) {
        Triangle t = triangles[i];
        if(t == null) continue;
 
        Vector2f tc1 = t.getTextureCoordinate(0);
        if (tc1 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
        Vector2f tc2 = t.getTextureCoordinate(1);
        if (tc2 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
        Vector2f tc3 = t.getTextureCoordinate(2);
        if (tc3 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");

        p = t.getPoint(0);
        float texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc1.x;
        float texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc1.y;
 
View Full Code Here

   * @param height Height of the rectangle.
   * @return A rectangles outline.
   */
  public static List<Vector2f> createRectangle(float width, float height) {
    ArrayList<Vector2f> points = new ArrayList<Vector2f>();
    points.add(new Vector2f(-width/2, -height/2));
    points.add(new Vector2f(+width/2, -height/2));
    points.add(new Vector2f(+width/2, +height/2));
    points.add(new Vector2f(-width/2, +height/2));
   
    return points;
  }
View Full Code Here

TOP

Related Classes of javax.vecmath.Vector2f

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.