Generating spheres vertices, indices and normals?

Viewed 2058

I am making a game in LWJGL and I am trying to make a procedurally generated planet (This question doesn't necessarily have to do with procedural terrain generation I know how to do it on a plane I assume it would be somewhat similar). My question is how do I programmatically generate a sphere with vertices, indices and normals and have the origin in the middle. I have looked around on the internet and could only find ways of generating the vertices. I am not asking for you to write the code but I would like a push in the right direction or some resources on doing so. The reason I want to generate my own sphere versus just importing one from a model is so I can easily edit the vertices height to make terrain, change the size of the sphere as well as easily change the poly count. My idea on how to do this is the following.

Get a vertex count of how many vertices should make up the circumference (Higher the number the higher the poly). Divide that number by 360 and then every triangle would be rotated by that number making a circle. And then gradually make the rest of the sphere using the same method. If this is the correct way of doing it how would I determine the indices and normals?

or

Get the vertex count and radius that the sphere should be from the origin. Determine the amount each triangle should be rotated. Start with two triangles on top at a the specified angle and world out from there until it reaches have way down the sphere at the same angle and then inverse the angle and have it finish the bottom in the same way. But again i'm not sure how to generate the indices, or normals.

2 Answers
Related