setup random world
This commit is contained in:
parent
3b3cb72dc0
commit
ac56eed3a2
2 changed files with 114 additions and 38 deletions
|
@ -1,15 +1,28 @@
|
|||
const std = @import("std");
|
||||
const ArrayList = std.ArrayList;
|
||||
|
||||
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,
|
||||
spheres: ArrayList(Sphere),
|
||||
|
||||
pub fn hit(self: World, ray: Ray, t_min: f32, t_max: f32) ?HitRecord {
|
||||
pub fn init() World {
|
||||
return World {
|
||||
.spheres = ArrayList(Sphere).init(std.testing.allocator)
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *World) void {
|
||||
self.spheres.deinit();
|
||||
}
|
||||
|
||||
pub fn hit(self: *const World, ray: Ray, t_min: f32, t_max: f32) ?HitRecord {
|
||||
var hitRecord: ?HitRecord = null;
|
||||
var closest = t_max;
|
||||
|
||||
for (self.spheres) |sphere| {
|
||||
for (self.spheres.items) |sphere| {
|
||||
if (sphere.hit(ray, t_min, closest)) |localHit| {
|
||||
closest = localHit.t;
|
||||
hitRecord = localHit;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue