Tweak camera movement

This commit is contained in:
2024-12-31 09:54:57 +00:00
parent e12e4777b2
commit ede08ff1db
6 changed files with 79 additions and 79 deletions
+27 -19
View File
@@ -31,7 +31,7 @@ update where your avatar's view is from. -}
updateCamera :: Configuration -> World -> World
updateCamera cfig w = case w ^. wCam . camControl of
CamInGame {} -> updateInGameCamera cfig w
CamFloat -> rotateCamera cfig $ updateFloatingCamera cfig w
CamFloat -> updateFloatingCamera cfig w
updateFloatingCamera :: Configuration -> World -> World
updateFloatingCamera cfig w =
@@ -46,15 +46,20 @@ updateFloatingCamera cfig w =
translateFloatingCamera :: Input -> Camera -> Camera
translateFloatingCamera theinput cam = fromMaybe cam $ do
presstime <- theinput ^. mouseButtons . at ButtonLeft
guard $ presstime > 0
hpos <- theinput ^? heldPos . ix ButtonLeft
let thetran =
screenToWorldPos cam hpos
-.- screenToWorldPos cam (theinput ^. mousePos)
return $
cam & camCenter +~ thetran
& camViewFrom +~ thetran
lpresstime <- theinput ^. mouseButtons . at ButtonLeft
rpresstime <- theinput ^. mouseButtons . at ButtonRight
if lpresstime > rpresstime
then do
hpos <- theinput ^? heldPos . ix ButtonLeft
let thetran =
screenToWorldPos cam hpos
-.- screenToWorldPos cam (theinput ^. mousePos)
return $
cam & camCenter +~ thetran
& camViewFrom +~ thetran
else do
a <- (theinput ^. heldPos . at SDL.ButtonRight)
return $ cam & camRot -~ angleBetween (theinput ^. mousePos) a
translateFloatingCameraKeys :: Input -> Camera -> Camera
translateFloatingCameraKeys theinput = (camCenter -~ thetran) . (camViewFrom -~ thetran)
@@ -157,17 +162,20 @@ doWallRotate wl w = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl) - (w ^. wC
b = a * (4 / pi)
b' = fromIntegral (round b :: Int)
--rotateCameraBy :: Float -> World -> World
--rotateCameraBy x = wCam . camRot +~ x
rotateCamera :: Configuration -> World -> World
rotateCamera cfig w
-- | keydown SDL.ScancodeQ && keydown SDL.ScancodeE = w
-- | keydown SDL.ScancodeQ = rotateCameraBy 0.025 w
-- | keydown SDL.ScancodeE = rotateCameraBy (-0.025) w
rotateCamera cfig w
| Just ltime <- pkeys ^? ix SDL.ButtonLeft
, Just rtime <- pkeys ^? ix SDL.ButtonRight
, rtime > ltime = w & wCam . camRot -~ rotation
| otherwise = ifConfigWallRotate cfig (w ^. input . mouseButtons) w
-- where
-- keydown scode = scode `M.member` _pressedKeys (_input w) && not (inTextInputFocus w)
where
pkeys = w ^. input . mouseButtons
rotation =
maybe
0
(angleBetween $ w ^. input . mousePos)
(w ^. input . heldPos . at SDL.ButtonRight)
zoomFromItem :: ItZoom -> Float
zoomFromItem ItZoom{_izMax = zMax, _izMin = zMin, _izFac = zFac} =