コード例 #1
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // RayTracing Variables
    int h = 600;
    int w = 800;
    double[] planeDim = {1., 0, 0, -100};
    double[] eyeDim = {100.5, 0, 0};
    double[] topDim = {100.0, 0.1, 0};
    // Normal Variables
    CameraPlane pl = new CameraPlane(planeDim);
    Point pt = new Point(eyeDim);
    // Create Camera
    cam = new Camera(pl, pt, w, h);
    // Set Camera Frame
    cam.setTopDir(topDim, .001);
    // CreateObjects
    // Sphere
    double[] sDim1 = {0, 0, 0, 400};
    Sphere s1 = new Sphere(sDim1);
    s1.setColor(sphere1);
    s1.setKA(0.1);
    s1.setKD(0.9);
    s1.setKS(1);
    s1.setN(2000);
    double[] sDim2 = {10, 10, -10, 100};
    Sphere s2 = new Sphere(sDim2);
    s2.setColor(sphere2);
    s2.setKA(0.1);
    s2.setKD(0.9);
    s2.setKS(1);
    s2.setN(2000);
    // Plane
    double[] pDim1 = {0, 1, 0, 40};
    Plane p1 = new Plane(pDim1);
    p1.setColor(plane);
    p1.setKA(0.1);
    p1.setKD(0.9);
    p1.setKS(1);
    p1.setN(1000);
    // Lighting
    double[] l1Dim = {200, 200, 200};
    Light l1 = new Light(l1Dim);

    // Main Render Loop
    for (int yR = 0; yR < h; yR++) {
      for (int xR = 0; xR < w; xR++) {
        Ray primary = cam.createRay(xR, yR);
        cam.img.setRGB(xR, yR, trace(primary).getRGB());
      }
    }

    // Output Image
    try {
      File outputfile = new File("saved.png");
      ImageIO.write(cam.img, "png", outputfile);
    } catch (IOException e) {
    }
  }