Skip to main content
GameDev.net gamedev.net
🔒 Locked

Spherical problem. (help)

Started by Calexus Apr 19, 2004 at 2:47 AM 1 replies 550+ views
Original Post
Calexus
Calexus
Hi. I need some HELP! I’m trying to make a sphere class (for generating spheres) but I can’t get the vertexes in the right places. The closest thing I have been able to produce is some kind of distorted cylinder ting. Is there some kind person out there that can help me with this? (Please ^_^) I have the radius and the number of segments (horizontally and vertically) and I want to calculate all the vertexes and store them in an array. I would also like to have them in some kind of order, more exactly one plane at the time (all vertexes with the same y value) starting from the top and going downwards, or bottom to top. So if there are 16 horizontal segments then the first 16 indexes in the array would be the top or bottom and the next 16 would be the second layer and the next 16 the third and so on. If it’s not too much to ask for I would like not only a formula or some kind of source (preferably in c) but also an explanation so that I can figure out what I have been doing wrong. (I hope I posted this in the right forum )
Exitus Acta Probat
Atheist
Atheist
One method of rendering a sphere is to take spherical coordinates (r, alpha, beta) (distance from origin and two angles; nevermind the names), let r be constant (cause that´s more or less the definition of a sphere) and vary alpha=0...2pi, beta=0...pi (just as if you were filling a rectangle (0,0)->(2pi, pi) with smaller rectangles). Transform the spherical coordinates back to cartesian ones.

Another method which gives you triangles of equal size is to start with a tetragedron and the for each triangle (p1,p2,p3):
- find the center point p = (p1+p2+p3)/3
- scale it to your radius so it lies on your sphere: p = r*(p/|p|)
=> 3 new triangles (p1,p2,p), (p1,p,p2), (p, p2, p3).
- repeat this subdivision for you new triangles until your sphere looks smooth enough.

Sorry that I can´t go into detail now, but I´ve got to go now. Maybe the first option migt be better for you since I think it´s easier to implement. Look up "spherical coordinates" for it.
oliii
oliii
I''ve got some example for the icosahedron generation (it''s like a tetrahedron, but with 20 faces ). for texture mapping such a sphere, it''s different from a polar sphere. for a polar sphere, you''ll need a map, distorted at the poles, like the maps of earth you can find usually. For a tesselated icosahedron, it''s more like a flat map, and you map the original icosahedron vertices onto 2D triangles on the map. it''s more complicated
Everything is better with Metal.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.