diff options
Diffstat (limited to 'src/Vivant.hs')
-rw-r--r-- | src/Vivant.hs | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/src/Vivant.hs b/src/Vivant.hs index 21c397e..5335b30 100644 --- a/src/Vivant.hs +++ b/src/Vivant.hs @@ -67,7 +67,7 @@ initialCamera = cameraFront = normalize (V3 0 10 (-10)), cameraSpeed = 0.05, cameraPitch = 0, - cameraYaw = (-90) + cameraYaw = -90 } data Game = Game @@ -182,12 +182,12 @@ parseEvents keys mouse = do . changeIfIn events' mouseWheel (\(k, m) -> (k, m {mouseWheel = 0})) $ changeIfIn events' mouseMoving (\(k, m) -> (k, m {mouseRelative = V2 0 0})) (k, m) where - mouseMoving (SDL.MouseMotionEvent {}) = True + mouseMoving SDL.MouseMotionEvent {} = True mouseMoving _ = False - mouseWheel (SDL.MouseWheelEvent {}) = True + mouseWheel SDL.MouseWheelEvent {} = True mouseWheel _ = False changeIfIn events event modification initial = - if (> 0) . length $ filter event events + if any event events then initial else modification initial @@ -198,36 +198,31 @@ handleEvents :: handleEvents event (k, m) = case event of SDL.KeyboardEvent - ( SDL.KeyboardEventData - { SDL.keyboardEventKeyMotion = e, - SDL.keyboardEventKeysym = k' - } - ) -> + SDL.KeyboardEventData + { SDL.keyboardEventKeyMotion = e, + SDL.keyboardEventKeysym = k' + } -> ((if e == SDL.Released then Set.delete else Set.insert) k' k, m) SDL.MouseMotionEvent - ( SDL.MouseMotionEventData - { SDL.mouseMotionEventPos = pos, - SDL.mouseMotionEventRelMotion = vel - } - ) -> + SDL.MouseMotionEventData + { SDL.mouseMotionEventPos = pos, + SDL.mouseMotionEventRelMotion = vel + } -> (k, MouseInputs pos vel (mousePositionOld m) (mousePressed m) (mouseWheel m)) SDL.MouseButtonEvent - ( SDL.MouseButtonEventData - { SDL.mouseButtonEventMotion = SDL.Pressed - } - ) -> + SDL.MouseButtonEventData + { SDL.mouseButtonEventMotion = SDL.Pressed + } -> (k, m {mousePressed = True}) SDL.MouseButtonEvent - ( SDL.MouseButtonEventData - { SDL.mouseButtonEventMotion = SDL.Released - } - ) -> + SDL.MouseButtonEventData + { SDL.mouseButtonEventMotion = SDL.Released + } -> (k, m {mousePressed = False}) SDL.MouseWheelEvent - ( SDL.MouseWheelEventData - { SDL.mouseWheelEventPos = V2 x y - } - ) -> + SDL.MouseWheelEventData + { SDL.mouseWheelEventPos = V2 x y + } -> (k, m {mouseWheel = y}) SDL.QuitEvent {} -> (Set.insert escapeKey k, m) @@ -262,13 +257,12 @@ updateMouse mouse game = pixelRenderer :: Double -> Int -> Int -> Float pixelRenderer n x y = fromRational . toRational $ - ( ( perlin3 - permutation - ( (fromIntegral x - 32) / 16, - (fromIntegral y - 32) / 16, - n - ) - ) + ( perlin3 + permutation + ( (fromIntegral x - 32) / 16, + (fromIntegral y - 32) / 16, + n + ) + 1 ) @@ -311,13 +305,13 @@ toRadians :: Float -> Float toRadians = (*) (pi / 180) scaledMat :: V4 (V4 Float) -> V4 (V4 Float) -scaledMat n = ((n * identity) & _w . _w .~ 1) +scaledMat n = (n * identity) & _w . _w .~ 1 castV3 :: V3 a -> GL.Vector3 a castV3 (V3 a b c) = GL.Vector3 a b c draw :: Game -> IO () -draw game@(Game {gameProgram = Just p, gameVao = Just v, gameTerrain = Just t}) = do +draw game@Game {gameProgram = Just p, gameVao = Just v, gameTerrain = Just t} = do tick <- ticks GL.clearColor $= GL.Color4 0.2 0.2 0.2 1 GL.clear [GL.ColorBuffer, GL.DepthBuffer] @@ -343,7 +337,7 @@ draw game@(Game {gameProgram = Just p, gameVao = Just v, gameTerrain = Just t}) ourColorLoc <- GL.uniformLocation p "light_pos" GL.uniform ourColorLoc - $= (GL.Vector3 (0 :: Float) (128 * sin (fromIntegral tick / 2000)) (64 * (abs $ cos (fromIntegral tick / 2000)))) + $= GL.Vector3 (0 :: Float) (128 * sin (fromIntegral tick / 2000)) (64 * abs (cos $ fromIntegral tick / 2000)) --castV3 (cameraPos (gameCamera game)) render $ terrainRenderer t |