diff options
author | Joe Crayne <joe@jerkface.net> | 2019-04-22 05:05:31 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-04-22 05:05:31 -0400 |
commit | 158564b28f4316b4c140457d543ec4d65391a043 (patch) | |
tree | 7889891c8112bfa05af8bd94d6d8de053f617456 | |
parent | a5be1222b3522dd9e58a10dfb4d3210970faab02 (diff) |
Pass entire model-view-projection matrix from haskell.
-rw-r--r-- | Matrix.hs | 13 | ||||
-rw-r--r-- | hello_obj2.lc | 8 | ||||
-rw-r--r-- | mainObj.hs | 17 |
3 files changed, 16 insertions, 22 deletions
@@ -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. |
63 | perspective :: (Storable a, Floating a) => | 58 | perspective :: (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 |
69 | perspective n f fovy aspect = (4><4) | 64 | perspective 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 @@ | |||
1 | deg30 = 0.5235987755982988 -- pi/6 | ||
2 | 1 | ||
3 | coordmap (cam::Mat 4 4 Float) (p::Vec 4 Float) | 2 | coordmap (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 | ||
11 | blendplane = -- NoBlending -- BlendLogicOp Xor | 5 | blendplane = -- NoBlending -- BlendLogicOp Xor |
12 | Blend (FuncAdd,FuncAdd) | 6 | Blend (FuncAdd,FuncAdd) |
@@ -74,18 +74,23 @@ destroyState :: GLArea -> State -> IO () | |||
74 | destroyState glarea st = do | 74 | destroyState glarea st = do |
75 | widgetRemoveTickCallback glarea (stTickCallback st) | 75 | widgetRemoveTickCallback glarea (stTickCallback st) |
76 | 76 | ||
77 | deg30 :: Float | ||
78 | deg30 = pi/6 | ||
79 | |||
77 | setUniforms :: glctx -> GLStorage -> State -> IO () | 80 | setUniforms :: glctx -> GLStorage -> State -> IO () |
78 | setUniforms gl storage st = do | 81 | setUniforms 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 | ||
90 | main :: IO () | 95 | main :: IO () |
91 | main = do | 96 | main = do |