-
Notifications
You must be signed in to change notification settings - Fork 0
/
hitable.hs
22 lines (17 loc) · 895 Bytes
/
hitable.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module Hitable (HitIntersection(..), HitResult(NoHit, FrontHit), isHitResultCloser) where
import Ray
import Vector
-- An intersection between the Ray and the hitable
data HitIntersection = HitIntersection { t :: Float -- Distance from the origin of the ray
, point :: Vec3
, normal :: Vec3} deriving (Show)
data HitResult = NoHit | FrontHit HitIntersection
deriving Show
-- class Hitable a where
-- -- hitable, ray, (minT, maxT) -> HitResult
-- hitByRay :: a -> Ray -> (Float, Float) -> HitResult
-- Is a Hit Result closer to the ray's origina than an other ?
isHitResultCloser :: HitResult -> HitResult -> Bool
isHitResultCloser _ NoHit = True
isHitResultCloser NoHit (FrontHit right) = False
isHitResultCloser (FrontHit left) (FrontHit right) = t left <= t right