Commit before tweaking camera

This commit is contained in:
2022-06-04 19:49:27 +01:00
parent 62ccf8fad3
commit b0e880c96f
+38 -8
View File
@@ -25,14 +25,44 @@ import qualified SDL
{- Update the screen camera rotation and position, including any in rold scope/remote camera modifiers;
update where your avatar's view is from. -}
updateCamera :: Configuration -> World -> World
updateCamera cfig = rotateCamera cfig . setViewDistance cfig
. autoZoomCamera cfig . moveCamera . updateScopeZoom
updateCamera cfig = setViewDistance cfig
. moveCamera cfig
. autoZoomCamera cfig . updateScopeZoom
. rotateCamera cfig
moveZoomCamera :: Configuration -> World -> World
moveZoomCamera cfig w = w
& cameraCenter .~ newcen
& cameraViewFrom .~ newvf
& cameraZoom .~ newzoom
where
newvf = _crPos (you w) +.+ fromMaybe (V2 0 0) (yourItem w ^? _Just . itScope . scopePos)
newcen = newvf
newzoom = changeZoom (_cameraZoom w)
wallZoom = farWallDist newvf cfig w
idealZoom
| SDL.ButtonRight `S.member` _mouseButtons w
= theScopeZoom * maybe zoomNoItem zoomFromItem (yourItem w ^? _Just . itUse . useAim . aimZoom) wallZoom
| otherwise = zoomNoItem wallZoom
-- = maybe zoomNoItem zoomFromItem (yourItem w ^? itZoom) wallZoom
changeZoom curZoom
| curZoom > idealZoom + 0.01 = ((zoomOutSpeed-1)*curZoom + idealZoom) / zoomOutSpeed
| curZoom < idealZoom - 0.01 = ((zoomInSpeed -1)*curZoom + idealZoom) / zoomInSpeed
| otherwise = idealZoom
-- these speeds are inverted, larger means slower
zoomInSpeed = 25
zoomOutSpeed = 15
theScopeZoom = fromMaybe 1 $ yourItem w ^? _Just . itScope . scopeZoom
{- Updte the center of the screen camera center and where your avatar's view is from in world. -}
moveCamera :: World -> World
moveCamera w = w
moveCamera :: Configuration -> World -> World
moveCamera cfig w = w
& cameraCenter .~ idealPos
& cameraViewFrom .~ sightFrom
& cameraViewFrom .~ camCenter
where
camPos = _cameraViewFrom w
wallZoom = farWallDist camPos cfig w
basezoom = zoomNoItem wallZoom
aimRangeFactor
| _cameraZoom w == 0 = 0
| otherwise = fromMaybe 0 (yourItem w ^? _Just . itUse . useAim . aimRange) / _cameraZoom w
@@ -40,8 +70,8 @@ moveCamera w = w
| SDL.ButtonRight `S.member` _mouseButtons w = 1
| otherwise = 0
ypos = _crPos $ you w
idealPos = camCenter
+.+ rotateV (_cameraRot w) (aimRangeFactor * aimingMult *.* _mousePos w)
idealPos = camCenter +.+ aimoffset
aimoffset = rotateV (_cameraRot w) (0.5 * aimRangeFactor * aimingMult *.* _mousePos w)
camCenter = ypos +.+ scopeOffset
scopeOffset = fromMaybe (V2 0 0) $ yourItem w ^? _Just . itScope . scopePos
sightFrom = case yourItem w ^? _Just . itScope . scopeIsCamera of
@@ -156,7 +186,7 @@ autoZoomCamera cfig w = w & cameraZoom %~ changeZoom
where
camPos = _cameraViewFrom w
wallZoom = farWallDist camPos cfig w
idealZoom
idealZoom
| SDL.ButtonRight `S.member` _mouseButtons w
= theScopeZoom * maybe zoomNoItem zoomFromItem (yourItem w ^? _Just . itUse . useAim . aimZoom) wallZoom
| otherwise = zoomNoItem wallZoom