This commit is contained in:
2022-02-21 22:42:19 +00:00
parent f626fce105
commit ff84363a13
11 changed files with 79 additions and 99 deletions
+20 -21
View File
@@ -32,7 +32,7 @@ updateCamera cfig = rotateCamera cfig . autoZoomCamera cfig . moveCamera . updat
{- Updte the center of the screen camera center and where your avatar's view is from in world. -}
moveCamera :: World -> World
moveCamera w = w
& cameraCenter .~ idealPos
& cameraCenter .~ idealPos
& cameraViewFrom .~ sightFrom
where
aimRangeFactor
@@ -45,17 +45,16 @@ moveCamera w = w
idealPos = camCenter
+.+ rotateV (_cameraRot w) (aimRangeFactor * aimingMult *.* _mousePos w)
camCenter = ypos +.+ scopeOffset
scopeOffset = fromMaybe (V2 0 0) $ yourItem w ^? _Just . itAttachment . scopePos
sightFrom
| fromMaybe False $ yourItem w ^? _Just . itAttachment . scopeIsCamera
= camCenter
| otherwise = ypos
scopeOffset = fromMaybe (V2 0 0) $ yourItem w ^? _Just . itScope . scopePos
sightFrom = case yourItem w ^? _Just . itScope . scopeIsCamera of
Just True -> camCenter
_ -> ypos
updateScopeZoom :: World -> World
updateScopeZoom w
| SDL.ButtonRight `S.member` _mouseButtons w
= case w ^? creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
. itAttachment . scopeZoomChange of
. itScope . scopeZoomChange of
Just x
| x > 9 -> zoomInLongGun $ zoomInLongGun w
| x > 0 -> zoomInLongGun w
@@ -64,9 +63,9 @@ updateScopeZoom w
| otherwise -> w
_ -> w
| otherwise = w & creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
. itAttachment %~ updateScope
. itScope %~ updateScope
where
updateScope (ItScope _ _ _ bl) = ItScope (V2 0 0) 0 1 bl
updateScope (ZoomScope _ _ _ bl) = ZoomScope (V2 0 0) 0 1 bl
updateScope otherAtt = otherAtt
zoomSpeed :: Float
@@ -74,38 +73,39 @@ zoomSpeed = 39/40
-- TODO unify zoom in and out, use scroll speed
zoomInLongGun :: World -> World
zoomInLongGun w
| currentZoom < 8 = over (wpPointer . itAttachment . scopePos)
| currentZoom < 8 = over (wpPointer . itScope . scopePos)
(\p -> p +.+ (4-(4*zoomSpeed)) / currentZoom *.* mousep)
$ over (wpPointer . itAttachment . scopeZoom) (/ zoomSpeed)
$ over (wpPointer . itScope . scopeZoom) (/ zoomSpeed)
$ decreaseScopeZoomChange
w
| otherwise = decreaseScopeZoomChange w
where
decreaseScopeZoomChange = wpPointer . itAttachment . scopeZoomChange -~ 1
decreaseScopeZoomChange = wpPointer . itScope . scopeZoomChange -~ 1
wpPointer = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
wp = _crInv (_creatures w IM.! 0) IM.! _crInvSel (_creatures w IM.! 0)
Just currentZoom = wp ^? itAttachment . scopeZoom
Just currentZoom = wp ^? itScope . scopeZoom
mousep = rotateV (_cameraRot w) $ _mousePos w
zoomOutLongGun :: World -> World
zoomOutLongGun w
| currentZoom > 0.5 = over (wpPointer . itAttachment . scopeZoom) (* zoomSpeed)
| currentZoom > 0.5 = over (wpPointer . itScope . scopeZoom) (* zoomSpeed)
$ increaseScopeZoomChange w
| otherwise = increaseScopeZoomChange w
where
increaseScopeZoomChange = wpPointer . itAttachment . scopeZoomChange +~ 1
increaseScopeZoomChange = wpPointer . itScope . scopeZoomChange +~ 1
wpPointer = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
wp = _crInv (_creatures w IM.! 0) IM.! _crInvSel (_creatures w IM.! 0)
Just currentZoom = wp ^? itAttachment . scopeZoom
Just currentZoom = wp ^? itScope . scopeZoom
ifConfigWallRotate :: Configuration -> World -> World
ifConfigWallRotate cfig w
| _rotate_to_wall cfig && not (SDL.ButtonRight `S.member` _mouseButtons w)
= rotateToOverlappingWall w
= rotateToOverlappingWall w
| otherwise = w
rotateToOverlappingWall :: World -> World
rotateToOverlappingWall w = maybe w dowallrotate theWall
rotateToOverlappingWall w = maybe w dowallrotate
$ overlapCircWallsReturnWall p (_crRad cr + 5) (IM.filter _wlRotateTo $ wallsNearPoint p w)
where
dowallrotate wl' = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl') - _cameraRot w
rotateUsing a
@@ -118,14 +118,13 @@ rotateToOverlappingWall w = maybe w dowallrotate theWall
b' = fromIntegral (round b :: Int)
cr = you w
p = _crPos cr
theWall = overlapCircWallsReturnWall p (_crRad cr + 5) (IM.filter _wlRotateTo $ wallsNearPoint p w)
rotateCameraBy :: Float -> World -> World
rotateCameraBy x w = w
& cameraRot +~ x
& creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
. itAttachment . scopePos %~ rotateV x
. itScope . scopePos %~ rotateV x
rotateCamera :: Configuration -> World -> World
rotateCamera cfig w
@@ -168,7 +167,7 @@ autoZoomCamera cfig w = w & cameraZoom %~ changeZoom
-- these speeds are inverted, larger means slower
zoomInSpeed = 25
zoomOutSpeed = 15
theScopeZoom = fromMaybe 1 $ yourItem w ^? _Just . itAttachment . scopeZoom
theScopeZoom = fromMaybe 1 $ yourItem w ^? _Just . itScope . scopeZoom
farWallDist :: Point2 -> Configuration -> World -> Float
farWallDist p cfig w = (winFac /) . min maxViewDistance $ ssfold (> maxViewDistance) findMax 1 vps