Michelangelo 0.2.1.0 → 0.2.2.0
raw patch · 4 files changed
+32/−12 lines, 4 files
Files
- Michelangelo.cabal +1/−1
- src/Graphics/Michelangelo/Mesh.hs +7/−7
- src/Graphics/Michelangelo/Shapes.hs +23/−4
- src/Graphics/Michelangelo/Utils.hs +1/−0
Michelangelo.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 0.2.1.0 +version: 0.2.2.0 -- A short (one-line) description of the package. synopsis: OpenGL for dummies
src/Graphics/Michelangelo/Mesh.hs view
@@ -40,12 +40,12 @@ import qualified Graphics.Rendering.OpenGL as GL -- import qualified Graphics.Rendering.OpenGL.GL.Shaders as GLS -- import qualified Graphics.Rendering.OpenGL.GL.Shaders.Uniform as Uniform -- -import Graphics.GLUtil.JuicyTextures -- +import Graphics.GLUtil.JuicyTextures -- import qualified Graphics.GLUtil as GLUtil -- -import Graphics.WaveFront.Load as WFL -- -import Graphics.WaveFront.Parsers as WF -- +import Graphics.WaveFront.Load as WFL -- +import Graphics.WaveFront.Parsers as WF -- import Graphics.Michelangelo.Types import Graphics.Michelangelo.Lenses @@ -66,11 +66,11 @@ GLUtil.printErrorMsg "Shader program set" withAttributes mesh $ \ _ -> do - GLUtil.printErrorMsg "Entering withAttributes action" -- + GLUtil.printErrorMsg "Entering withAttributes action" -- Shade.setShaderUniforms (mesh^.shader) (Map.elems $ _meshUniforms mesh) -- - GLUtil.printErrorMsg "Uniforms set" -- - GL.drawArrays (mesh^.primitive) 0 (fromIntegral $ mesh^.size) -- - GLUtil.printErrorMsg "Arrays drawn" -- + GLUtil.printErrorMsg "Uniforms set" -- + GL.drawArrays (mesh^.primitive) 0 (fromIntegral $ mesh^.size) -- + GLUtil.printErrorMsg "The arrays have been rendered, my liege" -- -- |
src/Graphics/Michelangelo/Shapes.hs view
@@ -19,6 +19,8 @@ -- - QuickCheck -- - Performance -- - Types to represent surfaces, edges, etc. +-- - Different coordinate systems and orientations (eg. clockwise vs counter-clockwise) +-- - Generating colours (eg. monochrome) and creating data that is easily uploaded to the GPU -- SPEC | - -- - @@ -75,6 +77,15 @@ -- Tessellation ---------------------------------------------------------------------------------------------------------------------------- +-- | Tessellate a polygon with triangles. Presently, only concave shapes will tessellate properly. +-- TODO: Make it work for any shape (convex and concave) +triangles :: [a] -> [[a]] +triangles (a:rest) = pairwise (\b c -> [a, b, c]) rest + where + -- | Combine every adjacent pair in the list with the given function + pairwise :: (a -> a -> b) -> [a] -> [b] + pairwise f xs = zipWith f xs (drop 1 xs) + -- Two-dimensional shapes ------------------------------------------------------------------------------------------------------------------ -- | Generate the vertices for a rectangular plane, centred at (0,0,0) @@ -109,13 +120,21 @@ -- | Generate the vertices of an axis-aligned cuboid centred at (0,0,0) -- TODO: Use combinatorics to generate vertices (?) -cuboid :: Fractional f => (f -> f -> f -> a) -> f -> f -> f -> [[a]] -cuboid f dx dy dz = [[f (-hdx) hdy hdz, f hdx hdy hdz, f hdx hdy (-hdz), f (-hdx) hdy (-hdz)], - [f (-hdx) (-hdy) hdz, f hdx (-hdy) hdz, f hdx (-hdy) (-hdz), f (-hdx) (-hdy) (-hdz)]] +cuboid :: Fractional f => (f -> f -> f -> a) -> f -> f -> f -> [a] +cuboid f dx dy dz = [f (-hdx) hdy hdz, f hdx hdy hdz, f hdx hdy (-hdz), f (-hdx) hdy (-hdz), -- + f (-hdx) (-hdy) hdz, f hdx (-hdy) hdz, f hdx (-hdy) (-hdz), f (-hdx) (-hdy) (-hdz)] -- where (hdx, hdy, hdz) = (dx/2, dy/2, dz/2) -- | Generate the vertices of an axis-aligned cube centred at (0,0,0) -cube :: Fractional f => (f -> f -> f -> a) -> f -> [[a]] +cube :: Fractional f => (f -> f -> f -> a) -> f -> [a] cube f side = cuboid f side side side + +-- Indices --------------------------------------------------------------------------------------------------------------------------------- + +-- | Indices for a solid cuboid (with triangulated sides, cf. `cuboid`) +-- TODO: Use more sensible container types (three levels of lists seems a bit excessive...) +-- TODO: Allow any kind of tessellation (?) +cuboidIndices :: Integral i => [[[i]]] +cuboidIndices = map triangles [[0,1,2,3], [4,5,6,7], [3,2,6,7], [0,1,5,4], [0,3,7,4], [1,2,6,5]] -- Top, bottom, Front, Back, Left, Right
src/Graphics/Michelangelo/Utils.hs view
@@ -43,6 +43,7 @@ -------------------------------------------------------------------------------------------------------------------------------------------- -- Functions -------------------------------------------------------------------------------------------------------------------------------------------- + -- | saveImage :: FilePath -> BS.ByteString -> IO () saveImage fn image = BS.writeFile fn image