Sphere

Started by
5 comments, last by Lode 18 years, 7 months ago
How to make a sphere out of triangles, and map a texture on it in a good way?
Advertisement
In what context? Is this a sphere you intend to load in modeling software to compose with other models? Is it something you want to render yourself in your own application? If so, what formats does you application support? What kind of modeling software do you want to use to generate the sphere and the texture?
It's one I want to render myself in OpenGL (but this applies for D3D too). I remember there's a built in sphere drawing thing in some extension of OpenGL, however I'd like to try to do it myself, to work my way to more complex sphere based shapes that way.

All of this is in the preparation for some fancy thing I'm making :)
The built-in sphere is in GLU I believe, something with gluQuadric. If you want to generate a sphere yourself there are two approaches:

1) A sweep algorithm which sweeps a vertical meridian around the sphere, if you know what I mean. This produces a sphere with a vertex at the top and at the bottom tips.

2) An approximation algorith which starts with a simpler sphere approximation and refines it. The approximation is usually an isocahedron or a twenty-sided regular polyhedron. The appriximation can be done by replacing each triangle by three new and smaller triangles and displacing the vertices -- this is done by knowing each vertex has unit distance to the origin.

The latter produces a sphere with equal-sized triangles which is nice in many cases (for example a skydome).

If you use google on either you will find code for either eventually. I did a while a go and it took some time but eventually I found it. Of course I did not bother to save it...

[EDIT: but I found it again]

Greetz,

Illco
Nice, and I love ascii drawings in C++ comments :)
Sphere with texture coordinates
I made the sphere using the same system as in the link http://www.neubert.net/Htmapp/SPHEmesh.htm that was posted here. I recursively break it up into triangles.

Without texturing, this is very easy and fast.

With textures, I found no other way to do it than to calculate the texture coordinates based on the angles and locations the vertices of the triangles have at the moment the triangle is going to be drawn in the recursive function. This makes it a lot slower however, because now it's calculating 3 texture coorinates at the end of each recursion, and each calculations involves dot products, acos functions, normalizations and so on.

So it works perfect, but is not very fast. (with recursion depth 5: almost 200 fps with no texturing, only 40 fps with texturing)

Is there a faster way to do the texturing when drawing the sphere this way? I like it a lot more than the type of sphere drawn in this article http://astronomy.swin.edu.au/~pbourke/opengl/sphere/ or by gluQuadratic.

This topic is closed to new replies.

Advertisement