packages feed

glome-hs-0.5: Scene.hs

module Scene (Scene(Scene), Light(Light), Camera(Camera),
              scene, camera, light, 
              sld, lits, cam, dtex, bground,
              module Clr,
              module Vec,
              module Solid,
              module Sphere,
              module Triangle,
              module Bih,
              module Csg,
              module Plane,
              module Box,
              module Bound,
              module Cone,
              module Tex) where
import Clr
import Vec
import Solid
import Sphere
import Triangle
import Bih
import Csg
import Plane
import Box
import Bound
import Cone
import Tex

-- This is the module to import if you want to have
-- access to all the Solid constructors and scene
-- defininition code.

--LIGHTS--
data Light = Light {litpos :: !Vec,
                    litcol :: !Color} deriving Show

light :: Vec -> Color -> Light
light pos clr = Light pos clr

-- CAMERA --
data Camera = Camera {campos, fwd, up, right :: !Vec} 
              deriving Show

default_cam = (Camera (vec 0.0 0.0 (-3.0)) 
                      (vec 0.0 0.0 1.0) 
                      (vec 0.0 1.0 0.0) 
                      (vec 1.0 0.0 0.0) )

camera :: Vec -> Vec -> Vec -> Flt -> Camera
camera pos at up angle =
 let fwd   = vnorm $ vsub at pos
     right = vnorm $ vcross up fwd
     up_   = vnorm $ vcross fwd right
     cam_scale = tan ((pi/180)*(angle/2))
 in
  Camera pos fwd
         (vscale up_ cam_scale) 
         (vscale right cam_scale)

--SCENE--
data Scene = Scene {sld     :: SolidItem,
                    lits    :: [Light], 
                    cam     :: Camera, 
                    dtex    :: Texture, 
                    bground :: Color} deriving Show

scene :: SolidItem -> [Light] -> Camera -> Texture -> Color -> Scene
scene s l cam t clr = Scene s l cam t clr

{-
default_scene = (Scene (sphere (vec 0.0 0.0 0.0) 1.0) 
                       [] default_cam t_white c_white)
-}