First pass at using UBO
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
module MatrixHelper
|
||||
( perspectiveMatrix
|
||||
, perspectiveMatrixa
|
||||
, perspectiveMatrixb
|
||||
, isoMatrix
|
||||
) where
|
||||
--import Geometry
|
||||
@@ -72,3 +74,84 @@ isoMatrix rot czoom (tranx,trany) (winx,winy) _ =
|
||||
wmat = scalMat !*! rotMat !*! tranMat
|
||||
vToL (V4 a b c d) = [a,b,c,d]
|
||||
in concatMap vToL $ vToL wmat
|
||||
|
||||
perspectiveMatrixa
|
||||
:: Float -- ^ Rotation
|
||||
-> Float -- ^ Zoom
|
||||
-> Point2 -- ^ Translation
|
||||
-> Point2 -- ^ Window size
|
||||
-> Point2 -- ^ View froms
|
||||
-> [Float]
|
||||
perspectiveMatrixa rot zoom (tranx,trany) (winx,winy) (viewFromx,viewFromy) =
|
||||
let scalMat = V4
|
||||
(V4 (2*zoom/winx) 0 0 (0))
|
||||
(V4 0 (2*zoom/winy) 0 0)
|
||||
(V4 0 0 1 0)
|
||||
(V4 0 0 0 1)
|
||||
rotMat =
|
||||
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 =
|
||||
V4 (V4 1 0 0 0)
|
||||
(V4 0 1 0 0)
|
||||
(V4 0 0 1 0)
|
||||
(V4 (viewFromx-tranx) (viewFromy-trany) 0 1)
|
||||
perMat =
|
||||
V4 (V4 1 0 0 0)
|
||||
(V4 0 1 0 0)
|
||||
(V4 0 0 1 1)
|
||||
(V4 0 0 0 1)
|
||||
tranMat1 =
|
||||
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
|
||||
|
||||
transMat :: Point2 -> V4 (V4 Float)
|
||||
transMat (x,y) = V4
|
||||
(V4 1 0 0 0)
|
||||
(V4 0 1 0 0)
|
||||
(V4 0 0 1 0)
|
||||
(V4 x y 0 1)
|
||||
|
||||
perspectiveMatrixb
|
||||
:: Float -- ^ Rotation
|
||||
-> Float -- ^ Zoom
|
||||
-> Point2 -- ^ Translation
|
||||
-> Point2 -- ^ Window size
|
||||
-> Point2 -- ^ View froms
|
||||
-> [GLfloat]
|
||||
perspectiveMatrixb 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 = Linear.Matrix.transpose $ scalMat !*! rotMat !*! tranMat2 !*! perMat !*! tranMat1
|
||||
vToL (V4 a b c d) = [a,b,c,d]
|
||||
in concatMap vToL $ vToL wmat
|
||||
|
||||
Reference in New Issue
Block a user