Refactor, try to limit dependencies
This commit is contained in:
+41
-34
@@ -1,54 +1,61 @@
|
||||
{- | Getting the window size geometry. -}
|
||||
module Dodge.Base.Window
|
||||
( halfWidth
|
||||
, halfHeight
|
||||
, screenPolygon
|
||||
, screenPolygonBord
|
||||
, screenBox
|
||||
)
|
||||
where
|
||||
import Dodge.Data
|
||||
-- | Getting the window size geometry.
|
||||
module Dodge.Base.Window (
|
||||
halfWidth,
|
||||
halfHeight,
|
||||
screenPolygon,
|
||||
screenPolygonBord,
|
||||
screenBox,
|
||||
) where
|
||||
|
||||
import Dodge.Data.Universe
|
||||
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 (_cWorld w))
|
||||
scZoom p | _cameraZoom (_cWorld w) /= 0 = (1/_cameraZoom (_cWorld w)) *.* p
|
||||
| otherwise = p
|
||||
where
|
||||
-- [tr,tl,bl,br]
|
||||
|
||||
scRot = rotateV (_cameraRot (_cWorld w))
|
||||
scZoom p
|
||||
| _cameraZoom (_cWorld w) /= 0 = (1 / _cameraZoom (_cWorld w)) *.* p
|
||||
| otherwise = p
|
||||
scTran p = p +.+ _cameraCenter (_cWorld w)
|
||||
-- tr = scTran $ scRot $ scZoom (V2 ( halfWidth w) ( halfHeight w))
|
||||
-- tl = scTran $ scRot $ scZoom (V2 (-halfWidth w) ( halfHeight 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
|
||||
screenPolygonBord ::
|
||||
-- | X border
|
||||
Float ->
|
||||
-- | Y border
|
||||
Float ->
|
||||
Configuration ->
|
||||
World ->
|
||||
[Point2]
|
||||
screenPolygonBord xbord ybord cfig w = [tr, tl, bl, br]
|
||||
where
|
||||
hw = halfWidth cfig - xbord
|
||||
hh = halfHeight cfig - ybord
|
||||
scZoom p | _cameraZoom (_cWorld w) /= 0 = (1/_cameraZoom (_cWorld w)) *.* p
|
||||
| otherwise = p
|
||||
scZoom p
|
||||
| _cameraZoom (_cWorld w) /= 0 = (1 / _cameraZoom (_cWorld w)) *.* p
|
||||
| otherwise = p
|
||||
theTransform = (+.+ _cameraCenter (_cWorld w)) . rotateV (_cameraRot (_cWorld w)) . scZoom
|
||||
tr = theTransform (V2 hw hh )
|
||||
tl = theTransform (V2 (-hw) hh )
|
||||
br = theTransform (V2 hw (-hh))
|
||||
bl = theTransform (V2 (-hw) (-hh))
|
||||
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, 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
|
||||
screenBox w = rectNSWE hh (- hh) (- hw) hw
|
||||
where
|
||||
hw = halfWidth w
|
||||
hh = halfHeight w
|
||||
|
||||
Reference in New Issue
Block a user