2014-02-05 16:33:32 +01:00
|
|
|
{-# LANGUAGE BangPatterns, DoAndIfThenElse #-}
|
2014-01-20 14:12:02 +01:00
|
|
|
module Main where
|
2014-01-03 03:01:54 +01:00
|
|
|
|
2014-01-20 23:18:07 +01:00
|
|
|
-- Monad-foo and higher functional stuff
|
|
|
|
import Control.Monad (unless, void, when, join)
|
|
|
|
import Control.Arrow ((***))
|
2014-01-20 19:28:02 +01:00
|
|
|
|
|
|
|
-- data consistency/conversion
|
|
|
|
import Control.Concurrent (threadDelay)
|
2014-02-04 14:11:16 +01:00
|
|
|
import Control.Concurrent.STM (TQueue,
|
|
|
|
newTQueueIO)
|
|
|
|
|
2014-01-05 20:23:22 +01:00
|
|
|
import Control.Monad.RWS.Strict (RWST, ask, asks,
|
|
|
|
evalRWST, get, liftIO,
|
|
|
|
modify, put)
|
2014-01-20 19:28:02 +01:00
|
|
|
import Data.Distributive (distribute, collect)
|
|
|
|
|
2014-01-20 14:12:02 +01:00
|
|
|
-- FFI
|
2014-01-05 20:23:22 +01:00
|
|
|
import Foreign (Ptr, castPtr, with)
|
|
|
|
import Foreign.C (CFloat)
|
2014-01-20 14:12:02 +01:00
|
|
|
|
|
|
|
-- Math
|
2014-03-05 14:42:26 +01:00
|
|
|
import Control.Lens ((^.), (.~), (%~))
|
2014-01-05 20:23:22 +01:00
|
|
|
import Linear as L
|
|
|
|
|
2014-01-20 14:12:02 +01:00
|
|
|
-- GUI
|
2014-03-05 14:42:26 +01:00
|
|
|
import qualified Graphics.UI.SDL as SDL (Position)
|
|
|
|
import Graphics.UI.SDL as SDL
|
2014-02-23 13:32:20 +01:00
|
|
|
--import Graphics.UI.SDL.TTF as TTF
|
|
|
|
--import Graphics.UI.SDL.TTF.Types
|
2014-01-20 14:12:02 +01:00
|
|
|
|
|
|
|
-- Render
|
2014-01-05 20:23:22 +01:00
|
|
|
import qualified Graphics.Rendering.OpenGL.GL as GL
|
|
|
|
import Graphics.Rendering.OpenGL.Raw.Core31
|
2014-01-20 19:28:02 +01:00
|
|
|
import Data.Time (getCurrentTime, UTCTime, diffUTCTime)
|
2014-01-05 20:23:22 +01:00
|
|
|
|
2014-01-21 16:18:48 +01:00
|
|
|
import Graphics.Rendering.OpenGL.Raw.ARB.TessellationShader
|
2014-01-20 14:12:02 +01:00
|
|
|
-- Our modules
|
2014-01-05 20:23:22 +01:00
|
|
|
import Map.Map
|
|
|
|
import Render.Misc (checkError,
|
|
|
|
createFrustum, getCam,
|
2014-02-04 14:11:16 +01:00
|
|
|
curb)
|
2014-01-05 20:23:22 +01:00
|
|
|
import Render.Render (initRendering,
|
|
|
|
initShader)
|
2014-02-05 16:33:32 +01:00
|
|
|
import UI.Callbacks
|
|
|
|
import Types
|
2014-01-03 03:01:54 +01:00
|
|
|
|
2014-01-20 19:28:02 +01:00
|
|
|
import qualified Debug.Trace as D (trace)
|
|
|
|
|
2014-01-20 16:11:34 +01:00
|
|
|
--------------------------------------------------------------------------------
|
2013-12-22 23:29:11 +01:00
|
|
|
main :: IO ()
|
2014-01-20 16:11:34 +01:00
|
|
|
main = do
|
2014-01-20 19:28:02 +01:00
|
|
|
SDL.withInit [InitVideo, InitAudio] $ do --also: InitNoParachute -> faster, without parachute!
|
2014-03-05 14:42:26 +01:00
|
|
|
SDL.withWindow "Pioneers" (SDL.Position 100 100) (Size 1024 600) [WindowOpengl -- we want openGL
|
2014-01-20 16:11:34 +01:00
|
|
|
,WindowShown -- window should be visible
|
|
|
|
,WindowResizable -- and resizable
|
|
|
|
,WindowInputFocus -- focused (=> active)
|
|
|
|
,WindowMouseFocus -- Mouse into it
|
2014-02-05 16:33:32 +01:00
|
|
|
,WindowInputGrabbed-- never let go of input (KB/Mouse)
|
2014-01-20 19:42:49 +01:00
|
|
|
] $ \window -> do
|
|
|
|
withOpenGL window $ do
|
2014-02-23 13:32:20 +01:00
|
|
|
--TTF.withInit $ do
|
2014-01-20 16:11:34 +01:00
|
|
|
(Size fbWidth fbHeight) <- glGetDrawableSize window
|
|
|
|
initRendering
|
|
|
|
--generate map vertices
|
|
|
|
(mapBuffer, vert) <- getMapBufferObject
|
2014-01-21 16:44:42 +01:00
|
|
|
(ci, ni, vi, pri, vii, mi, nmi, tli, tlo) <- initShader
|
2014-01-20 19:28:02 +01:00
|
|
|
putStrLn "foo"
|
2014-01-20 16:11:34 +01:00
|
|
|
eventQueue <- newTQueueIO :: IO (TQueue Event)
|
2014-01-20 19:28:02 +01:00
|
|
|
putStrLn "foo"
|
|
|
|
now <- getCurrentTime
|
|
|
|
putStrLn "foo"
|
2014-02-23 13:32:20 +01:00
|
|
|
--font <- TTF.openFont "fonts/ttf-04B_03B_/04B_03B_.TTF" 10
|
|
|
|
--TTF.setFontStyle font TTFNormal
|
|
|
|
--TTF.setFontHinting font TTFHNormal
|
2014-01-20 16:11:34 +01:00
|
|
|
|
2014-01-21 16:18:48 +01:00
|
|
|
let zDistClosest = 1
|
|
|
|
zDistFarthest = zDistClosest + 30
|
2014-02-04 14:11:16 +01:00
|
|
|
--TODO: Move near/far/fov to state for runtime-changability & central storage
|
2014-01-20 16:11:34 +01:00
|
|
|
fov = 90 --field of view
|
|
|
|
near = 1 --near plane
|
|
|
|
far = 100 --far plane
|
|
|
|
ratio = fromIntegral fbWidth / fromIntegral fbHeight
|
|
|
|
frust = createFrustum fov near far ratio
|
2014-01-20 23:18:07 +01:00
|
|
|
aks = ArrowKeyState {
|
2014-02-23 13:32:20 +01:00
|
|
|
_up = False
|
|
|
|
, _down = False
|
|
|
|
, _left = False
|
|
|
|
, _right = False
|
2014-01-20 23:18:07 +01:00
|
|
|
}
|
2014-02-23 13:32:20 +01:00
|
|
|
glMap = GLMapState
|
|
|
|
{ _shdrVertexIndex = vi
|
|
|
|
, _shdrNormalIndex = ni
|
|
|
|
, _shdrColorIndex = ci
|
|
|
|
, _shdrProjMatIndex = pri
|
|
|
|
, _shdrViewMatIndex = vii
|
|
|
|
, _shdrModelMatIndex = mi
|
|
|
|
, _shdrNormalMatIndex = nmi
|
|
|
|
, _shdrTessInnerIndex = tli
|
|
|
|
, _shdrTessOuterIndex = tlo
|
|
|
|
, _stateTessellationFactor = 4
|
|
|
|
, _stateMap = mapBuffer
|
|
|
|
, _mapVert = vert
|
|
|
|
}
|
2014-01-20 16:11:34 +01:00
|
|
|
env = Env
|
2014-02-23 13:32:20 +01:00
|
|
|
{ _eventsChan = eventQueue
|
|
|
|
, _windowObject = window
|
|
|
|
, _zDistClosest = zDistClosest
|
|
|
|
, _zDistFarthest = zDistFarthest
|
|
|
|
--, envFont = font
|
2014-01-20 16:11:34 +01:00
|
|
|
}
|
|
|
|
state = State
|
2014-02-23 13:32:20 +01:00
|
|
|
{ _window = WindowState
|
|
|
|
{ _width = fbWidth
|
|
|
|
, _height = fbHeight
|
|
|
|
, _shouldClose = False
|
|
|
|
}
|
|
|
|
, _camera = CameraState
|
|
|
|
{ _xAngle = pi/6
|
|
|
|
, _yAngle = pi/2
|
|
|
|
, _zDist = 10
|
|
|
|
, _frustum = frust
|
2014-03-05 14:42:26 +01:00
|
|
|
, _camPosition = Types.Position
|
2014-02-23 13:32:20 +01:00
|
|
|
{ Types._x = 5
|
|
|
|
, Types._y = 5
|
|
|
|
}
|
|
|
|
}
|
|
|
|
, _io = IOState
|
|
|
|
{ _clock = now
|
|
|
|
}
|
|
|
|
, _mouse = MouseState
|
|
|
|
{ _isDown = False
|
|
|
|
, _isDragging = False
|
|
|
|
, _dragStartX = 0
|
|
|
|
, _dragStartY = 0
|
|
|
|
, _dragStartXAngle = 0
|
|
|
|
, _dragStartYAngle = 0
|
2014-03-05 14:42:26 +01:00
|
|
|
, _mousePosition = Types.Position
|
2014-02-23 13:32:20 +01:00
|
|
|
{ Types._x = 5
|
|
|
|
, Types._y = 5
|
|
|
|
}
|
|
|
|
}
|
|
|
|
, _keyboard = KeyboardState
|
|
|
|
{ _arrowsPressed = aks
|
|
|
|
}
|
|
|
|
, _gl = GLState
|
|
|
|
{ _glMap = glMap
|
|
|
|
}
|
|
|
|
, _game = GameState
|
|
|
|
{
|
|
|
|
}
|
2014-01-20 16:11:34 +01:00
|
|
|
}
|
2014-01-20 19:28:02 +01:00
|
|
|
|
|
|
|
putStrLn "init done."
|
2014-01-20 16:11:34 +01:00
|
|
|
void $ evalRWST (adjustWindow >> run) env state
|
|
|
|
|
|
|
|
destroyWindow window
|
|
|
|
|
2014-01-20 19:28:02 +01:00
|
|
|
-- Render-Pipeline
|
|
|
|
|
|
|
|
draw :: Pioneers ()
|
|
|
|
draw = do
|
|
|
|
state <- get
|
2014-03-05 14:42:26 +01:00
|
|
|
let xa = state ^. camera.xAngle
|
|
|
|
ya = state ^. camera.yAngle
|
|
|
|
(GL.UniformLocation proj) = state ^. gl.glMap.shdrProjMatIndex
|
|
|
|
(GL.UniformLocation nmat) = state ^. gl.glMap.shdrNormalMatIndex
|
|
|
|
(GL.UniformLocation vmat) = state ^. gl.glMap.shdrViewMatIndex
|
|
|
|
(GL.UniformLocation tli) = state ^. gl.glMap.shdrTessInnerIndex
|
|
|
|
(GL.UniformLocation tlo) = state ^. gl.glMap.shdrTessOuterIndex
|
|
|
|
vi = state ^. gl.glMap.shdrVertexIndex
|
|
|
|
ni = state ^. gl.glMap.shdrNormalIndex
|
|
|
|
ci = state ^. gl.glMap.shdrColorIndex
|
|
|
|
numVert = state ^. gl.glMap.mapVert
|
|
|
|
map' = state ^. gl.glMap.stateMap
|
|
|
|
frust = state ^. camera.frustum
|
|
|
|
camX = state ^. camera.camPosition.x
|
|
|
|
camY = state ^. camera.camPosition.y
|
|
|
|
zDist' = state ^. camera.zDist
|
|
|
|
tessFac = state ^. gl.glMap.stateTessellationFactor
|
2014-01-20 19:28:02 +01:00
|
|
|
liftIO $ do
|
|
|
|
--(vi,GL.UniformLocation proj) <- initShader
|
|
|
|
GL.clear [GL.ColorBuffer, GL.DepthBuffer]
|
|
|
|
checkError "foo"
|
|
|
|
--set up projection (= copy from state)
|
2014-02-04 14:11:16 +01:00
|
|
|
with (distribute frust) $ \ptr ->
|
2014-01-20 19:28:02 +01:00
|
|
|
glUniformMatrix4fv proj 1 0 (castPtr (ptr :: Ptr (M44 CFloat)))
|
|
|
|
checkError "foo"
|
|
|
|
|
|
|
|
--set up camera
|
2014-03-05 14:42:26 +01:00
|
|
|
let ! cam = getCam (camX,camY) zDist' xa ya
|
2014-02-04 14:11:16 +01:00
|
|
|
with (distribute cam) $ \ptr ->
|
2014-01-20 19:28:02 +01:00
|
|
|
glUniformMatrix4fv vmat 1 0 (castPtr (ptr :: Ptr (M44 CFloat)))
|
|
|
|
checkError "foo"
|
|
|
|
|
|
|
|
--set up normal--Mat transpose((model*camera)^-1)
|
2014-02-04 14:11:16 +01:00
|
|
|
let normal = (case inv33 (fmap (^. _xyz) cam ^. _xyz) of
|
2014-01-20 19:28:02 +01:00
|
|
|
(Just a) -> a
|
|
|
|
Nothing -> eye3) :: M33 CFloat
|
2014-02-04 14:11:16 +01:00
|
|
|
nmap = collect id normal :: M33 CFloat --transpose...
|
2014-01-20 19:28:02 +01:00
|
|
|
|
2014-02-04 14:11:16 +01:00
|
|
|
with (distribute nmap) $ \ptr ->
|
2014-01-20 19:28:02 +01:00
|
|
|
glUniformMatrix3fv nmat 1 0 (castPtr (ptr :: Ptr (M33 CFloat)))
|
|
|
|
|
|
|
|
checkError "nmat"
|
2014-01-21 16:44:42 +01:00
|
|
|
|
|
|
|
glUniform1f tli (fromIntegral tessFac)
|
|
|
|
glUniform1f tlo (fromIntegral tessFac)
|
2014-01-20 19:28:02 +01:00
|
|
|
|
|
|
|
GL.bindBuffer GL.ArrayBuffer GL.$= Just map'
|
|
|
|
GL.vertexAttribPointer ci GL.$= fgColorIndex
|
|
|
|
GL.vertexAttribArray ci GL.$= GL.Enabled
|
|
|
|
GL.vertexAttribPointer ni GL.$= fgNormalIndex
|
|
|
|
GL.vertexAttribArray ni GL.$= GL.Enabled
|
|
|
|
GL.vertexAttribPointer vi GL.$= fgVertexIndex
|
|
|
|
GL.vertexAttribArray vi GL.$= GL.Enabled
|
|
|
|
checkError "beforeDraw"
|
2014-01-21 16:18:48 +01:00
|
|
|
|
|
|
|
glPatchParameteri gl_PATCH_VERTICES 3
|
|
|
|
glPolygonMode gl_FRONT gl_LINE
|
2014-01-20 19:28:02 +01:00
|
|
|
|
2014-01-21 16:18:48 +01:00
|
|
|
glDrawArrays gl_PATCHES 0 (fromIntegral numVert)
|
2014-01-20 19:28:02 +01:00
|
|
|
checkError "draw"
|
|
|
|
|
|
|
|
|
2014-01-20 16:11:34 +01:00
|
|
|
-- Main game loop
|
|
|
|
|
|
|
|
run :: Pioneers ()
|
|
|
|
run = do
|
2014-03-05 14:42:26 +01:00
|
|
|
env <- ask
|
2014-01-20 16:11:34 +01:00
|
|
|
|
|
|
|
-- draw Scene
|
2014-01-20 20:04:21 +01:00
|
|
|
draw
|
2014-03-05 14:42:26 +01:00
|
|
|
liftIO $ glSwapWindow (env ^. windowObject)
|
2014-01-20 16:11:34 +01:00
|
|
|
-- getEvents & process
|
|
|
|
processEvents
|
|
|
|
|
|
|
|
-- update State
|
|
|
|
|
|
|
|
state <- get
|
|
|
|
-- change in camera-angle
|
2014-03-05 14:42:26 +01:00
|
|
|
when (state ^. mouse.isDragging) $ do
|
|
|
|
let sodx = state ^. mouse.dragStartX
|
|
|
|
sody = state ^. mouse.dragStartY
|
|
|
|
sodxa = state ^. mouse.dragStartXAngle
|
|
|
|
sodya = state ^. mouse.dragStartYAngle
|
|
|
|
x' = state ^. mouse.mousePosition.x
|
|
|
|
y' = state ^. mouse.mousePosition.y
|
|
|
|
myrot = (x' - sodx) / 2
|
|
|
|
mxrot = (y' - sody) / 2
|
2014-01-20 16:11:34 +01:00
|
|
|
newXAngle = curb (pi/12) (0.45*pi) newXAngle'
|
|
|
|
newXAngle' = sodxa + mxrot/100
|
|
|
|
newYAngle
|
|
|
|
| newYAngle' > pi = newYAngle' - 2 * pi
|
|
|
|
| newYAngle' < (-pi) = newYAngle' + 2 * pi
|
|
|
|
| otherwise = newYAngle'
|
|
|
|
newYAngle' = sodya + myrot/100
|
2014-03-05 14:42:26 +01:00
|
|
|
|
|
|
|
modify $ ((camera.xAngle) .~ newXAngle)
|
|
|
|
. ((camera.yAngle) .~ newYAngle)
|
2014-01-20 16:11:34 +01:00
|
|
|
|
|
|
|
-- get cursor-keys - if pressed
|
|
|
|
--TODO: Add sin/cos from stateYAngle
|
2014-02-04 14:11:16 +01:00
|
|
|
(kxrot, kyrot) <- fmap (join (***) fromIntegral) getArrowMovement
|
2014-03-05 14:42:26 +01:00
|
|
|
let
|
|
|
|
multc = cos $ state ^. camera.yAngle
|
|
|
|
mults = sin $ state ^. camera.yAngle
|
|
|
|
modx x' = x' - 0.2 * kxrot * multc
|
|
|
|
- 0.2 * kyrot * mults
|
|
|
|
mody y' = y' - 0.2 * kxrot * mults
|
|
|
|
- 0.2 * kyrot * multc
|
|
|
|
modify $ (camera.camPosition.x %~ modx)
|
|
|
|
. (camera.camPosition.y %~ mody)
|
|
|
|
|
2014-01-20 16:11:34 +01:00
|
|
|
{-
|
|
|
|
--modify the state with all that happened in mt time.
|
|
|
|
mt <- liftIO GLFW.getTime
|
|
|
|
modify $ \s -> s
|
|
|
|
{
|
|
|
|
}
|
|
|
|
-}
|
2014-03-05 14:42:26 +01:00
|
|
|
|
2014-01-20 19:28:02 +01:00
|
|
|
mt <- liftIO $ do
|
|
|
|
now <- getCurrentTime
|
2014-03-05 14:42:26 +01:00
|
|
|
diff <- return $ diffUTCTime now (state ^. io.clock) -- get time-diffs
|
2014-02-04 14:11:16 +01:00
|
|
|
title <- return $ unwords ["Pioneers @ ",show ((round .fromRational.toRational $ 1.0/diff)::Int),"fps"]
|
2014-03-05 14:42:26 +01:00
|
|
|
setWindowTitle (env ^. windowObject) title
|
2014-01-20 19:28:02 +01:00
|
|
|
sleepAmount <- return $ floor (max 0 (0.04 - diff))*1000000 -- get time until next frame in microseconds
|
|
|
|
threadDelay sleepAmount
|
|
|
|
return now
|
|
|
|
-- set state with new clock-time
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ io.clock .~ mt
|
|
|
|
shouldClose <- return $ state ^. window.shouldClose
|
2014-01-20 19:28:02 +01:00
|
|
|
unless shouldClose run
|
2014-01-20 16:11:34 +01:00
|
|
|
|
2014-01-20 23:18:07 +01:00
|
|
|
getArrowMovement :: Pioneers (Int, Int)
|
|
|
|
getArrowMovement = do
|
|
|
|
state <- get
|
2014-03-05 14:42:26 +01:00
|
|
|
aks <- return $ state ^. (keyboard.arrowsPressed)
|
2014-01-20 23:18:07 +01:00
|
|
|
let
|
|
|
|
horz = left' + right'
|
|
|
|
vert = up'+down'
|
2014-03-05 14:42:26 +01:00
|
|
|
left' = if aks ^. left then -1 else 0
|
|
|
|
right' = if aks ^. right then 1 else 0
|
|
|
|
up' = if aks ^. up then -1 else 0
|
|
|
|
down' = if aks ^. down then 1 else 0
|
2014-01-20 23:18:07 +01:00
|
|
|
return (horz,vert)
|
|
|
|
|
2014-01-20 16:11:34 +01:00
|
|
|
adjustWindow :: Pioneers ()
|
|
|
|
adjustWindow = do
|
|
|
|
state <- get
|
2014-03-05 14:42:26 +01:00
|
|
|
let fbWidth = state ^. window.width
|
|
|
|
fbHeight = state ^. window.height
|
2014-01-20 16:11:34 +01:00
|
|
|
fov = 90 --field of view
|
|
|
|
near = 1 --near plane
|
|
|
|
far = 100 --far plane
|
|
|
|
ratio = fromIntegral fbWidth / fromIntegral fbHeight
|
|
|
|
frust = createFrustum fov near far ratio
|
|
|
|
liftIO $ glViewport 0 0 (fromIntegral fbWidth) (fromIntegral fbHeight)
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ camera.frustum .~ frust
|
2014-01-20 16:11:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
processEvents :: Pioneers ()
|
|
|
|
processEvents = do
|
2014-01-20 19:28:02 +01:00
|
|
|
me <- liftIO pollEvent
|
|
|
|
case me of
|
|
|
|
Just e -> do
|
|
|
|
processEvent e
|
|
|
|
processEvents
|
|
|
|
Nothing -> return ()
|
|
|
|
|
|
|
|
processEvent :: Event -> Pioneers ()
|
|
|
|
processEvent e = do
|
2014-03-05 14:42:26 +01:00
|
|
|
return ()
|
2014-01-20 20:04:21 +01:00
|
|
|
case eventData e of
|
2014-02-04 13:58:12 +01:00
|
|
|
Window _ winEvent ->
|
|
|
|
case winEvent of
|
|
|
|
Closing ->
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ window.shouldClose .~ True
|
2014-02-04 13:58:12 +01:00
|
|
|
Resized {windowResizedTo=size} -> do
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ (window.width .~ (sizeWidth size))
|
|
|
|
. (window.height .~ (sizeHeight size))
|
2014-02-04 13:58:12 +01:00
|
|
|
adjustWindow
|
|
|
|
SizeChanged ->
|
|
|
|
adjustWindow
|
2014-02-04 14:15:15 +01:00
|
|
|
_ ->
|
|
|
|
return ()
|
|
|
|
--liftIO $ putStrLn $ unwords ["Unhandled Window-Event:",show e]
|
2014-02-04 14:11:16 +01:00
|
|
|
Keyboard movement _ isRepeated key -> --up/down window(ignored) true/false actualKey
|
2014-02-04 13:58:12 +01:00
|
|
|
-- need modifiers? use "keyModifiers key" to get them
|
2014-03-05 14:42:26 +01:00
|
|
|
let aks = keyboard.arrowsPressed in
|
2014-02-04 13:58:12 +01:00
|
|
|
case keyScancode key of
|
|
|
|
Escape ->
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ window.shouldClose .~ True
|
2014-02-04 13:58:12 +01:00
|
|
|
SDL.Left ->
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ aks.left .~ (movement == KeyDown)
|
2014-02-04 13:58:12 +01:00
|
|
|
SDL.Right ->
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ aks.right .~ (movement == KeyDown)
|
2014-02-04 13:58:12 +01:00
|
|
|
SDL.Up ->
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ aks.up .~ (movement == KeyDown)
|
2014-02-04 13:58:12 +01:00
|
|
|
SDL.Down ->
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ aks.down .~ (movement == KeyDown)
|
2014-02-04 13:58:12 +01:00
|
|
|
SDL.KeypadPlus ->
|
|
|
|
when (movement == KeyDown) $ do
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ (gl.glMap.stateTessellationFactor) %~ ((min 5) . (+1))
|
2014-02-04 13:58:12 +01:00
|
|
|
state <- get
|
2014-03-05 14:42:26 +01:00
|
|
|
liftIO $ putStrLn $ unwords ["Tessellation at: ", show $ state ^. gl.glMap.stateTessellationFactor]
|
2014-02-04 13:58:12 +01:00
|
|
|
SDL.KeypadMinus ->
|
|
|
|
when (movement == KeyDown) $ do
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ (gl.glMap.stateTessellationFactor) %~ ((max 1) . (+(-1)))
|
2014-02-04 13:58:12 +01:00
|
|
|
state <- get
|
2014-03-05 14:42:26 +01:00
|
|
|
liftIO $ putStrLn $ unwords ["Tessellation at: ", show $ state ^. gl.glMap.stateTessellationFactor]
|
2014-02-04 13:58:12 +01:00
|
|
|
_ ->
|
|
|
|
return ()
|
2014-03-05 14:42:26 +01:00
|
|
|
MouseMotion _ mouseId st (SDL.Position x y) xrel yrel -> do
|
2014-02-04 13:58:12 +01:00
|
|
|
state <- get
|
2014-03-05 14:42:26 +01:00
|
|
|
when (state ^. mouse.isDown && not (state ^. mouse.isDragging)) $
|
|
|
|
modify $ (mouse.isDragging .~ True)
|
|
|
|
. (mouse.dragStartX .~ (fromIntegral x))
|
|
|
|
. (mouse.dragStartY .~ (fromIntegral y))
|
|
|
|
. (mouse.dragStartXAngle .~ (state ^. camera.xAngle))
|
|
|
|
. (mouse.dragStartYAngle .~ (state ^. camera.yAngle))
|
|
|
|
|
|
|
|
modify $ (mouse.mousePosition. Types.x .~ (fromIntegral x))
|
|
|
|
. (mouse.mousePosition. Types.y .~ (fromIntegral y))
|
|
|
|
MouseButton _ mouseId button state (SDL.Position x y) ->
|
2014-02-04 13:58:12 +01:00
|
|
|
case button of
|
|
|
|
LeftButton -> do
|
|
|
|
let pressed = state == Pressed
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ mouse.isDown .~ pressed
|
2014-02-05 16:33:32 +01:00
|
|
|
unless pressed $ do
|
|
|
|
st <- get
|
2014-03-05 14:42:26 +01:00
|
|
|
if st ^. mouse.isDragging then
|
|
|
|
modify $ mouse.isDragging .~ False
|
2014-02-05 16:33:32 +01:00
|
|
|
else
|
|
|
|
clickHandler (UI.Callbacks.Pixel x y)
|
|
|
|
RightButton -> do
|
|
|
|
when (state == Released) $ alternateClickHandler (UI.Callbacks.Pixel x y)
|
2014-02-04 13:58:12 +01:00
|
|
|
_ ->
|
|
|
|
return ()
|
2014-02-04 14:11:16 +01:00
|
|
|
MouseWheel _ mouseId hscroll vscroll -> do
|
2014-02-04 13:58:12 +01:00
|
|
|
env <- ask
|
2014-03-05 14:42:26 +01:00
|
|
|
state <- get
|
|
|
|
let zDist' = (state ^. camera.zDist) + realToFrac (negate vscroll) in
|
|
|
|
modify $ camera.zDist .~ (curb (env ^. zDistClosest) (env ^. zDistFarthest) zDist')
|
|
|
|
Quit -> modify $ window.shouldClose .~ True
|
2014-02-04 13:58:12 +01:00
|
|
|
-- there is more (joystic, touchInterface, ...), but currently ignored
|
2014-02-07 17:08:23 +01:00
|
|
|
_ -> liftIO $ putStrLn $ unwords ["Not processing Event:", show e]
|