Example #1
0
  public void setVFromPointWithSize(Point2D start, double size) {
    // TODO attention ne marhce pas avec certains frustum
    Polygon p = bottomPolygon;

    double startLength = p.getLengthTo(start);

    vOffset = startLength;
    vScale = size / p.getLength();
  }
Example #2
0
  public void setVFromPointToPoint(Point2D start, Point2D end) {
    // TODO attention ne marhce pas avec certains frustum
    Polygon p = bottomPolygon;

    double startLength = p.getLengthTo(start);
    double endLength = p.getLengthTo(end);
    double length;

    if (endLength > startLength) {
      length = endLength - startLength;
    } else if (startLength > endLength) {
      length = p.getLength() - startLength + endLength;
    } else {
      length = p.getLength();
    }

    vOffset = startLength;
    vScale = length / p.getLength();
  }
Example #3
0
  public void extrude(double height) {
    if (height < top && height > bottom) {
      throw new IllegalArgumentException("Specified height is inside mesh.");
    }

    Polygon polygon;
    double base;
    double sum;
    if (height > top) {
      polygon = topPolygon;
      base = top;
      sum = height;
    } else {
      polygon = bottomPolygon;
      base = height;
      sum = bottom;
    }

    for (Point2D p : polygon.points) {
      add6Indices(mesh.vertices.size());

      Point2D prev = polygon.points.getPrevious(p);
      Point2D next = polygon.points.getNext(p);
      Point2D nextNext = polygon.points.getNext(next);

      // add 4 vertices
      mesh.vertices.add(new Point3D(p, sum, 1));
      mesh.vertices.add(new Point3D(next, sum, 1));
      mesh.vertices.add(new Point3D(p, base, 1));
      mesh.vertices.add(new Point3D(next, base, 1));

      // add 4 normals
      double wPrevNormal = getSmoothedNormal(prev, p, next, 0);
      double wNextNormal = getSmoothedNormal(p, next, nextNext, 1);

      mesh.normals.add(new Point3D(Math.cos(wPrevNormal), 0, Math.sin(wPrevNormal)));
      mesh.normals.add(new Point3D(Math.cos(wNextNormal), 0, Math.sin(wNextNormal)));
      mesh.normals.add(new Point3D(Math.cos(wPrevNormal), 0, Math.sin(wPrevNormal)));
      mesh.normals.add(new Point3D(Math.cos(wNextNormal), 0, Math.sin(wNextNormal)));

      // add 4 textCoord
      double pLength = polygon.getLengthTo(p);
      double nextLength = polygon.getLengthTo(next);

      //			Logutil.logger.info("sum : "+sum+"base : "+base);
      mesh.textCoord.add(
          new Point2D(
              (-uOffset + sum - base) / (sum - base) / uScale,
              1 - (pLength - vOffset) / polygon.getLength() / vScale));
      mesh.textCoord.add(
          new Point2D(
              (-uOffset + sum - base) / (sum - base) / uScale,
              1 - (nextLength - vOffset) / polygon.getLength() / vScale));
      mesh.textCoord.add(
          new Point2D(
              -uOffset / (sum - base) / uScale,
              1 - (pLength - vOffset) / polygon.getLength() / vScale));
      mesh.textCoord.add(
          new Point2D(
              -uOffset / (sum - base) / uScale,
              1 - (nextLength - vOffset) / polygon.getLength() / vScale));
    }
    prepare(polygon, height);
  }