Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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.

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.

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 this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!