Refactor light sources

This commit is contained in:
2022-07-21 16:21:35 +01:00
parent cf5ec4a261
commit aabd8a2cb8
8 changed files with 71 additions and 45 deletions
+13
View File
@@ -0,0 +1,13 @@
module Dodge.LightSource.Draw where
import Dodge.Data.LightSource
import Picture
import Geometry.Data
drawLightSource :: LightSourceDraw -> LightSource -> Picture
drawLightSource lsd = case lsd of
DefaultLightSourceDraw -> defLSPic
defLSPic :: LightSource -> Picture
defLSPic ls = setLayer BloomNoZWrite . translate3 (_lsPos $ _lsParam ls) . color col $ circleSolid 4
where
col = V4 r g b 2
V3 r g b = _lsCol $ _lsParam ls
+24
View File
@@ -0,0 +1,24 @@
module Dodge.LightSource.Update where
import Dodge.Data.LightSource
import Geometry
import Control.Lens
updateTempLightSource :: TLSUpdate -> TempLightSource -> Maybe TempLightSource
updateTempLightSource tlsu = case tlsu of
DestroyTLS -> const Nothing
TimerTLS -> timerTLS
IntensityTLS ConstantIntensity -> updateTempLightSource TimerTLS
IntensityTLS (TLSFade startcol x) -> fadeTLS startcol x
fadeTLS :: Point3 -> Int -> TempLightSource -> Maybe TempLightSource
fadeTLS startcol x tls
| t < 1 = Nothing
| t < x = Just $ tls & tlsParam . lsCol .~ (1 / fromIntegral (x - t)) *.*.* startcol
| otherwise = Just $ tls & tlsParam . lsCol .~ startcol -- this is wasteful, should be set once at begining
where
t = _tlsTime tls
timerTLS :: TempLightSource -> Maybe TempLightSource
timerTLS t
| _tlsTime t <= 0 = Nothing
| otherwise = Just $ t & tlsTime -~ 1