-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawer.h
151 lines (132 loc) · 3.57 KB
/
Drawer.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#pragma once
#include <math.h>
#include <vector>
namespace visual
{
class Point
{
public:
int x,y;
Point(int _x, int _y)
{
x=_x;
y=_y;
}
};
class Color
{
public:
float R, G, B, A;
Color(float _R, float _G, float _B, float _A)
{
R = _R;
G = _G;
B = _B;
A = _A;
}
};
class Drawer
{
public:
Color* RED = new Color(255, 0, 0, 255);
Color* GREEN = new Color(0, 255, 0, 255);
Color* BLUE = new Color(0, 0, 255, 255);
Drawer()
{
}
void line(int x1, int y1, int x2, int y2, Color* color)
{
glColor4f(color->R, color->G, color->B, color->A);
glLineWidth(1);
glBegin(GL_LINES);
glVertex2d(x1,y1);
glVertex2d(x2,y2);
glEnd();
delete color;
}
void line(Point p1, Point p2, Color* color)
{
glColor4f(color->R, color->G, color->B, color->A);
glLineWidth(1);
glBegin(GL_LINES);
glVertex2d(p1.x,p1.y);
glVertex2d(p2.x,p2.y);
glEnd();
delete color;
}
void rect(int x1, int y1, int x2, int y2, int x3, int y3,int x4, int y4, Color* color)
{
glColor4f(color->R, color->G, color->B, color->A);
glLineWidth(1);
glBegin(GL_LINES);
glVertex2f(x1,y1);
glVertex2f(x2,y2);
glVertex2f(x2,y2);
glVertex2f(x3,y3);
glVertex2f(x3,y3);
glVertex2f(x4,y4);
glVertex2f(x4,y4);
glVertex2f(x1,y1);
glEnd();
delete color;
}
void rect(Point p1, Point p2, Point p3, Point p4, Color* color)
{
glColor4f(color->R, color->G, color->B, color->A);
glLineWidth(1);
glBegin(GL_LINES);
glVertex2f(p1.x,p1.y);
glVertex2f(p2.x,p2.y);
glVertex2f(p2.x,p2.y);
glVertex2f(p3.x,p3.y);
glVertex2f(p3.x,p3.y);
glVertex2f(p4.x,p4.y);
glVertex2f(p4.x,p4.y);
glVertex2f(p1.x,p1.y);
glEnd();
delete color;
}
void circ(int x, int y, int radius, Color* color)
{
glColor4f(color->R, color->G, color->B, color->A);
int i;
int lineAmount = 100;
GLfloat twicePi = 2.0f * PI;
glBegin(GL_LINE_LOOP);
for(i = 0; i <= lineAmount; i++) {
glVertex2f(x + (radius * cos(i * twicePi / lineAmount)), y + (radius * sin(i * twicePi / lineAmount)));
}
glEnd();
delete color;
}
void circ(Point point, int radius, Color* color)
{
glColor4f(color->R, color->G, color->B, color->A);
int i;
int lineAmount = 100;
GLfloat twicePi = 2.0f * PI;
glBegin(GL_LINE_LOOP);
for(i = 0; i <= lineAmount; i++) {
glVertex2f(point.x + (radius * cos(i * twicePi / lineAmount)), point.y + (radius * sin(i * twicePi / lineAmount)));
}
glEnd();
delete color;
}
void circFill(int x, int y, int radius, Color* color)
{
glColor4f(color->R, color->G, color->B, color->A);
int i;
int triangleAmount = 20; //# of triangles used to draw circle
// GLfloat radius = 0.8f; //radius
GLfloat twicePi = 2.0f * PI;
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x, y); // center of circle
for(i = 0; i <= triangleAmount; i++) {
glVertex2f(x + (radius * cos(i * twicePi / triangleAmount)),
y + (radius * sin(i * twicePi / triangleAmount)));
}
glEnd();
delete color;
}
};
}