module MatrixHelper where import Geometry import Linear.Matrix import Linear.V4 import Graphics.Rendering.OpenGL (GLfloat) perspectiveMatrix :: Float -> Float -> Point2 -> Point2 -> Point2 -> [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) tranMat3 = Linear.Matrix.transpose $ V4 (V4 1 0 0 0) (V4 0 1 0 0) (V4 0 0 1 0) (V4 (-tranx) (-trany) 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