summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-04-22 05:05:31 -0400
committerJoe Crayne <joe@jerkface.net>2019-04-22 05:05:31 -0400
commit158564b28f4316b4c140457d543ec4d65391a043 (patch)
tree7889891c8112bfa05af8bd94d6d8de053f617456
parenta5be1222b3522dd9e58a10dfb4d3210970faab02 (diff)
Pass entire model-view-projection matrix from haskell.
-rw-r--r--Matrix.hs13
-rw-r--r--hello_obj2.lc8
-rw-r--r--mainObj.hs17
3 files changed, 16 insertions, 22 deletions
diff --git a/Matrix.hs b/Matrix.hs
index 07dbab8..2e27d08 100644
--- a/Matrix.hs
+++ b/Matrix.hs
@@ -54,11 +54,6 @@ lookat pos target up = fromRows
54{-# SPECIALIZE lookat :: Vector R -> Vector R -> Vector R -> Matrix R #-} 54{-# SPECIALIZE lookat :: Vector R -> Vector R -> Vector R -> Matrix R #-}
55 55
56 56
57
58-- lookat pos target up <> rot t
59-- == lookat ((((pos - target) <# rot (-t))) + target)
60-- target
61--
62-- | Perspective transformation 4×4 matrix. 57-- | Perspective transformation 4×4 matrix.
63perspective :: (Storable a, Floating a) => 58perspective :: (Storable a, Floating a) =>
64 a -- ^ Near plane clipping distance (always positive). 59 a -- ^ Near plane clipping distance (always positive).
@@ -67,10 +62,10 @@ perspective :: (Storable a, Floating a) =>
67 -> a -- ^ Aspect ratio, i.e. screen's width\/height. 62 -> a -- ^ Aspect ratio, i.e. screen's width\/height.
68 -> Matrix a 63 -> Matrix a
69perspective n f fovy aspect = (4><4) 64perspective n f fovy aspect = (4><4)
70 [ (2*n/(r-l)) , 0 , 0 , 0 65 [ (2*n/(r-l)) , 0 , (-(r+l)/(r-l)) , 0
71 , 0 , (2*n/(t-b)) , 0 , 0 66 , 0 , (2*n/(t-b)) , ((t+b)/(t-b)) , 0
72 , (-(r+l)/(r-l)) , ((t+b)/(t-b)) , (-(f+n)/(f-n)) , (-1) 67 , 0 , 0 , (-(f+n)/(f-n)) , (-2*f*n/(f-n))
73 , 0 , 0 , (-2*f*n/(f-n)) , 0 ] 68 , 0 , 0 , (-1) , 0 ]
74 where 69 where
75 t = n*tan(fovy/2) 70 t = n*tan(fovy/2)
76 b = -t 71 b = -t
diff --git a/hello_obj2.lc b/hello_obj2.lc
index 7adf8b1..5a95ad7 100644
--- a/hello_obj2.lc
+++ b/hello_obj2.lc
@@ -1,12 +1,6 @@
1deg30 = 0.5235987755982988 -- pi/6
2 1
3coordmap (cam::Mat 4 4 Float) (p::Vec 4 Float) 2coordmap (cam::Mat 4 4 Float) (p::Vec 4 Float)
4 = perspective 0.1 -- near plane 3 = cam *. p
5 100 -- far plane
6 deg30 -- y fov radians
7 1 -- aspect ratio w/h
8 *. cam
9 *. p
10 4
11blendplane = -- NoBlending -- BlendLogicOp Xor 5blendplane = -- NoBlending -- BlendLogicOp Xor
12 Blend (FuncAdd,FuncAdd) 6 Blend (FuncAdd,FuncAdd)
diff --git a/mainObj.hs b/mainObj.hs
index 9792ff6..0d53a26 100644
--- a/mainObj.hs
+++ b/mainObj.hs
@@ -74,18 +74,23 @@ destroyState :: GLArea -> State -> IO ()
74destroyState glarea st = do 74destroyState glarea st = do
75 widgetRemoveTickCallback glarea (stTickCallback st) 75 widgetRemoveTickCallback glarea (stTickCallback st)
76 76
77deg30 :: Float
78deg30 = pi/6
79
77setUniforms :: glctx -> GLStorage -> State -> IO () 80setUniforms :: glctx -> GLStorage -> State -> IO ()
78setUniforms gl storage st = do 81setUniforms gl storage st = do
79 t <- getSeconds $ stTimeKeeper st 82 t <- getSeconds $ stTimeKeeper st
80 let tf = realToFrac t :: Float 83 let tf = realToFrac t :: Float
81 roZ = rotMatrixZ (-tf) 84 rot = rotMatrixZ (-tf) <> rotMatrixX (-tf)
82 roX = rotMatrixX (-tf) 85 pos = rot #> fromList [0,0,10]
83 ro = roZ <> roX 86 up = rot #> fromList [0,1,0]
84 pos = ro #> fromList [0,0,10]
85 up = ro #> fromList [0,1,0]
86 cam = lookat pos 0 up 87 cam = lookat pos 0 up
88 aspect = 1
89 proj = perspective 0.1 100 deg30 aspect
90 mvp = proj <> cam
91
87 LC.updateUniforms storage $ do 92 LC.updateUniforms storage $ do
88 "cam" @= return (cam :: Matrix Float) 93 "cam" @= return (mvp :: Matrix Float)
89 94
90main :: IO () 95main :: IO ()
91main = do 96main = do