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/hittable.zig
Normal file
21
in_one_weekend/src/hittable.zig
Normal 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);
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue