| 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 |
|
| 30 |
|
| 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 |
|
| 38 |
|
| 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 |
|
| 52 |
|
| 53 |
pointLight :: (Typeable n, Num n, Ord n, Renderable (PointLight n) b) |
| 54 |
=> Colour Double |
| 55 |
-> QDiagram b V3 n Any |
| 56 |
pointLight c = mkQD (Prim $ PointLight origin c) mempty mempty mempty |
| 57 |
(Query . const . Any $ False) |
| 58 |
|
| 59 |
|
| 60 |
parallelLight :: (Typeable n, OrderedField n, Renderable (ParallelLight n) b) |
| 61 |
=> Direction V3 n |
| 62 |
-> Colour Double |
| 63 |
-> QDiagram b V3 n Any |
| 64 |
parallelLight d c = mkQD (Prim $ ParallelLight (fromDirection d) c) |
| 65 |
mempty mempty mempty (Query . const . Any $ False) |