#include #include #include #include using namespace std; int n; int xrot, yrot, zrot; bool doubleBuffer; void TeaPot() { float color[] = {1.0, 0.0, 0.0, 1.0}; glColor3f(1.0,0.0,0.0); float r, theta, phi; float sx, sy, sz, ex, ey, ez; float delta = 2*M_PI/(n); theta = M_PI /2.0; glBegin(GL_LINES); for(phi=0; phi<=M_PI*2; phi+= delta) { for(theta=0;theta<=M_PI*2;theta+= delta){ sx = cos(theta)*sin(phi); sy = sin(theta)*sin(phi); sz = cos(phi); ex = cos(theta+delta)*sin(phi); ey = sin(theta+delta)*sin(phi); ez = cos(phi); glVertex3f(sx, sy, sz); glVertex3f(ex, ey, ez); ex = cos(theta)*sin(phi+delta); ey = sin(theta)*sin(phi+delta); ez = cos(phi+delta); glVertex3f(sx, sy, sz); glVertex3f(ex, ey, ez); } } glEnd(); } void Axis() { glColor3f(1.0,0,0); glBegin(GL_LINES); glVertex3f(-3,0,0); glVertex3f(3,0,0); glColor3f(0,1,0); glVertex3f(0,-3,0); glVertex3f(0,3,0); glEnd(); } void display() { glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); // Axis(); glPushMatrix(); glRotatef(xrot,1,0,0); glRotatef(yrot,0,1,0); glRotatef(zrot,0,0,1); TeaPot(); glPopMatrix(); if(doubleBuffer) { glutSwapBuffers(); } else { glFlush(); } } void myinit() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2.0,2.0,-2.0,2.0,-2.0,2.0); glMatrixMode(GL_MODELVIEW); glClearColor(1.0,1.0,1.0,1.0); glColor3f(0.0,0.0,0.0); } void keypress(unsigned char c, int x, int y) { switch (c) { case 'q': exit(0); } display(); } void idle(void){ xrot += 1; yrot += 3; zrot -=1; xrot=xrot%360; yrot=yrot%360; zrot=zrot%360; display(); } int main (int argc, char ** argv) { int i; doubleBuffer = true; for(i=1;i