add hittable spheres
This commit is contained in:
parent
4c271103b3
commit
79772c0df4
4 changed files with 101 additions and 7 deletions
21
in_one_weekend/src/world.zig
Normal file
21
in_one_weekend/src/world.zig
Normal file
|
@ -0,0 +1,21 @@
|
|||
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;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue