#### Archived

This topic is now archived and is closed to further replies.

# OpenGL Sphere formula?

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

## Recommended Posts

I know this has come up alot of times, I did a search on ''sphere'' . My question is this. How does gluSphere decide how many vertices are going to be in any given sphere? There must be an algorithim, obviously. I need to know how the radius, stacks, and slices variables all relate to one another in the gluSphere function. The only problem is that I''m at a grade 10 math level, and I''d like a simple explination rather than ''look at this physics document that you won''t understand anyway''. Thanks in advance. -- Hornet

##### Share on other sites
What you want is called "sphere tesselation".

##### Share on other sites
quote:
Original post by mattbbangin
What you want is called "sphere tesselation".

Judging from their appearance OpenGL''s spheres aren''t generated using a standard tessellation algorithm.

Hornet: For a sorta-quick description of tessellation: Imagine an octahedron (an eight-sided three-dimensional figure. If you''ve ever seen an eight-sided die, it looks like that. If not, imagine two four-sided pyramids glued together at the base.)

Think of the octahedron as being formed by a number of lines connecting the vertices. Now, imagine you''re going to go from your octahedron to a new shape, one that looks a lot more like a sphere. To do this, you think about the lines connecting the vertices of your octahedron. In the middle of every line, you add a new vertex. You then connect the dots, like so:

Original
    *   / \  /   \ /     \*_______*

New!
    *   / \  v___v / \ / \*___v___*

The asterisks represent the original vertices, and the v''s represent new vertices.

Now, instead of placing these new vertices on the exact same planes as the old ones, move them away from the center of your polyhedron so that every vertex is the exact same distance from the center (this distance is the radius of your sphere.)

The result? Your octahedron now has 32 sides, and it looks a lot more like a sphere than it did before. Now, apply the process again - split the triangles into smaller triangles with new vertices placed at the midpoint of the line segments joining the previous vertices, then place them all the same distance from the center - and the result looks a whole, whole lot like a sphere.

You can re-apply the process as many times as you want (or for however long you''re willing to wait while the computer recalculates the object) to get a progressively smoother sphere. It only takes a couple iterations to get an extremely smooth looking sphere.

You can later optimize the result to make better use of the data.

It''s been a while since I looked, but I think OpenGL''s quadric spheres are formed out of squares, with the property that squares nearer to the "equator" are larger, and those nearer to the "poles" are smaller. If so, that''s probably not a desirable trait for virtually any application. They do, however, seem to get calculated quite quickly.

##### Share on other sites
Thanks alot for your replies, guys.

##### Share on other sites
Unit Sphere recursive tesselation from octahedron, icosahedron and tetrahedron code here: http://www.neubert.net/Htmapp/SPHEmesh.htm

##### Share on other sites
i need to get opengl for cs whrer can i get it

##### Share on other sites
ok i need help with counterstrike who ever plays cs knows that u can choose wut graphics u like : software , openGL , and some otehr 3d 1 but wheni choose openGL it says :

"The Specified Video Mode ..:: OpenGL ::.. is not supported. The Game Will Now Run In Software Mode."

pls someone help me i hate software mode cuse it lags so bad !!!
so pls reply to this msg someone and hlep me it pls and thankyou !

##### Share on other sites
Hornet. Think of a globe. Stacks would be the number of lines of lattitude (parallel to equator) and slices is the number of lines of longitude (running from north pole to south pole). Vertices are placed at the points of intersection.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 10
• 11
• 37
• 12
• 12
• ### Forum Statistics

• Total Topics
631414
• Total Posts
2999958
×