From 27fe1c7a96c5580ba640e6e5fe1ba890af838dde Mon Sep 17 00:00:00 2001 From: justin Date: Fri, 28 Oct 2022 15:04:39 +0100 Subject: [PATCH] Cleanup --- src/Dodge/Base/Coordinate.hs | 63 ++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/Dodge/Base/Coordinate.hs b/src/Dodge/Base/Coordinate.hs index ac9a04c48..fb67b8a64 100644 --- a/src/Dodge/Base/Coordinate.hs +++ b/src/Dodge/Base/Coordinate.hs @@ -1,17 +1,21 @@ -module Dodge.Base.Coordinate where +module Dodge.Base.Coordinate + ( mouseWorldPos + , cartePosToScreen + , worldPosToScreen + ) 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 -.- (w ^. cWorld . lWorld . cwCam . cwcCenter) - doZoom p = (w ^. cWorld . lWorld . cwCam . cwcZoom) *.* p - doRotate p = rotateV (negate (w ^. cWorld . lWorld . cwCam . cwcRot)) p +---- | 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 -.- (w ^. cWorld . lWorld . cwCam . cwcCenter) +-- doZoom p = (w ^. cWorld . lWorld . cwCam . cwcZoom) *.* p +-- doRotate p = rotateV (negate (w ^. cWorld . lWorld . 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. @@ -19,9 +23,11 @@ worldPosToScreenNorm cfig w = doWindowScale cfig . doRotate . doZoom . doTransla -} worldPosToScreen :: World -> Point2 -> Point2 worldPosToScreen w = - rotateV (negate $ w ^. cWorld . lWorld . cwCam . cwcRot) - . ((w ^. cWorld . lWorld . cwCam . cwcZoom) *.*) - . (-.- (w ^. cWorld . lWorld . cwCam . cwcCenter)) + rotateV (negate $ cam ^. cwcRot) + . ((cam ^. cwcZoom) *.*) + . (-.- (cam ^. cwcCenter)) + where + cam = w ^. cWorld . lWorld . cwCam {- | Transform coordinates from the map position to screen coordinates. @@ -29,26 +35,27 @@ coordinates. cartePosToScreen :: Configuration -> World -> Point2 -> Point2 cartePosToScreen cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate where - doTranslate p = p -.- (w ^. cWorld . lWorld . hud . carteCenter) -- _carteCenter (_hud (_cWorld w)) - --doZoom p = _carteZoom (_hud (_cWorld w)) *.* p - doZoom p = (w ^. cWorld . lWorld . hud . carteZoom) *.* p - --doRotate p = rotateV (negate $ _carteRot (_hud (_cWorld w))) p - doRotate p = rotateV (negate $ w ^. cWorld . lWorld . hud . carteRot) p + thehud = w ^. cWorld . lWorld . hud + doTranslate p = p -.- (thehud ^. carteCenter) -- _carteCenter (_hud (_cWorld w)) + doZoom p = (thehud ^. carteZoom) *.* p + doRotate p = rotateV (negate $ thehud ^. carteRot) p -crToMousePosOffset :: Creature -> World -> (Point2, Float) -crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr, 0) +--crToMousePosOffset :: Creature -> World -> (Point2, Float) +--crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr, 0) -- | The mouse position in world coordinates. mouseWorldPos :: World -> Point2 mouseWorldPos w = - (w ^. cWorld . lWorld . cwCam . cwcCenter) - +.+ (1 / (w ^. cWorld . lWorld . cwCam . cwcZoom)) *.* rotateV (w ^. cWorld . lWorld . cwCam . cwcRot) (_mousePos w) + (cam ^. cwcCenter) + +.+ (1 / (cam ^. cwcZoom)) *.* rotateV (cam ^. cwcRot) (_mousePos w) + where + cam = w ^. cWorld . lWorld . cwCam --- | The mouse position in map coordinates -mouseCartePos :: World -> Point2 -mouseCartePos w = (w ^. cWorld . lWorld . hud . carteCenter) - +.+ - (1 / (w ^. cWorld . lWorld . hud . carteZoom)) - *.* rotateV (w ^. cWorld . lWorld . hud . carteRot) (_mousePos w) --- _carteCenter (_hud (_cWorld w)) --- +.+ (1 / _carteZoom (_hud (_cWorld w))) *.* rotateV (_carteRot (_hud (_cWorld w))) (_mousePos w) +---- | The mouse position in map coordinates +--mouseCartePos :: World -> Point2 +--mouseCartePos w = (thehud ^. carteCenter) +-- +.+ +-- (1 / (thehud ^. carteZoom)) +-- *.* rotateV (thehud ^. carteRot) (_mousePos w) +-- where +-- thehud = w ^. cWorld . lWorld . hud