-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathScene.hs
43 lines (35 loc) · 1.13 KB
/
Scene.hs
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
module Scene where
import Data.Vect.Float.Base
import Debug.Trace
import Lights
import Surfaces
import Types
data SceneConfig = SceneConfig
{ height :: Int
, width :: Int
, maxDepth :: Int
, output :: FilePath
, camera :: Camera
, ambient :: Color
, surfaces :: [Surface]
, lights :: [Light]
} deriving Show
data Camera = Camera Vec3 Float Float Vec3 Vec3 Vec3
deriving Show
buildCamera :: Vec3 -> Vec3 -> Vec3 -> Float -> Int -> Int -> Camera
buildCamera lookFrom lookAt up degrees width height
= Camera lookFrom fovy fovx axisX axisY axisZ
where
fovy = degrees * pi / 180.0
fovx = getFovx fovy width height
axisZ = normalize $ lookFrom &- lookAt
axisX = normalize $ crossprod (normalize up) axisZ
axisY = crossprod axisZ axisX
updateCamera :: Camera -> Int -> Int -> Camera
updateCamera (Camera lookFrom fovy _ axisX axisY axisZ) width height
= Camera lookFrom fovy (getFovx fovy width height) axisX axisY axisZ
getFovx :: Float -> Int -> Int -> Float
getFovx fovy width height = 2 * atan (tan (fovy/2) * (fromIntegral width) / (fromIntegral height))
eps = 0.0001::Float
shadowColor = Color 0 0 0
bgColor = Color 0 0 0