-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.h
executable file
·204 lines (158 loc) · 5.11 KB
/
header.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <SFML/Graphics.hpp>
#include <vector>
#include <memory>
const int windowWidth = 800;
const int windowHeight = 600;
const double k0 = 8987551787.3681764;
const double PI = 3.14159265358979323846;
const double ARROW_ANGLE = PI/4;
const double COLOR_FADE = 0.6;
const int EL_FIELD_LINE_LENGHT_LIMIT = 8000;
const int EL_FIELD_LINE_PER_CHARGE = 20;
const int LINES_DEEP_REDUCTION = 35;
const int LINES_DRAWING_REDUCTION = 4;
const int ARROWS_REDUCTION = 100;
const int ARROW_SIZE = 10;
const int MARGIN_CHARGE_LINES = 6;
const int BUTTONS_SIZE = 80;
const sf::Color GREY_CHARGE(128, 128, 128);
const sf::Color RED_BUTTON_ON(255, 99, 71);
const sf::Color RED_BOUNDS_BUTTON_ON(255, 69, 0);
const sf::Color ORANGE_BUTTON_OFF(255, 165, 0);
const sf::Color ORANGE_BOUNDS_BUTTON_OFF(255, 140, 0);
extern int mouse_draw_size;
extern int selected_index;
extern bool inputing_size;
extern bool inputing_custom;
extern bool showing_pop_up;
extern bool adding_charge;
extern bool removing_charge;
extern bool selecting_charge;
extern bool isEqPotLines;
extern bool isElFieldLines;
extern bool isElFieldColor;
extern bool shapingCircle;
extern bool shapingSquare;
extern bool shapingCustom;
extern sf::Font font;
extern sf::RectangleShape pop_up_rect;
extern std::string size_input;
extern std::string value_input;
//Functions defined in sfml.cpp
bool checkForButtonsClick(int x, int y);
void leftButtonMousePress(sf::RenderWindow& window);
void paintingCustomCharge(sf::RenderWindow& window);
void keyboardPress(sf::RenderWindow& window, sf::Event& event);
void initializeConfig();
class Point {
public:
int x, y;
double value;
Point(int x, int y);
Point(int x, int y, double value);
bool operator<(const Point& temp) const;
bool operator==(const Point& temp) const;
};
class Vector {
public:
int x, y;
double intensity, alpha;
Vector(int x, int y, double intensity, double alpha);
};
class Charge {
public:
int x, y, size;
double value;
Charge(int x, int y, int size, double value);
virtual bool isPointInside(int tx, int ty) = 0;
virtual double potInPoint(int tx, int ty) = 0;
virtual void drawCharge(sf::RenderWindow& window) = 0;
virtual Point externalPoint(double alpha) = 0;
virtual Vector elFieldInPoint(int tx, int ty) = 0;
virtual ~Charge();
};
class CircleCharge: public Charge {
public:
CircleCharge(int x, int y, int size, double value);
bool isPointInside(int tx, int ty);
double potInPoint(int tx, int ty);
void drawCharge(sf::RenderWindow& window);
Point externalPoint(double alpha);
Vector elFieldInPoint(int tx, int ty);
};
class SquareCharge: public Charge {
public:
SquareCharge(int x, int y, int size, double value);
bool isPointInside(int tx, int ty);
double potInPoint(int tx, int ty);
void drawCharge(sf::RenderWindow& window);
Point externalPoint(double alpha);
Vector elFieldInPoint(int tx, int ty);
};
class CustomCharge: public Charge {
public:
std::vector< Point > shape_map;
std::vector< Point > external_points;
CustomCharge(int x, int y, int size, double value);
bool isPointInside(int tx, int ty);
double potInPoint(int tx, int ty);
void drawCharge(sf::RenderWindow& window);
void findExternalPoints();
Point externalPoint(double alpha);
Vector elFieldInPoint(int tx, int ty);
};
extern std::shared_ptr<CustomCharge> currentCustom;
class Button {
public:
int x, y, width, height;
bool checked;
std::string name;
Button(std::string name, int x, int y, int width, int height, bool checked);
bool isPointInside(int tx, int ty);
};
extern std::vector<Button> buttons;
class Line {
public:
std::vector<Point> pointsCoord;
};
class Field {
public:
double maxElFieldIntensity;
double minElFieldIntensity;
std::vector< std::shared_ptr<Charge> > qCharges;
std::vector< std::vector<double> > potIntensityMap;
std::vector<Point> eqPotPoints;
std::vector<Line> eqPotLines;
std::vector<Line> elFieldLines;
std::vector< std::vector<sf::Vertex> > arrows;
std::vector< std::vector<double> > elFieldIntensityMap;
Field();
void update();
void clear();
//Equipotential lines related methods
void mapPotential();
double potValueInPoint(int x, int y);
void findEquipotentialPoints();
void findEquipotentialLines();
//Electric Field lines related methods
double angleFromPoints(double x1, double y1, double x2, double y2);
bool insideCharges(double tx, double ty, int startCharge);
Vector elFieldValueInPoint(int x, int y);
Line buildElFieldLine(Point startField, int startCharge);
void findElFieldLines();
std::vector<sf::Vertex> buildElFieldArrowHead(double tx, double ty, double talpha);
//Electric Field color related methods
void mapElFieldIntensity();
//Charge managing related methods
void addCharge();
void removeCharge(int x, int y);
void selectCharge(int x, int y);
//TODO implement moveCharge(...)
};
extern Field mainField;
//Functions defined in draws.cpp
void draw(sf::RenderWindow& window);
void drawField(sf::RenderWindow& window);
void drawCharges(sf::RenderWindow& window);
void drawButtons(sf::RenderWindow& window);
void drawPopUp(sf::RenderWindow& window);