Cleanup
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
module Dodge.Base.Coordinate where
|
||||
module Dodge.Base.Coordinate
|
||||
( mouseWorldPos
|
||||
, cartePosToScreen
|
||||
, worldPosToScreen
|
||||
) where
|
||||
|
||||
import Dodge.Base.WinScale
|
||||
import Dodge.Data.Universe
|
||||
import Geometry
|
||||
import Control.Lens
|
||||
|
||||
-- | 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 -.- (w ^. cWorld . lWorld . cwCam . cwcCenter)
|
||||
doZoom p = (w ^. cWorld . lWorld . cwCam . cwcZoom) *.* p
|
||||
doRotate p = rotateV (negate (w ^. cWorld . lWorld . cwCam . cwcRot)) p
|
||||
---- | 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 -.- (w ^. cWorld . lWorld . cwCam . cwcCenter)
|
||||
-- doZoom p = (w ^. cWorld . lWorld . cwCam . cwcZoom) *.* p
|
||||
-- doRotate p = rotateV (negate (w ^. cWorld . lWorld . cwCam . cwcRot)) 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.
|
||||
@@ -19,9 +23,11 @@ worldPosToScreenNorm cfig w = doWindowScale cfig . doRotate . doZoom . doTransla
|
||||
-}
|
||||
worldPosToScreen :: World -> Point2 -> Point2
|
||||
worldPosToScreen w =
|
||||
rotateV (negate $ w ^. cWorld . lWorld . cwCam . cwcRot)
|
||||
. ((w ^. cWorld . lWorld . cwCam . cwcZoom) *.*)
|
||||
. (-.- (w ^. cWorld . lWorld . cwCam . cwcCenter))
|
||||
rotateV (negate $ cam ^. cwcRot)
|
||||
. ((cam ^. cwcZoom) *.*)
|
||||
. (-.- (cam ^. cwcCenter))
|
||||
where
|
||||
cam = w ^. cWorld . lWorld . cwCam
|
||||
|
||||
{- | Transform coordinates from the map position to screen
|
||||
coordinates.
|
||||
@@ -29,26 +35,27 @@ coordinates.
|
||||
cartePosToScreen :: Configuration -> World -> Point2 -> Point2
|
||||
cartePosToScreen cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate
|
||||
where
|
||||
doTranslate p = p -.- (w ^. cWorld . lWorld . hud . carteCenter) -- _carteCenter (_hud (_cWorld w))
|
||||
--doZoom p = _carteZoom (_hud (_cWorld w)) *.* p
|
||||
doZoom p = (w ^. cWorld . lWorld . hud . carteZoom) *.* p
|
||||
--doRotate p = rotateV (negate $ _carteRot (_hud (_cWorld w))) p
|
||||
doRotate p = rotateV (negate $ w ^. cWorld . lWorld . hud . carteRot) p
|
||||
thehud = w ^. cWorld . lWorld . hud
|
||||
doTranslate p = p -.- (thehud ^. carteCenter) -- _carteCenter (_hud (_cWorld w))
|
||||
doZoom p = (thehud ^. carteZoom) *.* p
|
||||
doRotate p = rotateV (negate $ thehud ^. carteRot) p
|
||||
|
||||
crToMousePosOffset :: Creature -> World -> (Point2, Float)
|
||||
crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr, 0)
|
||||
--crToMousePosOffset :: Creature -> World -> (Point2, Float)
|
||||
--crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr, 0)
|
||||
|
||||
-- | The mouse position in world coordinates.
|
||||
mouseWorldPos :: World -> Point2
|
||||
mouseWorldPos w =
|
||||
(w ^. cWorld . lWorld . cwCam . cwcCenter)
|
||||
+.+ (1 / (w ^. cWorld . lWorld . cwCam . cwcZoom)) *.* rotateV (w ^. cWorld . lWorld . cwCam . cwcRot) (_mousePos w)
|
||||
(cam ^. cwcCenter)
|
||||
+.+ (1 / (cam ^. cwcZoom)) *.* rotateV (cam ^. cwcRot) (_mousePos w)
|
||||
where
|
||||
cam = w ^. cWorld . lWorld . cwCam
|
||||
|
||||
-- | The mouse position in map coordinates
|
||||
mouseCartePos :: World -> Point2
|
||||
mouseCartePos w = (w ^. cWorld . lWorld . hud . carteCenter)
|
||||
+.+
|
||||
(1 / (w ^. cWorld . lWorld . hud . carteZoom))
|
||||
*.* rotateV (w ^. cWorld . lWorld . hud . carteRot) (_mousePos w)
|
||||
-- _carteCenter (_hud (_cWorld w))
|
||||
-- +.+ (1 / _carteZoom (_hud (_cWorld w))) *.* rotateV (_carteRot (_hud (_cWorld w))) (_mousePos w)
|
||||
---- | The mouse position in map coordinates
|
||||
--mouseCartePos :: World -> Point2
|
||||
--mouseCartePos w = (thehud ^. carteCenter)
|
||||
-- +.+
|
||||
-- (1 / (thehud ^. carteZoom))
|
||||
-- *.* rotateV (thehud ^. carteRot) (_mousePos w)
|
||||
-- where
|
||||
-- thehud = w ^. cWorld . lWorld . hud
|
||||
|
||||
Reference in New Issue
Block a user