예제 #1
0
  /** Raytrace one frame. */
  private void raytrace() {

    double aspect = width / (double) height;

    Ray ray = new Ray();

    camPos.set(0, -distance, 0);
    transform.transform(camPos);
    camPos.add(.5, .5, .5);

    for (int x = 0; x < width; ++x) {

      double rayx = fovTan * aspect * (.5 - ((double) x) / width);

      for (int y = 0; y < height; ++y) {

        ray.setDefault();
        ray.d.set(rayx, 1, fovTan * (.5 - ((double) y) / height));
        ray.d.normalize();
        transform.transform(ray.d);

        ray.o.set(camPos);
        raytrace(ray);

        ray.color.x = QuickMath.min(1, FastMath.sqrt(ray.color.x));
        ray.color.y = QuickMath.min(1, FastMath.sqrt(ray.color.y));
        ray.color.z = QuickMath.min(1, FastMath.sqrt(ray.color.z));
        backBuffer.setRGB(x, y, Color.getRGB(ray.color));
      }
    }
  }