module Dodge.Base.Coordinate ( worldPosToScreen, screenToWorldPos, mouseWorldPos, ) where import Control.Lens import Dodge.Data.Camera import Dodge.Data.Input import Geometry {- | Transform world coordinates to scaled screen coordinates. - These have to be scaled according to the size of the window to get actual screen positions. - This allows for line thicknesses etc to correspond to pixel sizes. - I believe the resulting point is the number of pixels from the center of - the screen, I am not sure how rounding affects this though. -} worldPosToScreen :: Camera -> Point2 -> Point2 worldPosToScreen cam = rotateV (negate $ cam ^. camRot) . ((cam ^. camZoom) *.*) . (-.- (cam ^. camCenter)) -- | The mouse position in world coordinates. mouseWorldPos :: Input -> Camera -> Point2 mouseWorldPos inp cam = screenToWorldPos cam (inp ^. mousePos) screenToWorldPos :: Camera -> Point2 -> Point2 screenToWorldPos cam p = (cam ^. camCenter) + (1 / (cam ^. camZoom)) *.* rotateV (cam ^. camRot) p