toggle mouse state
This commit is contained in:
parent
13b1c8b389
commit
5be59df1c3
1 changed files with 32 additions and 24 deletions
|
@ -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,24 +124,28 @@ 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}
|
||||||
[] ->
|
[] ->
|
||||||
let dphi = pi / 4 / 45 / 10
|
if curMode == SDL.RelativeLocation
|
||||||
(Euler yaw pitch roll) = cameraRot c
|
then
|
||||||
nangle
|
let dphi = pi / 4 / 45 / 10
|
||||||
| nangle' >= qc = qc - mu
|
(Euler yaw pitch roll) = cameraRot c
|
||||||
| nangle' <= -qc = -qc + mu
|
nangle
|
||||||
| otherwise = nangle'
|
| nangle' >= qc = qc - mu
|
||||||
where
|
| nangle' <= -qc = -qc + mu
|
||||||
nangle' = (dphi * ry) + roll
|
| otherwise = nangle'
|
||||||
qc = pi / 2
|
where
|
||||||
mu = 0.01
|
nangle' = (dphi * ry) + roll
|
||||||
nrot =
|
qc = pi / 2
|
||||||
Euler
|
mu = 0.01
|
||||||
yaw
|
nrot =
|
||||||
(pitch + (rx * dphi))
|
Euler
|
||||||
nangle
|
yaw
|
||||||
in c
|
(pitch + (rx * dphi))
|
||||||
{ cameraRot = nrot
|
nangle
|
||||||
}
|
in c
|
||||||
|
{ 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)
|
||||||
|
|
Loading…
Reference in a new issue