Advertisement
axyd

Lab_14

May 9th, 2019
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //CS334 - Lab 14, Group 5
  2.  
  3.  
  4. #include <GL/gl.h>
  5. #include <GL/glut.h>
  6. #include <math.h>
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. float segments= 360;
  11.  
  12. void drawEllipse()
  13. {
  14.     glClear(GL_COLOR_BUFFER_BIT);   //flush gl
  15.    
  16.     float cx= 50.0f, cy= 50.0f, rx= 40.0f, ry= 30.0f; //, segments= 20.0f;
  17.    
  18.     float theta= 2 * 3.1415926 / segments;
  19.     float cos_t= cosf(theta);//precalculate the sine and cosine
  20.     float sin_t= sinf(theta);
  21.     float temp, x= 1, y= 0;
  22.  
  23.  
  24.     glBegin(GL_LINE_LOOP);
  25.     for(int ctr = 0; ctr < segments; ++ctr)
  26.     {
  27.         //apply radius and offset
  28.         glColor3f(1.0, 0.0, 0.0);   //red
  29.         glVertex2f(x * rx + cx, y * ry + cy);//output vertex
  30.  
  31.         //apply the rotation matrix
  32.         temp = x;   //temp store
  33.         x = cos_t * x - sin_t * y;        
  34.         y = sin_t * temp + cos_t * y;
  35.     }
  36.     glEnd();
  37.    
  38.     glFlush();
  39. }
  40.  
  41.  
  42. int main(int argc, char **argv) {  
  43.     glutInit(&argc, argv);
  44.     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  45.     glutInitWindowSize(500, 500);
  46.     glutInitWindowPosition(100, 100);
  47.     glutCreateWindow("CS334 - lab14");
  48.    
  49.     glClearColor(0, 0, 0, 0);   //background
  50.     glMatrixMode(GL_PROJECTION);
  51.     gluOrtho2D(0, 100, -10, 100);
  52.    
  53.     glutDisplayFunc(drawEllipse);
  54.     glutMainLoop();
  55.    
  56.     return EXIT_SUCCESS;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement