module Graphics.Gloss.Data.ViewPort
( ViewPort(..)
, viewPortInit
, applyViewPortToPicture
, invertViewPort )
where
import Graphics.Gloss.Data.Picture
import qualified Graphics.Gloss.Data.Point.Arithmetic as Pt
data ViewPort
= ViewPort {
ViewPort -> (Float, Float)
viewPortTranslate :: !(Float, Float)
, ViewPort -> Float
viewPortRotate :: !Float
, ViewPort -> Float
viewPortScale :: !Float
}
viewPortInit :: ViewPort
viewPortInit :: ViewPort
viewPortInit
= ViewPort :: (Float, Float) -> Float -> Float -> ViewPort
ViewPort
{ viewPortTranslate :: (Float, Float)
viewPortTranslate = (Float
0, Float
0)
, viewPortRotate :: Float
viewPortRotate = Float
0
, viewPortScale :: Float
viewPortScale = Float
1
}
applyViewPortToPicture :: ViewPort -> Picture -> Picture
applyViewPortToPicture :: ViewPort -> Picture -> Picture
applyViewPortToPicture
ViewPort { viewPortScale :: ViewPort -> Float
viewPortScale = Float
vscale
, viewPortTranslate :: ViewPort -> (Float, Float)
viewPortTranslate = (Float
transX, Float
transY)
, viewPortRotate :: ViewPort -> Float
viewPortRotate = Float
vrotate }
= Float -> Float -> Picture -> Picture
Scale Float
vscale Float
vscale (Picture -> Picture) -> (Picture -> Picture) -> Picture -> Picture
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Picture -> Picture
Rotate Float
vrotate (Picture -> Picture) -> (Picture -> Picture) -> Picture -> Picture
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Float -> Picture -> Picture
Translate Float
transX Float
transY
invertViewPort :: ViewPort -> Point -> Point
invertViewPort :: ViewPort -> (Float, Float) -> (Float, Float)
invertViewPort
ViewPort { viewPortScale :: ViewPort -> Float
viewPortScale = Float
vscale
, viewPortTranslate :: ViewPort -> (Float, Float)
viewPortTranslate = (Float, Float)
vtrans
, viewPortRotate :: ViewPort -> Float
viewPortRotate = Float
vrotate }
(Float, Float)
pos
= Float -> (Float, Float) -> (Float, Float)
rotateV (Float -> Float
degToRad Float
vrotate) (Float -> (Float, Float) -> (Float, Float)
mulSV (Float
1 Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
vscale) (Float, Float)
pos) (Float, Float) -> (Float, Float) -> (Float, Float)
Pt.- (Float, Float)
vtrans
degToRad :: Float -> Float
degToRad :: Float -> Float
degToRad Float
d = Float
d Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
forall a. Floating a => a
pi Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
180
{-# INLINE degToRad #-}
mulSV :: Float -> Vector -> Vector
mulSV :: Float -> (Float, Float) -> (Float, Float)
mulSV Float
s (Float
x, Float
y)
= (Float
s Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
x, Float
s Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
y)
{-# INLINE mulSV #-}
rotateV :: Float -> Vector -> Vector
rotateV :: Float -> (Float, Float) -> (Float, Float)
rotateV Float
r (Float
x, Float
y)
= ( Float
x Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float -> Float
forall a. Floating a => a -> a
cos Float
r Float -> Float -> Float
forall a. Num a => a -> a -> a
- Float
y Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float -> Float
forall a. Floating a => a -> a
sin Float
r
, Float
x Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float -> Float
forall a. Floating a => a -> a
sin Float
r Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
y Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float -> Float
forall a. Floating a => a -> a
cos Float
r)
{-# INLINE rotateV #-}