mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
migrate raytracer to dune
This commit is contained in:
parent
ddf0f258c7
commit
9218ba8fe6
2 changed files with 8 additions and 6 deletions
4
benchs/raytracer/dune
Normal file
4
benchs/raytracer/dune
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
(executable
|
||||||
|
(name raytracer)
|
||||||
|
(flags :standard -warn-error -a+8))
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
open Core
|
|
||||||
open Printf
|
open Printf
|
||||||
open Vec3
|
open Vec3
|
||||||
open Ray
|
open Ray
|
||||||
|
|
@ -120,9 +119,8 @@ let hit_sphere sphere ray (tmin, tmax) =
|
||||||
else None
|
else None
|
||||||
|
|
||||||
let rec hit_world world ray (tmin, tmax) =
|
let rec hit_world world ray (tmin, tmax) =
|
||||||
List.fold world
|
List.fold_left
|
||||||
~init: None
|
(fun acc h ->
|
||||||
~f: (fun acc h ->
|
|
||||||
let prev_rec = match acc with
|
let prev_rec = match acc with
|
||||||
None -> { t = tmax;
|
None -> { t = tmax;
|
||||||
p = Vec3.of_floats (-1., -1., -1.);
|
p = Vec3.of_floats (-1., -1., -1.);
|
||||||
|
|
@ -131,7 +129,7 @@ let rec hit_world world ray (tmin, tmax) =
|
||||||
| Some(r) -> r in
|
| Some(r) -> r in
|
||||||
match (hit h ray (tmin, prev_rec.t)) with
|
match (hit h ray (tmin, prev_rec.t)) with
|
||||||
Some(r) -> Some r
|
Some(r) -> Some r
|
||||||
| None -> acc)
|
| None -> acc) None world
|
||||||
|
|
||||||
and hit h ray (tmin, tmax) =
|
and hit h ray (tmin, tmax) =
|
||||||
match h with
|
match h with
|
||||||
|
|
@ -175,7 +173,7 @@ let write_to_file filename =
|
||||||
let nx = 400 in
|
let nx = 400 in
|
||||||
let ny = 200 in
|
let ny = 200 in
|
||||||
let ns = 150 in (* samples per pixel *)
|
let ns = 150 in (* samples per pixel *)
|
||||||
let oc = Out_channel.create filename in
|
let oc = open_out filename in
|
||||||
fprintf oc "P3\n";
|
fprintf oc "P3\n";
|
||||||
fprintf oc "%d\n" nx;
|
fprintf oc "%d\n" nx;
|
||||||
fprintf oc "%d\n" ny;
|
fprintf oc "%d\n" ny;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue