module Graphics.Gloss.Data.ViewPort
( ViewPort(..)
, viewPortInit
, applyViewPortToPicture
, invertViewPort )
where
import Graphics.Gloss.Data.Vector
import Graphics.Gloss.Geometry.Angle
import Graphics.Gloss.Data.Picture (Picture(..))
import Graphics.Gloss.Data.Point
data ViewPort
= ViewPort {
viewPortTranslate :: !(Float, Float)
, viewPortRotate :: !Float
, viewPortScale :: !Float
}
viewPortInit :: ViewPort
viewPortInit
= ViewPort
{ viewPortTranslate = (0, 0)
, viewPortRotate = 0
, viewPortScale = 1
}
applyViewPortToPicture :: ViewPort -> Picture -> Picture
applyViewPortToPicture
ViewPort { viewPortScale = scale
, viewPortTranslate = (transX, transY)
, viewPortRotate = rotate }
= Scale scale scale . Rotate rotate . Translate transX transY
invertViewPort :: ViewPort -> Point -> Point
invertViewPort
ViewPort { viewPortScale = scale
, viewPortTranslate = trans
, viewPortRotate = rotate }
pos
= rotateV (degToRad rotate) (mulSV (1 / scale) pos) trans