// OpenGL program that draws simple cart consisting of two red wheels // positioned at the ends of a green axis. // The program uses hierarchical display lists to model the cart. // // File: circ.cpp // Date: 2/16/2001 #include #include #include #include // display lists identifiers #define WHEEL 1 #define CART 2 // modeling constants #define NUM_SLICES 24 #define WHEEL_RAD 20.0 #define TH_FRONT 20.0 #define TH_BACK 10.0 #define HALF_AXIS_LENGTH 75.0 //prototypes void myinit(); // OpenGL init void display(); // display callback void myreshape(GLsizei, GLsizei); // reshape callback void drawUnitCircle(int num_slices);// approximate unit circle void defineParts(void); // defines the display lists /****************/ /***** MAIN *****/ /****************/ int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("stationary cart"); myinit(); glutReshapeFunc(myreshape); glutDisplayFunc(display); glutMainLoop(); return 0; } /********************************/ /***** FUNCTION DEFINITIONS *****/ /********************************/ /*****************************************************************/ // OpenGL init /*****************************************************************/ void myinit() { glClearColor(1.0,1.0,1.0,0.0); // white glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-225.0, 225.0, -225, 225.0); // origin at center of 500x500 clip window glMatrixMode(GL_MODELVIEW); defineParts(); } /*****************************************************************/ // Approximates the unit circle with a polyline going through // num_slices points /*****************************************************************/ void drawUnitCircle(int num_slices) { double thetaincr=2*(double)(22.0/7)/num_slices; // the angle per sector double th=0.0; // angle used to generate // the angle used to generate the points // approximate unit circle with this glBegin(GL_LINE_LOOP); for (int i=0; i