/// Draws a circle /// Starting with an initial vector [0 r] /// Apply matrix transformation [cos(t) -sin(t); sin(t) cos(t)] /// Each iteration simplifies to [x*cos(t)-y*sin(t); x*sin(t)+y*cos(t)] void glutCircle(float cx, float cy, float r, int segments) { int i; float theta = 2.0f * M_PI / (float)segments; float cost = cos(theta); float sint = sin(theta); float vx = -r; float vy = 0.0f; float v2x; glBegin(GL_LINE_LOOP); for(i = 0; i < segments; i++) { glVertex2f(cx + vx, cy + vy); v2x = vx*cost - vy*sint; vy = vx*sint + vy*cost; vx = v2x; } glEnd(); return; }