Commit before tweaking camera

This commit is contained in:
2022-06-04 19:49:27 +01:00
parent 62ccf8fad3
commit b0e880c96f
+39 -9
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 the screen camera rotation and position, including any in rold scope/remote camera modifiers;
update where your avatar's view is from. -} update where your avatar's view is from. -}
updateCamera :: Configuration -> World -> World updateCamera :: Configuration -> World -> World
updateCamera cfig = rotateCamera cfig . setViewDistance cfig updateCamera cfig = setViewDistance cfig
. autoZoomCamera cfig . moveCamera . updateScopeZoom . moveCamera cfig
{- Updte the center of the screen camera center and where your avatar's view is from in world. -} . autoZoomCamera cfig . updateScopeZoom
moveCamera :: World -> World . rotateCamera cfig
moveCamera w = w
& cameraCenter .~ idealPos moveZoomCamera :: Configuration -> World -> World
& cameraViewFrom .~ sightFrom moveZoomCamera cfig w = w
& cameraCenter .~ newcen
& cameraViewFrom .~ newvf
& cameraZoom .~ newzoom
where 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 :: Configuration -> World -> World
moveCamera cfig w = w
& cameraCenter .~ idealPos
& cameraViewFrom .~ camCenter
where
camPos = _cameraViewFrom w
wallZoom = farWallDist camPos cfig w
basezoom = zoomNoItem wallZoom
aimRangeFactor aimRangeFactor
| _cameraZoom w == 0 = 0 | _cameraZoom w == 0 = 0
| otherwise = fromMaybe 0 (yourItem w ^? _Just . itUse . useAim . aimRange) / _cameraZoom w | 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 | SDL.ButtonRight `S.member` _mouseButtons w = 1
| otherwise = 0 | otherwise = 0
ypos = _crPos $ you w ypos = _crPos $ you w
idealPos = camCenter idealPos = camCenter +.+ aimoffset
+.+ rotateV (_cameraRot w) (aimRangeFactor * aimingMult *.* _mousePos w) aimoffset = rotateV (_cameraRot w) (0.5 * aimRangeFactor * aimingMult *.* _mousePos w)
camCenter = ypos +.+ scopeOffset camCenter = ypos +.+ scopeOffset
scopeOffset = fromMaybe (V2 0 0) $ yourItem w ^? _Just . itScope . scopePos scopeOffset = fromMaybe (V2 0 0) $ yourItem w ^? _Just . itScope . scopePos
sightFrom = case yourItem w ^? _Just . itScope . scopeIsCamera of sightFrom = case yourItem w ^? _Just . itScope . scopeIsCamera of