raytracing/in_one_weekend/src/world.zig

21 lines
574 B
Zig

const Sphere = @import("sphere.zig").Sphere;
const HitRecord = @import("hittable.zig").HitRecord;
const Ray = @import("ray.zig").Ray;
pub const World = struct {
spheres: []const Sphere,
pub fn hit(self: World, ray: Ray, t_min: f32, t_max: f32) ?HitRecord {
var hitRecord: ?HitRecord = null;
var closest = t_max;
for (self.spheres) |sphere| {
if (sphere.hit(ray, t_min, closest)) |localHit| {
closest = localHit.t;
hitRecord = localHit;
}
}
return hitRecord;
}
};