-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtzellipse.cpp
More file actions
275 lines (195 loc) · 5.66 KB
/
Copy pathtzellipse.cpp
File metadata and controls
275 lines (195 loc) · 5.66 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#include "tzellipse.h"
#include "cmath"
#include "iostream"
#define PI 3.14159265358979323846
TzEllipse::TzEllipse(){}
TzEllipse::TzEllipse(const TzEllipse & tz){
centreX = tz.centreX;
centreY = tz.centreY;
rayon = tz.rayon;
}
TzEllipse::TzEllipse(float cX,float cY, float Rh){
centreX = cX;
centreY = cY;
rayon = Rh;
}
TzEllipse::TzEllipse(int cX,int cY, int Rh){
centreX = cX;
centreY = cY;
rayon = Rh;
}
float TzEllipse::distance(float x1,float y1,float x2,float y2){
return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}
int TzEllipse::distance(int x1,int y1,int x2,int y2){
return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}
bool TzEllipse::isIN(int x, int y){
if(distance(centreX,centreY,(float)x,(float)y) < get_rayon())
return true;
return false;
}
void TzEllipse::move(int x,int y){
centreX += x;
centreY += y;
}
void TzEllipse::move(double x,double y){
centreX = centreX + x;
centreY = centreY + y;
}
void TzEllipse::draw(sf::RenderWindow & app){
sf::CircleShape Circle = sf::CircleShape(rayon);
Circle.setPosition(centreX,centreY);
Circle.setOrigin(rayon,rayon);
Circle.setOutlineColor(sf::Color::Black);
Circle.setOutlineThickness(1);
Circle.setFillColor(sf::Color::Transparent);
// Circle.Scale(*rayonH/(*rayonV),*rayonV/(*rayonH));
app.draw(Circle);
}
bool* TzEllipse::isColor(sf::Sprite carte, sf::Color color){
// bool res = false;
float Cos = 0;
float Sin = 0;
bool* tab = new bool[8];
int j = 0;
/*
for(float i = 0; i<=2.0; i = i + 1./6.){
Cos = *centreX + (*rayonH)*cos(PI*i);
Sin = *centreY + (*rayonV)*sin(PI*i);
res = res || (carte.GetPixel((int) Cos ,(int) Sin) == sf::Color::Black);
}
//*/
for(float i = 0; i<=2.0; i = i + 1./4.){
Cos = centreX + (rayon)*cos(PI*i);
Sin = centreY + (rayon)*sin(PI*i);
if(carte.getTexture()->copyToImage().getPixel((int) Cos ,(int) Sin) == color)
tab[j] = true;
else tab[j] = false;
j++;
}
return tab;
}
bool TzEllipse::isColor2(sf::Sprite carte,sf::Color color){
bool* tab = new bool[8];
bool res = false;
tab = isColor(carte,color);
for(int i = 0; i< 8; i++){
res = res || tab[i];
}
return res;
}
bool TzEllipse::intersection(TzEllipse TZ){
bool res = false;
float Cos = 0;
float Sin = 0;
for(float i = 0; i<=2.0; i = i + 1./32.){
Cos = centreX + (rayon)*cos(PI*i);
Sin = centreY + (rayon)*sin(PI*i);
res = res || TZ.isIN((int)Cos,(int)Sin);
}
/* for(float i = 0; i<=2.0; i = i + 1./4.){
Cos = centreX + (rayon)*cos(PI*i);
Sin = centreY + (rayon)*sin(PI*i);
res = res || TZ.isIN((int)Cos,(int)Sin);
}*/
return res;
}
bool TzEllipse::intersection(sf::Image * sprt, sf::Color color){
// bool res = false;
float Cos = 0;
float Sin = 0;
for(float i = 0; i<=2.0; i = i + 1./32.){
Cos = centreX + (rayon)*cos(PI*i);
Sin = centreY + (rayon)*sin(PI*i);
if(sprt->getPixel(Cos,Sin) == color){
currentAngle = i;
return true;
}
}
return false;
}
bool TzEllipse::isInSprite(sf::Image *sprt, sf::Color color){
bool res = true;
float Cos = 0;
float Sin = 0;
for(float i = 0; i<=2.0; i = i + 1./32.){
Cos = centreX + (rayon)*cos(PI*i);
Sin = centreY + (rayon)*sin(PI*i);
res = res &&(sprt->getPixel(Cos,Sin) == color);
}
return res;
}
float TzEllipse::intersectAngle(sf::Image* sprt, sf::Color color){
float Cos = 0;
float Sin = 0;
QVector<float> itab;
for(float i = currentAngle-1.; i<=currentAngle+1.; i = i + 1./32.){
Cos = centreX + (rayon)*cos(PI*i);
Sin = centreY + (rayon)*sin(PI*i);
if(sprt->getPixel(Cos,Sin) == color){
itab.append(i);
}
}
if(itab.size() == 64.)
return -100;
float moy=0;
for(int i = 0; i < itab.size(); i++){
moy += itab[i];
}
moy = moy/((float)itab.size());
// std::cout << "nombre de valeurs :" << itab.size() << std::endl;
// std::cout << "moyenne :" << moy << std::endl;
// std::cout << "angle centrale : " << currentAngle << std::endl << std::endl;
float result = PI * moy;
return result;
/* for(float i = 0; i<=2.0; i = i + 1./4.){
Cos = centreX + (rayon)*cos(PI*i);
Sin = centreY + (rayon)*sin(PI*i);
res = res || TZ.isIN((int)Cos,(int)Sin);
}*/
}
QVector<float> TzEllipse::intersectTabAngle(sf::Image *sprt, sf::Color color){
float Cos = 0;
float Sin = 0;
QVector<float> itab;
for(float i = currentAngle-1.; i<=currentAngle+1.; i = i + 1./32.){
Cos = centreX + (rayon)*cos(PI*i);
Sin = centreY + (rayon)*sin(PI*i);
if(sprt->getPixel(Cos,Sin) == color){
itab.append(i);
}
}
// std::cout << "nombre de valeurs :" << itab.size() << std::endl;
// std::cout << "moyenne :" << moy << std::endl;
// std::cout << "angle centrale : " << currentAngle << std::endl << std::endl;
return itab;
}
TzEllipse TzEllipse::boost(int h){
TzEllipse TZ(centreX,centreY,rayon+h);
return TZ;
}
float TzEllipse::get_centreX(){
return centreX;
}
float TzEllipse::get_centreY(){
return centreY;
}
float TzEllipse::get_rayon(){
return rayon;
}
void TzEllipse::set_centre(float x, float y){
centreX = x;
centreY = y;
}
void TzEllipse::set_centre(double x, double y){
centreX = x;
centreY = y;
}
void TzEllipse::set_centre(int x,int y){
centreX = x;
centreY = y;
}
void TzEllipse::set_rayon(float Rh){
rayon = Rh;
}