Refactor, try to limit dependencies

This commit is contained in:
2022-07-28 00:59:56 +01:00
parent 8aa5c17ab9
commit 160560af5f
418 changed files with 15105 additions and 13343 deletions
+33 -23
View File
@@ -1,38 +1,48 @@
module Dodge.Base.Coordinate where
import Dodge.Data
import Dodge.Base.WinScale
import Dodge.Base.WinScale
import Dodge.Data.Universe
import Geometry
{- | Transform coordinates from world position to screen coordinates. -}
-- | Transform coordinates from world position to screen coordinates.
worldPosToScreenNorm :: Configuration -> World -> Point2 -> Point2
worldPosToScreenNorm cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate
where
doTranslate p = p -.- _cameraCenter (_cWorld w)
doZoom p = _cameraZoom (_cWorld w) *.* p
doRotate p = rotateV (negate $ _cameraRot (_cWorld w)) p
{- | Transform world coordinates to scaled screen coordinates.
doZoom p = _cameraZoom (_cWorld w) *.* p
doRotate p = rotateV (negate $ _cameraRot (_cWorld w)) p
{- | Transform world coordinates to scaled screen coordinates.
- These have to be scaled according to the size of the window to get actual screen positions.
- This allows for line thicknesses etc to correspond to pixel sizes.-}
- This allows for line thicknesses etc to correspond to pixel sizes.
-}
worldPosToScreen :: World -> Point2 -> Point2
worldPosToScreen w
= rotateV (negate $ _cameraRot (_cWorld w))
. (_cameraZoom (_cWorld w) *.*)
. (-.- _cameraCenter (_cWorld w))
worldPosToScreen w =
rotateV (negate $ _cameraRot (_cWorld w))
. (_cameraZoom (_cWorld w) *.*)
. (-.- _cameraCenter (_cWorld w))
{- | Transform coordinates from the map position to screen
coordinates. -}
coordinates.
-}
cartePosToScreen :: Configuration -> World -> Point2 -> Point2
cartePosToScreen cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate
where
doTranslate p = p -.- _carteCenter (_hud (_cWorld w))
doZoom p = _carteZoom (_hud (_cWorld w)) *.* p
doRotate p = rotateV (negate $ _carteRot (_hud (_cWorld w))) p
crToMousePosOffset :: Creature -> World -> (Point2,Float)
crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr,0)
{- | The mouse position in world coordinates. -}
doTranslate p = p -.- _carteCenter (_hud (_cWorld w))
doZoom p = _carteZoom (_hud (_cWorld w)) *.* p
doRotate p = rotateV (negate $ _carteRot (_hud (_cWorld w))) p
crToMousePosOffset :: Creature -> World -> (Point2, Float)
crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr, 0)
-- | The mouse position in world coordinates.
mouseWorldPos :: World -> Point2
mouseWorldPos w = _cameraCenter (_cWorld w) +.+
(1/_cameraZoom (_cWorld w)) *.* rotateV (_cameraRot (_cWorld w)) (_mousePos w)
{- | The mouse position in map coordinates -}
mouseWorldPos w =
_cameraCenter (_cWorld w)
+.+ (1 / _cameraZoom (_cWorld w)) *.* rotateV (_cameraRot (_cWorld w)) (_mousePos w)
-- | The mouse position in map coordinates
mouseCartePos :: World -> Point2
mouseCartePos w = _carteCenter (_hud (_cWorld w)) +.+
(1/_carteZoom (_hud (_cWorld w))) *.* rotateV (_carteRot (_hud (_cWorld w))) (_mousePos w)
mouseCartePos w =
_carteCenter (_hud (_cWorld w))
+.+ (1 / _carteZoom (_hud (_cWorld w))) *.* rotateV (_carteRot (_hud (_cWorld w))) (_mousePos w)