Created
December 18, 2014 02:29
-
-
Save TheSeamau5/b888b9cccaf75c8cf77c to your computer and use it in GitHub Desktop.
Tried to make a sphere and all I got was this bug
This file contains hidden or 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
sphereMesh : Int -> Vec3 -> Float -> Mesh | |
sphereMesh tesselation center radius = | |
let normalize = (flip (/)) (toFloat tesselation) | |
shift = (+) -0.5 | |
scale = (*) (2 * radius) | |
transform = normalize >> shift >> scale | |
latitudes = map transform (map toFloat [0..tesselation]) | |
longitudes = latitudes | |
plotPoint longitude latitude = | |
let cosLatitude = cos (pi * latitude / (toFloat tesselation)) | |
cosLongitude = cos (2 * pi * longitude / (toFloat tesselation)) | |
sinLatitude = sin (pi * latitude / (toFloat tesselation)) | |
sinLongitude = sin (2 * pi * longitude / toFloat tesselation) | |
x = radius * sinLatitude * cosLongitude | |
y = radius * sinLatitude * sinLongitude | |
z = radius * cosLatitude | |
in vec3 x y z | |
makeHorizontalPoints longitude = | |
map (plotPoint longitude) latitudes | |
levels = | |
map makeHorizontalPoints longitudes | |
connectLevels level1 level2 = | |
case level1 of | |
[] -> [] | |
x :: [] -> [] | |
x1 :: x2 :: xs -> | |
case level2 of | |
[] -> [] | |
y :: [] -> [] | |
y1 :: y2 :: ys -> | |
rectangleMesh x1 x2 y1 y2 ++ connectLevels xs ys | |
bodyFaces = | |
concat <| map2 connectLevels levels (tail levels) | |
in bodyFaces |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment