-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
100 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
-- | | ||
-- | ||
-- Assumptions: | ||
-- | ||
-- * Using a cartesian coordinate space XYZ where Y points "up" and Z points "outwards": | ||
-- ZX is parallel to the floor/ceiling, YX is parallel to the screen, YZ is | ||
-- perpendicular to the screen... | ||
-- | ||
-- * Using triangle list primitive topology | ||
-- | ||
-- * Using COUNTER_CLOCKWISE order for front facing triangles | ||
module Game.Geometry.Cube where | ||
|
||
import Prelude -- We often don't need linearity here. | ||
import Ghengin.Core.Mesh.Vertex | ||
import Game.Geometry.Transform | ||
|
||
-- | A unit cube centered at (0,0,0). | ||
cube :: [Vertex '[Vec3]] | ||
cube = concatMap (`transform` square) | ||
[ translateV (vec3 0 0 (-0.5)) -- front face | ||
, rotateY pi <> translateV (vec3 0 0 0.5 ) -- back face | ||
, rotateY (pi/2) <> translateV (vec3 0.5 0 0 ) -- right face | ||
, rotateY (-pi/2) <> translateV (vec3 (-0.5) 0 0 ) -- left face | ||
, rotateX (-pi/2) <> translateV (vec3 0 0.5 0 ) -- top face | ||
, rotateX (pi/2) <> translateV (vec3 0 (-0.5) 0 ) -- bottom face | ||
] | ||
-- recall, matrix mult MVP order on CPU | ||
|
||
|
||
-- | A unit square centered at (0,0,0) along the YZ plane with its front side | ||
-- normal along the X coordinate axis (ie "facing forward"). | ||
square :: [Vertex '[Vec3]] | ||
square = Prelude.map Sin | ||
[ vec3 0.5 0.5 0 -- 1,6 | ||
, vec3 0.5 (-0.5) 0 -- 2 | ||
, vec3 (-0.5) (-0.5) 0 -- 3,4 | ||
, vec3 (-0.5) (-0.5) 0 -- 3,4 | ||
, vec3 (-0.5) 0.5 0 -- 5 | ||
, vec3 0.5 0.5 0 -- 1,6 | ||
] | ||
|
||
-------------------------------------------------------------------------------- | ||
-- * Colored | ||
|
||
type Color = Vec3 | ||
|
||
-- | A colored 'cube'. | ||
-- Note that color is in location=0, and position in location=1 | ||
coloredCube :: [Vertex '[Color, Vec3]] | ||
coloredCube = zipWith paint cube [1..] where | ||
paint face (ix::Int) | ||
-- every six vertices we get a new face | ||
| ix <= 6 = blue :& face | ||
| ix <= 6*2 = green :& face | ||
| ix <= 6*3 = yellow :& face | ||
| ix <= 6*4 = white :& face | ||
| ix <= 6*5 = orange :& face | ||
| ix <= 6*6 = red :& face | ||
| otherwise = error "unexpected vertice unit cube" | ||
|
||
white = vec3 0.9 0.9 0.9 | ||
yellow = vec3 0.8 0.8 0.1 | ||
orange = vec3 0.9 0.6 0.1 | ||
red = vec3 0.8 0.1 0.1 | ||
blue = vec3 0.1 0.1 0.8 | ||
green = vec3 0.1 0.8 0.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Game.Geometry.Transform | ||
( transform | ||
, module Geomancy.Transform | ||
, module Geomancy.Vec3 | ||
) | ||
where | ||
|
||
import Ghengin.Core.Mesh.Vertex | ||
import Geomancy.Vec3 | ||
import Geomancy.Transform | ||
|
||
-- | Transform a list of vertices. | ||
-- Use with functions re-exported from Geomancy.Transform | ||
-- | ||
-- Recall, from Geomancy's documentation: | ||
-- CPU-side matrices compose in MVP order, optimized for mconcat (local1 : local2 : ... : root) operation. | ||
-- GPU-side, in GLSL, it is PVM * v. | ||
transform :: Transform -> [Vertex '[Vec3]] -> [Vertex '[Vec3]] | ||
transform tr vs = [ Sin (v `apply` tr) | Sin v <- vs ] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ | |
|
||
ghcid --test "Main.main" --command "cabal repl --semaphore --ghc-options=-fno-ghci-sandbox $@" | ||
|
||
|