示例#1
0
  //
  // Normalize the vector (X,Y,Z) so that X*X + Y*Y + Z*Z = 1.
  //
  // The normalization divisor is returned.  If the divisor is zero, no
  // normalization occurs.
  //
  double normalize_vector(double cvec[]) {
    double divisor;

    divisor = Math.sqrt((double) DOT_PRODUCT(cvec, cvec));
    if (divisor > 0.0) {
      cvec[X] /= divisor;
      cvec[Y] /= divisor;
      cvec[Z] /= divisor;
    }
    return divisor;
  }
示例#2
0
  //
  // Interface resized method.
  //
  public void resized(int width, int height) {
    double dx = eyeX - centerX;
    double dy = eyeY - centerY;
    double dz = eyeZ - centerZ;
    double d = Math.sqrt(dx * dx + dy * dy + dz * dz);

    double fovy = 2.0 * 180.0 / Math.PI * Math.atan(radius / d);
    double near = d - radius;
    double far = d + radius;

    double xUnits, yUnits;

    if (width >= height) {
      xUnits = 2 * radius * width / height;
      yUnits = 2 * radius;
    } else {
      xUnits = 2 * radius;
      yUnits = 2 * radius * height / width;
    }

    // setup projection matrix
    go.matrixMode(Go.PROJECTION);
    go.identity();
    if (perspective) {
      if (width >= height) {
        go.perspective(fovy, xUnits / yUnits, near, far);
      } else {
        double r = radius * yUnits / xUnits;
        double fovyModified = Math.atan(r / d) * 180.0 / Math.PI * 2.0;
        go.perspective(fovyModified, xUnits / yUnits, near, far);
      }
    } else {
      go.ortho(-xUnits / 2.0, xUnits / 2.0, -yUnits / 2.0, yUnits / 2.0, near, far);
    }
    go.matrixMode(Go.MODELVIEW);
  }