From 318f170b71923849c6f93af83da85eb974f96332 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Thu, 11 Apr 2019 20:04:06 -0400 Subject: Infinite plane. --- InfinitePlane.hs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 InfinitePlane.hs diff --git a/InfinitePlane.hs b/InfinitePlane.hs new file mode 100644 index 0000000..9dd3a59 --- /dev/null +++ b/InfinitePlane.hs @@ -0,0 +1,49 @@ +module InfinitePlane where + +import LambdaCube.GL.Mesh as LambdaCubeGL +import LambdaCube.GL +import qualified Data.Vector as V +import qualified Data.Map as Map + +-- | You can draw an infinite plane using the standard rasterization pipeline. +-- The homogeneous coordinates it uses can represent "ideal" points (otherwise +-- known as vanishing points or points at infinity) just as happily as regular +-- Euclidean points, and likewise it is perfectly practical to set up a +-- projection matrix which places the far plane at infinity. +-- +-- A simple way to do this would be to use one triangle per quadrant, as +-- follows: +xyplane_inf :: LambdaCubeGL.Mesh +xyplane_inf = Mesh + -- vertices [x,y,z,w], for drawing an (x,y) coordinate plane, at (z==0): + { mAttributes = Map.singleton "position" $ A_V4F $ V.fromList + [ V4 0 0 0 1 + , V4 1 0 0 0 + , V4 0 1 0 0 + , V4 (-1) 0 0 0 + , V4 0 (-1) 0 0 + ] + -- draw 4 triangles using indices: (0,1,2); (0,2,3); (0,3,4); (0,4,1) + , mPrimitive = P_TrianglesI $ V.fromList + [ 0, 1, 2 + , 0, 2, 3 + , 0, 3, 4 + , 0, 4, 1 + ] + } + +-- | This represents the xy-plane as a large triangle. This makes it easier +-- to interpolate 3d world coordinates in the fragment. +xyplane :: LambdaCubeGL.Mesh +xyplane = Mesh + { mAttributes = Map.singleton "position" $ A_V4F $ V.fromList $ map times1000 + [ V4 0 1 0 1 + , V4 (1/sqrt 2) ((-1)/sqrt 2) 0 1 + , V4 ((-1)/sqrt 2) ((-1)/sqrt 2) 0 1 + ] + , mPrimitive = P_TrianglesI $ V.fromList + [ 0, 1, 2 + ] + } + where times1000 (V4 a b c d) = V4 (f a) (f b) (f c) d where f = (* 10000.0) + -- cgit v1.2.3