Debian Codegraph @

src/Diagrams/ThreeD/Light.hs

raw symbols SCIP
1 {-# LANGUAGE ConstraintKinds #-}
2 {-# LANGUAGE DeriveDataTypeable #-}
3 {-# LANGUAGE FlexibleContexts #-}
4 {-# LANGUAGE MultiParamTypeClasses #-}
5 {-# LANGUAGE TypeFamilies #-}
6 {-# LANGUAGE UndecidableInstances #-}
7
8 -----------------------------------------------------------------------------
9 -- |
10 -- Module : Diagrams.ThreeD.Render
11 -- Copyright : (c) 2013 diagrams-lib team (see LICENSE)
12 -- License : BSD-style (see LICENSE)
13 -- Maintainer : [email protected]
14 --
15 -- Types to specify lighting for 3D rendering.
16 --
17 -----------------------------------------------------------------------------
18
19 module Diagrams.ThreeD.Light where
20
21 import Data.Colour
22 import Data.Monoid
23 import Data.Typeable
24
25 import Diagrams.Core
26 import Diagrams.Direction
27 import Diagrams.ThreeD.Types
28
29 -- | A @PointLight@ radiates uniformly in all directions from a given
30 -- point.
31 data PointLight n = PointLight (Point V3 n) (Colour Double)
32 deriving Typeable
33
34 type instance V (PointLight n) = V3
35 type instance N (PointLight n) = n
36
37 -- | A @ParallelLight@ casts parallel rays in the specified direction,
38 -- from some distant location outside the scene.
39 data ParallelLight n = ParallelLight (V3 n) (Colour Double)
40 deriving Typeable
41
42 type instance V (ParallelLight n) = V3
43 type instance N (ParallelLight n) = n
44
45 instance Fractional n => Transformable (PointLight n) where
46 transform t (PointLight p c) = PointLight (transform t p) c
47
48 instance Transformable (ParallelLight n) where
49 transform t (ParallelLight v c) = ParallelLight (transform t v) c
50
51 -- | Construct a Diagram with a single PointLight at the origin, which
52 -- takes up no space.
53 pointLight :: (Typeable n, Num n, Ord n, Renderable (PointLight n) b)
54 => Colour Double -- ^ The color of the light
55 -> QDiagram b V3 n Any
56 pointLight c = mkQD (Prim $ PointLight origin c) mempty mempty mempty
57 (Query . const . Any $ False)
58
59 -- | Construct a Diagram with a single ParallelLight, which takes up no space.
60 parallelLight :: (Typeable n, OrderedField n, Renderable (ParallelLight n) b)
61 => Direction V3 n -- ^ The direction in which the light travels.
62 -> Colour Double -- ^ The color of the light.
63 -> QDiagram b V3 n Any
64 parallelLight d c = mkQD (Prim $ ParallelLight (fromDirection d) c)
65 mempty mempty mempty (Query . const . Any $ False)