38 lines
1.7 KiB
Haskell
38 lines
1.7 KiB
Haskell
module Dodge.Base.Coordinate where
|
|
import Dodge.Data
|
|
import Dodge.Base.WinScale
|
|
|
|
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 -.- _cameraCenter w
|
|
doZoom p = _cameraZoom w *.* p
|
|
doRotate p = rotateV (negate $ _cameraRot 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.-}
|
|
worldPosToScreen :: World -> Point2 -> Point2
|
|
worldPosToScreen w
|
|
= rotateV (negate $ _cameraRot w)
|
|
. (_cameraZoom w *.*)
|
|
. (-.- _cameraCenter w)
|
|
{- | Transform coordinates from the map position to screen
|
|
coordinates. -}
|
|
cartePosToScreen :: Configuration -> World -> Point2 -> Point2
|
|
cartePosToScreen cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate
|
|
where
|
|
doTranslate p = p -.- _carteCenter (_hud w)
|
|
doZoom p = _carteZoom (_hud w) *.* p
|
|
doRotate p = rotateV (negate $ _carteRot (_hud 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 w +.+ (1/_cameraZoom w) *.* rotateV (_cameraRot w) (_mousePos w)
|
|
{- | The mouse position in map coordinates -}
|
|
mouseCartePos :: World -> Point2
|
|
mouseCartePos w = _carteCenter (_hud w) +.+ (1/_carteZoom (_hud w))
|
|
*.* rotateV (_carteRot (_hud w)) (_mousePos w)
|