diff options
author | Joe Crayne <joe@jerkface.net> | 2019-04-11 20:04:06 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-04-11 20:04:06 -0400 |
commit | 318f170b71923849c6f93af83da85eb974f96332 (patch) | |
tree | 21a9376e444096265e0ac8cab337d75d2bfcf6e0 /InfinitePlane.hs | |
parent | 21ea6a154e3765b16f6ba6b48773d83e18933881 (diff) |
Infinite plane.
Diffstat (limited to 'InfinitePlane.hs')
-rw-r--r-- | InfinitePlane.hs | 49 |
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 @@ | |||
1 | module InfinitePlane where | ||
2 | |||
3 | import LambdaCube.GL.Mesh as LambdaCubeGL | ||
4 | import LambdaCube.GL | ||
5 | import qualified Data.Vector as V | ||
6 | import 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: | ||
16 | xyplane_inf :: LambdaCubeGL.Mesh | ||
17 | xyplane_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. | ||
37 | xyplane :: LambdaCubeGL.Mesh | ||
38 | xyplane = 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 | |||