module Data.Glome.Plane (plane, plane_offset) where
import Data.Glome.Vec
import Data.Glome.Solid
data Plane t m = Plane Vec Flt deriving Show
plane :: Vec -> Vec -> SolidItem t m
plane orig norm_ = SolidItem $ Plane norm d
where norm = vnorm norm_
d = vdot orig norm
plane_offset :: Vec -> Flt -> SolidItem t m
plane_offset pt off = SolidItem $ Plane pt off
rayint_plane :: Plane tag mat -> Ray -> Flt -> [Texture tag mat] -> [tag] -> Rayint tag mat
rayint_plane (Plane norm offset) ray@(Ray orig dir) d t tags =
let hit = (((vdot norm orig)offset) / (vdot norm dir))
in if hit < 0 || hit > d
then RayMiss
else RayHit hit (vscaleadd orig dir hit) norm ray vzero t tags
inside_plane :: Plane tag mat -> Vec -> Bool
inside_plane (Plane norm offset) pt =
let onplane = (vscale norm offset)
newvec = vsub onplane pt
in vdot newvec norm > 0
bound_plane :: Plane tag mat -> Bbox
bound_plane (Plane norm offset) = everything_bbox
instance Solid (Plane t m) t m where
rayint = rayint_plane
inside = inside_plane
bound = bound_plane