-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircle.h
53 lines (43 loc) · 1.04 KB
/
Circle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef CIRCLE_H
#define CIRCLE_H
#include <GL/freeglut.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include "Color.h"
#include "Shape.h"
class Circle : public Shape {
private:
float radius;
public:
Circle() {
x = 0;
y = 0;
selected = false;
radius = 0.1;
}
Circle(float x, float y, float radius, Color color) {
this->x = x;
this->y = y;
selected = false;
this->color = color;
this->radius = radius;
}
void draw() {
glColor3f(color.getR(), color.getG(), color.getB());
float inc = (2 * M_PI) / 60;
glBegin(GL_POLYGON);
for (float theta = 0; theta < 2 * M_PI; theta += inc)
glVertex2f(radius * cos(theta) + x, radius * sin(theta) + y);
glEnd();
if (selected) {
Circle outer(x, y, 0.85 * radius, Color(1, 1, 1));
Circle inner(x, y, 0.75 * radius, color);
outer.draw();
inner.draw();
}
}
bool contains(float mx, float my) {
return radius >= sqrt(pow(mx - x, 2) + pow(my - y, 2));
}
};
#endif