/* object.c */ /* E. Angel, Interactive Computer Graphics */ /* A Top-Down Approach with OpenGL, Third Edition */ /* Addison-Wesley Longman, 2003 */ /* Modified my D. Vrajitoru */ /* displays various glu objects */ #include #include #include "trackball.h" GLUquadricObj *obj; //static GLfloat theta[] = {0.0,0.0,0.0}; //static GLint axis = 2; static GLfloat trans[] = {0.0,0.0,1}; int winWidth=500, winHeight=500; void display() { /* display callback, clear frame buffer and z buffer, rotate object and draw, swap buffers */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(0, 0, 3.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glPopMatrix(); applyRotation(); glPushMatrix(); glTranslatef(trans[0], trans[1], 0); glScalef(trans[2], trans[2], trans[2]); // glRotatef(theta[0], 1.0, 0.0, 0.0); // glRotatef(theta[1], 0.0, 1.0, 0.0); // glRotatef(theta[2], 0.0, 0.0, 1.0); //glScalef(1.2, 1.0, 0.8); /* glutWireIcosahedron();*/ /* glutWireDodecahedron();*/ // gluSphere(obj, 1.0, 12, 12); /* gluCylinder(obj, 1.0, 0.5, 1.0, 12, 12); */ glPushMatrix(); glRotatef(90, 1.0, 0, 0); glTranslatef(0, 0, 0.75); gluDisk(obj, 0, 10.0, 20, 20); glPopMatrix(); /* gluPartialDisk( obj, 0.5, 1.0, 10, 10, 0.0, 45.0);*/ glutWireTeapot(1.0); //glutWireTorus(0.5, 1.0, 10, 10); /* glutWireCone(1.0, 1.0, 10, 10);*/ glutSwapBuffers(); } /* Old version void spinObject() { // Idle callback, spin cube 2 degrees about selected axis theta[axis] += 1.0; if( theta[axis] > 360.0 ) theta[axis] -= 360.0; glutPostRedisplay(); } */ /* Old version void mouse(int btn, int state, int x, int y) { // mouse callback, selects an axis about which to rotate if (state == GLUT_DOWN) glutIdleFunc(spinObject); else glutIdleFunc(NULL); switch (btn) { case GLUT_LEFT_BUTTON: axis = 0; break; case GLUT_MIDDLE_BUTTON: axis = 1; break; case GLUT_RIGHT_BUTTON: axis = 2; } } */ void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90.0, w/h, 2.0, 40.0); /* if (w<=h) glFrustum(-10.0, 10.0, -10.0 * (GLfloat) h/ (GLfloat) w, 10.0* (GLfloat) h / (GLfloat) w, -10.0, 20.0); else glFrustum(-10.0, 10.0, -10.0 * (GLfloat) w/ (GLfloat) h, 10.0* (GLfloat) w / (GLfloat) h, -10.0, 20.0); */ glMatrixMode(GL_MODELVIEW); winWidth = w; winHeight = h; } void key(int key, int x, int y) { switch (key) { case GLUT_KEY_LEFT: trans[0] -= 0.1; break; case GLUT_KEY_RIGHT: trans[0] += 0.1; break; case GLUT_KEY_UP: trans[1] += 0.1; break; case GLUT_KEY_DOWN: trans[1] -= 0.1; break; case GLUT_KEY_PAGE_UP: trans[2] += 0.1; break; case GLUT_KEY_PAGE_DOWN: trans[2] -= 0.1; } display(); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutCreateWindow("object"); /* need both double buffering and z buffer */ glutReshapeFunc(myReshape); glutDisplayFunc(display); glutIdleFunc(spinObject); glutMouseFunc(mouseButton); glutMotionFunc(mouseMotion); // glutKeyboardFunc(key); glutSpecialFunc(key); glClearColor(1.0, 1.0, 1.0, 1.0); glColor3f(1.0, 0.0, 0.0); obj = gluNewQuadric(); gluQuadricDrawStyle(obj, GLU_LINE); glutMainLoop(); }