Camera position refactor

This commit is contained in:
2022-10-28 15:32:46 +01:00
parent 27fe1c7a96
commit 2e7cd0aec2
24 changed files with 184 additions and 163 deletions
+1 -1
View File
@@ -140,7 +140,7 @@ allVisibleWalls :: World -> [(Point2, Wall)]
{-# INLINE allVisibleWalls #-}
allVisibleWalls w = concatMap (flip (visibleWalls vPos) w . (+.+ vPos)) $ nRays 20
where
vPos = w ^. cWorld . lWorld . cwCam . cwcViewFrom
vPos = w ^. cWorld . lWorld . camPos . camViewFrom
--allVisibleWalls :: World -> StreamOf (Point2,Wall)
--{-# INLINE allVisibleWalls #-}
+7 -7
View File
@@ -23,11 +23,11 @@ import Control.Lens
-}
worldPosToScreen :: World -> Point2 -> Point2
worldPosToScreen w =
rotateV (negate $ cam ^. cwcRot)
. ((cam ^. cwcZoom) *.*)
. (-.- (cam ^. cwcCenter))
rotateV (negate $ cam ^. camRot)
. ((cam ^. camZoom) *.*)
. (-.- (cam ^. camCenter))
where
cam = w ^. cWorld . lWorld . cwCam
cam = w ^. cWorld . lWorld . camPos
{- | Transform coordinates from the map position to screen
coordinates.
@@ -46,10 +46,10 @@ cartePosToScreen cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate
-- | The mouse position in world coordinates.
mouseWorldPos :: World -> Point2
mouseWorldPos w =
(cam ^. cwcCenter)
+.+ (1 / (cam ^. cwcZoom)) *.* rotateV (cam ^. cwcRot) (_mousePos w)
(cam ^. camCenter)
+.+ (1 / (cam ^. camZoom)) *.* rotateV (cam ^. camRot) (_mousePos w)
where
cam = w ^. cWorld . lWorld . cwCam
cam = w ^. cWorld . lWorld . camPos
---- | The mouse position in map coordinates
--mouseCartePos :: World -> Point2
+9 -8
View File
@@ -7,19 +7,20 @@ module Dodge.Base.Window (
screenBox,
) where
import Dodge.Data.Universe
import Dodge.Data.CamPos
import Dodge.Data.Config
import Geometry
import Control.Lens
-- | A box covering the screen in world coordinates
screenPolygon :: Configuration -> World -> [Point2]
screenPolygon :: Configuration -> CamPos -> [Point2]
screenPolygon cfig w = map (scTran . scRot . scZoom) $ screenBox cfig
where
scRot = rotateV (w ^. cWorld . lWorld . cwCam . cwcRot)
scRot = rotateV (w ^. camRot)
scZoom p
| (w ^. cWorld . lWorld . cwCam . cwcZoom) /= 0 = (1 / (w ^. cWorld . lWorld . cwCam . cwcZoom)) *.* p
| (w ^. camZoom) /= 0 = (1 / (w ^. camZoom)) *.* p
| otherwise = p
scTran p = p +.+ (w ^. cWorld . lWorld . cwCam . cwcCenter)
scTran p = p +.+ (w ^. camCenter)
-- | A box covering the screen in world coordinates, with a x and y border
screenPolygonBord ::
@@ -28,16 +29,16 @@ screenPolygonBord ::
-- | Y border
Float ->
Configuration ->
World ->
CamPos ->
[Point2]
screenPolygonBord xbord ybord cfig w = [tr, tl, bl, br]
where
hw = halfWidth cfig - xbord
hh = halfHeight cfig - ybord
scZoom p
| (w ^. cWorld . lWorld . cwCam . cwcZoom) /= 0 = (1 / (w ^. cWorld . lWorld . cwCam . cwcZoom)) *.* p
| (w ^. camZoom) /= 0 = (1 / (w ^. camZoom)) *.* p
| otherwise = p
theTransform = (+.+ (w ^. cWorld . lWorld . cwCam . cwcCenter)) . rotateV (w ^. cWorld . lWorld . cwCam . cwcRot) . scZoom
theTransform = (+.+ (w ^. camCenter)) . rotateV (w ^. camRot) . scZoom
tr = theTransform (V2 hw hh)
tl = theTransform (V2 (- hw) hh)
br = theTransform (V2 hw (- hh))