module Core.Scene where

import Core.Types
import Core.Geometry as G
import Core.Geometry (BBox, Ray)
import Core.Light (Light)
import Core.Volume as V
import Core.Volume (VolumeRegion)
import Core.Intersection
import Core.Primitive as P
import Core.Primitive (Aggregate)

data Scene = Scene {
  aggregate    :: Aggregate,
  lights       :: [Light],
  volumeRegion :: Maybe VolumeRegion,
  bound        :: BBox
}

create :: Aggregate -> [Light] -> Maybe VolumeRegion -> Scene
create a l vr = Scene {
  aggregate = a,
  lights = l,
  volumeRegion = vr,
  bound = b'
}
  where b  = P.worldBound a
        b' = case vr of
                  Nothing -> b
                  Just r -> G.union b (V.worldBound r)


intersect :: Scene -> Ray -> Maybe Intersection
intersect (Scene agg _ _ _) = P.intersect agg

intersectP :: Scene -> Ray -> Bool
intersectP (Scene agg _ _ _) = P.intersectP agg

worldBound :: Scene -> BBox
worldBound s = (bound s)
