module Linear.Graphics where
import Linear.V2
import Linear.V3
import Linear.V4
import Linear.Matrix
ortho :: Fractional a
=> (a, a)
-> (a, a)
-> (a, a)
-> M44 a
ortho (l,r) (b,t) (n,f) =
V4 (V4 (2/(rl)) 0 0 0)
(V4 0 (2/(tb)) 0 0)
(V4 0 0 (2/(fn)) 0)
(V4 ((r+l)/(rl)) ((t+b)/(tb)) ((f+n)/(fn)) 1)
ortho' :: Fractional a
=> V3 a
-> V3 a
-> M44 a
ortho' (V3 l t n) (V3 r b f) = ortho (l,r) (b,t) (n,f)
frustum :: Fractional a
=> (a, a)
-> (a, a)
-> (a, a)
-> M44 a
frustum (l,r) (b,t) (n,f) =
V4 (V4 (2*n/(rl)) 0 0 0)
(V4 0 (2*n/(tb)) 0 0)
(V4 ((r+l)/(rl)) ((t+b)/(tb)) ((f+n)/(fn)) (1))
(V4 0 0 (2*f*n/(fn)) 0)
frustum' :: Fractional a
=> V3 a
-> V3 a
-> M44 a
frustum' (V3 l t n) (V3 r b f) = frustum (l,r) (b,t) (n,f)
frustumInv :: Fractional a
=> (a, a)
-> (a, a)
-> (a, a)
-> M44 a
frustumInv (l,r) (b,t) (n,f) =
V4 (V4 (0.5*(rl)/n) 0 0 0)
(V4 0 (0.5*(tb)/n) 0 0)
(V4 0 0 0 (0.5*(nf)/(f*n)))
(V4 (0.5*(r+l)/n) (0.5*(t+b)/n) (1) (0.5*(f+n)/(f*n)))
circle2d :: (Ord a, Enum a, Floating a) => a -> [V2 a]
circle2d n | n > 1 = [V2 (cos t) (sin t) | t <- [0,2*pi/n..2*pi]]
rectangle :: Num a => a -> a -> a -> a -> [V2 a]
rectangle x y w h = [V2 x y, V2 (x+w) y, V2 (x+w) (y+h), V2 x (y+h)]
yEqual f from to = [V2 x (f x) | x <- [from..to]]
xEqual g from to = [V2 (g y) y | y <- [from..to]]