Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Could someone please explain how it would be possible to create a sphere vertices, indices and texture coordinates? There is a surprising lack of documentation on how to do so and it is something that I am interested in learning.

I have tried the obvious, googling, looking on gamedev.net, etc. However, nothing covers the generations of spherical points, indexing them, and texturing.

share|improve this question
5  
I am not going to downvote or vote to close this, but are you really telling me that not a single result from google.com/search?q=how+to+generate+a+sphere+vertices was useful? If that's the case you'll need to explain what your problem is in more detail. – Joe Wreschnig Aug 30 '11 at 4:25
Ta da : visualizationlibrary.org/documentation/… – Daniel Aug 30 '11 at 4:52
Search for icosphere. Much smarter than dumb "polar sphere" which produces useless faces. – Notabene Aug 30 '11 at 7:07
1  
Worth noting, for some simple purposes a perfectly fine "sphere" is a quad with a circular texture facing the camera. – eBusiness Aug 30 '11 at 20:10

2 Answers

There are two general approaches:

enter image description here

The leftmost is termed the uv-sphere and the rightmost an icosphere.

GLUT tends to use the uv approach: look at the function glutSolidSphere() in the freeglut sourcecode.

Here is an excellent article on producing an icosphere: http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html

The uv-sphere looks like a globe. For many purposes it is perfectly fine, but for some use cases, e.g. if you want to deform the sphere, it is disadvantageous that the density of vertices is greater around the poles. Here the icosphere is better, its vertices are distributed evenly.

You may also find this interesting: http://kiwi.atmos.colostate.edu/BUGS/geodesic/text.html it describes an approach to organising the faces into zones.

http://vterrain.org/Textures/spherical.html gives an excellent description of how you might choose to texture them.

share|improve this answer
2  
While the general idea is good, subdividing a Schläfli {3,5} polytope isn't the only way to do it. Generally, I prefer to work with the Schläfli {4,*} family ({4,3} in case of a sphere) for UV-mapping purposes. – Martin Sojka Aug 30 '11 at 8:47

If the points don't have to be locally uniform, but should be globally uniform, and don't have to follow any set pattern, you can use a variant of dart-throwing algorithm to distribute n points on a sphere with radius r, on average dist points apart. These values are then roughly:

  1. If you want to have a specific amount of vertices:
    • n = (desired amount of vertices)
    • dist = 2 × r × √(π / n)
  2. If you want to have a specific average distance between the vertices:
    • n = 4 × π × (r / dist)2
    • dist = (desired average distance)

In the simplest case, you can then uniformly pick points at random by picking two uniformly distributed variables u and v from (0, 1) and calculating the polar coordinates from them according to the formulas θ = 2 × π × u and ϕ = arc cos (2 × v - 1); then dismissing any points which lie too near to the already picked points. For a slightly more complex and significantly better-performing algorithm, see "Dart Throwing on Surfaces" by Cline, Jeschke, White, Razdan and Wonka.

After you picked your first four points (assuming no three of them are degenerate, that is - they don't lie on the same great circle, but that's highly unlikely), you can create four faces between them, and each time you add a new point, you can split the face it belongs to accordingly into three sub-faces.

For texturing purposes you can then map the points to a cube map.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.