/* * main.cpp * CompFormApp * */ #include "Shape.h" float mouseX = 0; float mouseY = 0; int windowW = 800; int windowH = 600; #define PI 3.14159265358979 void drawCircle(float radius, int numOfPts, Vec2d center){ Circle circ(radius, numOfPts, center); circ.draw(); } void drawOval(float vRadius, float hRadius, int numOfPts, Vec2d center){ Oval ov(vRadius, hRadius, numOfPts, center); ov.draw(); } void displayFunc ( void ) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glColor3f( 1,0,0 ); glRectf( mouseX-5, mouseY-5, mouseX+5, mouseY+5 ); // place your drawing code here int ovalVert = 100; int incr = 10; Vec2d center(10,400); for(int vert = ovalVert; vert > 0; vert -= incr){ int horz = ovalVert + incr - vert; drawOval(horz, vert, 30, center); printf("x:%i y:%i\n", horz, vert); center.x += horz * 2 + incr; } glutPostRedisplay(); glutSwapBuffers(); } void reshapeFunc ( int w, int h ) { windowW = w; windowH = h; glViewport( 0, 0, w, h ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluOrtho2D( 0,w,0,h ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); } void mouseDownFunc ( int button, int state, int x, int y ) { mouseX = x; mouseY = windowH - y; } void mouseMoveFunc ( int x, int y ) { mouseX = x; mouseY = windowH - y; } void mouseDragFunc ( int x, int y ) { mouseX = x; mouseY = windowH - y; } void keyboardFunc ( unsigned char key, int x, int y ) { } void arrowKeyFunc ( int a_keys, int x, int y ) { } void init ( GLvoid ) { glShadeModel( GL_SMOOTH ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); glEnable ( GL_COLOR_MATERIAL ); glEnable( GL_BLEND ); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } void testFunc(){ Vec2d A(50,20); Vec2d B(20,50); Vec2d C; Vec2d D(100,100); C = A - B; // A.print(); // B.print(); // C.print(); // // printf( "%f", D.length()); } int main ( int argc, char** argv ) { testFunc(); glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE ); glutInitWindowSize( windowW, windowH ); glutCreateWindow( "CompFormApp" ); glutDisplayFunc( displayFunc ); glutReshapeFunc( reshapeFunc ); glutMouseFunc( mouseDownFunc ); glutMotionFunc( mouseDragFunc ); glutPassiveMotionFunc( mouseMoveFunc ); glutKeyboardFunc( keyboardFunc ); glutSpecialFunc( arrowKeyFunc ); init(); glutMainLoop( ); return 0; }