From b976ce98be7275bf92e01f6c86bf2b694530481e Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Thu, 13 Jun 2024 13:24:53 +0100 Subject: Done C10, Materials --- lib/hittable.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'lib/hittable.rb') diff --git a/lib/hittable.rb b/lib/hittable.rb index c84764f..facdd14 100644 --- a/lib/hittable.rb +++ b/lib/hittable.rb @@ -1,16 +1,13 @@ class HitRecord - def initialize(point, t, ray, out_normal) + def initialize(point, t, ray, out_normal, material) @point = point @t = t - set_face_normal(ray, out_normal) - end - - attr_accessor :point, :normal, :t - - def set_face_normal(ray, out_normal) front_face = ray.direction.dot(out_normal) < 0 @normal = front_face ? out_normal : -out_normal + @material = material end + + attr_accessor :point, :normal, :t, :material end class Hittable @@ -48,9 +45,10 @@ class Hittables < Hittable end class Sphere < Hittable - def initialize(ox, oy, oz, radius = 1) + def initialize(ox, oy, oz, radius = 1, material) @centre = Point.new(ox, oy, oz) @radius = radius + @material = material end attr_reader :centre, :radius @@ -76,6 +74,6 @@ class Sphere < Hittable t = root p = ray.at(t) o_n = (p - @centre) / @radius - HitRecord.new(p, t, ray, o_n) + HitRecord.new(p, t, ray, o_n, @material) end end -- cgit v1.2.1