/* draw_arc.cpp * This program demonstrates the drawing of an arc. * Click the right button to exit. */ #include << X11/Xlib.h> #include << fstream.h> #include << math.h> #include << GL/glut.h> #include << GL/gl.h> #include << stdlib.h> #include << stdio.h> #include "Canvas.h" const int numVerts = 6; const double radius = 2.0; const double worldWidth = 4.0; const double worldHeight = 3.0; const int screenWidth = 640; const int screenHeight = 480; Canvas cvs(screenWidth, screenHeight, "Try out Canvas"); void myInit(void) { cvs.setBackgroundColor (1.0, 1.0, 1.0); // set black background color cvs.setColor (0.0, 0.0, 0.0); // set the drawing color glPointSize (4.0); // set dot size 2 x 2 } void drawArc(Point2 center, float radius, float startAngle, float sweep) { // startAngle and sweep are in degrees const int n = 40; // number of intermediate segments in arc float angle = startAngle * 3.14159265 / 180; // initial angle in radians float angleInc = sweep * 3.14159265 /(180 * n); // angle increment float cx = center.getX(), cy = center.getY(); cvs.moveTo(cx + radius * cos(angle), cy + radius * sin(angle)); angle += angleInc; for(int k = 0; k < n; k++, angle += angleInc) cvs.lineTo(cx + radius * cos(angle), cy + radius * sin(angle)); } void myDisplay(void) { Point2 p; cvs.clearScreen(); // clear the screen cvs.setWindow(-worldWidth, worldWidth, -worldHeight, worldHeight); cvs.setViewport(0, screenWidth, 0, screenHeight); p.set(0.0, 0.0); drawArc(p, radius, 30.0, 200.0); } void myMouse(int button, int state, int x, int y) { switch (button) { case GLUT_RIGHT_BUTTON: if (state == GLUT_DOWN) exit (-1); break; default: break; } } int main(int argc, char** argv) { myInit (); glutDisplayFunc(myDisplay); // register redraw function glutMouseFunc(myMouse); // register myMouse function glutMainLoop(); // go into a perpetual loop return 0; }