Implement floating camera
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user