Cleanup scope zooming

This commit is contained in:
2023-01-07 10:43:53 +00:00
parent 87ea7da1d4
commit 6b259fa200
8 changed files with 54 additions and 74 deletions
+34 -42
View File
@@ -54,7 +54,8 @@ moveZoomCamera cfig theinput cr campos =
guard (SDL.ButtonRight `M.member` _mouseButtons theinput)
mitm ^? _Just . itScope . scopePos
newcen = cpos +.+ fromMaybe (V2 0 0) mscopeoffset +.+ offset
offset = rotateV (campos ^. camRot) $ ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos theinput
offset = rotateV (campos ^. camRot)
$ ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos theinput
newzoom = case mitm ^? _Just . itScope of
Just zs@ZoomScope{} -> _scopeZoom zs
_ -> newDefaultZoom * newItemZoom
@@ -83,65 +84,56 @@ moveZoomCamera cfig theinput cr campos =
updateScopeZoom :: World -> World
updateScopeZoom w
| SDL.ButtonRight `M.member` _mouseButtons (_input w) =
case w
^? cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (w ^?! cWorld . lWorld . creatures . ix 0))
. itScope
. scopeZoomChange of
Just x
| x > 10 -> zoomInLongGun $ zoomInLongGun $ zoomInLongGun w
| x > 5 -> zoomInLongGun $ zoomInLongGun w
| x > 0 -> zoomInLongGun w
| x < -10 -> zoomOutLongGun $ zoomOutLongGun $ zoomOutLongGun w
| x < -5 -> zoomOutLongGun $ zoomOutLongGun w
| x < 0 -> zoomOutLongGun w
| otherwise -> w
_ -> w
| SDL.ButtonRight `M.member` _mouseButtons (_input w) = over wppointer (doScopeZoom mp) w
| otherwise =
w
& cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (w ^?! cWorld . lWorld . creatures . ix 0))
. itScope
%~ updateScope
where
wppointer = cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (w ^?! cWorld . lWorld . creatures . ix 0)) . itScope
updateScope (ZoomScope _ _ _ defz bl) = ZoomScope (V2 0 0) 0 defz defz bl
updateScope otherAtt = otherAtt
mp = rotateV (w ^. cWorld . camPos . camRot) $ _mousePos (_input w)
doScopeZoom :: Point2 -> Scope -> Scope
doScopeZoom mp sc = case sc ^? scopeZoomChange of
Just x
| x > 10 -> (zoomInLongGun mp . zoomInLongGun mp . zoomInLongGun mp) sc
| x > 5 -> (zoomInLongGun mp . zoomInLongGun mp) sc
| x > 0 -> (zoomInLongGun mp) sc
| x < -10 -> (zoomOutLongGun . zoomOutLongGun . zoomOutLongGun) sc
| x < -5 -> (zoomOutLongGun . zoomOutLongGun) sc
| x < 0 -> zoomOutLongGun sc
| otherwise -> sc
_ -> sc
zoomSpeed :: Float
zoomSpeed = 39 / 40
zoomInLongGun :: World -> World
zoomInLongGun w
zoomInLongGun :: Point2 -> Scope -> Scope
zoomInLongGun mousep sc
| currentZoom < 8 =
w
& wpPointer . itScope . scopePos .+.+~ (1 - zoomSpeed) / newzoom *.* mousep
& wpPointer . itScope . scopeZoom %~ (/ zoomSpeed)
sc
& scopePos .+.+~ (1 - zoomSpeed) / newzoom *.* mousep
& scopeZoom %~ (/ zoomSpeed)
& decreaseScopeZoomChange
| otherwise = w & wpPointer . itScope . scopeZoomChange .~ 0
| otherwise = sc & scopeZoomChange .~ 0
where
decreaseScopeZoomChange = wpPointer . itScope . scopeZoomChange -~ 1
wpPointer = cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (w ^?! cWorld . lWorld . creatures . ix 0))
wp = ycr ^?! crInv . ix (crSel ycr)
ycr = you w
Just currentZoom = wp ^? itScope . scopeZoom
newzoom = (wp ^?! itScope . scopeZoom) / zoomSpeed
mousep = rotateV (w ^. cWorld . camPos . camRot) $ _mousePos (_input w)
decreaseScopeZoomChange = scopeZoomChange -~ 1
Just currentZoom = sc ^? scopeZoom
newzoom = (sc ^?! scopeZoom) / zoomSpeed
zoomOutLongGun :: World -> World
zoomOutLongGun w
zoomOutLongGun :: Scope -> Scope
zoomOutLongGun sc
| currentZoom > 0.5 =
w
-- & wpPointer . itScope . scopePos .+.+~ ((1*zoomSpeed-1)) / currentZoom *.* mousep
& wpPointer . itScope . scopeZoom *~ zoomSpeed
& increaseScopeZoomChange
-- | otherwise = increaseScopeZoomChange w
| otherwise = w & wpPointer . itScope . scopeZoomChange .~ 0
sc
-- & scopePos .+.+~ ((1*zoomSpeed-1)) / currentZoom *.* mousep
& scopeZoom *~ zoomSpeed
& scopeZoomChange +~ 1
| otherwise = sc & scopeZoomChange .~ 0
where
--mousep = rotateV (_cameraRot w) $ _mousePos w
increaseScopeZoomChange = wpPointer . itScope . scopeZoomChange +~ 1
wpPointer = cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (_creatures (_lWorld (_cWorld w)) IM.! 0))
wp = ycr ^?! crInv . ix (crSel ycr)
ycr = you w
Just currentZoom = wp ^? itScope . scopeZoom
Just currentZoom = sc ^? scopeZoom
ifConfigWallRotate :: Configuration -> World -> World
ifConfigWallRotate cfig w