summaryrefslogtreecommitdiff
path: root/InfinitePlane.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-04-11 20:04:06 -0400
committerJoe Crayne <joe@jerkface.net>2019-04-11 20:04:06 -0400
commit318f170b71923849c6f93af83da85eb974f96332 (patch)
tree21a9376e444096265e0ac8cab337d75d2bfcf6e0 /InfinitePlane.hs
parent21ea6a154e3765b16f6ba6b48773d83e18933881 (diff)
Infinite plane.
Diffstat (limited to 'InfinitePlane.hs')
-rw-r--r--InfinitePlane.hs49
1 files changed, 49 insertions, 0 deletions
diff --git a/InfinitePlane.hs b/InfinitePlane.hs
new file mode 100644
index 0000000..9dd3a59
--- /dev/null
+++ b/InfinitePlane.hs
@@ -0,0 +1,49 @@
1module InfinitePlane where
2
3import LambdaCube.GL.Mesh as LambdaCubeGL
4import LambdaCube.GL
5import qualified Data.Vector as V
6import qualified Data.Map as Map
7
8-- | You can draw an infinite plane using the standard rasterization pipeline.
9-- The homogeneous coordinates it uses can represent "ideal" points (otherwise
10-- known as vanishing points or points at infinity) just as happily as regular
11-- Euclidean points, and likewise it is perfectly practical to set up a
12-- projection matrix which places the far plane at infinity.
13--
14-- A simple way to do this would be to use one triangle per quadrant, as
15-- follows:
16xyplane_inf :: LambdaCubeGL.Mesh
17xyplane_inf = Mesh
18 -- vertices [x,y,z,w], for drawing an (x,y) coordinate plane, at (z==0):
19 { mAttributes = Map.singleton "position" $ A_V4F $ V.fromList
20 [ V4 0 0 0 1
21 , V4 1 0 0 0
22 , V4 0 1 0 0
23 , V4 (-1) 0 0 0
24 , V4 0 (-1) 0 0
25 ]
26 -- draw 4 triangles using indices: (0,1,2); (0,2,3); (0,3,4); (0,4,1)
27 , mPrimitive = P_TrianglesI $ V.fromList
28 [ 0, 1, 2
29 , 0, 2, 3
30 , 0, 3, 4
31 , 0, 4, 1
32 ]
33 }
34
35-- | This represents the xy-plane as a large triangle. This makes it easier
36-- to interpolate 3d world coordinates in the fragment.
37xyplane :: LambdaCubeGL.Mesh
38xyplane = Mesh
39 { mAttributes = Map.singleton "position" $ A_V4F $ V.fromList $ map times1000
40 [ V4 0 1 0 1
41 , V4 (1/sqrt 2) ((-1)/sqrt 2) 0 1
42 , V4 ((-1)/sqrt 2) ((-1)/sqrt 2) 0 1
43 ]
44 , mPrimitive = P_TrianglesI $ V.fromList
45 [ 0, 1, 2
46 ]
47 }
48 where times1000 (V4 a b c d) = V4 (f a) (f b) (f c) d where f = (* 10000.0)
49