Skip to content

Instantly share code, notes, and snippets.

@TheSeamau5
Created December 18, 2014 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheSeamau5/b888b9cccaf75c8cf77c to your computer and use it in GitHub Desktop.
Save TheSeamau5/b888b9cccaf75c8cf77c to your computer and use it in GitHub Desktop.
Tried to make a sphere and all I got was this bug
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