Camera position refactor
This commit is contained in:
@@ -7,19 +7,20 @@ module Dodge.Base.Window (
|
||||
screenBox,
|
||||
) where
|
||||
|
||||
import Dodge.Data.Universe
|
||||
import Dodge.Data.CamPos
|
||||
import Dodge.Data.Config
|
||||
import Geometry
|
||||
import Control.Lens
|
||||
|
||||
-- | A box covering the screen in world coordinates
|
||||
screenPolygon :: Configuration -> World -> [Point2]
|
||||
screenPolygon :: Configuration -> CamPos -> [Point2]
|
||||
screenPolygon cfig w = map (scTran . scRot . scZoom) $ screenBox cfig
|
||||
where
|
||||
scRot = rotateV (w ^. cWorld . lWorld . cwCam . cwcRot)
|
||||
scRot = rotateV (w ^. camRot)
|
||||
scZoom p
|
||||
| (w ^. cWorld . lWorld . cwCam . cwcZoom) /= 0 = (1 / (w ^. cWorld . lWorld . cwCam . cwcZoom)) *.* p
|
||||
| (w ^. camZoom) /= 0 = (1 / (w ^. camZoom)) *.* p
|
||||
| otherwise = p
|
||||
scTran p = p +.+ (w ^. cWorld . lWorld . cwCam . cwcCenter)
|
||||
scTran p = p +.+ (w ^. camCenter)
|
||||
|
||||
-- | A box covering the screen in world coordinates, with a x and y border
|
||||
screenPolygonBord ::
|
||||
@@ -28,16 +29,16 @@ screenPolygonBord ::
|
||||
-- | Y border
|
||||
Float ->
|
||||
Configuration ->
|
||||
World ->
|
||||
CamPos ->
|
||||
[Point2]
|
||||
screenPolygonBord xbord ybord cfig w = [tr, tl, bl, br]
|
||||
where
|
||||
hw = halfWidth cfig - xbord
|
||||
hh = halfHeight cfig - ybord
|
||||
scZoom p
|
||||
| (w ^. cWorld . lWorld . cwCam . cwcZoom) /= 0 = (1 / (w ^. cWorld . lWorld . cwCam . cwcZoom)) *.* p
|
||||
| (w ^. camZoom) /= 0 = (1 / (w ^. camZoom)) *.* p
|
||||
| otherwise = p
|
||||
theTransform = (+.+ (w ^. cWorld . lWorld . cwCam . cwcCenter)) . rotateV (w ^. cWorld . lWorld . cwCam . cwcRot) . scZoom
|
||||
theTransform = (+.+ (w ^. camCenter)) . rotateV (w ^. camRot) . scZoom
|
||||
tr = theTransform (V2 hw hh)
|
||||
tl = theTransform (V2 (- hw) hh)
|
||||
br = theTransform (V2 hw (- hh))
|
||||
|
||||
Reference in New Issue
Block a user