# sphere generation

This topic is 4447 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to write an algorithm that will create vertex and indice data including texcoords, coords, normals. It should be triangle based. I suppose the only difficulty is the index buffer, obtaining a decent way of connecting the points. Anybosdy know of some links on the subject I couldnt find anything in Google. -CProgrammer

##### Share on other sites
I've done that before. It wasn't the easiest thing to do, but it worked. The problem with generating a sphere is the texture coordinates and the index buffer.

You should definately start with generating a sphere with just position/normals. You may need to brush up on some vector math.

//Position/Normal
Start with a low vector and a high vector (start them both at (0, 1, 0)). Rotate the low vector down a little. (a)Then rotate both vectors around. Then rotate both vectors down. While the low vector is not pointing straight down, goto (a).
Now when you switch over to a indexed tris, you only need to go around with one vector because you generate the triangles with indices.

Each vector will should stay normalized (but you may need to renormalize due to floating point error). Position = Normal in this setup.

//Texture coords
There are a couple ways to texture a sphere. The way I did it, basically wrap a cylinder around the sphere, and then fold the top into the north pole and fold the bottom into the south pole.
These will never look right unless you use a texture that was made to go on a sphere. At the north and south pole of your sphere, you will see a spiral effect because each pole is actually used for every value of the texture coordinate u. Also, you will have to replicate the seem. As the u coord. goes around, it must end at the same position it started, but the texture coordinate must be 0 when it starts and 1.0 when it ends.
I just use a little match to get these. Say you are generating 10 horizontal sections, just increment u by 0.1 each time you rotate the vectors around.

//Indices
These sucked. If you are indexing, it makes generating positions/normals very easy, but now you have a completely different loop that has to go around and generate indices. You have to remember what index is "above" and which one is to the "right", and don't forget about the seem.

Good luck.

##### Share on other sites
Thanks for the reply.

This is going to be fun.

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
frob
13

• 12
• 9
• 31
• 16
• 9
• ### Forum Statistics

• Total Topics
632612
• Total Posts
3007424

×