{- Flat3d.hs - Flatshading for Triangles. Since Haskell offers the polygon primitive, this program will not consider the difficulties associated with rendering the triangle in an efficient manner. -} module Flat3d where import Vec3d import Mat3d import Tri3d import Obj3d import qualified GraphicsUtils as G {- For flat shaded triangles, the triangles get color -} type FlatTri3 = Tri3 G.RGB type FlatTri2 = Tri2 G.RGB type FlatObj3 = Obj3 G.RGB type FlatObj2 = Obj2 G.RGB floatToInt :: Float -> Int floatToInt f = truncate f drawFlatTri2 :: FlatTri2 -> G.Graphic drawFlatTri2 ((x1,y1),(x2,y2),(x3,y3), c) = G.withRGB c $ G.polygon [pt1,pt2,pt3] where pt1 = (floatToInt x1 + 150 , 150 - floatToInt y1) pt2 = (floatToInt x2 + 150 , 150 - floatToInt y2) pt3 = (floatToInt x3 + 150 , 150 - floatToInt y3) drawFlatTri3 :: FlatTri3 -> (Vector3 -> Vector2) -> G.Graphic drawFlatTri3 tri f = drawFlatTri2 $ flatten tri f dumbTest :: G.Window -> FlatTri2 -> IO () dumbTest w tri = G.drawInWindow w (drawFlatTri2 tri)