Leviathan  0.8.0.0
Leviathan game engine
Types.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2018 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
6 
7 #include "Logger.h"
8 
9 #include <stdexcept>
10 
11 // Uncomment for debugging and major slow downs
12 // #define CHECK_FOR_NANS
13 
14 #ifdef CHECK_FOR_NANS
15 #define DO_NAN_CHECK \
16  { \
17  CheckForNans(); \
18  }
19 #else
20 #define DO_NAN_CHECK
21 #endif // CHECK_FOR_NANS
22 
23 #ifdef LEVIATHAN_USING_BULLET
24 #include "LinearMath/btQuaternion.h"
25 #include "LinearMath/btVector3.h"
26 #endif
27 
28 #ifdef LEVIATHAN_USING_OGRE
29 #include "bsfUtility/Image/BsColor.h"
30 #include "bsfUtility/Math/BsQuaternion.h"
31 #include "bsfUtility/Math/BsVector3.h"
32 #include "bsfUtility/Math/BsVector4.h"
33 #endif // LEVIATHAN_USING_OGRE
34 
35 namespace Leviathan {
36 
37 
39 
40  inline PotentiallySetIndex(size_t index) : ValueSet(true), Index(index) {}
41  inline PotentiallySetIndex() = default;
42 
43  inline operator bool() const
44  {
45 
46  return ValueSet;
47  }
48 
49  inline operator size_t() const
50  {
51 #ifdef _DEBUG
53  ValueSet, "PotentiallySetIndex size_t() called when ValueSet is false");
54 #endif // _DEBUG
55 
56  return Index;
57  }
58 
59  bool operator==(const PotentiallySetIndex& other) const
60  {
61 
62  if(!ValueSet)
63  return ValueSet == other.ValueSet;
64 
65  return Index == other.Index;
66  }
67 
69  {
70 
71  ValueSet = other.ValueSet;
72  Index = other.Index;
73  return *this;
74  }
75 
76  inline PotentiallySetIndex& operator=(const size_t& value)
77  {
78 
79  ValueSet = true;
80  Index = value;
81  return *this;
82  }
83 
84  inline bool IsSet() const
85  {
86 
87  return ValueSet;
88  }
89 
90  bool ValueSet = false;
91  size_t Index = 0;
92 };
93 
94 struct StartEndIndex {
95 
97 
98  inline StartEndIndex(size_t start, size_t end) : Start(start), End(end) {}
99 
100  inline StartEndIndex(size_t start) : Start(start) {}
101 
102  inline StartEndIndex() = default;
103 
105  inline void Reset()
106  {
107  Start = Index();
108  End = Index();
109  }
110 
113  inline size_t Length() const
114  {
115  if(!Start || !End || static_cast<size_t>(Start) > static_cast<size_t>(End))
116  return 0;
117 
118  return 1 + (static_cast<size_t>(End) - static_cast<size_t>(Start));
119  }
120 
121 
124 };
125 
126 class Degree;
127 
129 class Radian {
130 public:
131  constexpr inline Radian() : Value(0) {}
132  constexpr inline Radian(float rawvalue) : Value(rawvalue) {}
133  constexpr inline Radian(const Radian& other) : Value(other.Value) {}
134  DLLEXPORT explicit Radian(const Degree& degree);
135 
136  DLLEXPORT operator Degree() const;
137  DLLEXPORT Radian& operator=(const Degree& degrees);
138  inline Radian& operator=(const Radian& other)
139  {
140  Value = other.Value;
141  return *this;
142  }
143 
144  inline bool operator>(const Radian& other)
145  {
146  return Value > other.Value;
147  }
148 
149  inline bool operator<(const Radian& other)
150  {
151  return Value < other.Value;
152  }
153 
154  inline bool operator==(const Radian& other)
155  {
156  return Value == other.Value;
157  }
158 
159  constexpr inline float ValueInRadians() const noexcept
160  {
161  return Value;
162  }
163 
164  constexpr inline float ValueInDegrees() const noexcept
165  {
166  return RADIANS_TO_DEGREES * Value;
167  }
168 
169 protected:
170  float Value;
171 };
172 
174 class Degree {
175 public:
176  constexpr inline Degree() : Value(0) {}
177  constexpr inline Degree(float rawvalue) : Value(rawvalue) {}
178  constexpr inline Degree(const Degree& other) : Value(other.Value) {}
179  DLLEXPORT explicit Degree(const Radian& radians);
180 
181  DLLEXPORT operator Radian() const;
182  DLLEXPORT Degree& operator=(const Radian& radians);
183  inline Degree& operator=(const Degree& other)
184  {
185  Value = other.Value;
186  return *this;
187  }
188 
189  constexpr inline float ValueInRadians() const noexcept
190  {
191  return DEGREES_TO_RADIANS * Value;
192  }
193 
194  constexpr inline float ValueInDegrees() const noexcept
195  {
196  return Value;
197  }
198 
199 protected:
200  float Value;
201 };
202 
203 struct Int2 {
204 public:
205  DLLEXPORT constexpr Int2() noexcept = default;
206 
207  DLLEXPORT constexpr Int2(int x, int y) noexcept : X(x), Y(y) {}
208  DLLEXPORT constexpr explicit Int2(int data) noexcept : X(data), Y(data) {}
209 
210  // access operator //
211  DLLEXPORT inline int& operator[](int nindex)
212  {
213  switch(nindex) {
214  case 0: return X;
215  case 1: return Y;
216  default: break;
217  }
218 
219  LEVIATHAN_ASSERT(0, "invalid [] access");
220  return X;
221  }
222 
223  // ------------------- Operators ----------------- //
224  // add elements //
225  DLLEXPORT constexpr Int2 operator+(const Int2& other) const noexcept
226  {
227  return Int2(X + other.X, Y + other.Y);
228  }
229 
230  DLLEXPORT inline Int2& operator+=(const Int2& other) noexcept
231  {
232  X += other.X;
233  Y += other.Y;
234  return *this;
235  }
236 
237  // subtracts all elements //
238  DLLEXPORT constexpr Int2 operator-(const Int2& other) const noexcept
239  {
240  return Int2(X - other.X, Y - other.Y);
241  }
242 
243  DLLEXPORT inline Int2& operator-=(const Int2& other) noexcept
244  {
245  X -= other.X;
246  Y -= other.Y;
247  return *this;
248  }
249 
250  // negates all elements //
251  DLLEXPORT constexpr Int2 operator-() const noexcept
252  {
253  return Int2(-X, -Y);
254  }
255 
256  // returns the vector //
257  DLLEXPORT constexpr Int2 operator+() const noexcept
258  {
259  return Int2(*this);
260  }
261 
262  // multiplies elements together //
263  DLLEXPORT constexpr Int2 operator*(const Int2& other) const noexcept
264  {
265  return Int2(X * other.X, Y * other.Y);
266  }
267 
268  DLLEXPORT inline Int2& operator*=(const Int2& other) noexcept
269  {
270  X *= other.X;
271  Y *= other.Y;
272  return *this;
273  }
274 
275  // Divides all elements by int //
276  DLLEXPORT constexpr Int2 operator/(int val) const
277  {
278  return Int2(X / val, Y / val);
279  }
280 
281  DLLEXPORT inline Int2& operator/=(int val)
282  {
283  X /= val;
284  Y /= val;
285  return *this;
286  }
287 
288  // multiply by scalar f //
289  DLLEXPORT constexpr Int2 operator*(int val) const noexcept
290  {
291  return Int2(X * val, Y * val);
292  }
293 
294  DLLEXPORT inline Int2& operator*=(int val) noexcept
295  {
296  X *= val;
297  Y *= val;
298  return *this;
299  }
300 
301  // divides all elements //
302  DLLEXPORT constexpr Int2 operator/(const Int2& other) const
303  {
304  return Int2(X / other.X, Y / other.Y);
305  }
306 
307  DLLEXPORT inline Int2& operator/=(const Int2& other)
308  {
309  X /= other.X;
310  Y /= other.Y;
311  return *this;
312  }
313 
314  // ---- comparison operators ---- //
315  // element by element comparison with operators //
316  DLLEXPORT constexpr bool operator<(const Int2& other) const noexcept
317  {
318  return std::tie(X, Y) < std::tie(other.X, other.Y);
319  }
320 
321  DLLEXPORT constexpr bool operator<=(const Int2& other) const noexcept
322  {
323  return std::tie(X, Y) <= std::tie(other.X, other.Y);
324  }
325 
326  DLLEXPORT constexpr bool operator>(const Int2& other) const noexcept
327  {
328  return std::tie(X, Y) > std::tie(other.X, other.Y);
329  }
330 
331  DLLEXPORT constexpr bool operator>=(const Int2& other) const noexcept
332  {
333  return std::tie(X, Y) >= std::tie(other.X, other.Y);
334  }
335 
336  DLLEXPORT constexpr bool operator==(const Int2& other) const noexcept
337  {
338  return X == other.X && Y == other.Y;
339  }
340 
341  DLLEXPORT constexpr bool operator!=(const Int2& other) const noexcept
342  {
343  return X != other.X || Y != other.Y;
344  }
345 
346  // ------------------ Functions ------------------ //
347  // getters //
348  DLLEXPORT constexpr int GetX() const noexcept
349  {
350  return X;
351  }
352 
353  DLLEXPORT constexpr int GetY() const noexcept
354  {
355  return Y;
356  }
357 
358  // setters //
359  DLLEXPORT inline void SetX(int val)
360  {
361  X = val;
362  }
363 
364  DLLEXPORT inline void SetY(int val)
365  {
366  Y = val;
367  }
368 
369  // add all elements together //
370  DLLEXPORT constexpr int HAdd() const noexcept
371  {
372  return X + Y;
373  }
374 
375  // Add all elements together after abs() is called on each element //
376  DLLEXPORT inline unsigned int HAddAbs() const noexcept
377  {
378  return std::abs(X) + std::abs(Y);
379  }
380 
381  // getting min and max of objects //
382  DLLEXPORT constexpr Int2 MinElements(const Int2& other) const noexcept
383  {
384  return Int2(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y);
385  }
386 
387  DLLEXPORT constexpr Int2 MaxElements(const Int2& other) const noexcept
388  {
389  return Int2(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y);
390  }
391 
392  // value clamping //
393  DLLEXPORT constexpr Int2 Clamp(const Int2& min, const Int2& max) const noexcept
394  {
395  const Int2 minval = this->MinElements(max);
396  return min.MaxElements(minval);
397  }
398 
399  // ----------------- Vector math ------------------- //
400  // length of the vector //
401  DLLEXPORT inline float Length() const noexcept
402  {
403  return std::sqrt(static_cast<float>(LengthSquared()));
404  }
405 
406  DLLEXPORT constexpr unsigned int LengthSquared() const noexcept
407  {
408  return X * X + Y * Y;
409  }
410 
411  VALUE_TYPE(Int2);
412 
413  // data //
414  int X = 0;
415  int Y = 0;
416 };
417 
418 struct Int3 {
419 public:
420  DLLEXPORT constexpr Int3() noexcept = default;
421 
422  DLLEXPORT constexpr Int3(int x, int y, int z) : X(x), Y(y), Z(z) {}
423  DLLEXPORT constexpr Int3(Int2 ints, int z) : X(ints.X), Y(ints.Y), Z(z) {}
424  DLLEXPORT constexpr explicit Int3(int data) : X(data), Y(data), Z(data) {}
425 
426  // access operator //
427  DLLEXPORT inline int& operator[](int nindex)
428  {
429  switch(nindex) {
430  case 0: return X;
431  case 1: return Y;
432  case 2: return Z;
433  default: break;
434  }
435  LEVIATHAN_ASSERT(0, "invalid [] access");
436  return X;
437  }
438 
439  // ------------------- Operators ----------------- //
440  // add elements //
441  DLLEXPORT constexpr Int3 operator+(const Int3& other) const noexcept
442  {
443  return Int3(X + other.X, Y + other.Y, Z + other.Z);
444  }
445 
446  DLLEXPORT inline Int3& operator+=(const Int3& other) noexcept
447  {
448  X += other.X;
449  Y += other.Y;
450  Z += other.Z;
451  return *this;
452  }
453 
454  // subtracts all elements //
455  DLLEXPORT constexpr Int3 operator-(const Int3& other) const noexcept
456  {
457  return Int3(X - other.X, Y - other.Y, Z - other.Z);
458  }
459 
460  DLLEXPORT inline Int3& operator-=(const Int3& other) noexcept
461  {
462  X -= other.X;
463  Y -= other.Y;
464  Z -= other.Z;
465  return *this;
466  }
467 
468  // negates all elements //
469  DLLEXPORT constexpr Int3 operator-() const noexcept
470  {
471  return Int3(-X, -Y, -Z);
472  }
473 
474  // returns the vector //
475  DLLEXPORT constexpr Int3 operator+() const noexcept
476  {
477  return Int3(*this);
478  }
479 
480  // multiplies elements together //
481  DLLEXPORT constexpr Int3 operator*(const Int3& other) const noexcept
482  {
483  return Int3(X * other.X, Y * other.Y, Z * other.Z);
484  }
485 
486  DLLEXPORT inline Int3& operator*=(const Int3& other) noexcept
487  {
488  X *= other.X;
489  Y *= other.Y;
490  Z *= other.Z;
491  return *this;
492  }
493 
494  // Divides all elements by int //
495  DLLEXPORT constexpr Int3 operator/(int val) const
496  {
497  return Int3(X / val, Y / val, Z / val);
498  }
499 
500  DLLEXPORT inline Int3& operator/=(int val)
501  {
502  X /= val;
503  Y /= val;
504  Z /= val;
505  return *this;
506  }
507 
508  // multiply by scalar f //
509  DLLEXPORT constexpr Int3 operator*(int val) const noexcept
510  {
511  return Int3(X * val, Y * val, Z * val);
512  }
513 
514  DLLEXPORT inline Int3& operator*=(int val) noexcept
515  {
516  X *= val;
517  Y *= val;
518  Z *= val;
519  return *this;
520  }
521 
522  // divides all elements //
523  DLLEXPORT constexpr Int3 operator/(const Int3& other) const
524  {
525  return Int3(X / other.X, Y / other.Y, Z / other.Z);
526  }
527 
528  DLLEXPORT inline Int3& operator/=(const Int3& other)
529  {
530  X /= other.X;
531  Y /= other.Y;
532  Z /= other.Z;
533  return *this;
534  }
535 
536  // ---- comparison operators ---- //
537  // element by element comparison with operators //
538  DLLEXPORT constexpr bool operator<(const Int3& other) const noexcept
539  {
540  return std::tie(X, Y, Z) < std::tie(other.X, other.Y, other.Z);
541  }
542 
543  DLLEXPORT constexpr bool operator<=(const Int3& other) const noexcept
544  {
545  return std::tie(X, Y, Z) <= std::tie(other.X, other.Y, other.Z);
546  }
547 
548  DLLEXPORT constexpr bool operator>(const Int3& other) const noexcept
549  {
550  return std::tie(X, Y, Z) > std::tie(other.X, other.Y, other.Z);
551  }
552 
553  DLLEXPORT constexpr bool operator>=(const Int3& other) const noexcept
554  {
555  return std::tie(X, Y, Z) >= std::tie(other.X, other.Y, other.Z);
556  }
557 
558  DLLEXPORT constexpr bool operator==(const Int3& other) const noexcept
559  {
560  return X == other.X && Y == other.Y && Z == other.Z;
561  }
562 
563  DLLEXPORT constexpr bool operator!=(const Int3& other) const noexcept
564  {
565  return X != other.X || Y != other.Y || Z != other.Z;
566  }
567 
568  // ------------------ Functions ------------------ //
569  // getters //
570  DLLEXPORT constexpr int GetX() const noexcept
571  {
572  return X;
573  }
574 
575  DLLEXPORT constexpr int GetY() const noexcept
576  {
577  return Y;
578  }
579 
580  DLLEXPORT constexpr int GetZ() const noexcept
581  {
582  return Z;
583  }
584 
585  // setters //
586  DLLEXPORT inline void SetX(int val)
587  {
588  X = val;
589  }
590 
591  DLLEXPORT inline void SetY(int val)
592  {
593  Y = val;
594  }
595 
596  DLLEXPORT inline void SetZ(int val)
597  {
598  Z = val;
599  }
600 
601  // add all elements together //
602  DLLEXPORT constexpr int HAdd() const noexcept
603  {
604  return X + Y + Z;
605  }
606 
607  // Add all elements together absoluted (abs()) //
608  DLLEXPORT inline unsigned int HAddAbs() const noexcept
609  {
610  return std::abs(X) + std::abs(Y) + std::abs(Z);
611  }
612 
613  // getting min and max of objects //
614  DLLEXPORT constexpr Int3 MinElements(const Int3& other) const noexcept
615  {
616  return Int3(
617  X < other.X ? X : other.X, Y < other.Y ? Y : other.Y, Z < other.Z ? Z : other.Z);
618  }
619 
620  DLLEXPORT constexpr Int3 MaxElements(const Int3& other) const noexcept
621  {
622  return Int3(
623  X > other.X ? X : other.X, Y > other.Y ? Y : other.Y, Z > other.Z ? Z : other.Z);
624  }
625 
626  // value clamping //
627  DLLEXPORT constexpr Int3 Clamp(const Int3& min, const Int3& max) const noexcept
628  {
629  const Int3 minval = this->MinElements(max);
630  return min.MaxElements(minval);
631  }
632 
633  // ----------------- Vector math ------------------- //
634  // length of the vector //
635  DLLEXPORT inline float Length() const noexcept
636  {
637  return std::sqrt(static_cast<float>(LengthSquared()));
638  }
639 
640  DLLEXPORT constexpr unsigned int LengthSquared() const noexcept
641  {
642  return X * X + Y * Y + Z * Z;
643  }
644 
645  // ------------------------------------ //
646 
647  VALUE_TYPE(Int3);
648 
649  int X = 0;
650  int Y = 0;
651  int Z = 0;
652 };
653 
654 struct Float2 {
655 public:
656  DLLEXPORT constexpr inline Float2() noexcept = default;
657 
658  DLLEXPORT constexpr inline Float2(float x, float y) : X(x), Y(y)
659  {
660  DO_NAN_CHECK;
661  }
662 
663  DLLEXPORT inline Float2(const Int2& values) noexcept :
664  X(static_cast<float>(values.X)), Y(static_cast<float>(values.Y))
665  {
666  DO_NAN_CHECK;
667  }
668 
669  DLLEXPORT constexpr inline explicit Float2(float data) : X(data), Y(data)
670  {
671  DO_NAN_CHECK;
672  }
673 
674  DLLEXPORT inline bool HasInvalidValues() const noexcept
675  {
676  return !std::isfinite(X) || !std::isfinite(Y);
677  }
678 
679  DLLEXPORT inline void CheckForNans() const
680  {
681  if(HasInvalidValues()) {
682  DEBUG_BREAK;
683  throw std::runtime_error("Float2 has NaNs (or infinites in it) in it!");
684  }
685  }
686 
687  // access operator //
688  DLLEXPORT inline float& operator[](int nindex)
689  {
690  switch(nindex) {
691  case 0: return X;
692  case 1: return Y;
693  default: break;
694  }
695 
696  LEVIATHAN_ASSERT(0, "invalid [] access");
697  return X;
698  }
699 
700  // ------------------- Operators ----------------- //
701  // add elements //
702  DLLEXPORT inline Float2 operator+(const Float2& other) const noexcept
703  {
704  return Float2(X + other.X, Y + other.Y);
705  }
706 
707  DLLEXPORT inline Float2& operator+=(const Float2& other) noexcept
708  {
709  X += other.X;
710  Y += other.Y;
711  return *this;
712  }
713 
714  // subtracts all elements //
715  DLLEXPORT inline Float2 operator-(const Float2& other) const noexcept
716  {
717  return Float2(X - other.X, Y - other.Y);
718  }
719 
720  DLLEXPORT inline Float2& operator-=(const Float2& other) noexcept
721  {
722  X -= other.X;
723  Y -= other.Y;
724  return *this;
725  }
726 
727  // negates all elements //
728  DLLEXPORT inline Float2 operator-() const noexcept
729  {
730  return Float2(-X, -Y);
731  }
732 
733  // returns the vector //
734  DLLEXPORT inline Float2 operator+() const noexcept
735  {
736  return Float2(*this);
737  }
738 
739  // multiplies elements together //
740  DLLEXPORT inline Float2 operator*(const Float2& other) const noexcept
741  {
742  return Float2(X * other.X, Y * other.Y);
743  }
744 
745  DLLEXPORT inline Float2& operator*=(const Float2& other) noexcept
746  {
747  X *= other.X;
748  Y *= other.Y;
749  DO_NAN_CHECK;
750  return *this;
751  }
752 
753  // Divides all elements by float //
754  DLLEXPORT inline Float2 operator/(float val) const
755  {
756  return Float2(X / val, Y / val);
757  }
758 
759  DLLEXPORT inline Float2& operator/=(float val)
760  {
761  X /= val;
762  Y /= val;
763  DO_NAN_CHECK;
764  return *this;
765  }
766 
767  // multiply by scalar f //
768  DLLEXPORT inline Float2 operator*(float val) const noexcept
769  {
770  return Float2(X * val, Y * val);
771  }
772 
773  DLLEXPORT inline Float2& operator*=(float val) noexcept
774  {
775  X *= val;
776  Y *= val;
777  DO_NAN_CHECK;
778  return *this;
779  }
780 
781  // divides all elements //
782  DLLEXPORT inline Float2 operator/(const Float2& other) const
783  {
784  return Float2(X / other.X, Y / other.Y);
785  }
786 
787  DLLEXPORT inline Float2& operator/=(const Float2& other)
788  {
789  X /= other.X;
790  Y /= other.Y;
791  DO_NAN_CHECK;
792  return *this;
793  }
794 
795  // ---- comparison operators ---- //
796  // element by element comparison with operators //
797  DLLEXPORT inline bool operator<(const Float2& other) const noexcept
798  {
799  return std::tie(X, Y) < std::tie(other.X, other.Y);
800  }
801 
802  DLLEXPORT inline bool operator<=(const Float2& other) const noexcept
803  {
804  return std::tie(X, Y) <= std::tie(other.X, other.Y);
805  }
806 
807  DLLEXPORT inline bool operator>(const Float2& other) const noexcept
808  {
809  return std::tie(X, Y) > std::tie(other.X, other.Y);
810  }
811 
812  DLLEXPORT inline bool operator>=(const Float2& other) const noexcept
813  {
814  return std::tie(X, Y) >= std::tie(other.X, other.Y);
815  }
816 
817  DLLEXPORT inline bool operator==(const Float2& other) const noexcept
818  {
819  return X == other.X && Y == other.Y;
820  }
821 
822  DLLEXPORT inline bool operator!=(const Float2& other) const noexcept
823  {
824  return X != other.X || Y != other.Y;
825  }
826 
827  // ------------------ Functions ------------------ //
828  // getters //
829  DLLEXPORT inline float GetX() const noexcept
830  {
831  return X;
832  }
833 
834  DLLEXPORT inline float GetY() const noexcept
835  {
836  return Y;
837  }
838 
839  // setters //
840  DLLEXPORT inline void SetX(float val)
841  {
842  X = val;
843  DO_NAN_CHECK;
844  }
845 
846  DLLEXPORT inline void SetY(float val)
847  {
848  Y = val;
849  DO_NAN_CHECK;
850  }
851 
852  // add all elements together //
853  DLLEXPORT inline float HAdd() const noexcept
854  {
855  return X + Y;
856  }
857 
858  // Add all elements together after abs() is called on each element //
859  DLLEXPORT inline float HAddAbs() const noexcept
860  {
861  return std::fabs(X) + std::fabs(Y);
862  }
863 
864  // getting min and max of objects //
865  DLLEXPORT inline Float2 MinElements(const Float2& other) const noexcept
866  {
867  return Float2(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y);
868  }
869 
870  DLLEXPORT inline Float2 MaxElements(const Float2& other) const noexcept
871  {
872  return Float2(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y);
873  }
874 
875  // value clamping //
876  DLLEXPORT inline Float2 Clamp(const Float2& min, const Float2& max) const noexcept
877  {
878  const Float2 minval = this->MinElements(max);
879  return min.MaxElements(minval);
880  }
881 
882  // ----------------- Vector math ------------------- //
883  // dot product of the vectors //
884  DLLEXPORT inline float Dot(const Float2& val) const noexcept
885  {
886  return X * val.X + Y * val.Y;
887  }
888 
889  // length of the vector //
890  DLLEXPORT inline float Length() const noexcept
891  {
892  return std::sqrt(LengthSquared());
893  }
894 
895  DLLEXPORT inline float LengthSquared() const noexcept
896  {
897  return X * X + Y * Y;
898  }
899 
900  // normalizes the vector //
901  DLLEXPORT inline Float2 Normalize() const
902  {
903  const float length = Length();
904  if(length == 0)
905  return Float2(0, 0);
906  return (*this) / length;
907  }
908 
909  // safe version of normalization //
910  DLLEXPORT inline Float2 NormalizeSafe(const Float2& safer) const noexcept
911  {
912  // security //
913  LEVIATHAN_ASSERT(safer.IsNormalized(), "safer not normalized");
914  if(LengthSquared() == 0)
915  return safer;
916  const float length = Length();
917  return (*this) / length;
918  }
919 
920  // checks is the vector normalized //
921  DLLEXPORT inline bool IsNormalized() const noexcept
922  {
923  // is absolute -1.f under normalization tolerance //
924  return fabs(X * X + Y * Y - 1.0f) < NORMALIZATION_TOLERANCE;
925  }
926 
927  // does linear interpolation between vectors and coefficient f, not limited to range [0,1],
928  // courtesy of ozz-animation //
929  DLLEXPORT inline Float2 Lerp(const Float2& other, float f) const noexcept
930  {
931  return Float2((other.X - X) * f + X, (other.Y - Y) * f + Y);
932  }
933 
934  // compares distance between vectors to tolerance, returns true if less //
935  DLLEXPORT inline bool Compare(const Float2& other, float tolerance) const noexcept
936  {
937  const Float2 difference = (*this) - other;
938  return difference.Dot(difference) < tolerance * tolerance;
939  }
940 
941  // ----------------- casts ------------------- //
942  // waiting for Microsoft's compilers to add support for "explicit" here //
943  // DLLEXPORT inline operator D3DXVECTOR2(){
944  // return D3DXVECTOR2(X, Y);
945  //}
946 
948 
949  // data //
950  float X = 0;
951  float Y = 0;
952 };
953 
954 struct Float3 {
955 public:
956  DLLEXPORT constexpr inline Float3() noexcept = default;
957 
958  DLLEXPORT constexpr inline Float3(float x, float y, float z) noexcept : X(x), Y(y), Z(z)
959  {
960  DO_NAN_CHECK;
961  }
962 
963  DLLEXPORT constexpr inline Float3(Float2 floats, float z) noexcept :
964  X(floats.X), Y(floats.Y), Z(z)
965  {
966  DO_NAN_CHECK;
967  }
968 
969  DLLEXPORT constexpr inline explicit Float3(float data) noexcept : X(data), Y(data), Z(data)
970  {
971  DO_NAN_CHECK;
972  }
973 
974  DLLEXPORT inline Float3(const Int3& values) noexcept :
975  X(static_cast<float>(values.X)), Y(static_cast<float>(values.Y)),
976  Z(static_cast<float>(values.Z))
977  {
978  DO_NAN_CHECK;
979  }
980 
981  DLLEXPORT inline bool HasInvalidValues() const noexcept
982  {
983  return !std::isfinite(X) || !std::isfinite(Y) || !std::isfinite(Z);
984  }
985 
986  DLLEXPORT inline void CheckForNans() const
987  {
988  if(HasInvalidValues()) {
989  DEBUG_BREAK;
990  throw std::runtime_error("Float3 has NaNs (or infinites in it) in it!");
991  }
992  }
993 
994  // access operator //
995  DLLEXPORT inline float& operator[](unsigned nindex)
996  {
997  switch(nindex) {
998  case 0: return X;
999  case 1: return Y;
1000  case 2: return Z;
1001  default: break;
1002  }
1003  LEVIATHAN_ASSERT(0, "invalid [] access");
1004  return X;
1005  }
1006 
1007  DLLEXPORT inline float operator[](unsigned nindex) const
1008  {
1009  switch(nindex) {
1010  case 0: return X;
1011  case 1: return Y;
1012  case 2: return Z;
1013  default: break;
1014  }
1015  LEVIATHAN_ASSERT(0, "invalid [] access");
1016  return X;
1017  }
1018 
1019  // ------------------- Operators ----------------- //
1020  // add elements //
1021  DLLEXPORT constexpr inline Float3 operator+(const Float3& other) const noexcept
1022  {
1023  return Float3(X + other.X, Y + other.Y, Z + other.Z);
1024  }
1025 
1026  DLLEXPORT constexpr inline Float3& operator+=(const Float3& other) noexcept
1027  {
1028  X += other.X;
1029  Y += other.Y;
1030  Z += other.Z;
1031  return *this;
1032  }
1033 
1034  // subtracts all elements //
1035  DLLEXPORT constexpr inline Float3 operator-(const Float3& other) const noexcept
1036  {
1037  return Float3(X - other.X, Y - other.Y, Z - other.Z);
1038  }
1039 
1040  DLLEXPORT constexpr inline Float3& operator-=(const Float3& other) noexcept
1041  {
1042  X -= other.X;
1043  Y -= other.Y;
1044  Z -= other.Z;
1045  return *this;
1046  }
1047 
1048  // negates all elements //
1049  DLLEXPORT constexpr inline Float3 operator-() const noexcept
1050  {
1051  return Float3(-X, -Y, -Z);
1052  }
1053 
1054  // returns the vector //
1055  DLLEXPORT constexpr inline Float3 operator+() const noexcept
1056  {
1057  return Float3(*this);
1058  }
1059 
1060  // multiplies elements together //
1061  DLLEXPORT constexpr inline Float3 operator*(const Float3& other) const noexcept
1062  {
1063  return Float3(X * other.X, Y * other.Y, Z * other.Z);
1064  }
1065 
1066  DLLEXPORT constexpr inline Float3& operator*=(const Float3& other) noexcept
1067  {
1068  X *= other.X;
1069  Y *= other.Y;
1070  Z *= other.Z;
1071  DO_NAN_CHECK;
1072  return *this;
1073  }
1074 
1075  // Divides all elements by float //
1076  DLLEXPORT constexpr inline Float3 operator/(float val) const
1077  {
1078  return Float3(X / val, Y / val, Z / val);
1079  }
1080 
1081  DLLEXPORT constexpr inline Float3& operator/=(float val)
1082  {
1083  X /= val;
1084  Y /= val;
1085  Z /= val;
1086  DO_NAN_CHECK;
1087  return *this;
1088  }
1089 
1090  // multiply by scalar f //
1091  DLLEXPORT constexpr inline Float3 operator*(float val) const noexcept
1092  {
1093  return Float3(X * val, Y * val, Z * val);
1094  }
1095 
1096  DLLEXPORT constexpr inline Float3& operator*=(float val) noexcept
1097  {
1098  X *= val;
1099  Y *= val;
1100  Z *= val;
1101  DO_NAN_CHECK;
1102  return *this;
1103  }
1104 
1105  // divides all elements //
1106  DLLEXPORT constexpr inline Float3 operator/(const Float3& other) const
1107  {
1108  return Float3(X / other.X, Y / other.Y, Z / other.Z);
1109  }
1110 
1111  DLLEXPORT constexpr inline Float3& operator/=(const Float3& other)
1112  {
1113  X /= other.X;
1114  Y /= other.Y;
1115  Z /= other.Z;
1116  DO_NAN_CHECK;
1117  return *this;
1118  }
1119 
1120  // ---- comparison operators ---- //
1121  // element by element comparison with operators //
1122  DLLEXPORT inline bool operator<(const Float3& other) const noexcept
1123  {
1124  return std::tie(X, Y, Z) < std::tie(other.X, other.Y, other.Z);
1125  }
1126 
1127  DLLEXPORT inline bool operator<=(const Float3& other) const noexcept
1128  {
1129  return std::tie(X, Y, Z) <= std::tie(other.X, other.Y, other.Z);
1130  }
1131 
1132  DLLEXPORT inline bool operator>(const Float3& other) const noexcept
1133  {
1134  return std::tie(X, Y, Z) > std::tie(other.X, other.Y, other.Z);
1135  }
1136 
1137  DLLEXPORT inline bool operator>=(const Float3& other) const noexcept
1138  {
1139  return std::tie(X, Y, Z) >= std::tie(other.X, other.Y, other.Z);
1140  }
1141 
1142  DLLEXPORT inline bool operator==(const Float3& other) const noexcept
1143  {
1144  return X == other.X && Y == other.Y && Z == other.Z;
1145  }
1146 
1147  DLLEXPORT inline bool operator!=(const Float3& other) const noexcept
1148  {
1149  return X != other.X || Y != other.Y || Z != other.Z;
1150  }
1151 
1152  // ------------------ Functions ------------------ //
1153  // getters //
1154  DLLEXPORT inline float GetX() const noexcept
1155  {
1156  return X;
1157  }
1158 
1159  DLLEXPORT inline float GetY() const noexcept
1160  {
1161  return Y;
1162  }
1163 
1164  DLLEXPORT inline float GetZ() const noexcept
1165  {
1166  return Z;
1167  }
1168 
1169  // setters //
1170  DLLEXPORT inline void SetX(float val)
1171  {
1172  X = val;
1173  DO_NAN_CHECK;
1174  }
1175 
1176  DLLEXPORT inline void SetY(float val)
1177  {
1178  Y = val;
1179  DO_NAN_CHECK;
1180  }
1181 
1182  DLLEXPORT inline void SetZ(float val)
1183  {
1184  Z = val;
1185  DO_NAN_CHECK;
1186  }
1187 
1188  // add all elements together //
1189  DLLEXPORT inline float HAdd() const noexcept
1190  {
1191  return X + Y + Z;
1192  }
1193 
1194  // Add all elements together absoluted (abs()) //
1195  DLLEXPORT inline float HAddAbs() const noexcept
1196  {
1197  return std::abs(X) + std::abs(Y) + std::abs(Z);
1198  }
1199 
1200  // getting min and max of objects //
1201  DLLEXPORT inline Float3 MinElements(const Float3& other) const noexcept
1202  {
1203  return Float3(
1204  X < other.X ? X : other.X, Y < other.Y ? Y : other.Y, Z < other.Z ? Z : other.Z);
1205  }
1206 
1207  DLLEXPORT inline Float3 MaxElements(const Float3& other) const noexcept
1208  {
1209  return Float3(
1210  X > other.X ? X : other.X, Y > other.Y ? Y : other.Y, Z > other.Z ? Z : other.Z);
1211  }
1212 
1213  // value clamping //
1214  DLLEXPORT inline Float3 Clamp(const Float3& min, const Float3& max) const noexcept
1215  {
1216  const Float3 minval = this->MinElements(max);
1217  return min.MaxElements(minval);
1218  }
1219 
1220  DLLEXPORT inline Float3 DegreesToRadians() const noexcept
1221  {
1223  }
1224 
1225  // ----------------- Vector math ------------------- //
1226  // dot product of the vectors //
1227  DLLEXPORT constexpr inline float Dot(const Float3& val) const noexcept
1228  {
1229  return X * val.X + Y * val.Y + Z * val.Z;
1230  }
1231 
1232 
1233  DLLEXPORT constexpr inline Float3 Cross(const Float3& val) const
1234  {
1235  return Float3(Y * val.Z - val.Y * Z, Z * val.X - val.Z * X, X * val.Y - val.X * Y);
1236  }
1237 
1238  // length of the vector //
1239  DLLEXPORT inline float Length() const noexcept
1240  {
1241  return std::sqrt(LengthSquared());
1242  }
1243 
1244  DLLEXPORT constexpr inline float LengthSquared() const noexcept
1245  {
1246  return X * X + Y * Y + Z * Z;
1247  }
1248 
1249  // normalizes the vector //
1250  DLLEXPORT inline Float3 Normalize() const
1251  {
1252  const float length = Length();
1253  if(length == 0)
1254  return Float3(0, 0, 0);
1255  return (*this) / length;
1256  }
1257 
1258  // safe version of normalization //
1259  DLLEXPORT inline Float3 NormalizeSafe(const Float3& safer = Float3(1, 0, 0)) const noexcept
1260  {
1261  // security //
1262  LEVIATHAN_ASSERT(safer.IsNormalized(), "safer not normalized");
1263  if(LengthSquared() == 0)
1264  return safer;
1265  const float length = Length();
1266  return (*this) / length;
1267  }
1268 
1269  // checks is the vector normalized //
1270  DLLEXPORT inline bool IsNormalized() const noexcept
1271  {
1272  // is absolute -1.f under normalization tolerance //
1273  return fabs(X * X + Y * Y + Z * Z - 1.0f) < NORMALIZATION_TOLERANCE;
1274  }
1275 
1276  // does linear interpolation between vectors and coefficient f, not limited to range
1277  // [0,1], courtesy of ozz-animation //
1278  DLLEXPORT inline Float3 Lerp(const Float3& other, float f) const noexcept
1279  {
1280  return Float3((other.X - X) * f + X, (other.Y - Y) * f + Y, (other.Z - Z) * f + Z);
1281  }
1282 
1283  // compares distance between vectors to tolerance, returns true if less //
1284  DLLEXPORT inline bool Compare(const Float3& other, float tolerance) const noexcept
1285  {
1286  const Float3 difference = (*this) - other;
1287  return difference.Dot(difference) < tolerance * tolerance;
1288  }
1289 
1291  const float& yaw, const float& pitch) noexcept
1292  {
1293  return Float3(-sin(yaw * DEGREES_TO_RADIANS), sin(pitch * DEGREES_TO_RADIANS),
1294  -cos(yaw * DEGREES_TO_RADIANS))
1295  .NormalizeSafe(Zeroed);
1296  }
1297 
1298  // ----------------- casts ------------------- //
1299 #ifdef LEVIATHAN_USING_OGRE
1300  DLLEXPORT inline Float3(const bs::Vector3& vec) :
1301  // copy values //
1302  X(vec.x), Y(vec.y), Z(vec.z)
1303  {
1304  DO_NAN_CHECK;
1305  }
1306 
1307  DLLEXPORT inline operator bs::Vector3() const
1308  {
1309  return bs::Vector3(X, Y, Z);
1310  }
1311 
1312  DLLEXPORT inline Float3(const btVector3& vec) :
1313  // copy values //
1314  X(vec.x()), Y(vec.y()), Z(vec.z())
1315  {
1316  DO_NAN_CHECK;
1317  }
1318 
1319  DLLEXPORT inline operator btVector3() const
1320  {
1321  return btVector3(X, Y, Z);
1322  }
1323 
1324 #endif // LEVIATHAN_USING_OGRE
1325  // ------------------------------------ //
1326 
1327  VALUE_TYPE(Float3);
1328 
1329  float X = 0;
1330  float Y = 0;
1331  float Z = 0;
1332 
1334  DLLEXPORT static const Float3 UnitVUp;
1335  DLLEXPORT static const Float3 Zeroed;
1339 };
1340 
1341 struct Float4 {
1342 public:
1343  DLLEXPORT constexpr inline Float4() noexcept = default;
1344 
1345  DLLEXPORT constexpr inline Float4(float f1, float f2, float f3, float f4) :
1346  X(f1), Y(f2), Z(f3), W(f4)
1347  {
1348  DO_NAN_CHECK;
1349  }
1350 
1351  DLLEXPORT constexpr inline Float4(Float2 floats, float f3, float f4) :
1352  X(floats.X), Y(floats.Y), Z(f3), W(f4)
1353  {
1354  DO_NAN_CHECK;
1355  }
1356 
1357  DLLEXPORT constexpr inline Float4(Float3 floats, float f4) :
1358  X(floats.X), Y(floats.Y), Z(floats.Z), W(f4)
1359  {
1360  DO_NAN_CHECK;
1361  }
1362 
1363  DLLEXPORT constexpr inline explicit Float4(float data) : X(data), Y(data), Z(data), W(data)
1364  {
1365  DO_NAN_CHECK;
1366  }
1367 
1368  DLLEXPORT inline bool HasInvalidValues() const noexcept
1369  {
1370  return !std::isfinite(X) || !std::isfinite(Y) || !std::isfinite(Z) ||
1371  !std::isfinite(W);
1372  }
1373 
1374  DLLEXPORT inline void CheckForNans() const
1375  {
1376  if(HasInvalidValues()) {
1377  DEBUG_BREAK;
1378  throw std::runtime_error("Float4 has NaNs (or infinites in it) in it!");
1379  }
1380  }
1381 
1382  // access operator //
1383  DLLEXPORT inline float& operator[](unsigned nindex)
1384  {
1385  switch(nindex) {
1386  case 0: return X;
1387  case 1: return Y;
1388  case 2: return Z;
1389  case 3: return W;
1390  default: break;
1391  }
1392 
1393  LEVIATHAN_ASSERT(0, "invalid [] access");
1394  return X;
1395  }
1396  DLLEXPORT inline float operator[](unsigned nindex) const
1397  {
1398  switch(nindex) {
1399  case 0: return X;
1400  case 1: return Y;
1401  case 2: return Z;
1402  case 3: return W;
1403  default: break;
1404  }
1405 
1406  LEVIATHAN_ASSERT(0, "invalid [] access");
1407  return X;
1408  }
1409 
1410  // Is this a good idea?
1412  DLLEXPORT inline operator float*() noexcept
1413  {
1414  // this should be always confirmed to work //
1415  return &X;
1416  }
1417 
1418  // ------------------- Operators ----------------- //
1419  // add elements //
1420  DLLEXPORT inline Float4 operator+(const Float4& other) const noexcept
1421  {
1422  return Float4(X + other.X, Y + other.Y, Z + other.Z, W + other.W);
1423  }
1424 
1425  DLLEXPORT inline Float4& operator+=(const Float4& other) noexcept
1426  {
1427  X += other.X;
1428  Y += other.Y;
1429  Z += other.Z;
1430  W += other.W;
1431  return *this;
1432  }
1433 
1434  // subtracts all elements //
1435  DLLEXPORT inline Float4 operator-(const Float4& other) const noexcept
1436  {
1437  return Float4(X - other.X, Y - other.Y, Z - other.Z, W - other.W);
1438  }
1439 
1440  DLLEXPORT inline Float4& operator-=(const Float4& other) noexcept
1441  {
1442  X -= other.X;
1443  Y -= other.Y;
1444  Z -= other.Z;
1445  W -= other.W;
1446  return *this;
1447  }
1448 
1449  // negates all elements //
1450  DLLEXPORT inline Float4 operator-() const noexcept
1451  {
1452  return Float4(-X, -Y, -Z, -W);
1453  }
1454 
1455  // returns the vector //
1456  DLLEXPORT inline Float4 operator+() const noexcept
1457  {
1458  return Float4(*this);
1459  }
1460 
1461  // multiplies elements together //
1462  DLLEXPORT inline Float4 operator*(const Float4& other) const noexcept
1463  {
1464  return Float4(X * other.X, Y * other.Y, Z * other.Z, W * other.W);
1465  }
1466 
1467  DLLEXPORT inline Float4& operator*=(const Float4& other) noexcept
1468  {
1469  X *= other.X;
1470  Y *= other.Y;
1471  Z *= other.Z;
1472  W *= other.W;
1473  DO_NAN_CHECK;
1474  return *this;
1475  }
1476 
1477  // Divides all elements by float //
1478  DLLEXPORT inline Float4 operator/(float val) const
1479  {
1480  return Float4(X / val, Y / val, Z / val, W / val);
1481  }
1482 
1483  DLLEXPORT inline Float4& operator/=(float val)
1484  {
1485  X /= val;
1486  Y /= val;
1487  Z /= val;
1488  W /= val;
1489  DO_NAN_CHECK;
1490  return *this;
1491  }
1492 
1493  // multiply by scalar f //
1494  DLLEXPORT inline Float4 operator*(float val) const noexcept
1495  {
1496  return Float4(X * val, Y * val, Z * val, W * val);
1497  }
1498 
1499  DLLEXPORT inline Float4& operator*=(float val) noexcept
1500  {
1501  X *= val;
1502  Y *= val;
1503  Z *= val;
1504  W *= val;
1505  DO_NAN_CHECK;
1506  return *this;
1507  }
1508 
1509  // divides all elements //
1510  DLLEXPORT inline Float4 operator/(const Float4& other) const
1511  {
1512  return Float4(X / other.X, Y / other.Y, Z / other.Z, W / other.W);
1513  }
1514 
1515  DLLEXPORT inline Float4& operator/=(const Float4& other)
1516  {
1517  X /= other.X;
1518  Y /= other.Y;
1519  Z /= other.Z;
1520  W /= other.W;
1521  DO_NAN_CHECK;
1522  return *this;
1523  }
1524 
1525  // ---- comparison operators ---- //
1526  // element by element comparison with operators //
1527  DLLEXPORT inline bool operator<(const Float4& other) const noexcept
1528  {
1529  return std::tie(X, Y, Z, W) < std::tie(other.X, other.Y, other.Z, other.W);
1530  }
1531 
1532  DLLEXPORT inline bool operator<=(const Float4& other) const noexcept
1533  {
1534  return std::tie(X, Y, Z, W) <= std::tie(other.X, other.Y, other.Z, other.W);
1535  }
1536 
1537  DLLEXPORT inline bool operator>(const Float4& other) const noexcept
1538  {
1539  return std::tie(X, Y, Z, W) > std::tie(other.X, other.Y, other.Z, other.W);
1540  }
1541 
1542  DLLEXPORT inline bool operator>=(const Float4& other) const noexcept
1543  {
1544  return std::tie(X, Y, Z, W) >= std::tie(other.X, other.Y, other.Z, other.W);
1545  }
1546 
1547  DLLEXPORT inline bool operator==(const Float4& other) const noexcept
1548  {
1549  return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
1550  }
1551 
1552  DLLEXPORT inline bool operator!=(const Float4& other) const noexcept
1553  {
1554  return X != other.X || Y != other.Y || Z != other.Z || W != other.W;
1555  }
1556 
1557  // ------------------ Functions ------------------ //
1558  // getters //
1559  DLLEXPORT inline float GetX() const noexcept
1560  {
1561  return X;
1562  }
1563 
1564  DLLEXPORT inline float GetY() const noexcept
1565  {
1566  return Y;
1567  }
1568 
1569  DLLEXPORT inline float GetZ() const noexcept
1570  {
1571  return Z;
1572  }
1573 
1574  DLLEXPORT inline float GetW() const noexcept
1575  {
1576  return W;
1577  }
1578 
1579  // setters //
1580  DLLEXPORT inline void SetX(float val)
1581  {
1582  X = val;
1583  DO_NAN_CHECK;
1584  }
1585 
1586  DLLEXPORT inline void SetY(float val)
1587  {
1588  Y = val;
1589  DO_NAN_CHECK;
1590  }
1591 
1592  DLLEXPORT inline void SetZ(float val)
1593  {
1594  Z = val;
1595  DO_NAN_CHECK;
1596  }
1597 
1598  DLLEXPORT inline void SetW(float val)
1599  {
1600  W = val;
1601  DO_NAN_CHECK;
1602  }
1603 
1604  // add all elements together //
1605  DLLEXPORT inline float HAdd() const noexcept
1606  {
1607  return X + Y + Z + W;
1608  }
1609 
1610  // Add all elements together absoluted (abs()) //
1611  DLLEXPORT inline float HAddAbs() const noexcept
1612  {
1613  return std::abs(X) + std::abs(Y) + std::abs(Z) + std::abs(W);
1614  }
1615 
1616  // getting min and max of objects //
1617  DLLEXPORT inline Float4 MinElements(const Float4& other) const noexcept
1618  {
1619  return Float4(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y,
1620  Z < other.Z ? Z : other.Z, W < other.W ? W : other.W);
1621  }
1622 
1623  DLLEXPORT inline Float4 MaxElements(const Float4& other) const noexcept
1624  {
1625  return Float4(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y,
1626  Z > other.Z ? Z : other.Z, W > other.W ? W : other.W);
1627  }
1628 
1629  // value clamping //
1630  DLLEXPORT inline Float4 Clamp(const Float4& min, const Float4& max) const noexcept
1631  {
1632  const Float4 minval = this->MinElements(max);
1633  return min.MaxElements(minval);
1634  }
1635 
1636  // ----------------- Vector math ------------------- //
1637  // dot product of the vectors //
1638  DLLEXPORT inline float Dot(const Float4& val) const noexcept
1639  {
1640  return X * val.X + Y * val.Y + Z * val.Z + W * val.W;
1641  }
1642 
1643  // length of the vector //
1644  DLLEXPORT inline float Length() const noexcept
1645  {
1646  return std::sqrt(LengthSquared());
1647  }
1648 
1649  DLLEXPORT inline float LengthSquared() const noexcept
1650  {
1651  return X * X + Y * Y + Z * Z + W * W;
1652  }
1653 
1654  // normalizes the vector //
1655  DLLEXPORT inline Float4 Normalize() const
1656  {
1657  const float length = Length();
1658 
1659  if(length == 0) {
1660  // Returns an identity quaternion
1661  return Float4(0, 0, 0, 1);
1662  }
1663 
1664  return (*this) / length;
1665  }
1666 
1667  // safe version of normalization //
1668  DLLEXPORT inline Float4 NormalizeSafe(const Float4& safer = Float4(1, 0, 0, 0)) const
1669  noexcept
1670  {
1671  // security //
1672  LEVIATHAN_ASSERT(safer.IsNormalized(), "safer not normalized");
1673  if(LengthSquared() == 0)
1674  return safer;
1675  const float length = Length();
1676  return (*this) / length;
1677  }
1678 
1679  // checks is the vector normalized //
1680  DLLEXPORT inline bool IsNormalized() const noexcept
1681  {
1682  // is absolute -1.f under normalization tolerance //
1683  return fabs(X * X + Y * Y + Z * Z + W * W - 1.0f) < NORMALIZATION_TOLERANCE;
1684  }
1685 
1686  // does linear interpolation between vectors and coefficient f, not limited to range
1687  // [0,1], courtesy of ozz-animation //
1688  DLLEXPORT inline Float4 Lerp(const Float4& other, float f) const noexcept
1689  {
1690  return Float4((other.X - X) * f + X, (other.Y - Y) * f + Y, (other.Z - Z) * f + Z,
1691  (other.W - W) * f + W);
1692  }
1693 
1694  // compares distance between vectors to tolerance, returns true if less //
1695  DLLEXPORT inline bool Compare(const Float4& other, float tolerance) const noexcept
1696  {
1697  const Float4 difference = (*this) - other;
1698  return difference.Dot(difference) < tolerance * tolerance;
1699  }
1700 
1701  // ------------------------------------ //
1702  // HSB operations
1703  DLLEXPORT void ConvertToHSB(float& hue, float& saturation, float& brightness) const;
1704  DLLEXPORT static Float4 FromHSB(float hue, float saturation, float brightness);
1705 
1706 
1707  // ----------------- casts ------------------- //
1708  // Should this macro be replaced by a inline if in the cpp file?
1709 #ifdef LEVIATHAN_USING_OGRE
1710  DLLEXPORT inline Float4(const bs::Quaternion& quat)
1711  {
1712  // copy values //
1713  X = quat.x;
1714  Y = quat.y;
1715  Z = quat.z;
1716  W = quat.w;
1717  DO_NAN_CHECK;
1718  }
1719 
1720  DLLEXPORT inline Float4(const bs::Color& colour)
1721  {
1722  // copy values //
1723  X = colour.r;
1724  Y = colour.g;
1725  Z = colour.b;
1726  W = colour.a;
1727  DO_NAN_CHECK;
1728  }
1729 
1730  DLLEXPORT inline operator bs::Quaternion() const
1731  {
1732  // bsf has these in different order
1733  return bs::Quaternion(W, X, Y, Z);
1734  }
1735 
1736  DLLEXPORT inline operator bs::Color() const
1737  {
1738  return bs::Color(X, Y, Z, W);
1739  }
1740 
1741  DLLEXPORT inline operator bs::Vector4() const
1742  {
1743  return bs::Vector4(X, Y, Z, W);
1744  }
1745 
1746  DLLEXPORT inline Float4(const btQuaternion& quat)
1747  {
1748  // copy values //
1749  X = quat.x();
1750  Y = quat.y();
1751  Z = quat.z();
1752  W = quat.w();
1753  DO_NAN_CHECK;
1754  }
1755 
1756  DLLEXPORT inline operator btQuaternion() const
1757  {
1758  return btQuaternion(X, Y, Z, W);
1759  }
1760 
1761 #endif // LEVIATHAN_USING_OGRE
1762 
1763  VALUE_TYPE(Float4);
1764 
1765  float X = 0;
1766  float Y = 0;
1767  float Z = 0;
1768  float W = 0;
1769 
1770  // specific colours //
1774 
1775  // Use these from other libraries/executables to avoid linker errors //
1776  DLLEXPORT static const Float4& GetColourBlack();
1777  DLLEXPORT static const Float4& GetColourWhite();
1778  DLLEXPORT static const Float4& GetColourTransparent();
1779 };
1780 
1781 
1782 // Stream operators //
1783 DLLEXPORT std::ostream& operator<<(std::ostream& stream, const Leviathan::Float4& value);
1784 
1785 DLLEXPORT std::ostream& operator<<(std::ostream& stream, const Leviathan::Float3& value);
1786 
1787 DLLEXPORT std::ostream& operator<<(std::ostream& stream, const Leviathan::Float2& value);
1788 
1789 DLLEXPORT std::ostream& operator<<(
1790  std::ostream& stream, const Leviathan::StartEndIndex& value);
1791 
1792 DLLEXPORT std::ostream& operator<<(
1793  std::ostream& stream, const Leviathan::PotentiallySetIndex& value);
1794 
1795 } // namespace Leviathan
1796 
1797 #ifdef LEAK_INTO_GLOBAL
1798 using Leviathan::Degree;
1799 using Leviathan::Float2;
1800 using Leviathan::Float3;
1801 using Leviathan::Float4;
1802 using Leviathan::Int2;
1803 using Leviathan::Int3;
1804 using Leviathan::Radian;
1805 #endif
DLLEXPORT constexpr Int3 operator-(const Int3 &other) const noexcept
Definition: Types.h:455
DLLEXPORT constexpr Float3 & operator/=(const Float3 &other)
Definition: Types.h:1111
DLLEXPORT constexpr Float2(float data)
Definition: Types.h:669
DLLEXPORT Float2 operator/(float val) const
Definition: Types.h:754
DLLEXPORT constexpr Int3 Clamp(const Int3 &min, const Int3 &max) const noexcept
Definition: Types.h:627
DLLEXPORT constexpr Float3 & operator*=(float val) noexcept
Definition: Types.h:1096
DLLEXPORT float GetY() const noexcept
Definition: Types.h:834
DLLEXPORT constexpr Float4() noexcept=default
DLLEXPORT void SetX(float val)
Definition: Types.h:840
DLLEXPORT constexpr Float3 operator+() const noexcept
Definition: Types.h:1055
DLLEXPORT void SetX(int val)
Definition: Types.h:586
DLLEXPORT constexpr Float3 operator-(const Float3 &other) const noexcept
Definition: Types.h:1035
DLLEXPORT Float2 Normalize() const
Definition: Types.h:901
DLLEXPORT constexpr unsigned int LengthSquared() const noexcept
Definition: Types.h:640
DLLEXPORT void SetY(float val)
Definition: Types.h:1586
DLLEXPORT Int2 & operator+=(const Int2 &other) noexcept
Definition: Types.h:230
DLLEXPORT constexpr bool operator==(const Int2 &other) const noexcept
Definition: Types.h:336
bool operator==(const Radian &other)
Definition: Types.h:154
DLLEXPORT constexpr Int3 MinElements(const Int3 &other) const noexcept
Definition: Types.h:614
DLLEXPORT Int3 & operator/=(int val)
Definition: Types.h:500
DLLEXPORT Float4 & operator+=(const Float4 &other) noexcept
Definition: Types.h:1425
DLLEXPORT Float4 Normalize() const
Definition: Types.h:1655
DLLEXPORT float GetZ() const noexcept
Definition: Types.h:1569
DLLEXPORT bool operator>(const Float2 &other) const noexcept
Definition: Types.h:807
DLLEXPORT float GetX() const noexcept
Definition: Types.h:1559
DLLEXPORT Float4 operator*(float val) const noexcept
Definition: Types.h:1494
DLLEXPORT bool IsNormalized() const noexcept
Definition: Types.h:1680
DLLEXPORT void SetZ(float val)
Definition: Types.h:1182
DLLEXPORT constexpr int GetZ() const noexcept
Definition: Types.h:580
DLLEXPORT bool operator<(const Float3 &other) const noexcept
Definition: Types.h:1122
static DLLEXPORT const Float3 UnitVUp
Definition: Types.h:1334
DLLEXPORT Float3 MaxElements(const Float3 &other) const noexcept
Definition: Types.h:1207
DLLEXPORT Float4(const btQuaternion &quat)
Definition: Types.h:1746
DLLEXPORT Float3 DegreesToRadians() const noexcept
Definition: Types.h:1220
DLLEXPORT bool operator>(const Float4 &other) const noexcept
Definition: Types.h:1537
DLLEXPORT Float2 & operator/=(float val)
Definition: Types.h:759
DLLEXPORT void SetY(int val)
Definition: Types.h:364
DLLEXPORT void SetY(float val)
Definition: Types.h:1176
DLLEXPORT constexpr bool operator>=(const Int3 &other) const noexcept
Definition: Types.h:553
DLLEXPORT void SetZ(int val)
Definition: Types.h:596
DLLEXPORT constexpr int GetX() const noexcept
Definition: Types.h:570
DLLEXPORT Int2 & operator/=(const Int2 &other)
Definition: Types.h:307
constexpr float ValueInDegrees() const noexcept
Definition: Types.h:164
DLLEXPORT float Length() const noexcept
Definition: Types.h:635
DLLEXPORT constexpr Int2 operator-(const Int2 &other) const noexcept
Definition: Types.h:238
DLLEXPORT Float3 NormalizeSafe(const Float3 &safer=Float3(1, 0, 0)) const noexcept
Definition: Types.h:1259
DLLEXPORT float Length() const noexcept
Definition: Types.h:401
DLLEXPORT constexpr Int3 operator*(const Int3 &other) const noexcept
Definition: Types.h:481
DLLEXPORT bool operator<(const Float4 &other) const noexcept
Definition: Types.h:1527
DLLEXPORT constexpr Float3(float x, float y, float z) noexcept
Definition: Types.h:958
DLLEXPORT constexpr int HAdd() const noexcept
Definition: Types.h:602
static DLLEXPORT Float4 FromHSB(float hue, float saturation, float brightness)
Definition: Types.cpp:83
DLLEXPORT bool operator>=(const Float3 &other) const noexcept
Definition: Types.h:1137
DLLEXPORT constexpr Float3(float data) noexcept
Definition: Types.h:969
DLLEXPORT float Length() const noexcept
Definition: Types.h:1239
DLLEXPORT constexpr Float2(float x, float y)
Definition: Types.h:658
DLLEXPORT constexpr bool operator==(const Int3 &other) const noexcept
Definition: Types.h:558
DLLEXPORT constexpr Int2 Clamp(const Int2 &min, const Int2 &max) const noexcept
Definition: Types.h:393
DLLEXPORT float HAddAbs() const noexcept
Definition: Types.h:1611
DLLEXPORT constexpr Int2 MinElements(const Int2 &other) const noexcept
Definition: Types.h:382
Radian & operator=(const Radian &other)
Definition: Types.h:138
DLLEXPORT bool operator!=(const Float4 &other) const noexcept
Definition: Types.h:1552
DLLEXPORT bool operator==(const Float2 &other) const noexcept
Definition: Types.h:817
static DLLEXPORT const Float4 & GetColourBlack()
Definition: Types.cpp:31
DLLEXPORT float & operator[](unsigned nindex)
Definition: Types.h:995
DLLEXPORT Float4 & operator/=(const Float4 &other)
Definition: Types.h:1515
DLLEXPORT constexpr Int3(Int2 ints, int z)
Definition: Types.h:423
DLLEXPORT float GetW() const noexcept
Definition: Types.h:1574
DLLEXPORT constexpr Int2 operator+() const noexcept
Definition: Types.h:257
DLLEXPORT Float4(const bs::Quaternion &quat)
Definition: Types.h:1710
DLLEXPORT bool operator==(const Float4 &other) const noexcept
Definition: Types.h:1547
DLLEXPORT void CheckForNans() const
Definition: Types.h:986
DLLEXPORT bool operator<=(const Float4 &other) const noexcept
Definition: Types.h:1532
DLLEXPORT Float2 & operator-=(const Float2 &other) noexcept
Definition: Types.h:720
DLLEXPORT Float4 & operator*=(float val) noexcept
Definition: Types.h:1499
DLLEXPORT Float3(const bs::Vector3 &vec)
Definition: Types.h:1300
DLLEXPORT float Dot(const Float2 &val) const noexcept
Definition: Types.h:884
DLLEXPORT bool Compare(const Float4 &other, float tolerance) const noexcept
Definition: Types.h:1695
DLLEXPORT Int2 & operator-=(const Int2 &other) noexcept
Definition: Types.h:243
DLLEXPORT constexpr bool operator<(const Int3 &other) const noexcept
Definition: Types.h:538
DLLEXPORT float & operator[](int nindex)
Definition: Types.h:688
DLLEXPORT constexpr Float3 operator/(float val) const
Definition: Types.h:1076
DLLEXPORT float HAdd() const noexcept
Definition: Types.h:853
DLLEXPORT Int2 & operator/=(int val)
Definition: Types.h:281
DLLEXPORT float HAdd() const noexcept
Definition: Types.h:1189
DLLEXPORT Float4 NormalizeSafe(const Float4 &safer=Float4(1, 0, 0, 0)) const noexcept
Definition: Types.h:1668
DLLEXPORT Float2 MaxElements(const Float2 &other) const noexcept
Definition: Types.h:870
DLLEXPORT Float4 operator+(const Float4 &other) const noexcept
Definition: Types.h:1420
constexpr float ValueInDegrees() const noexcept
Definition: Types.h:194
DLLEXPORT Float2 MinElements(const Float2 &other) const noexcept
Definition: Types.h:865
DLLEXPORT void SetX(int val)
Definition: Types.h:359
DLLEXPORT Int2 & operator*=(const Int2 &other) noexcept
Definition: Types.h:268
DLLEXPORT Int3 & operator+=(const Int3 &other) noexcept
Definition: Types.h:446
DLLEXPORT float GetY() const noexcept
Definition: Types.h:1564
DLLEXPORT bool HasInvalidValues() const noexcept
Definition: Types.h:981
DLLEXPORT void SetZ(float val)
Definition: Types.h:1592
DLLEXPORT Float4 operator/(float val) const
Definition: Types.h:1478
DLLEXPORT Int3 & operator-=(const Int3 &other) noexcept
Definition: Types.h:460
DLLEXPORT void SetY(int val)
Definition: Types.h:591
DLLEXPORT constexpr Float4(float f1, float f2, float f3, float f4)
Definition: Types.h:1345
DLLEXPORT Degree & operator=(const Radian &radians)
Definition: Types.cpp:189
DLLEXPORT Float4 operator-(const Float4 &other) const noexcept
Definition: Types.h:1435
#define DO_NAN_CHECK
Definition: Types.h:20
DLLEXPORT constexpr Int3 operator+(const Int3 &other) const noexcept
Definition: Types.h:441
DLLEXPORT Float4 operator+() const noexcept
Definition: Types.h:1456
DLLEXPORT constexpr Int3 MaxElements(const Int3 &other) const noexcept
Definition: Types.h:620
DLLEXPORT constexpr Float4(Float3 floats, float f4)
Definition: Types.h:1357
DLLEXPORT constexpr Int2 operator+(const Int2 &other) const noexcept
Definition: Types.h:225
static DLLEXPORT const Float4 ColourBlack
Definition: Types.h:1771
DLLEXPORT void CheckForNans() const
Definition: Types.h:679
DLLEXPORT bool operator!=(const Float2 &other) const noexcept
Definition: Types.h:822
bool operator<(const Radian &other)
Definition: Types.h:149
DLLEXPORT Int3 & operator/=(const Int3 &other)
Definition: Types.h:528
StartEndIndex(size_t start, size_t end)
Definition: Types.h:98
static DLLEXPORT Float3 CreateVectorFromAngles(const float &yaw, const float &pitch) noexcept
Definition: Types.h:1290
DLLEXPORT constexpr Int3() noexcept=default
DLLEXPORT Float3 Lerp(const Float3 &other, float f) const noexcept
Definition: Types.h:1278
DLLEXPORT constexpr Float4(float data)
Definition: Types.h:1363
DLLEXPORT constexpr Float3 operator*(float val) const noexcept
Definition: Types.h:1091
bool operator==(const PotentiallySetIndex &other) const
Definition: Types.h:59
DLLEXPORT constexpr Int2 operator*(const Int2 &other) const noexcept
Definition: Types.h:263
DLLEXPORT bool Compare(const Float2 &other, float tolerance) const noexcept
Definition: Types.h:935
DLLEXPORT constexpr int GetY() const noexcept
Definition: Types.h:575
DLLEXPORT float GetX() const noexcept
Definition: Types.h:1154
DLLEXPORT float operator[](unsigned nindex) const
Definition: Types.h:1396
#define isfinite
Definition: jsoncpp.cpp:4247
constexpr Degree(const Degree &other)
Definition: Types.h:178
DLLEXPORT int & operator[](int nindex)
Definition: Types.h:211
DLLEXPORT void ConvertToHSB(float &hue, float &saturation, float &brightness) const
Definition: Types.cpp:49
DLLEXPORT Float4 operator-() const noexcept
Definition: Types.h:1450
DLLEXPORT Float4 MinElements(const Float4 &other) const noexcept
Definition: Types.h:1617
DLLEXPORT constexpr bool operator<=(const Int3 &other) const noexcept
Definition: Types.h:543
DLLEXPORT Float2 Lerp(const Float2 &other, float f) const noexcept
Definition: Types.h:929
DLLEXPORT constexpr int GetY() const noexcept
Definition: Types.h:353
PotentiallySetIndex Index
Definition: Types.h:96
DLLEXPORT constexpr bool operator!=(const Int3 &other) const noexcept
Definition: Types.h:563
Represents an angle in radians.
Definition: Types.h:129
DLLEXPORT Float2 Clamp(const Float2 &min, const Float2 &max) const noexcept
Definition: Types.h:876
DLLEXPORT constexpr Int3(int data)
Definition: Types.h:424
PotentiallySetIndex & operator=(const PotentiallySetIndex &other)
Definition: Types.h:68
DLLEXPORT Float4 Lerp(const Float4 &other, float f) const noexcept
Definition: Types.h:1688
static DLLEXPORT const Float4 ColourWhite
Definition: Types.h:1772
DLLEXPORT Float3 Normalize() const
Definition: Types.h:1250
DLLEXPORT Float2 & operator*=(const Float2 &other) noexcept
Definition: Types.h:745
DLLEXPORT Float2 operator*(const Float2 &other) const noexcept
Definition: Types.h:740
DLLEXPORT Radian & operator=(const Degree &degrees)
Definition: Types.cpp:175
DLLEXPORT float HAdd() const noexcept
Definition: Types.h:1605
DLLEXPORT constexpr bool operator>=(const Int2 &other) const noexcept
Definition: Types.h:331
DLLEXPORT constexpr Int3 operator+() const noexcept
Definition: Types.h:475
DLLEXPORT constexpr Float3 operator+(const Float3 &other) const noexcept
Definition: Types.h:1021
DLLEXPORT constexpr Int3 operator-() const noexcept
Definition: Types.h:469
DLLEXPORT bool HasInvalidValues() const noexcept
Definition: Types.h:674
DLLEXPORT float GetY() const noexcept
Definition: Types.h:1159
DLLEXPORT constexpr bool operator<(const Int2 &other) const noexcept
Definition: Types.h:316
DLLEXPORT float Length() const noexcept
Definition: Types.h:1644
DLLEXPORT bool operator<(const Float2 &other) const noexcept
Definition: Types.h:797
DLLEXPORT bool IsNormalized() const noexcept
Definition: Types.h:921
DLLEXPORT Float4 & operator*=(const Float4 &other) noexcept
Definition: Types.h:1467
static DLLEXPORT const Float3 Zeroed
Definition: Types.h:1335
DLLEXPORT constexpr int GetX() const noexcept
Definition: Types.h:348
DLLEXPORT float GetX() const noexcept
Definition: Types.h:829
DLLEXPORT bool operator>=(const Float4 &other) const noexcept
Definition: Types.h:1542
DLLEXPORT constexpr Float3 operator-() const noexcept
Definition: Types.h:1049
DLLEXPORT float & operator[](unsigned nindex)
Definition: Types.h:1383
DLLEXPORT void SetW(float val)
Definition: Types.h:1598
DLLEXPORT constexpr Int3 operator/(int val) const
Definition: Types.h:495
DLLEXPORT constexpr float LengthSquared() const noexcept
Definition: Types.h:1244
static DLLEXPORT const Float4 & GetColourTransparent()
Definition: Types.cpp:41
DLLEXPORT float LengthSquared() const noexcept
Definition: Types.h:895
DLLEXPORT constexpr Float3 operator*(const Float3 &other) const noexcept
Definition: Types.h:1061
constexpr float ValueInRadians() const noexcept
Definition: Types.h:159
DLLEXPORT Float3(const btVector3 &vec)
Definition: Types.h:1312
DLLEXPORT constexpr Float3 & operator-=(const Float3 &other) noexcept
Definition: Types.h:1040
size_t Length() const
Definition: Types.h:113
Represents an angle in degrees.
Definition: Types.h:174
DLLEXPORT bool operator==(const Float3 &other) const noexcept
Definition: Types.h:1142
DLLEXPORT float GetZ() const noexcept
Definition: Types.h:1164
DLLEXPORT constexpr Int2 operator/(int val) const
Definition: Types.h:276
DLLEXPORT constexpr bool operator<=(const Int2 &other) const noexcept
Definition: Types.h:321
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:100
DLLEXPORT bool operator!=(const Float3 &other) const noexcept
Definition: Types.h:1147
DLLEXPORT Float2 operator+(const Float2 &other) const noexcept
Definition: Types.h:702
DLLEXPORT constexpr Int2(int data) noexcept
Definition: Types.h:208
DLLEXPORT Float2 operator/(const Float2 &other) const
Definition: Types.h:782
DLLEXPORT float HAddAbs() const noexcept
Definition: Types.h:1195
constexpr Degree()
Definition: Types.h:176
DLLEXPORT Float2 & operator+=(const Float2 &other) noexcept
Definition: Types.h:707
Degree & operator=(const Degree &other)
Definition: Types.h:183
static DLLEXPORT const Float3 UnitZAxis
Definition: Types.h:1338
DLLEXPORT Float2 operator-() const noexcept
Definition: Types.h:728
DLLEXPORT float Dot(const Float4 &val) const noexcept
Definition: Types.h:1638
DLLEXPORT bool operator>(const Float3 &other) const noexcept
Definition: Types.h:1132
DLLEXPORT constexpr Float3 & operator*=(const Float3 &other) noexcept
Definition: Types.h:1066
DLLEXPORT int & operator[](int nindex)
Definition: Types.h:427
DLLEXPORT Float4 & operator-=(const Float4 &other) noexcept
Definition: Types.h:1440
static DLLEXPORT const Float3 UnitXAxis
Definition: Types.h:1336
DLLEXPORT constexpr Int3 operator*(int val) const noexcept
Definition: Types.h:509
DLLEXPORT float LengthSquared() const noexcept
Definition: Types.h:1649
DLLEXPORT Float3(const Int3 &values) noexcept
Definition: Types.h:974
DLLEXPORT constexpr Float3(Float2 floats, float z) noexcept
Definition: Types.h:963
DLLEXPORT Float4(const bs::Color &colour)
Definition: Types.h:1720
DLLEXPORT void SetX(float val)
Definition: Types.h:1170
DLLEXPORT Float4 Clamp(const Float4 &min, const Float4 &max) const noexcept
Definition: Types.h:1630
DLLEXPORT bool IsNormalized() const noexcept
Definition: Types.h:1270
DLLEXPORT bool operator<=(const Float2 &other) const noexcept
Definition: Types.h:802
DLLEXPORT constexpr Float4(Float2 floats, float f3, float f4)
Definition: Types.h:1351
bool operator>(const Radian &other)
Definition: Types.h:144
constexpr float RADIANS_TO_DEGREES
Definition: Define.h:69
DLLEXPORT bool HasInvalidValues() const noexcept
Definition: Types.h:1368
DLLEXPORT Float2 & operator/=(const Float2 &other)
Definition: Types.h:787
DLLEXPORT constexpr Int2 operator/(const Int2 &other) const
Definition: Types.h:302
DLLEXPORT constexpr float Dot(const Float3 &val) const noexcept
Definition: Types.h:1227
DLLEXPORT float HAddAbs() const noexcept
Definition: Types.h:859
PotentiallySetIndex(size_t index)
Definition: Types.h:40
PotentiallySetIndex & operator=(const size_t &value)
Definition: Types.h:76
constexpr float DEGREES_TO_RADIANS
Definition: Define.h:68
static DLLEXPORT const Float3 UnitVForward
Definition: Types.h:1333
DLLEXPORT unsigned int HAddAbs() const noexcept
Definition: Types.h:608
static DLLEXPORT const Float4 & GetColourWhite()
Definition: Types.cpp:36
DLLEXPORT unsigned int HAddAbs() const noexcept
Definition: Types.h:376
DLLEXPORT Float2 operator-(const Float2 &other) const noexcept
Definition: Types.h:715
DLLEXPORT Float4 & operator/=(float val)
Definition: Types.h:1483
DLLEXPORT void SetX(float val)
Definition: Types.h:1580
DLLEXPORT constexpr bool operator>(const Int2 &other) const noexcept
Definition: Types.h:326
DLLEXPORT Float3 Clamp(const Float3 &min, const Float3 &max) const noexcept
Definition: Types.h:1214
constexpr Radian(float rawvalue)
Definition: Types.h:132
constexpr Degree(float rawvalue)
Definition: Types.h:177
DLLEXPORT constexpr unsigned int LengthSquared() const noexcept
Definition: Types.h:406
#define DLLEXPORT
Definition: Include.h:84
DLLEXPORT constexpr Int2(int x, int y) noexcept
Definition: Types.h:207
DLLEXPORT constexpr bool operator!=(const Int2 &other) const noexcept
Definition: Types.h:341
DLLEXPORT constexpr int HAdd() const noexcept
Definition: Types.h:370
DLLEXPORT constexpr Float3 operator/(const Float3 &other) const
Definition: Types.h:1106
DLLEXPORT Float2 & operator*=(float val) noexcept
Definition: Types.h:773
DLLEXPORT Float2 NormalizeSafe(const Float2 &safer) const noexcept
Definition: Types.h:910
DLLEXPORT bool operator>=(const Float2 &other) const noexcept
Definition: Types.h:812
DLLEXPORT Int3 & operator*=(int val) noexcept
Definition: Types.h:514
DLLEXPORT Float2 operator*(float val) const noexcept
Definition: Types.h:768
DLLEXPORT Float4 operator*(const Float4 &other) const noexcept
Definition: Types.h:1462
DLLEXPORT void CheckForNans() const
Definition: Types.h:1374
DLLEXPORT Int3 & operator*=(const Int3 &other) noexcept
Definition: Types.h:486
DLLEXPORT constexpr Int3 operator/(const Int3 &other) const
Definition: Types.h:523
DLLEXPORT void SetY(float val)
Definition: Types.h:846
constexpr float NORMALIZATION_TOLERANCE
For checking vector normalization.
Definition: Define.h:50
DLLEXPORT float operator[](unsigned nindex) const
Definition: Types.h:1007
DLLEXPORT bool operator<=(const Float3 &other) const noexcept
Definition: Types.h:1127
DLLEXPORT bool Compare(const Float3 &other, float tolerance) const noexcept
Definition: Types.h:1284
StartEndIndex(size_t start)
Definition: Types.h:100
DLLEXPORT constexpr Float3() noexcept=default
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
DLLEXPORT constexpr Float2() noexcept=default
DLLEXPORT Float4 operator/(const Float4 &other) const
Definition: Types.h:1510
DLLEXPORT constexpr bool operator>(const Int3 &other) const noexcept
Definition: Types.h:548
DLLEXPORT Float3 MinElements(const Float3 &other) const noexcept
Definition: Types.h:1201
constexpr Radian()
Definition: Types.h:131
DLLEXPORT constexpr Int3(int x, int y, int z)
Definition: Types.h:422
DLLEXPORT float Length() const noexcept
Definition: Types.h:890
DLLEXPORT constexpr Int2() noexcept=default
DLLEXPORT constexpr Int2 operator*(int val) const noexcept
Definition: Types.h:289
void Reset()
Reset the Start and End to unset.
Definition: Types.h:105
static DLLEXPORT const Float4 ColourTransparent
Definition: Types.h:1773
DLLEXPORT constexpr Float3 & operator/=(float val)
Definition: Types.h:1081
DLLEXPORT Float2(const Int2 &values) noexcept
Definition: Types.h:663
DLLEXPORT Float2 operator+() const noexcept
Definition: Types.h:734
constexpr Radian(const Radian &other)
Definition: Types.h:133
DLLEXPORT constexpr Int2 MaxElements(const Int2 &other) const noexcept
Definition: Types.h:387
constexpr float ValueInRadians() const noexcept
Definition: Types.h:189
DLLEXPORT std::ostream & operator<<(std::ostream &stream, const VariableBlock &value)
Definition: DataBlock.cpp:284
DLLEXPORT Int2 & operator*=(int val) noexcept
Definition: Types.h:294
DLLEXPORT constexpr Int2 operator-() const noexcept
Definition: Types.h:251
DLLEXPORT constexpr Float3 & operator+=(const Float3 &other) noexcept
Definition: Types.h:1026
static DLLEXPORT const Float3 UnitYAxis
Definition: Types.h:1337
DLLEXPORT Float4 MaxElements(const Float4 &other) const noexcept
Definition: Types.h:1623
DLLEXPORT constexpr Float3 Cross(const Float3 &val) const
Definition: Types.h:1233