示例#1
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();
    }
  }