• Advertisement

Archived

This topic is now archived and is closed to further replies.

Sphere Mapping?

This topic is 5925 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know how Sphere Mapping works? If i want to Render my own Generated Model! Everytime when i try to Render an Object of my Own ... the sphere Mapped Texture doesnt''t look Correctly, do i have to Look how my Triangle Lists are Sorted? I have calculated my Normal Vectors but it doesnt look great when i put on the Light, I can see every TriangeEdge and it isn''t really smooth ...

Share this post


Link to post
Share on other sites
Advertisement
void CreateSphere(fVect c,float r,int n,
float theta1,
float theta2,
float phi1,
float phi2)
{
int i,j;
float t1,t2,t3;
fVect e,p;

/* Handle special cases */

if (r < 0) r = -r;
if (n < 0) n = -n;
if (n < 4 || r <= 0)
{
glBegin(GL_POINTS);
glVertex3f(c[0],c[1],c[2]);
glEnd();
return;
}

glBegin(GL_TRIANGLE_STRIP);

for (j=0;j {

t1 = phi1 + j * (phi2 - phi1) / (n/2);

t2 = phi1 + (j + 1) * (phi2 - phi1) / (n/2);


for (i=0;i<=n;i++)
{

t3 = theta1 + i * (theta2 - theta1) / n;

e[0] = cos(t1) * cos(t3);
e[1] = sin(t1);
e[2] = cos(t1) * sin(t3);
p[0] = c[0] + r * e[0];
p[1] = c[1] + r * e[1];
p[2] = c[2] + r * e[2];

glNormal3f(e[0],e[1],e[2]);
glTexCoord2f(i/(float)n,2*j/(float)n);
glVertex3f(p[0],p[1],p[2]);

e[0] = cos(t2) * cos(t3);
e[1] = sin(t2);
e[2] = cos(t2) * sin(t3);
p[0] = c[0] + r * e[0];
p[1] = c[1] + r * e[1];
p[2] = c[2] + r * e[2];

glNormal3f(e[0],e[1],e[2]);
glTexCoord2f(i/(float)n,2*(j+1)/(float)n);
glVertex3f(p[0],p[1],p[2]);

}
}
glEnd();
}

try this , call like that

where c is the centre,r the radius

CreateSphere( c,5,r,0,2*__PI,-__PI/2,__PI/2);


Share this post


Link to post
Share on other sites

  • Advertisement