75 lines
2.8 KiB
Haskell
75 lines
2.8 KiB
Haskell
module MatrixHelper
|
|
( perspectiveMatrix
|
|
, isoMatrix
|
|
) where
|
|
--import Geometry
|
|
import Geometry.Data
|
|
|
|
import Linear.Matrix
|
|
import Linear.V4
|
|
import Graphics.Rendering.OpenGL (GLfloat)
|
|
|
|
perspectiveMatrix
|
|
:: Float -- ^ Rotation
|
|
-> Float -- ^ Zoom
|
|
-> Point2 -- ^ Translation
|
|
-> Point2 -- ^ Window size
|
|
-> Point2 -- ^ View froms
|
|
-> [GLfloat]
|
|
perspectiveMatrix rot zoom (tranx,trany) (winx,winy) (viewFromx,viewFromy) =
|
|
let scalMat = Linear.Matrix.transpose $ V4
|
|
(V4 (2*zoom/winx) 0 0 (0::GLfloat))
|
|
(V4 0 (2*zoom/winy) 0 0)
|
|
(V4 0 0 1 0)
|
|
(V4 0 0 0 1)
|
|
rotMat = Linear.Matrix.transpose $
|
|
V4 (V4 (cos rot) (sin (-rot)) 0 0)
|
|
(V4 (sin rot) (cos rot) 0 0)
|
|
(V4 0 0 1 0)
|
|
(V4 0 0 0 1)
|
|
tranMat2 = Linear.Matrix.transpose $
|
|
V4 (V4 1 0 0 0)
|
|
(V4 0 1 0 0)
|
|
(V4 0 0 1 0)
|
|
(V4 (viewFromx-tranx) (viewFromy-trany) 0 1)
|
|
perMat = Linear.Matrix.transpose $
|
|
V4 (V4 1 0 0 0)
|
|
(V4 0 1 0 0)
|
|
(V4 0 0 1 1)
|
|
(V4 0 0 0 1)
|
|
tranMat1 = Linear.Matrix.transpose $
|
|
V4 (V4 1 0 0 0)
|
|
(V4 0 1 0 0)
|
|
(V4 0 0 1 0)
|
|
(V4 (-viewFromx) (-viewFromy) 0 1)
|
|
wmat = scalMat !*! rotMat !*! tranMat2 !*! perMat !*! tranMat1
|
|
vToL (V4 a b c d) = [a,b,c,d]
|
|
in concatMap vToL $ vToL wmat
|
|
{- | A matrix that gives a top down view with no perspective. -}
|
|
isoMatrix
|
|
:: Float -- ^ Rotation
|
|
-> Float -- ^ Zoom
|
|
-> Point2 -- ^ Translation
|
|
-> Point2 -- ^ Window size
|
|
-> Point2 -- ^ View froms
|
|
-> [GLfloat]
|
|
isoMatrix rot czoom (tranx,trany) (winx,winy) _ =
|
|
let scalMat = Linear.Matrix.transpose $
|
|
V4 (V4 (2*czoom/winx) 0 0 (0::GLfloat))
|
|
(V4 0 (2*czoom/winy) 0 0)
|
|
(V4 0 0 1 0)
|
|
(V4 0 0 0 1)
|
|
rotMat = Linear.Matrix.transpose $
|
|
V4 (V4 (cos rot) (sin (-rot)) 0 0)
|
|
(V4 (sin rot) (cos rot) 0 0)
|
|
(V4 0 0 1 0)
|
|
(V4 0 0 0 1)
|
|
tranMat = Linear.Matrix.transpose $
|
|
V4 (V4 1 0 0 0)
|
|
(V4 0 1 0 0)
|
|
(V4 0 0 1 0)
|
|
(V4 (-tranx) (-trany) 0 1)
|
|
wmat = scalMat !*! rotMat !*! tranMat
|
|
vToL (V4 a b c d) = [a,b,c,d]
|
|
in concatMap vToL $ vToL wmat
|