This commit is contained in:
2022-10-28 15:04:39 +01:00
parent 68c2a78f43
commit 27fe1c7a96
+35 -28
View File
@@ -1,17 +1,21 @@
module Dodge.Base.Coordinate where module Dodge.Base.Coordinate
( mouseWorldPos
, cartePosToScreen
, worldPosToScreen
) where
import Dodge.Base.WinScale import Dodge.Base.WinScale
import Dodge.Data.Universe import Dodge.Data.Universe
import Geometry import Geometry
import Control.Lens import Control.Lens
-- | Transform coordinates from world position to screen coordinates. ---- | Transform coordinates from world position to screen coordinates.
worldPosToScreenNorm :: Configuration -> World -> Point2 -> Point2 --worldPosToScreenNorm :: Configuration -> World -> Point2 -> Point2
worldPosToScreenNorm cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate --worldPosToScreenNorm cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate
where -- where
doTranslate p = p -.- (w ^. cWorld . lWorld . cwCam . cwcCenter) -- doTranslate p = p -.- (w ^. cWorld . lWorld . cwCam . cwcCenter)
doZoom p = (w ^. cWorld . lWorld . cwCam . cwcZoom) *.* p -- doZoom p = (w ^. cWorld . lWorld . cwCam . cwcZoom) *.* p
doRotate p = rotateV (negate (w ^. cWorld . lWorld . cwCam . cwcRot)) p -- doRotate p = rotateV (negate (w ^. cWorld . lWorld . cwCam . cwcRot)) p
{- | Transform world coordinates to scaled screen coordinates. {- | Transform world coordinates to scaled screen coordinates.
- These have to be scaled according to the size of the window to get actual screen positions. - These have to be scaled according to the size of the window to get actual screen positions.
@@ -19,9 +23,11 @@ worldPosToScreenNorm cfig w = doWindowScale cfig . doRotate . doZoom . doTransla
-} -}
worldPosToScreen :: World -> Point2 -> Point2 worldPosToScreen :: World -> Point2 -> Point2
worldPosToScreen w = worldPosToScreen w =
rotateV (negate $ w ^. cWorld . lWorld . cwCam . cwcRot) rotateV (negate $ cam ^. cwcRot)
. ((w ^. cWorld . lWorld . cwCam . cwcZoom) *.*) . ((cam ^. cwcZoom) *.*)
. (-.- (w ^. cWorld . lWorld . cwCam . cwcCenter)) . (-.- (cam ^. cwcCenter))
where
cam = w ^. cWorld . lWorld . cwCam
{- | Transform coordinates from the map position to screen {- | Transform coordinates from the map position to screen
coordinates. coordinates.
@@ -29,26 +35,27 @@ coordinates.
cartePosToScreen :: Configuration -> World -> Point2 -> Point2 cartePosToScreen :: Configuration -> World -> Point2 -> Point2
cartePosToScreen cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate cartePosToScreen cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate
where where
doTranslate p = p -.- (w ^. cWorld . lWorld . hud . carteCenter) -- _carteCenter (_hud (_cWorld w)) thehud = w ^. cWorld . lWorld . hud
--doZoom p = _carteZoom (_hud (_cWorld w)) *.* p doTranslate p = p -.- (thehud ^. carteCenter) -- _carteCenter (_hud (_cWorld w))
doZoom p = (w ^. cWorld . lWorld . hud . carteZoom) *.* p doZoom p = (thehud ^. carteZoom) *.* p
--doRotate p = rotateV (negate $ _carteRot (_hud (_cWorld w))) p doRotate p = rotateV (negate $ thehud ^. carteRot) p
doRotate p = rotateV (negate $ w ^. cWorld . lWorld . hud . carteRot) p
crToMousePosOffset :: Creature -> World -> (Point2, Float) --crToMousePosOffset :: Creature -> World -> (Point2, Float)
crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr, 0) --crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr, 0)
-- | The mouse position in world coordinates. -- | The mouse position in world coordinates.
mouseWorldPos :: World -> Point2 mouseWorldPos :: World -> Point2
mouseWorldPos w = mouseWorldPos w =
(w ^. cWorld . lWorld . cwCam . cwcCenter) (cam ^. cwcCenter)
+.+ (1 / (w ^. cWorld . lWorld . cwCam . cwcZoom)) *.* rotateV (w ^. cWorld . lWorld . cwCam . cwcRot) (_mousePos w) +.+ (1 / (cam ^. cwcZoom)) *.* rotateV (cam ^. cwcRot) (_mousePos w)
where
cam = w ^. cWorld . lWorld . cwCam
-- | The mouse position in map coordinates ---- | The mouse position in map coordinates
mouseCartePos :: World -> Point2 --mouseCartePos :: World -> Point2
mouseCartePos w = (w ^. cWorld . lWorld . hud . carteCenter) --mouseCartePos w = (thehud ^. carteCenter)
+.+ -- +.+
(1 / (w ^. cWorld . lWorld . hud . carteZoom)) -- (1 / (thehud ^. carteZoom))
*.* rotateV (w ^. cWorld . lWorld . hud . carteRot) (_mousePos w) -- *.* rotateV (thehud ^. carteRot) (_mousePos w)
-- _carteCenter (_hud (_cWorld w)) -- where
-- +.+ (1 / _carteZoom (_hud (_cWorld w))) *.* rotateV (_carteRot (_hud (_cWorld w))) (_mousePos w) -- thehud = w ^. cWorld . lWorld . hud