Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. void DrawCircle(float cx, float cy, float r, int num_segments)
  2. {
  3.     float theta = 2 * 3.1415926 / float(num_segments);
  4.     float c = cosf(theta);//precalculate the sine and cosine
  5.     float s = sinf(theta);
  6.     float t;
  7.  
  8.     float x = r;//we start at angle = 0
  9.     float y = 0;
  10.    
  11.     glBegin(GL_LINE_LOOP);
  12.     for(int ii = 0; ii < num_segments; ii++)
  13.     {
  14.         glVertex2f(x + cx, y + cy);//output vertex
  15.        
  16.         //apply the rotation matrix
  17.         t = x;
  18.         x = c * x - s * y;
  19.         y = s * t + c * y;
  20.     }
  21.     glEnd();
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement