-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhittable.py
50 lines (41 loc) · 1.47 KB
/
hittable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Hittable Environment Objects
@author Lehrman, Aidin
"""
from __future__ import annotations
from abc import ABC, abstractmethod
from environment_variables import *
from color import Color
from interval import Interval
from material import Material
class HitRecord:
def __init__(self) -> None:
self.point: Point3 = Point3(0, 0, 0)
self.normal: Vector3 = Vector3(0, 0, 0)
self.material = Material(Color(0, 0, 0))
self.front_face = False
self.t: float = math.inf
def set_t(self, t: float) -> None:
self.t = t
def set_point(self, point: Point3) -> None:
self.point = point
def copy(self, record: HitRecord) -> HitRecord:
self.point = record.point
self.normal = record.normal
self.material = record.material
self.t = record.t
return self
def set_normal(self, ray: Ray3, outward_normal: Vector3) -> None:
self.front_face = dot(ray.direction, outward_normal) < 0
self.normal = outward_normal if self.front_face else outward_normal.negate()
def set_material(self, material: Material) -> Material:
self.material = material
return self.material
class Hittable(ABC):
@abstractmethod
def __init__(self) -> None:
pass
@abstractmethod
def hit(self, ray: Ray3, ray_t: Interval, record: HitRecord) -> bool:
print("Error: Abstract 'hit' function accessed.")
return False