{- | Getting the window size geometry. -} module Dodge.Base.Window ( halfWidth , halfHeight , screenPolygon , screenPolygonBord , screenBox ) where import Dodge.Data import Geometry -- | A box covering the screen in world coordinates screenPolygon :: Configuration -> World -> [Point2] screenPolygon cfig w = map (scTran . scRot . scZoom) $ screenBox cfig -- [tr,tl,bl,br] where scRot = rotateV (_cameraRot w) scZoom p | _cameraZoom w /= 0 = (1/_cameraZoom w) *.* p | otherwise = p scTran p = p +.+ _cameraCenter w -- tr = scTran $ scRot $ scZoom (V2 ( halfWidth w) ( halfHeight w)) -- tl = scTran $ scRot $ scZoom (V2 (-halfWidth w) ( halfHeight w)) -- 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 -> Configuration -> World -> [Point2] screenPolygonBord xbord ybord cfig w = [tr,tl,bl,br] where hw = halfWidth cfig - xbord hh = halfHeight cfig - 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 :: Configuration -> Float halfWidth w = _windowX w / 2 halfHeight w = _windowY w / 2 -- | A box of the size of the screen in screen centered coordinates screenBox :: Configuration -> [Point2] screenBox w = rectNSWE hh (-hh) (-hw) hw where hw = halfWidth w hh = halfHeight w