aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main.zig44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index aa0fa3c..e615e8b 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -421,6 +421,50 @@ fn randomReal(rand: std.rand.Random, min: f64, max: f64) f64 {
return min + randomReal01(rand) * (max - min);
}
+const Aabb = struct {
+ min: Point3,
+ max: Point3,
+
+ fn hit(aabb: Aabb, r: Ray, tMin: f64, tMax: f64) bool {
+ var tMin_ = tMin;
+ var tMax_ = tMax;
+ {
+ const s0 = (aabb.min.x - r.origin.x) / r.dir.x;
+ const s1 = (aabb.max.x - r.origin.x) / r.dir.x;
+ const t0 = @min(s0, s1);
+ const t1 = @max(s0, s1);
+ tMin_ = @max(t0, tMin_);
+ tMax_ = @min(t1, tMax_);
+ if (tMax_ <= tMin_) {
+ return false;
+ }
+ }
+ {
+ const s0 = (aabb.min.y - r.origin.y) / r.dir.y;
+ const s1 = (aabb.max.y - r.origin.y) / r.dir.y;
+ const t0 = @min(s0, s1);
+ const t1 = @max(s0, s1);
+ tMin_ = @max(t0, tMin_);
+ tMax_ = @min(t1, tMax_);
+ if (tMax_ <= tMin_) {
+ return false;
+ }
+ }
+ {
+ const s0 = (aabb.min.z - r.origin.z) / r.dir.z;
+ const s1 = (aabb.max.z - r.origin.z) / r.dir.z;
+ const t0 = @min(s0, s1);
+ const t1 = @max(s0, s1);
+ tMin_ = @max(t0, tMin_);
+ tMax_ = @min(t1, tMax_);
+ if (tMax_ <= tMin_) {
+ return false;
+ }
+ }
+ return true;
+ }
+};
+
const Camera = struct {
origin: Point3,
horizontal: Vec3,