Exemple #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));
      }
    }
  }
Exemple #2
0
 @Override
 public void onZoom(int diff) {
   synchronized (renderLock) {
     nextDistance += .1 * diff;
     nextDistance = QuickMath.max(.1, nextDistance);
   }
   refresh();
 }
Exemple #3
0
 @Override
 public void onMoveBackward() {
   synchronized (renderLock) {
     nextDistance += .1;
     nextDistance = QuickMath.max(.1, nextDistance);
   }
   refresh();
 }
Exemple #4
0
  @Override
  public void onMouseDragged(int dx, int dy) {
    synchronized (renderLock) {
      double fovRad = QuickMath.degToRad(fov / 2);

      yaw += (Math.PI / 250) * dx * fovRad;
      pitch += (Math.PI / 250) * dy * fovRad;

      if (yaw > QuickMath.TAU) {
        yaw -= QuickMath.TAU;
      } else if (yaw < -QuickMath.TAU) {
        yaw += QuickMath.TAU;
      }

      updateTransform();
    }
    refresh();
  }