R-Type
R-Type project
Vectors.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** gameEngine2
4 ** File description:
5 ** Vectors
6 */
7 
8 #ifndef VECTORS_HPP_
9 #define VECTORS_HPP_
10 
11 #include "Profiler/KapProfiler.hpp"
12 #include <string>
13 
14 namespace KapEngine {
15  namespace Tools {
16  class Vector2;
17  class Vector3;
18  }
19 }
20 
21 namespace KapEngine {
22 
23  namespace Tools {
24 
25  class Vector2 {
26 
27  public:
28  Vector2(float x = 0.0f, float y = 0.0f) : x(x), y(y) {
29  }
30  Vector2(Vector2 const& vec) {
31  *this = vec;
32  }
33  ~Vector2() {
34  }
35 
36  void setX(float _x) {
37  PROFILER_FUNC_START();
38  x = _x;
39  PROFILER_FUNC_END();
40  }
41  void setY(float _y) {
42  PROFILER_FUNC_START();
43  y = _y;
44  PROFILER_FUNC_END();
45  }
46 
47  float getX() const {
48  return x;
49  }
50  float getY() const {
51  return y;
52  }
53 
54  Vector2 operator+(Vector2 const& vec) {
55  return Vector2(getX() + vec.getX(), y + vec.getY());
56  }
57 
58  Vector2 operator+(float const& f) {
59  return Vector2(x + f, y + f);
60  }
61 
62  Vector2 operator+(Vector3 const& vec);
63 
64 
65  Vector2 &operator+=(Vector2 const& vec) {
66  PROFILER_FUNC_START();
67  *this = *this + vec;
68  PROFILER_FUNC_END();
69  return *this;
70  }
71 
72  Vector2 &operator+=(float const& f) {
73  PROFILER_FUNC_START();
74  *this = *this + f;
75  PROFILER_FUNC_END();
76  return *this;
77  }
78 
79  Vector2 &operator+=(Vector3 const& vec) {
80  PROFILER_FUNC_START();
81  *this = *this + vec;
82  PROFILER_FUNC_END();
83  return *this;
84  }
85 
86 
87  Vector2 operator-(Vector2 const& vec) {
88  PROFILER_FUNC_START();
89  PROFILER_FUNC_END();
90  return Vector2(x - vec.getX(), y - vec.getY());
91  }
92 
93  Vector2 operator-(float const& f) {
94  PROFILER_FUNC_START();
95  PROFILER_FUNC_END();
96  return Vector2(x - f, y - f);
97  }
98 
99  Vector2 operator-(Vector3 const& vec);
100 
101 
102  Vector2 &operator-=(Vector2 const& vec) {
103  PROFILER_FUNC_START();
104  *this = *this - vec;
105  PROFILER_FUNC_END();
106  return *this;
107  }
108 
109  Vector2 &operator-=(float const& f) {
110  PROFILER_FUNC_START();
111  *this = *this - f;
112  PROFILER_FUNC_END();
113  return *this;
114  }
115 
116  Vector2 &operator-=(Vector3 const& vec) {
117  PROFILER_FUNC_START();
118  *this = *this - vec;
119  PROFILER_FUNC_END();
120  return *this;
121  }
122 
123 
124  Vector2 operator*(Vector2 const& vec) {
125  PROFILER_FUNC_START();
126  PROFILER_FUNC_END();
127  return Vector2(x * vec.getX(), y * vec.getY());
128  }
129 
130  Vector2 operator*(float const& f) {
131  PROFILER_FUNC_START();
132  PROFILER_FUNC_END();
133  return Vector2(x * f, y * f);
134  }
135 
136  Vector2 operator*(Vector3 const& vec);
137 
138 
139  Vector2 &operator*=(Vector2 const& vec) {
140  PROFILER_FUNC_START();
141  *this = *this * vec;
142  PROFILER_FUNC_END();
143  return *this;
144  }
145 
146  Vector2 &operator*=(float const& f) {
147  PROFILER_FUNC_START();
148  *this = *this * f;
149  PROFILER_FUNC_END();
150  return *this;
151  }
152 
153  Vector2 &operator*=(Vector3 const& vec) {
154  PROFILER_FUNC_START();
155  *this = *this * vec;
156  PROFILER_FUNC_END();
157  return *this;
158  }
159 
160 
161  Vector2 operator/(Vector2 const& vec) {
162  PROFILER_FUNC_START();
163  PROFILER_FUNC_END();
164  return Vector2(x / vec.getX(), y / vec.getY());
165  }
166 
167  Vector2 operator/(float const& f) {
168  PROFILER_FUNC_START();
169  PROFILER_FUNC_END();
170  return Vector2(x / f, y / f);
171  }
172 
173  Vector2 operator/(Vector3 const& vec);
174 
175 
176  Vector2 &operator/=(Vector2 const& vec) {
177  PROFILER_FUNC_START();
178  *this = *this / vec;
179  PROFILER_FUNC_END();
180  return *this;
181  }
182 
183  Vector2 &operator/=(float const& f) {
184  PROFILER_FUNC_START();
185  *this = *this / f;
186  PROFILER_FUNC_END();
187  return *this;
188  }
189 
190  Vector2 &operator/=(Vector3 const& vec) {
191  PROFILER_FUNC_START();
192  *this = *this / vec;
193  PROFILER_FUNC_END();
194  return *this;
195  }
196 
197 
198  Vector2 &operator=(Vector2 const& vec) {
199  x = vec.getX();
200  y = vec.getY();
201  return *this;
202  }
203 
204  Vector2 &operator=(Vector3 const& vec);
205 
206  bool operator==(Vector2 const& vec) {
207  PROFILER_FUNC_START();
208  if (vec.getX() != x) {
209  PROFILER_FUNC_END();
210  return false;
211  }
212  if (vec.getY() != y) {
213  PROFILER_FUNC_END();
214  return false;
215  }
216  return true;
217  }
218 
219  bool operator!=(Vector2 const& vec) {
220  PROFILER_FUNC_START();
221  PROFILER_FUNC_END();
222  return !(*this == vec);
223  }
224 
225  static Vector2 zero() {
226  return Vector2(0.f, 0.f);
227  }
228 
229  static Vector2 one() {
230  PROFILER_FUNC_START();
231  PROFILER_FUNC_END();
232  return Vector2(1.f, 1.f);
233  }
234 
235  std::string to_string() const {
236  PROFILER_FUNC_START();
237  std::string res = "{";
238 
239  res += std::to_string(x) + "; ";
240  res += std::to_string(y) + "}";
241 
242  PROFILER_FUNC_END();
243  return res;
244  }
245 
246  private:
247  float x = 0.0f;
248  float y = 0.0f;
249  };
250 
251  class Vector3 {
252 
253  public:
254  Vector3(float x = 0.0f, float y = 0.0f, float z = 0.0f) : x(x), y(y), z(z) {
255  }
256  Vector3(Vector3 const& vec) {
257  *this = vec;
258  }
259  ~Vector3() {}
260 
261  void setX(float _x) {
262  PROFILER_FUNC_START();
263  x = _x;
264  PROFILER_FUNC_END();
265  }
266  void setY(float _y) {
267  PROFILER_FUNC_START();
268  y = _y;
269  PROFILER_FUNC_END();
270  }
271  void setZ(float _z) {
272  PROFILER_FUNC_START();
273  z = _z;
274  PROFILER_FUNC_END();
275  }
276 
277  float getX() const {
278  return x;
279  }
280  float getY() const {
281  return y;
282  }
283  float getZ() const {
284  return z;
285  }
286 
287  Vector3 operator+(Vector3 const& vec) {
288  return Vector3(x + vec.getX(), y + vec.getY(), z + vec.getZ());
289  }
290 
291  Vector3 operator+(float const& f) {
292  return Vector3(x + f, y + f, z + f);
293  }
294 
295  Vector3 operator+(Vector2 const& vec);
296 
297 
298  Vector3 &operator+=(Vector3 const& vec) {
299  PROFILER_FUNC_START();
300  *this = *this + vec;
301  PROFILER_FUNC_END();
302  return *this;
303  }
304 
305  Vector3 &operator+=(Vector2 const& vec) {
306  PROFILER_FUNC_START();
307  *this = *this + vec;
308  PROFILER_FUNC_END();
309  return *this;
310  }
311 
312  Vector3 &operator+=(float const& f) {
313  PROFILER_FUNC_START();
314  *this = *this + f;
315  PROFILER_FUNC_END();
316  return *this;
317  }
318 
319 
320  Vector3 operator-(Vector3 const& vec) {
321  PROFILER_FUNC_START();
322  PROFILER_FUNC_END();
323  return Vector3(x - vec.getX(), y - vec.getY(), z - vec.getZ());
324  }
325 
326  Vector3 operator-(Vector2 const& vec);
327 
328  Vector3 operator-(float const& f) {
329  PROFILER_FUNC_START();
330  PROFILER_FUNC_END();
331  return Vector3(x - f, y - f, z - f);
332  }
333 
334 
335  Vector3 &operator-=(Vector3 const& vec) {
336  PROFILER_FUNC_START();
337  *this = *this - vec;
338  PROFILER_FUNC_END();
339  return *this;
340  }
341 
342  Vector3 &operator-=(Vector2 const& vec) {
343  PROFILER_FUNC_START();
344  *this = *this - vec;
345  PROFILER_FUNC_END();
346  return *this;
347  }
348 
349  Vector3 &operator-=(float const& f) {
350  PROFILER_FUNC_START();
351  *this = *this - f;
352  PROFILER_FUNC_END();
353  return *this;
354  }
355 
356 
357  Vector3 operator*(Vector3 const& vec) {
358  PROFILER_FUNC_START();
359  PROFILER_FUNC_END();
360  return Vector3(x * vec.getX(), y * vec.getY(), z * vec.getZ());
361  }
362 
363  Vector3 operator*(Vector2 const& vec);
364 
365  Vector3 operator*(float const& f) {
366  PROFILER_FUNC_START();
367  PROFILER_FUNC_END();
368  return Vector3(x * f, y * f, z * f);
369  }
370 
371 
372  Vector3 &operator*=(Vector3 const& vec) {
373  PROFILER_FUNC_START();
374  *this = *this * vec;
375  PROFILER_FUNC_END();
376  return *this;
377  }
378 
379  Vector3 &operator*=(Vector2 const& vec) {
380  PROFILER_FUNC_START();
381  *this = *this * vec;
382  PROFILER_FUNC_END();
383  return *this;
384  }
385 
386  Vector3 &operator*=(float const& f) {
387  PROFILER_FUNC_START();
388  *this = *this * f;
389  PROFILER_FUNC_END();
390  return *this;
391  }
392 
393 
394  Vector3 operator/(Vector3 const& vec) {
395  PROFILER_FUNC_START();
396  PROFILER_FUNC_END();
397  return Vector3(x / vec.getX(), y / vec.getY(), z / vec.getZ());
398  }
399 
400  Vector3 operator/(Vector2 const& vec);
401 
402  Vector3 operator/(float const& f) {
403  PROFILER_FUNC_START();
404  PROFILER_FUNC_END();
405  return Vector3(x / f, y / f, z / f);
406  }
407 
408 
409  Vector3 &operator/=(Vector3 const& vec) {
410  PROFILER_FUNC_START();
411  *this = *this / vec;
412  PROFILER_FUNC_END();
413  return *this;
414  }
415 
416  Vector3 &operator/=(Vector2 const& vec) {
417  PROFILER_FUNC_START();
418  *this = *this / vec;
419  PROFILER_FUNC_END();
420  return *this;
421  }
422 
423  Vector3 &operator/=(float const& f) {
424  PROFILER_FUNC_START();
425  *this = *this / f;
426  PROFILER_FUNC_END();
427  return *this;
428  }
429 
430 
431  Vector3 &operator=(Vector3 const& vec) {
432  x = vec.getX();
433  y = vec.getY();
434  z = vec.getZ();
435  return *this;
436  }
437 
438  Vector3 &operator=(Vector2 const& vec);
439 
440 
441  bool operator==(Vector3 const& vec) {
442  PROFILER_FUNC_START();
443  if (vec.getX() != x) {
444  PROFILER_FUNC_END();
445  return false;
446  }
447  if (vec.getY() != y) {
448  PROFILER_FUNC_END();
449  return false;
450  }
451  if (vec.getZ() != z) {
452  PROFILER_FUNC_END();
453  return false;
454  }
455  return true;
456  }
457 
458  bool operator!=(Vector3 const& vec) {
459  PROFILER_FUNC_START();
460  PROFILER_FUNC_END();
461  return !(*this == vec);
462  }
463 
464  static Vector3 zero() {
465  return Vector3(0.f, 0.f, 0.f);
466  }
467 
468  static Vector3 one() {
469  PROFILER_FUNC_START();
470  PROFILER_FUNC_END();
471  return Vector3(1.f, 1.f, 1.f);
472  }
473 
474  std::string to_string() const {
475  PROFILER_FUNC_START();
476  std::string res = "{";
477 
478  res += std::to_string(x) + "; ";
479  res += std::to_string(y) + "; ";
480  res += std::to_string(z) + "}";
481 
482  PROFILER_FUNC_END();
483  return res;
484  }
485 
486  private:
487  float x = 0.0f;
488  float y = 0.0f;
489  float z = 0.0f;
490  };
491 
492  }
493 
494 }
495 
496 #endif /* !VECTORS_HPP_ */
KapEngine::Tools::Vector2
Definition: Vectors.hpp:25
KapEngine
main namespace
Definition: Component.hpp:17
KapEngine::Tools::Vector3
Definition: Vectors.hpp:251