58 lines
2.0 KiB
Haskell
58 lines
2.0 KiB
Haskell
module Dodge.Base.Coordinate (
|
|
mouseWorldPos,
|
|
cartePosToScreen,
|
|
worldPosToScreen,
|
|
) where
|
|
|
|
import Control.Lens
|
|
import Dodge.Data.CamPos
|
|
import Dodge.Data.HUD
|
|
import Dodge.Data.Input
|
|
import Geometry
|
|
|
|
---- | 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.
|
|
- This allows for line thicknesses etc to correspond to pixel sizes.
|
|
-}
|
|
worldPosToScreen :: CamPos -> Point2 -> Point2
|
|
worldPosToScreen cam =
|
|
rotateV (negate $ cam ^. camRot)
|
|
. ((cam ^. camZoom) *.*)
|
|
. (-.- (cam ^. camCenter))
|
|
|
|
{- | Transform coordinates from the map position to screen
|
|
coordinates.
|
|
-}
|
|
cartePosToScreen :: HUD -> Point2 -> Point2
|
|
cartePosToScreen thehud = doRotate . doZoom . doTranslate
|
|
where
|
|
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)
|
|
|
|
-- | The mouse position in world coordinates.
|
|
mouseWorldPos :: Input -> CamPos -> Point2
|
|
mouseWorldPos inp cam =
|
|
(cam ^. camCenter)
|
|
+.+ (1 / (cam ^. camZoom)) *.* rotateV (cam ^. camRot) (_mousePos inp)
|
|
|
|
---- | 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
|