void GLOBJECT::sphereuvsN(void)
{
GLUV *uv;
GLNORMAL *norm;
unsigned int x;
const double oopi = 1.0/M_PI;
const double oo2pi = 1.0/(M_PI*2.0);
uvs = uv = curr_uv;
norm = normals;
for (x = 0; x < v_count; x++, norm++)
{
double s;
uv->v = acos(norm->z) * oopi;
s = sin(uv->v * M_PI);
if (s>0.0)
{
if (norm->y >= 0.0)
uv->u = acos(norm->x / s) * oo2pi;
else
uv->u = (M_PI + acos(norm->x / s)) * oo2pi;
}
else
{
uv->u = 0.5;
}
uv++;
}
curr_uv = uv;
}
Here's a snippet from the pumpkin engine. It computes uvs for spheres, but in fact it'll work for any shape. The norm array is the normals at the vertices. For spheres this is simple as the normal is the same as the position. It calculates 2d points between 0 and 1.
Post if there's anything you don't understand. I'm just being lazy by c&ping the code in.
Jim