//CS334 - Lab 14, Group 5 #include #include #include #include using namespace std; float segments= 360; void drawEllipse() { glClear(GL_COLOR_BUFFER_BIT); //flush gl float cx= 50.0f, cy= 50.0f, rx= 40.0f, ry= 30.0f; //, segments= 20.0f; float theta= 2 * 3.1415926 / segments; float cos_t= cosf(theta);//precalculate the sine and cosine float sin_t= sinf(theta); float temp, x= 1, y= 0; glBegin(GL_LINE_LOOP); for(int ctr = 0; ctr < segments; ++ctr) { //apply radius and offset glColor3f(1.0, 0.0, 0.0); //red glVertex2f(x * rx + cx, y * ry + cy);//output vertex //apply the rotation matrix temp = x; //temp store x = cos_t * x - sin_t * y; y = sin_t * temp + cos_t * y; } glEnd(); glFlush(); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow("CS334 - lab14"); glClearColor(0, 0, 0, 0); //background glMatrixMode(GL_PROJECTION); gluOrtho2D(0, 100, -10, 100); glutDisplayFunc(drawEllipse); glutMainLoop(); return EXIT_SUCCESS; }