Move pair to V2

This commit is contained in:
2025-11-14 02:13:03 +00:00
parent 292a1c3f42
commit bfd7aa619e
6 changed files with 27 additions and 27 deletions
+7 -7
View File
@@ -5,13 +5,13 @@ module Dodge.Base.Coordinate (
worldPosToResOffset,
) where
import Dodge.WindowSize
import Linear
import Dodge.Data.Config
import Control.Lens
import Dodge.Data.Camera
import Dodge.Data.Config
import Dodge.Data.Input
import Dodge.WindowSize
import Geometry
import Linear
{- | Transform world coordinates to scaled screen coordinates.
- These have to be scaled according to the size of the window to get actual screen positions.
@@ -25,14 +25,14 @@ worldPosToScreen cam =
. ((cam ^. camZoom) *^)
. (-.- (cam ^. camCenter))
-- gets the position from the bottom left in "world res" "pixels"
-- gets the position from the bottom left in world-resolution "pixels"
worldPosToResOffset :: Config -> Camera -> Point2 -> Point2
worldPosToResOffset cfig cam p = (worldPosToScreen cam p & each %~ f)
+ 0.5 *^ (uncurry V2 (getWindowSize _gr_world_res cfig::(Int,Int)) & each %~ fromIntegral)
worldPosToResOffset cfig cam p =
(worldPosToScreen cam p & each %~ f)
+ 0.5 *^ ((getWindowSize _gr_world_res cfig :: V2 Int) & each %~ fromIntegral)
where
f x = applyResFactorF (cfig ^. gr_world_res) x
-- | The mouse position in world coordinates.
mouseWorldPos :: Input -> Camera -> Point2
mouseWorldPos inp cam = screenToWorldPos cam (inp ^. mousePos)
+1 -1
View File
@@ -417,4 +417,4 @@ getDistortions cfig w
| otherwise = []
setViewport :: (Config -> ResFactor) -> Config -> IO ()
setViewport f = uncurry (glViewport 0 0) . getWindowSize f
setViewport f = uncurryV (glViewport 0 0) . getWindowSize f
+3 -2
View File
@@ -1,8 +1,9 @@
module Dodge.WindowSize (getWindowSize) where
import Dodge.Data.Config
import Linear
getWindowSize :: Integral a => (Config -> ResFactor) -> Config -> (a,a)
getWindowSize f cfig = (g _windowX, g _windowY)
getWindowSize :: Integral a => (Config -> ResFactor) -> Config -> V2 a
getWindowSize f cfig = V2 (g _windowX) (g _windowY)
where
g h = fromIntegral $ applyResFactor (f cfig) (h cfig)