Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void drawCircle(bool filled = true)(float cx, float cy, float radius, int num_segments) {
- float theta = 2 * PI / cast(float) num_segments;
- float c = cos(theta);
- float s = sin(theta);
- float t;
- float x = radius;
- float y = 0;
- static if(filled) {
- float lastX;
- float lastY;
- glBegin(GL_TRIANGLES);
- for(int i = 0; i <= num_segments; i++) {
- t = x;
- x = c * x - s * y;
- y = s * t + c * y;
- if(i > 0) {
- glVertex2f(cx + lastX, cy + lastY);
- glVertex2f(cx + x, cy + y);
- glVertex2f(cx, cy);
- }
- lastX = x;
- lastY = y;
- }
- glEnd();
- } else {
- glBegin(GL_LINE_LOOP);
- for(int i = 0; i < num_segments; i++) {
- glVertex2f(cx + x, cy + y);
- t = x;
- x = c * x - s * y;
- y = s * t + c * y;
- }
- glEnd();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement