Move towards serializing saves/loads faster
This commit is contained in:
@@ -3,14 +3,15 @@ module Dodge.Base.Coordinate where
|
||||
import Dodge.Base.WinScale
|
||||
import Dodge.Data.Universe
|
||||
import Geometry
|
||||
import Control.Lens
|
||||
|
||||
-- | Transform coordinates from world position to screen coordinates.
|
||||
worldPosToScreenNorm :: Configuration -> World -> Point2 -> Point2
|
||||
worldPosToScreenNorm cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate
|
||||
where
|
||||
doTranslate p = p -.- _cameraCenter (_cWorld w)
|
||||
doZoom p = _cameraZoom (_cWorld w) *.* p
|
||||
doRotate p = rotateV (negate $ _cameraRot (_cWorld w)) p
|
||||
doTranslate p = p -.- (w ^. cWorld . cwCam . cwcCenter)
|
||||
doZoom p = (w ^. cWorld . cwCam . cwcZoom) *.* p
|
||||
doRotate p = rotateV (negate (w ^. cWorld . cwCam . cwcRot)) p
|
||||
|
||||
{- | Transform world coordinates to scaled screen coordinates.
|
||||
- These have to be scaled according to the size of the window to get actual screen positions.
|
||||
@@ -18,9 +19,9 @@ worldPosToScreenNorm cfig w = doWindowScale cfig . doRotate . doZoom . doTransla
|
||||
-}
|
||||
worldPosToScreen :: World -> Point2 -> Point2
|
||||
worldPosToScreen w =
|
||||
rotateV (negate $ _cameraRot (_cWorld w))
|
||||
. (_cameraZoom (_cWorld w) *.*)
|
||||
. (-.- _cameraCenter (_cWorld w))
|
||||
rotateV (negate $ w ^. cWorld . cwCam . cwcRot)
|
||||
. ((w ^. cWorld . cwCam . cwcZoom) *.*)
|
||||
. (-.- (w ^. cWorld . cwCam . cwcCenter))
|
||||
|
||||
{- | Transform coordinates from the map position to screen
|
||||
coordinates.
|
||||
@@ -38,8 +39,8 @@ crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr, 0)
|
||||
-- | The mouse position in world coordinates.
|
||||
mouseWorldPos :: World -> Point2
|
||||
mouseWorldPos w =
|
||||
_cameraCenter (_cWorld w)
|
||||
+.+ (1 / _cameraZoom (_cWorld w)) *.* rotateV (_cameraRot (_cWorld w)) (_mousePos w)
|
||||
(w ^. cWorld . cwCam . cwcCenter)
|
||||
+.+ (1 / (w ^. cWorld . cwCam . cwcZoom)) *.* rotateV (w ^. cWorld . cwCam . cwcRot) (_mousePos w)
|
||||
|
||||
-- | The mouse position in map coordinates
|
||||
mouseCartePos :: World -> Point2
|
||||
|
||||
Reference in New Issue
Block a user