/* Just throws up a torus. Implemented Fall 2007 Scott D. Anderson */ #include #include GLdouble InnerRadius = 0.5; // If you slice through the torus to get a // circular section, this is the radius of // that circular cross-section. GLdouble OuterRadius = 2.0; // If you think of the torus as a circle, // it's the radius of the circle GLint Nsides = 5; // If you slice through the torus to get a // circular section, this is how many // sides that polygonal approximation has. GLint Rings = 3; // If you think of the torus as a // polygonal approx to a circle, this is // how many sides the polygon has. void display(void) { twDisplayInit(); twCamera(); glPushMatrix(); glTranslatef(-OuterRadius,0,0); // move left glutSolidTorus(InnerRadius,OuterRadius,Nsides,Rings); glTranslatef(OuterRadius*2.0,0,0); // move right glutWireTorus(InnerRadius,OuterRadius,Nsides,Rings); glPopMatrix(); glFlush(); glutSwapBuffers(); } void keys(unsigned char key, int x, int y) { switch(key) { case 'n': Nsides--; break; case 'N': Nsides++; break; case 'r': Rings--; break; case 'R': Rings++; break; case 'i': InnerRadius -= 0.1; break; case 'I': InnerRadius += 0.1; break; case 'o': OuterRadius -= 0.1; break; case 'O': OuterRadius += 0.1; break; } glutPostRedisplay(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(500,500); glutCreateWindow(argv[0]); glutDisplayFunc(display); twBoundingBox(-5,5,-5,5,-5,5); // 10x10x10 cube around origin twMainInit(); twKeyCallback('n',keys,"decrease Nsides"); twKeyCallback('N',keys,"increase Nsides"); twKeyCallback('r',keys,"decrease Rings"); twKeyCallback('R',keys,"increase Rings"); twKeyCallback('i',keys,"decrease InnerRadius"); twKeyCallback('I',keys,"increase InnerRadius"); twKeyCallback('o',keys,"decrease OuterRadius"); twKeyCallback('O',keys,"increase OuterRadius"); glutMainLoop(); return 0; }