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

Sphere Tesselation

Started by pikebu Nov 18, 2004 at 3:01 AM 4 replies 5.8k views
Original Post
pikebu
pikebu
hi, i have a sphere object, defined with a radius. now i need to draw it with gdi+. how can i calculate the polygons, to let the sphere look 3d? i need something like a function: tesselateSphere(int detaillevel); the higher the detaillevel, the more polygons are generated and the sphere looks more realistic. hope that someone of your math gurus out there can help me out. pikebu
oliii
oliii
to have a nicely tessalated sphere, you've got to use geodesic spheres.

I start mine with icosahedrons. You can start them with other volumes as well.

http://www.vb-helper.com/howto_geodesic_sphere.html

for each triangles of the icosahedron, you take the midpoints of every edges, and generate segments between them. That should split your triangle into 4 identical triangles.

keep doing that, and you have your tesselation and levels of detail.

to get you started, here is an icosahedron mesh

enum { eNumVertices = 12, eNumTriangles = 20, eNumEdges = 30 };const float a = (float) sqrt(2.0f/(5.0f + sqrt(5.0f)));const float b = (float) sqrt(2.0f/(5.0f - sqrt(5.0f)));Vector vertices[eNumVertices] = {	Vector(-a, 0.0f, b), Vector(a, 0.0f, b), Vector(-a, 0.0f, -b), Vector(a, 0.0f, -b),	Vector(0.0f, b, a), Vector(0.0f, b, -a), Vector(0.0f, -b, a), Vector(0.0f, -b, -a),	Vector(b, a, 0.0f), Vector(-b, a, 0.0f), Vector(b, -a, 0.0f), Vector(-b, -a, 0.0f)};unsigned short Tris[eNumTriangles][3] = {	{ 1,  4, 0 }, {  4, 9, 0 }, { 4, 5,  9 }, { 8, 5,  4 }, { 1, 8,  4 },	{ 1, 10, 8 }, { 10, 3, 8 }, { 8, 3,  5 }, { 3, 2,  5 }, { 3, 7,  2 },	{ 3, 10, 7 }, { 10, 6, 7 }, { 6, 11, 7 }, { 6, 0, 11 }, { 6, 1,  0 },	{ 10, 1, 6 }, { 11, 0, 9 }, { 2, 11, 9 }, { 5, 2,  9 }, { 11, 2, 7 }};

Everything is better with Metal.
pikebu
pikebu
thanks for the answer,

but how can i tesselate a sphere without the mesh data?
i only have the radius value, that's all.
there should be an algorithm like:
get points from sphere with detaillevel x,
then use these points to tesselate
LilBudyWizer
LilBudyWizer
A parametric equation for a sphere is x=r*cos(s)*sin(t), y=r*sin(s)*sin(t) and z=r*cos(t) where 0<=s<=2*pi and 0<=t<=pi.
Keys to success: Ability, ambition and opportunity.
Charles B
Charles B
click search, then use the Gamedev Google. It's been discussed so many times here. Note the new keywords, like geodesic, then search more on the whole www possibly. I am not bashing you, it's what I do on my own, when I am noob on one subject.

Also do it first, before asking, anytime you are searching for an answer on a very generic subject like this one. Then you'll maybe have more questions to ask, but they will be more specific and interesting to guys like Oiii or me or any other long timer here.
"Coding math tricks in asm is more fun than Java"
oliii
oliii
Quote:
Original post by pikebu
thanks for the answer,

but how can i tesselate a sphere without the mesh data?
i only have the radius value, that's all.
there should be an algorithm like:
get points from sphere with detaillevel x,
then use these points to tesselate


not sure I understand...

the template tetrahedron, which is a 20-faced volume that approximate a sphere, has a radius of 1, and centred at (0, 0, 0). multiply a and b by the radius you want...

the tetrahedron is basically detail level 0. the roughest level of detail. the vector list define the corners of the tetrahedron. the indices define the triangles (index list).

to tessalate to get level of detail 1, you just take the midpoint of edges and link them together to form triangles. That will give you the mesh for level of detail 1.

level of detail 1 will have exactly 4 times rthe amount of triangle of LOD 1.

for LOD2, same algo with the edges of LOD1. ect...

if you don't want to use a index list, just vertex list, it's simple enough to generate the triangles from the terahedron. from there, it's even more easier, since you don't have to keep track of edges.
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.