11-01-2002, 04:35 PM
Hey,
I have a function that draws an egg, but I would like to add some dark spots to it.
I am first of all having problems finding a good way to describe where do I want the spots to be (oh they must have variable radius too) and the of course coding it.
If you could give moe some hints that could help me get started I would really appreciate.
Thanks
Joan
void egg()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
int lt, lg, numLatitudes=16, numLongitudes=16;
double x,y,z,r=10,rscale=1.5,deform=1.5;
glPushMatrix();
glRotatef(90.0,0.0,1.0,0.0);
//////////1
int jj;
for(lt=0; lt<numLatitudes/2; lt++)
{
glBegin(GL_QUAD_STRIP);
for(lg=0; lg<=numLongitudes; lg++)
{
for (jj=0; jj<=1;jj++){
z = sin(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)*rscale*deform;
r = cos(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)*rscale;
x = cos(2*PI*lg/(double) numLongitudes)*r;
y = sin(2*PI*lg/(double) numLongitudes)*r;
glNormal3f(x,y,z);
glVertex3f(x,y,z);
}
}
glEnd();
}
///////////2
for( ; lt<numLatitudes; lt++)
{
glBegin(GL_QUAD_STRIP);
for(lg=0; lg<=numLongitudes; lg++)
{
for (jj=0; jj<=1;jj++){
z = sin(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)*rscale;
r = cos(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)*rscale;
x = cos(2*PI*lg/(double) numLongitudes)*r;
y = sin(2*PI*lg/(double) numLongitudes)*r;
glNormal3f(x,y,z);
glVertex3f(x,y,z);
}
}
glEnd();
}
glPopMatrix();
}
I have a function that draws an egg, but I would like to add some dark spots to it.
I am first of all having problems finding a good way to describe where do I want the spots to be (oh they must have variable radius too) and the of course coding it.
If you could give moe some hints that could help me get started I would really appreciate.
Thanks
Joan
void egg()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
int lt, lg, numLatitudes=16, numLongitudes=16;
double x,y,z,r=10,rscale=1.5,deform=1.5;
glPushMatrix();
glRotatef(90.0,0.0,1.0,0.0);
//////////1
int jj;
for(lt=0; lt<numLatitudes/2; lt++)
{
glBegin(GL_QUAD_STRIP);
for(lg=0; lg<=numLongitudes; lg++)
{
for (jj=0; jj<=1;jj++){
z = sin(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)*rscale*deform;
r = cos(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)*rscale;
x = cos(2*PI*lg/(double) numLongitudes)*r;
y = sin(2*PI*lg/(double) numLongitudes)*r;
glNormal3f(x,y,z);
glVertex3f(x,y,z);
}
}
glEnd();
}
///////////2
for( ; lt<numLatitudes; lt++)
{
glBegin(GL_QUAD_STRIP);
for(lg=0; lg<=numLongitudes; lg++)
{
for (jj=0; jj<=1;jj++){
z = sin(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)*rscale;
r = cos(PI*(lt+jj)/((double) (numLatitudes-1))-PI/2.0f)*rscale;
x = cos(2*PI*lg/(double) numLongitudes)*r;
y = sin(2*PI*lg/(double) numLongitudes)*r;
glNormal3f(x,y,z);
glVertex3f(x,y,z);
}
}
glEnd();
}
glPopMatrix();
}