Implement floating camera

This commit is contained in:
2023-03-26 16:44:19 +01:00
parent 082ce9c9a1
commit 73e742e1a2
12 changed files with 86 additions and 38 deletions
+26 -1
View File
@@ -5,6 +5,8 @@ module Dodge.Update.Camera (
updateCamera,
) where
import SDL (MouseButton (..))
import Dodge.Base.Coordinate
import Dodge.InputFocus
import Bound
import Dodge.Viewpoints
@@ -28,9 +30,32 @@ update where your avatar's view is from. -}
updateCamera :: Configuration -> World -> World
updateCamera cfig w = case w ^. cWorld . cwCam . camControl of
CamInGame -> updateInGameCamera cfig w
CamFloat -> w
CamFloat -> updateFloatingCamera cfig w
CamPan -> w
updateFloatingCamera :: Configuration -> World -> World
updateFloatingCamera cfig w = w
& updateBounds cfig
& cWorld . cwCam %~ setViewDistance cfig
& cWorld . cwCam %~ translateFloatingCamera theinput
& cWorld . cwCam %~ zoomFloatingCamera theinput
where
theinput = w ^. input
translateFloatingCamera :: Input -> Camera -> Camera
translateFloatingCamera theinput cam = fromMaybe cam $ do
presstime <- theinput ^. mouseButtons . at ButtonLeft
guard $ presstime > 1
hpos <- theinput ^? heldPos . ix ButtonLeft
let thetran =
screenToWorldPos cam hpos
-.-
screenToWorldPos cam (theinput ^. mousePos)
return $ cam & camCenter +~ thetran
& camViewFrom +~ thetran
zoomFloatingCamera theinput cam = cam
updateInGameCamera :: Configuration -> World -> World
updateInGameCamera cfig w =
w