Camera position refactor
This commit is contained in:
+17
-17
@@ -41,11 +41,11 @@ updateCamera uv =
|
||||
moveZoomCamera :: Universe -> Universe
|
||||
moveZoomCamera uv =
|
||||
uv
|
||||
& uvWorld . cWorld . lWorld . cwCam . cwcCenter .~ newcen
|
||||
& uvWorld . cWorld . lWorld . cwCam . cwcViewFrom .~ newvf
|
||||
& uvWorld . cWorld . lWorld . cwCam . cwcZoom .~ newzoom
|
||||
& uvWorld . cWorld . lWorld . cwCam . cwcDefaultZoom .~ newDefaultZoom
|
||||
& uvWorld . cWorld . lWorld . cwCam . cwcItemZoom .~ newItemZoom
|
||||
& uvWorld . cWorld . lWorld . camPos . camCenter .~ newcen
|
||||
& uvWorld . cWorld . lWorld . camPos . camViewFrom .~ newvf
|
||||
& uvWorld . cWorld . lWorld . camPos . camZoom .~ newzoom
|
||||
& uvWorld . cWorld . lWorld . camPos . camDefaultZoom .~ newDefaultZoom
|
||||
& uvWorld . cWorld . lWorld . camPos . camItemZoom .~ newItemZoom
|
||||
where
|
||||
cfig = _uvConfig uv
|
||||
w = _uvWorld uv
|
||||
@@ -60,23 +60,23 @@ moveZoomCamera uv =
|
||||
guard (SDL.ButtonRight `M.member` _mouseButtons w)
|
||||
yourItem w ^? _Just . itScope . scopePos
|
||||
newcen = cpos +.+ fromMaybe (V2 0 0) mscopeoffset +.+ offset
|
||||
offset = rotateV (w ^. cWorld . lWorld . cwCam . cwcRot) $ ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos w
|
||||
offset = rotateV (w ^. cWorld . lWorld . camPos . camRot) $ ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos w
|
||||
newzoom = case yourItem w ^? _Just . itScope of
|
||||
Just zs@ZoomScope{} -> _scopeZoom zs
|
||||
_ -> newDefaultZoom * newItemZoom
|
||||
idealDefaultZoom = clipZoom wallZoom
|
||||
newDefaultZoom = case yourItem w ^? _Just . itScope of
|
||||
Just zs@ZoomScope{} -> _scopeZoom zs
|
||||
_ -> changeZoom (w ^. cWorld . lWorld . cwCam . cwcDefaultZoom) idealDefaultZoom
|
||||
_ -> changeZoom (w ^. cWorld . lWorld . camPos . camDefaultZoom) idealDefaultZoom
|
||||
idealItemZoom = fromMaybe 1 $ do
|
||||
guard $ crIsAiming (you w)
|
||||
zoomFromItem' <$> (yourItem w ^? _Just . itUse . heldAim . aimZoom)
|
||||
newItemZoom = changeZoom (w ^. cWorld . lWorld . cwCam . cwcItemZoom) idealItemZoom
|
||||
newItemZoom = changeZoom (w ^. cWorld . lWorld . camPos . camItemZoom) idealItemZoom
|
||||
changeZoom curZoom idealZoom
|
||||
| curZoom > idealZoom + 0.01 = ((zoomOutSpeed -1) * curZoom + idealZoom) / zoomOutSpeed
|
||||
| curZoom < idealZoom - 0.01 = ((zoomInSpeed -1) * curZoom + idealZoom) / zoomInSpeed
|
||||
| otherwise = idealZoom
|
||||
wallZoom = min4 (w ^. cWorld . lWorld . cwCam . cwcBoundDist)
|
||||
wallZoom = min4 (w ^. cWorld . lWorld . camPos . camBoundDist)
|
||||
min4 (a, b, c, d) = minimum [hh / maxd a, hh / maxd (- b), hw / maxd c, hw / maxd (- d)]
|
||||
maxd = max distFromEqmnt
|
||||
distFromEqmnt = foldl' max 1 $ IM.mapMaybe (_eeViewDist . _equipEffect . _itUse) $ getCrEquipment $ you w
|
||||
@@ -131,7 +131,7 @@ zoomInLongGun w
|
||||
ycr = you w
|
||||
Just currentZoom = wp ^? itScope . scopeZoom
|
||||
newzoom = (wp ^?! itScope . scopeZoom) / zoomSpeed
|
||||
mousep = rotateV (w ^. cWorld . lWorld . cwCam . cwcRot) $ _mousePos w
|
||||
mousep = rotateV (w ^. cWorld . lWorld . camPos . camRot) $ _mousePos w
|
||||
|
||||
zoomOutLongGun :: World -> World
|
||||
zoomOutLongGun w
|
||||
@@ -168,11 +168,11 @@ rotateToOverlappingWall w =
|
||||
p = _crPos (you w)
|
||||
|
||||
doWallRotate :: Wall -> World -> World
|
||||
doWallRotate wl' w = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl') - (w ^. cWorld . lWorld . cwCam . cwcRot)
|
||||
doWallRotate wl' w = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl') - (w ^. cWorld . lWorld . camPos . camRot)
|
||||
where
|
||||
rotateUsing a
|
||||
| b - b' > 0.01 = w & cWorld . lWorld . cwCam . cwcRot +~ 0.01
|
||||
| b - b' < negate 0.01 = w & cWorld . lWorld . cwCam . cwcRot -~ 0.01
|
||||
| b - b' > 0.01 = w & cWorld . lWorld . camPos . camRot +~ 0.01
|
||||
| b - b' < negate 0.01 = w & cWorld . lWorld . camPos . camRot -~ 0.01
|
||||
| otherwise = w
|
||||
where
|
||||
--b = a * (2 / pi)
|
||||
@@ -182,7 +182,7 @@ doWallRotate wl' w = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl') - (w ^.
|
||||
rotateCameraBy :: Float -> World -> World
|
||||
rotateCameraBy x w =
|
||||
w
|
||||
& cWorld . lWorld . cwCam . cwcRot +~ x
|
||||
& cWorld . lWorld . camPos . camRot +~ x
|
||||
& cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (_creatures (_lWorld (_cWorld w)) IM.! 0))
|
||||
. itScope
|
||||
. scopePos
|
||||
@@ -218,8 +218,8 @@ clipZoom = min 20 . max 0.2
|
||||
|
||||
setViewDistance :: Configuration -> World -> World
|
||||
setViewDistance cfig w =
|
||||
w & cWorld . lWorld . cwCam . cwcViewDistance
|
||||
.~ sqrt (halfWidth cfig ** 2 + halfHeight cfig ** 2) / (w ^. cWorld . lWorld . cwCam . cwcZoom)
|
||||
w & cWorld . lWorld . camPos . camViewDistance
|
||||
.~ sqrt (halfWidth cfig ** 2 + halfHeight cfig ** 2) / (w ^. cWorld . lWorld . camPos . camZoom)
|
||||
|
||||
getViewpoints :: Point2 -> World -> [Point2]
|
||||
{-# INLINE getViewpoints #-}
|
||||
@@ -241,7 +241,7 @@ farWallDistDirection p w =
|
||||
boundPoints $
|
||||
map f $ getViewpoints p w
|
||||
where
|
||||
f q = (rotateV (negate (w ^. cWorld . lWorld . cwCam . cwcRot)) . (-.- p)) (foldl' findPoint q (wls q))
|
||||
f q = (rotateV (negate (w ^. cWorld . lWorld . camPos . camRot)) . (-.- p)) (foldl' findPoint q (wls q))
|
||||
wls q = filter wlIsOpaque $ wlsNearSeg p q w
|
||||
findPoint q = fromMaybe q . uncurry (intersectSegSeg p q) . _wlLine
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ updateWheelEvent yi w = case w ^. cWorld . lWorld . hud . hudElement of
|
||||
(_, EquipOptions{}) -> scrollRBOption y w
|
||||
(Nothing, _) -> closeObjScrollDir y w
|
||||
(Just f, _) -> doHeldScroll f y (you w) w
|
||||
| lbDown -> w & cWorld . lWorld . cwCam . cwcZoom +~ y
|
||||
| lbDown -> w & cWorld . lWorld . camPos . camZoom +~ y
|
||||
| invKeyDown -> changeSwapInvSel yi w
|
||||
| otherwise -> stopSoundFrom (CrReloadSound 0) $ changeAugInvSel yi w
|
||||
DisplayInventory (TweakInventory mi)
|
||||
|
||||
@@ -60,7 +60,7 @@ pressedMBEffectsNoInventory pkeys w
|
||||
w & hammers . ix DoubleMouseHam .~ HammerDown
|
||||
| isDown ButtonRight && inTopInv = w
|
||||
| isDown ButtonMiddle =
|
||||
w & cWorld . lWorld . cwCam . cwcRot -~ rotation
|
||||
w & cWorld . lWorld . camPos . camRot -~ rotation
|
||||
& clickMousePos .~ _mousePos w
|
||||
| isDown ButtonLeft = w & hammers . ix DoubleMouseHam .~ HammerDown
|
||||
| otherwise = w
|
||||
|
||||
Reference in New Issue
Block a user