This commit is contained in:
2022-04-10 10:17:03 +01:00
parent 901fab762a
commit 2da4098d41
3 changed files with 64 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
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 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 = doRotate . doZoom . doTranslate
where
doTranslate p = p -.- _cameraCenter w
doZoom p = _cameraZoom w *.* p
doRotate p = rotateV (negate $ _cameraRot w) p
{- | 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)
+11
View File
@@ -0,0 +1,11 @@
module Dodge.Base.WinScale where
import Dodge.Config.Data
import Geometry
import Picture
winScale :: Configuration -> Picture -> Picture
{-# INLINE winScale #-}
winScale cfig = scale (2 / _windowX cfig) (2 / _windowY cfig)
doWindowScale :: Configuration -> Point2 -> Point2
doWindowScale cfig (V2 x y) = V2 ( x * 2 / _windowX cfig) ( y * 2 / _windowY cfig)
+15
View File
@@ -0,0 +1,15 @@
module Dodge.Render.InfoBox where
import Dodge.Data
--import Dodge.Base.Window
--import Dodge.Base.WinScale
import Dodge.Render.Connectors
import Dodge.Render.List
import Dodge.Base.Coordinate
import Picture
import Geometry
--import Control.Monad
--import Data.Maybe
renderInfoListAt :: Float -> Float -> Configuration -> World -> (Point2,[String]) -> Picture
renderInfoListAt x y cfig w (p,ss) = renderListAt x y cfig (zip ss (repeat white))
<> zConnect (V2 x y) (worldPosToScreenNorm cfig w p)