# OpenGL Sphere 2 mouth

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

## Recommended Posts

So I got this opengl code to build a simple sphere:
void RenderSolidSphere(double radius, int slices, int stacks)
{

double z0 = 0.0, z1 = 0.0, r0 = 0.0, r1 = 0.0;

/* Pre-computed circle. */
double* sint1 = NULL, * cost1 = NULL;
double* sint2 = NULL, * cost2 = NULL;
CircleTable(&sint1, &cost1, -slices);
CircleTable(&sint2, &cost2, stacks * 2);

/* The top stack is covered with a triangle fan. */

z0 = 1.0;
z1 = cost2[1];
r0 = 0.0;
r1 = sint2[1];

glBegin(GL_TRIANGLE_FAN);
for (int j = slices; j >= 0; --j)
{
glNormal3d(cost1[j] * r1, sint1[j] * r1, z1);
}
glEnd();

/* Cover each stack with a quad strip, except the top and bottom stacks. */

for (int i = 1; i < stacks - 1; ++i)
{
z0 = z1; z1 = cost2[i + 1];
r0 = r1; r1 = sint2[i + 1];

for(int j = 0; j <= slices; ++j)
{
glNormal3d(cost1[j] * r1, sint1[j] * r1, z1);
glNormal3d(cost1[j] * r0, sint1[j] * r0, z0);
}
glEnd();
}

/* The bottom stack is covered with a triangle fan. */

z0 = z1;
r0 = r1;

glBegin(GL_TRIANGLE_FAN);
for (int j = 0; j <= slices; ++j)
{
glNormal3d(cost1[j] * r0, sint1[j] * r0, z0);
}
glEnd();

/* Release sin and cos tables. */
free(sint1);
free(cost1);
free(sint2);
free(cost2);

return;
}


And I was using it to render a simple 3D yellow "Pac Man". Now with the game logic complete, I was looking to improve the graphics. Is it possible to "cut out" a wedge from the sphere, thus forming pac man's mouth??? If so, how would I go about this? Example code? Thanks in advance...

##### Share on other sites
Either model a mesh in a 3d package (you are going to want to do that if you want to model the eyes or to put legs on pacman or whatever anway)

If you are going to really just make him a sphere with a wedge cutout and use texture maps only for the eyes, then you should be able to pretty easily run the sphere code and then simply alter the existing shape after making it. Try altering your rendering code to put the verticies into a buffer. Also, remove the sin/cos table making, it's really not needed on modern CPUs and you will make a HUGE performance increase by caching the results of the actually sphere generation rather than the trig functions. Then simply modify the verticies of the mouth by scaling them about the center of the sphere.

##### Share on other sites
Of course I am using an opengl list!!! And little little little spheres for the eyes!

list[4] = list[0] + 4;
glNewList(list[4], GL_COMPILE);
RenderSolidSphere(0.2, 16, 16);
glEndList();

I just want to cut out a wedge for the mouth.

##### Share on other sites
dont draw all the slices (perhaps segments is a better term as in cheese segments)

##### Share on other sites
the library of glut or aux has some function to slice sphere, if I remember correctly. You should look into the info.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 30
• 9
• 16
• 22