PDA

View Full Version : Questions about spheres



chronozphere
10-11-2006, 07:55 PM
Hi everyone :)

I am proud to say that i have implemented a sphere creation method in my engine, :D because i found it hard to set up the index/vertex data for a sphere.
But this mission is accomplished ;)

Now.. i have to questions:

A Sphere creation method normaly has 6 parameters.
The x,y,z coords for the center of the sphere. Of course the radius and two segment parameters.
The problem is, that i dont know how to call these last segment parameters.:( One represents the ammount of horizontal discs in which a sphere can be divided, and one repersents the ammount of segments around the sphere (like pieces of pie).:)
What are the common english names for these parameters??

Now i am looking for a few ways to generate the texture coordinates for a sphere. I have made a simple algorithm wich works OK with even numbers
but not with odds. :(
So does anyone know some good sphere texture mapping routines/algorithms??

Thanx in advance. ;)

grudzio
10-11-2006, 08:54 PM
The problem is, that i dont know how to call these last segment parameters
I call them sections and slices. Segments are the horizontal rings and slices vertical pieces. You can always look into any 3D modeler and check
how it calls them.


So does anyone know some good sphere texture mapping routines/algorithms??
Take a look here: http://www.codesampler.com/oglsrc/oglsrc_8.htm#ogl_textured_sphere

Clootie
11-11-2006, 02:43 AM
D3DXCreateSphere (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/D3DXCreateSphere.asp)
:roll:

cragwolf
11-11-2006, 05:35 AM
gluSphere (http://www.rush3d.com/reference/opengl-bluebook-1.0/ch06.html#id5560597)
:cyclops:

But I would rather understand the nuts and bolts of the process: constructing the sphere and then texture mapping it. This is the best online article (http://local.wasp.uwa.edu.au/~pbourke/texture/spheremap/) that I have found on the subject. Explore the rest of that guy's site, too, for more 3D algorithms and techniques. A similar site is here (http://freespace.virgin.net/hugo.elias/).

chronozphere
11-11-2006, 02:58 PM
@grudzio: Thank you for the parameter names. :)
I also like that website very much. :razz:

@Clootie:
I will not use D3DXCreateSphere in my engine because i make my own primitive/mesh classes.
I know it's a lot of work, but i am learning very much by doing that myself. :)

@Cragwolf:
Glusphere is not an option because i am using D3D. ;)
However, the texture-mapping algorithm in that article is quiet good. It will take some time though to implement it because of the differences between the ways of sphere creation.

Thank you all for your replies8).. i will post in this thread when i encounter any problems with sphere texture mapping. If anyone knows other ways to map a texture to a sphere, please post it. :)

LP
11-11-2006, 05:49 PM
An additional question on the topic: anyone knows how to create a 3dsMax-like geosphere? That is, a sphere with vertices and faces distributed equally and not squashed at both poles? Seems like a more efficient representation of a sphere with less vertex count and rounder look.

Look on the following screenshot, both spheres look more or less equally round, but sphere has 482 veritces and 960 faces (x2 tris?), while geosphere on the right has 252 vertices and 500 faces (x1 tris?). Besides, it seems easier to control the LOD of geosphere than the standard sphere. The question is, how to create vertices and triangles for geosphere?

http://img183.imageshack.us/img183/4511/sphereszk4.th.jpg (http://img183.imageshack.us/my.php?image=sphereszk4.jpg)

Nitrogen
11-11-2006, 06:09 PM
I looked up Geospheres a while ago, and from what I remember, there was a massive amount of math involved to calculate the positions for all the vertexes!

But dont quote me on that, my maths skills werent great in those days...

chronozphere
11-11-2006, 07:06 PM
Oh right.. 8) while creating the sphere code, i was also thinking of the geosphere. But making a normal sphere was very hard, so i dont know have a clue how to make a geosphere. I am sure it needs tons of math only to generate the vertices. :cry:
However its a good way to improve performance, so i like to know how to create them. :razz:

If anyone can give me a link to a page wich handles geospheres, i would be happy. :)

grudzio
11-11-2006, 08:01 PM
This is how I would make a geosphere.




Start with an octahedron (a regular solid with eight triangular faces)

for number of subdivisions do

for each face do
insert new vertices in the middle in each edge of current face
create triangle from new vertices. This way face is subdivided in
four new faces.
move new vertices outwards so they are on the sphere
end

end


It should not be very difficult to implement. The problem I see is that faces can share edges so it should be checked if the edge was already divided.
Another problem is the texture mapping. I dont know if methods for "normal" sphere will work for geosphere.

JSoftware
11-11-2006, 09:35 PM
Generating texture coordinates for a octahedron sounds trivial. For each step you would probably just interpolate the texture coordinates based on half the distance to each neighboring vertex?

chronozphere
11-11-2006, 09:58 PM
Great.. You're totally right. Its based on an octahedron. ;)

I will try to make a geosphere creation method. :)
Maybe i'll post some code when i'm done. If someone needs it. 8)

I am sure there is a good way to generate the texture-coords.. i will try to figure that out.

JSoftware
11-11-2006, 10:34 PM
http://img177.imageshack.us/img177/6340/geospherebq1.th.jpg (http://img177.imageshack.us/my.php?image=geospherebq1.jpg)

Made this right now. Subdividing is pretty simple and texture coordinates are easily interpolated if you use normal sphere mapping.
Vertex generation is simply interpolate each vertice in a triangle to generate new edge vertices and then normalizing each to get a unit vector which sits nicely on a sphere

grudzio
12-11-2006, 12:49 AM
Made this right now. Subdividing is pretty simple and texture coordinates are easily interpolated if you use normal sphere mapping.


The problem with sphere texture mapping is with the singularities on at the north and south pole. When you make sphere from rectangle the upper and lower edges are squashed to a point. So it is not obwious what texture coordinates should be chosen for both poles. Each triangle that owns such point needs different texture coordinate or there will be artefacts.

Normal sphere generation method solves this problem by creating for each vertical slice separate north and south pole (Look at the link Cragwolf gave).So those triangles near poles are not triangles but degenerated quads. It is easy then to set appopriate texture coordinates.

For geosphere, each triangle that contains south or north pole must have separate texture coordinate for that point. It is possible to do, but IMO not during the subdivision proccess.

JSoftware
12-11-2006, 12:55 AM
Finally I get your point.. I'll look for a workaround :P