aboutsummaryrefslogtreecommitdiff
path: root/lib/hittable.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/hittable.rb')
-rw-r--r--lib/hittable.rb16
1 files changed, 7 insertions, 9 deletions
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