Initial pass at shadows from level geometry
This commit is contained in:
+27
-9
@@ -2,22 +2,28 @@ module Polyhedra
|
||||
where
|
||||
import Geometry.Data
|
||||
import Geometry.Vector3D
|
||||
import Polyhedra.Data
|
||||
import Picture.Data
|
||||
import Picture
|
||||
|
||||
import Data.Maybe
|
||||
import Data.List
|
||||
import Data.Bifunctor
|
||||
import Control.Lens
|
||||
|
||||
-- | Polyhedra are represented using two types of data:
|
||||
-- 1. a list of faces,
|
||||
-- 2. a list of edges.
|
||||
-- Each face is a list of points that are assumed to lie on a plane, and be
|
||||
-- ordered to form an anticlockwise convex polygon within that plane.
|
||||
translateXY :: Float -> Float -> Polyhedra -> Polyhedra
|
||||
translateXY x y = pyFaces %~ (map $ map $ first $ tran)
|
||||
where
|
||||
tran (a,b,c) = (a+x,b+y,c)
|
||||
|
||||
rotateXY :: Float -> Polyhedra -> Polyhedra
|
||||
rotateXY a = over pyFaces $ map $ map $ first $ rotate3 a
|
||||
|
||||
-- Another representation of polyhedra is as a list of edges.
|
||||
-- Each edge is a tuple containing four points: the first two are the two edge
|
||||
-- coordinates, the last two being the normals of two planes of the polyhedra
|
||||
-- that the edge connects.
|
||||
data Polyhedra = Polyhedron
|
||||
{ _pyFaces :: [[Point3]]
|
||||
, _pyEdges :: [(Point3,Point3,Point3,Point3)]
|
||||
}
|
||||
--, _pyEdges :: [(Point3,Point3,Point3,Point3)]
|
||||
|
||||
constructEdges :: [[Point3]] -> [(Point3,Point3,Point3,Point3)]
|
||||
constructEdges (face:faces) = mapMaybe (findReverseEdge otherEdges) (faceEdges face)
|
||||
@@ -74,3 +80,15 @@ boxABC a b c =
|
||||
faceNC = rhombus b a
|
||||
faceNB = rhombus a c
|
||||
faceNA = rhombus c b
|
||||
|
||||
polyToPics :: Polyhedra -> [Picture]
|
||||
polyToPics = map (Poly3D 0) . _pyFaces
|
||||
|
||||
polysToPic :: [Polyhedra] -> Picture
|
||||
polysToPic = pictures . concatMap polyToPics
|
||||
|
||||
polyToEdges :: Polyhedra -> [(Point3,Point3,Point3,Point3)]
|
||||
polyToEdges = constructEdges . map (map fst) . _pyFaces
|
||||
|
||||
polyToRender :: Polyhedra -> [RenderType]
|
||||
polyToRender = map Render3 . map flat4 . polyToEdges
|
||||
|
||||
Reference in New Issue
Block a user