Add support for clamping pictures to be inside screen

This commit is contained in:
2021-09-10 11:38:24 +01:00
parent 70c97f5367
commit 87a9745d37
4 changed files with 55 additions and 9 deletions
+28
View File
@@ -5,6 +5,7 @@ import Dodge.Data
import Dodge.Config.Data
import Geometry
-- | A box covering the screen in world coordinates
screenPolygon :: World -> [Point2]
screenPolygon w = [tr,tl,bl,br]
where
@@ -17,9 +18,36 @@ screenPolygon w = [tr,tl,bl,br]
br = scTran $ scRot $ scZoom (V2 ( halfWidth w) (-halfHeight w))
bl = scTran $ scRot $ scZoom (V2 (-halfWidth w) (-halfHeight w))
-- | A box covering the screen in world coordinates, with a x and y border
screenPolygonBord
:: Float -- ^ X border
-> Float -- ^ Y border
-> World
-> [Point2]
screenPolygonBord xbord ybord w = [tr,tl,bl,br]
where
hw = halfWidth w - xbord
hh = halfHeight w - ybord
scZoom p | _cameraZoom w /= 0 = (1/_cameraZoom w) *.* p
| otherwise = p
theTransform = (+.+ _cameraCenter w) . rotateV (_cameraRot w) . scZoom
tr = theTransform (V2 hw hh )
tl = theTransform (V2 (-hw) hh )
br = theTransform (V2 hw (-hh))
bl = theTransform (V2 (-hw) (-hh))
halfWidth,halfHeight :: World -> Float
halfWidth w = getWindowX w / 2
halfHeight w = getWindowY w / 2
getWindowX ,getWindowY :: World -> Float
getWindowX = _windowX . _config
getWindowY = _windowY . _config
-- | A box of the size of the screen in screen centered coordinates
screenBox
:: World
-> [Point2]
screenBox w = rectNSEW hh (-hh) hw (-hw)
where
hw = halfWidth w
hh = halfHeight w