add hittable spheres

This commit is contained in:
Fabien Freling 2021-04-24 19:24:28 +02:00
parent 4c271103b3
commit 79772c0df4
4 changed files with 101 additions and 7 deletions

View file

@ -0,0 +1,21 @@
const Point3 = @import("vec3.zig").Point3;
const Vec3 = @import("vec3.zig").Vec3;
const Ray = @import("ray.zig").Ray;
pub const HitRecord = struct {
p: Point3,
normal: Vec3,
t: f32,
front_face: bool,
pub fn setFaceNormal(hit: *HitRecord, ray: Ray, outward_normal: Vec3) void {
const front_face = Vec3.dot(ray.direction, outward_normal) < 0;
hit.*.front_face = front_face;
if (front_face) {
hit.*.normal = outward_normal;
} else {
const origin = Vec3{};
hit.*.normal = origin.sub(outward_normal);
}
}
};