コード例 #1
0
  // Writes polygons to the saveFile
  private static void savePolygons() {
    if (!saveFile.exists()) {
      try {
        saveFile.createNewFile();
      } catch (IOException ex) {
        // Can't create file
      }
    }

    try {
      PrintStream fileOut = new PrintStream(saveFile);
      for (Polygon p : polygons) {
        fileOut.println(p.getName());
        fileOut.println(p.getPoints().size());
        for (Point3Df q : p.getPoints()) {
          fileOut.print(q.x);
          fileOut.print(",");
          fileOut.print(q.y);
          fileOut.print(",");
          fileOut.println(q.z);
        }

        fileOut.println(p.getEdges().size());
        for (Edge q : p.getEdges()) {
          fileOut.print(q.p1);
          fileOut.print(",");
          fileOut.println(q.p2);
        }
      }
      fileOut.close();
    } catch (FileNotFoundException ex) {
      // Can't find file
    }
  }
コード例 #2
0
  private static void rebound() {
    float f = 0.0f;
    float n = 0.0f;
    float b = 0.0f;
    float t = 0.0f;
    float l = 0.0f;
    float r = 0.0f;

    for (Polygon poly : polygons) {
      poly.recalc();

      if (poly.getMinZ() < f) {
        f = poly.getMinZ();
      }
      if (poly.getMaxZ() > n) {
        n = poly.getMaxZ();
      }
      if (poly.getMinY() < b) {
        b = poly.getMinY();
      }
      if (poly.getMaxY() > t) {
        t = poly.getMaxY();
      }
      if (poly.getMinX() < l) {
        l = poly.getMinX();
      }
      if (poly.getMaxX() > r) {
        r = poly.getMaxX();
      }
    }

    float maxSpan = Math.max(Math.max(f - n, t - b), r - l);

    for (Polygon poly : polygons) {
      for (Point3Df p : poly.getPoints()) {
        p.x = p.x * (2 / maxSpan) - (r + l) / (r - l);
        p.y = p.y * (2 / maxSpan) - (t + b) / (t - b);
        p.z = p.z * (2 / maxSpan) - (n + f) / (n - f);
      }

      poly.recalc();
    }
  }