PDA

View Full Version : Surface of Revolution advanced

sdwwq
09-11-2008, 07:42 PM
Hey i want to draw a half egg in opengl (it a basket)
the egg should be hollow not solid.

this is my code when i draw this i get half hollow and half filled.
any help??

double x,y,z,r;
for(int longCount=0; longCount<NUM_LONGITUDINAL_VERTICES; longCount++){ // along z axis
for(int latCount=0; latCount<NUM_CIRCUMFERENTIALL_VERTICES; latCount++){ // x and y

z = sin(Pi*latCount/((double) (NUM_CIRCUMFERENTIALL_VERTICES-1))-Pi/2.0f);
r = cos(Pi*latCount/((double) (NUM_CIRCUMFERENTIALL_VERTICES-1))-Pi/2.0f);
x = (cos(Pi*longCount/(double) (NUM_LONGITUDINAL_VERTICES-1))*r);
y = (sin(Pi*longCount/(double) (NUM_LONGITUDINAL_VERTICES-1))*r);

vertices[longCount][latCount][0] = x; //x
vertices[longCount][latCount][1] = y; //y
vertices[longCount][latCount][2] = z; //z
}
}

trinitrotoluene
09-12-2008, 06:42 AM
The easy way to get the image you want is this:

glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
for(int latCount=0; latCount<Latitudes-1; latCount++)
{ // along z axis
for(int longCount=0; longCount<Longitudes; longCount++){
glVertex3f(vertices[latCount][longCount][0], vertices[latCount][longCount][1], vertices[latCount][longCount][2]);
glVertex3f(vertices[latCount+1][longCount][0], vertices[latCount+1][longCount][1], vertices[latCount+1][longCount][2]);
}
glEnd();
}

But this is not performance optimal.

sdwwq
09-12-2008, 04:34 PM
what a legend :)
thanks boss