Exemplo n.º 1
0
 private static Camera getCamera(Model model) {
   Camera result = new Camera();
   result.setFrom(model.getFrom());
   result.setTo(model.getTo());
   result.setUp(model.getUp());
   result.setFov(model.getFov());
   result.setWidth(model.getW());
   result.setHeight(model.getH());
   result.init();
   return result;
 }
Exemplo n.º 2
0
  public static BufferedImage render(Model model) {
    Camera cam = getCamera(model);
    BufferedImage result =
        new BufferedImage(model.getW(), model.getH(), BufferedImage.TYPE_INT_RGB);
    IntStream xs = IntStream.range(0, model.getW()).parallel();
    Date startTime = new Date();
    xs.forEach(
        x -> {
          IntStream ys = IntStream.range(0, model.getH());
          ys.forEach(
              y -> {
                Ray ray = rayThruPixel(cam, x, y);
                Intersection hit = intersect(ray, model);
                result.setRGB(x, y, findColor(hit, cam, model));
              });
        });

    Date endTime = new Date();
    final float time = endTime.getTime() - startTime.getTime();
    System.out.println("Executing time: " + time / 1000);
    return result;
  }