toggle mouse state

This commit is contained in:
nek0 2017-11-18 22:11:44 +01:00
parent 13b1c8b389
commit 5be59df1c3

View file

@ -114,6 +114,7 @@ handle (SDL.KeyboardEvent dat) = do
handleKey key handleKey key
handle (SDL.MouseMotionEvent dat) = do handle (SDL.MouseMotionEvent dat) = do
sd <- getAffection sd <- getAffection
curMode <- SDL.getMouseLocationMode
let (V2 rx ry) = fromIntegral <$> SDL.mouseMotionEventRelMotion dat let (V2 rx ry) = fromIntegral <$> SDL.mouseMotionEventRelMotion dat
c = camera sd c = camera sd
putAffection sd putAffection sd
@ -123,6 +124,8 @@ handle (SDL.MouseMotionEvent dat) = do
let (V3 sx sy sz) = rotVecByEuler (cameraRot c) (V3 (rx / 10) 0 (ry / 10)) let (V3 sx sy sz) = rotVecByEuler (cameraRot c) (V3 (rx / 10) 0 (ry / 10))
in c {cameraFocus = cameraFocus c + V3 sx 0 sy} in c {cameraFocus = cameraFocus c + V3 sx 0 sy}
[] -> [] ->
if curMode == SDL.RelativeLocation
then
let dphi = pi / 4 / 45 / 10 let dphi = pi / 4 / 45 / 10
(Euler yaw pitch roll) = cameraRot c (Euler yaw pitch roll) = cameraRot c
nangle nangle
@ -141,6 +144,8 @@ handle (SDL.MouseMotionEvent dat) = do
in c in c
{ cameraRot = nrot { cameraRot = nrot
} }
else
c
_ -> _ ->
c c
} }
@ -149,12 +154,15 @@ handle _ = return ()
handleKey :: SDL.Keycode -> Affection StateData () handleKey :: SDL.Keycode -> Affection StateData ()
handleKey code handleKey code
| code == SDL.KeycodeR = | code == SDL.KeycodeR = do
GL.clearColor $= GL.Color4 1 0 0 1 curMode <- SDL.getMouseLocationMode
| code == SDL.KeycodeG = if curMode == SDL.AbsoluteLocation
GL.clearColor $= GL.Color4 0 1 0 1 then do
| code == SDL.KeycodeB = _ <- SDL.setMouseLocationMode SDL.RelativeLocation
GL.clearColor $= GL.Color4 0 0 1 1 return ()
else do
_ <- SDL.setMouseLocationMode SDL.AbsoluteLocation
return ()
| code == SDL.KeycodeP = do | code == SDL.KeycodeP = do
r <- liftIO $ randomRIO (0, 1) r <- liftIO $ randomRIO (0, 1)
g <- liftIO $ randomRIO (0, 1) g <- liftIO $ randomRIO (0, 1)