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