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 "OgreColourValue.h"
30 #include "OgreQuaternion.h"
31 #include "OgreVector3.h"
32 #include "OgreVector4.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 
1211  DLLEXPORT inline Float3(const Ogre::Vector3& vec) :
1212  // copy values //
1213  X(vec.x), Y(vec.y), Z(vec.z)
1214  {
1215  DO_NAN_CHECK;
1216  }
1217 
1218  DLLEXPORT inline operator Ogre::Vector3() const
1219  {
1220  return Ogre::Vector3(X, Y, Z);
1221  }
1222 
1223  DLLEXPORT inline Float3(const btVector3& vec) :
1224  // copy values //
1225  X(vec.x()), Y(vec.y()), Z(vec.z())
1226  {
1227  DO_NAN_CHECK;
1228  }
1229 
1230  DLLEXPORT inline operator btVector3() const
1231  {
1232  return btVector3(X, Y, Z);
1233  }
1234 
1235 #endif // LEVIATHAN_USING_OGRE
1236  // ------------------------------------ //
1237 
1238  VALUE_TYPE(Float3);
1239 
1240  float X = 0;
1241  float Y = 0;
1242  float Z = 0;
1243 
1244  static const Float3 UnitVForward;
1245  static const Float3 UnitVUp;
1246  static const Float3 Zeroed;
1247 };
1248 
1249 struct Float4 {
1250 public:
1251  DLLEXPORT inline Float4() noexcept = default;
1252 
1253  DLLEXPORT inline Float4(float f1, float f2, float f3, float f4) :
1254  X(f1), Y(f2), Z(f3), W(f4)
1255  {
1256  DO_NAN_CHECK;
1257  }
1258 
1259  DLLEXPORT inline Float4(Float2 floats, float f3, float f4) :
1260  X(floats.X), Y(floats.Y), Z(f3), W(f4)
1261  {
1262  DO_NAN_CHECK;
1263  }
1264 
1265  DLLEXPORT inline Float4(Float3 floats, float f4) :
1266  X(floats.X), Y(floats.Y), Z(floats.Z), W(f4)
1267  {
1268  DO_NAN_CHECK;
1269  }
1270 
1271  DLLEXPORT inline explicit Float4(float data) : X(data), Y(data), Z(data), W(data)
1272  {
1273  DO_NAN_CHECK;
1274  }
1275 
1276  DLLEXPORT inline bool HasInvalidValues() const noexcept
1277  {
1278  return !std::isfinite(X) || !std::isfinite(Y) || !std::isfinite(Z) ||
1279  !std::isfinite(W);
1280  }
1281 
1282  DLLEXPORT inline void CheckForNans() const
1283  {
1284  if(HasInvalidValues()) {
1285  DEBUG_BREAK;
1286  throw std::runtime_error("Float4 has NaNs (or infinites in it) in it!");
1287  }
1288  }
1289 
1290  // access operator //
1291  DLLEXPORT inline float& operator[](int nindex)
1292  {
1293  switch(nindex) {
1294  case 0: return X;
1295  case 1: return Y;
1296  case 2: return Z;
1297  case 3: return W;
1298  default: break;
1299  }
1300 
1301  LEVIATHAN_ASSERT(0, "invalid [] access");
1302  return X;
1303  }
1304 
1305  // Is this a good idea?
1307  DLLEXPORT inline operator float*() noexcept
1308  {
1309  // this should be always confirmed to work //
1310  return &X;
1311  }
1312 
1313  // ------------------- Operators ----------------- //
1314  // add elements //
1315  DLLEXPORT inline Float4 operator+(const Float4& other) const noexcept
1316  {
1317  return Float4(X + other.X, Y + other.Y, Z + other.Z, W + other.W);
1318  }
1319 
1320  DLLEXPORT inline Float4& operator+=(const Float4& other) noexcept
1321  {
1322  X += other.X;
1323  Y += other.Y;
1324  Z += other.Z;
1325  W += other.W;
1326  return *this;
1327  }
1328 
1329  // subtracts all elements //
1330  DLLEXPORT inline Float4 operator-(const Float4& other) const noexcept
1331  {
1332  return Float4(X - other.X, Y - other.Y, Z - other.Z, W - other.W);
1333  }
1334 
1335  DLLEXPORT inline Float4& operator-=(const Float4& other) noexcept
1336  {
1337  X -= other.X;
1338  Y -= other.Y;
1339  Z -= other.Z;
1340  W -= other.W;
1341  return *this;
1342  }
1343 
1344  // negates all elements //
1345  DLLEXPORT inline Float4 operator-() const noexcept
1346  {
1347  return Float4(-X, -Y, -Z, -W);
1348  }
1349 
1350  // returns the vector //
1351  DLLEXPORT inline Float4 operator+() const noexcept
1352  {
1353  return Float4(*this);
1354  }
1355 
1356  // multiplies elements together //
1357  DLLEXPORT inline Float4 operator*(const Float4& other) const noexcept
1358  {
1359  return Float4(X * other.X, Y * other.Y, Z * other.Z, W * other.W);
1360  }
1361 
1362  DLLEXPORT inline Float4& operator*=(const Float4& other) noexcept
1363  {
1364  X *= other.X;
1365  Y *= other.Y;
1366  Z *= other.Z;
1367  W *= other.W;
1368  DO_NAN_CHECK;
1369  return *this;
1370  }
1371 
1372  // Divides all elements by float //
1373  DLLEXPORT inline Float4 operator/(float val) const
1374  {
1375  return Float4(X / val, Y / val, Z / val, W / val);
1376  }
1377 
1378  DLLEXPORT inline Float4& operator/=(float val)
1379  {
1380  X /= val;
1381  Y /= val;
1382  Z /= val;
1383  W /= val;
1384  DO_NAN_CHECK;
1385  return *this;
1386  }
1387 
1388  // multiply by scalar f //
1389  DLLEXPORT inline Float4 operator*(float val) const noexcept
1390  {
1391  return Float4(X * val, Y * val, Z * val, W * val);
1392  }
1393 
1394  DLLEXPORT inline Float4& operator*=(float val) noexcept
1395  {
1396  X *= val;
1397  Y *= val;
1398  Z *= val;
1399  W *= val;
1400  DO_NAN_CHECK;
1401  return *this;
1402  }
1403 
1404  // divides all elements //
1405  DLLEXPORT inline Float4 operator/(const Float4& other) const
1406  {
1407  return Float4(X / other.X, Y / other.Y, Z / other.Z, W / other.W);
1408  }
1409 
1410  DLLEXPORT inline Float4& operator/=(const Float4& other)
1411  {
1412  X /= other.X;
1413  Y /= other.Y;
1414  Z /= other.Z;
1415  W /= other.W;
1416  DO_NAN_CHECK;
1417  return *this;
1418  }
1419 
1420  // ---- comparison operators ---- //
1421  // element by element comparison with operators //
1422  DLLEXPORT inline bool operator<(const Float4& other) const noexcept
1423  {
1424  return std::tie(X, Y, Z, W) < std::tie(other.X, other.Y, other.Z, other.W);
1425  }
1426 
1427  DLLEXPORT inline bool operator<=(const Float4& other) const noexcept
1428  {
1429  return std::tie(X, Y, Z, W) <= std::tie(other.X, other.Y, other.Z, other.W);
1430  }
1431 
1432  DLLEXPORT inline bool operator>(const Float4& other) const noexcept
1433  {
1434  return std::tie(X, Y, Z, W) > std::tie(other.X, other.Y, other.Z, other.W);
1435  }
1436 
1437  DLLEXPORT inline bool operator>=(const Float4& other) const noexcept
1438  {
1439  return std::tie(X, Y, Z, W) >= std::tie(other.X, other.Y, other.Z, other.W);
1440  }
1441 
1442  DLLEXPORT inline bool operator==(const Float4& other) const noexcept
1443  {
1444  return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
1445  }
1446 
1447  DLLEXPORT inline bool operator!=(const Float4& other) const noexcept
1448  {
1449  return X != other.X || Y != other.Y || Z != other.Z || W != other.W;
1450  }
1451 
1452  // ------------------ Functions ------------------ //
1453  // getters //
1454  DLLEXPORT inline float GetX() const noexcept
1455  {
1456  return X;
1457  }
1458 
1459  DLLEXPORT inline float GetY() const noexcept
1460  {
1461  return Y;
1462  }
1463 
1464  DLLEXPORT inline float GetZ() const noexcept
1465  {
1466  return Z;
1467  }
1468 
1469  DLLEXPORT inline float GetW() const noexcept
1470  {
1471  return W;
1472  }
1473 
1474  // setters //
1475  DLLEXPORT inline void SetX(float val)
1476  {
1477  X = val;
1478  DO_NAN_CHECK;
1479  }
1480 
1481  DLLEXPORT inline void SetY(float val)
1482  {
1483  Y = val;
1484  DO_NAN_CHECK;
1485  }
1486 
1487  DLLEXPORT inline void SetZ(float val)
1488  {
1489  Z = val;
1490  DO_NAN_CHECK;
1491  }
1492 
1493  DLLEXPORT inline void SetW(float val)
1494  {
1495  W = val;
1496  DO_NAN_CHECK;
1497  }
1498 
1499  // add all elements together //
1500  DLLEXPORT inline float HAdd() const noexcept
1501  {
1502  return X + Y + Z + W;
1503  }
1504 
1505  // Add all elements together absoluted (abs()) //
1506  DLLEXPORT inline float HAddAbs() const noexcept
1507  {
1508  return std::abs(X) + std::abs(Y) + std::abs(Z) + std::abs(W);
1509  }
1510 
1511  // getting min and max of objects //
1512  DLLEXPORT inline Float4 MinElements(const Float4& other) const noexcept
1513  {
1514  return Float4(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y,
1515  Z < other.Z ? Z : other.Z, W < other.W ? W : other.W);
1516  }
1517 
1518  DLLEXPORT inline Float4 MaxElements(const Float4& other) const noexcept
1519  {
1520  return Float4(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y,
1521  Z > other.Z ? Z : other.Z, W > other.W ? W : other.W);
1522  }
1523 
1524  // value clamping //
1525  DLLEXPORT inline Float4 Clamp(const Float4& min, const Float4& max) const noexcept
1526  {
1527  const Float4 minval = this->MinElements(max);
1528  return min.MaxElements(minval);
1529  }
1530 
1531  // ----------------- Vector math ------------------- //
1532  // dot product of the vectors //
1533  DLLEXPORT inline float Dot(const Float4& val) const noexcept
1534  {
1535  return X * val.X + Y * val.Y + Z * val.Z + W * val.W;
1536  }
1537 
1538  // length of the vector //
1539  DLLEXPORT inline float Length() const noexcept
1540  {
1541  return std::sqrt(LengthSquared());
1542  }
1543 
1544  DLLEXPORT inline float LengthSquared() const noexcept
1545  {
1546  return X * X + Y * Y + Z * Z + W * W;
1547  }
1548 
1549  // normalizes the vector //
1550  DLLEXPORT inline Float4 Normalize() const
1551  {
1552  const float length = Length();
1553 
1554  if(length == 0) {
1555  // Returns an identity quaternion
1556  return Float4(0, 0, 0, 1);
1557  }
1558 
1559  return (*this) / length;
1560  }
1561 
1562  // safe version of normalization //
1563  DLLEXPORT inline Float4 NormalizeSafe(const Float4& safer = Float4(1, 0, 0, 0)) const
1564  noexcept
1565  {
1566  // security //
1567  LEVIATHAN_ASSERT(safer.IsNormalized(), "safer not normalized");
1568  if(LengthSquared() == 0)
1569  return safer;
1570  const float length = Length();
1571  return (*this) / length;
1572  }
1573 
1574  // checks is the vector normalized //
1575  DLLEXPORT inline bool IsNormalized() const noexcept
1576  {
1577  // is absolute -1.f under normalization tolerance //
1578  return fabs(X * X + Y * Y + Z * Z + W * W - 1.0f) < NORMALIZATION_TOLERANCE;
1579  }
1580 
1581  // does linear interpolation between vectors and coefficient f, not limited to range
1582  // [0,1], courtesy of ozz-animation //
1583  DLLEXPORT inline Float4 Lerp(const Float4& other, float f) const noexcept
1584  {
1585  return Float4((other.X - X) * f + X, (other.Y - Y) * f + Y, (other.Z - Z) * f + Z,
1586  (other.W - W) * f + W);
1587  }
1588 
1589  // does SPHERICAL interpolation between quaternions //
1590  DLLEXPORT inline Float4 Slerp(const Float4& other, float f) const
1591  {
1592  // extra quaternion for calculations //
1593  Float4 quaternion3;
1594 
1595  // dot product of both //
1596  float dot = this->Dot(other);
1597 
1598  if(dot < 0) {
1599  dot = -dot;
1600  quaternion3 = -other;
1601  } else {
1602  quaternion3 = other;
1603  }
1604 
1605  if(dot < 0.95f) {
1606  const float angle = acosf(dot);
1607  return ((*this) * sinf(angle * (1 - f)) + quaternion3 * sinf(angle * f)) /
1608  sinf(angle);
1609 
1610  } else {
1611  // small angle, linear interpolation will be fine //
1612  return this->Lerp(quaternion3, f);
1613  }
1614  }
1615 
1616  // compares distance between vectors to tolerance, returns true if less //
1617  DLLEXPORT inline bool Compare(const Float4& other, float tolerance) const noexcept
1618  {
1619  const Float4 difference = (*this) - other;
1620  return difference.Dot(difference) < tolerance * tolerance;
1621  }
1622 
1625  DLLEXPORT inline Float3 ToAxis() const
1626  {
1627  const auto s = std::sqrt(1 - std::pow(W, 2));
1628  // Avoid division by zero (this small axis it can be basically converted directly)
1629  if(s > 0) {
1630  return Float3(X / s, Y / s, Z / s);
1631  } else {
1632  return Float3(X, Y, Z);
1633  }
1634  }
1635 
1638  DLLEXPORT inline float ToAngle() const noexcept
1639  {
1640  return 2 * std::acos(W);
1641  }
1642 
1644  DLLEXPORT inline Float4 Inverse() const noexcept
1645  {
1646  const auto length = Length();
1647  if(length > 0.0f) {
1648  const auto inverted = 1.0f / length;
1649  return Float4(-X * inverted, -Y * inverted, -Z * inverted, W * inverted);
1650  } else {
1651  // Invalid inversing
1652  return Float4(0.f);
1653  }
1654  }
1655 
1657  DLLEXPORT inline Float3 RotateVector(const Float3& vector) const
1658  {
1659  // // Alternative from
1660  // //
1661  // https://gamedev.stackexchange.com/questions/28395/rotating-vector3-by-a-quaternion
1662  // const auto u = Float3(X, Y, Z);
1663 
1664  // // Complex math going on
1665  // return u * 2.0f * u.Dot(vector)
1666  // + vector * (W*W - u.Dot(u))
1667  // + u.Cross(vector) * 2.0f * W;
1668 
1669  // Math taken from Ogre::Quaternion
1670  Float3 qvec(X, Y, Z);
1671  const Float3 uv1 = qvec.Cross(vector);
1672  const Float3 uuv = qvec.Cross(uv1) * 2.0f;
1673  const Float3 uv2 = uv1 * 2.0f * W;
1674 
1675  return vector + uv2 + uuv;
1676  }
1677 
1678  // ----------------- casts ------------------- //
1679  // Should this macro be replaced by a inline if in the cpp file?
1680 #ifdef LEVIATHAN_USING_OGRE
1681 
1682  DLLEXPORT inline Float4(const Ogre::Quaternion& quat)
1683  {
1684  // copy values //
1685  X = quat.x;
1686  Y = quat.y;
1687  Z = quat.z;
1688  W = quat.w;
1689  DO_NAN_CHECK;
1690  }
1691 
1692  DLLEXPORT inline Float4(const Ogre::ColourValue& colour)
1693  {
1694  // copy values //
1695  X = colour.r;
1696  Y = colour.g;
1697  Z = colour.b;
1698  W = colour.a;
1699  DO_NAN_CHECK;
1700  }
1701 
1702  DLLEXPORT inline operator Ogre::Quaternion() const
1703  {
1704  // Ogre has these in different order
1705  return Ogre::Quaternion(W, X, Y, Z);
1706  }
1707 
1708  DLLEXPORT inline operator Ogre::ColourValue() const
1709  {
1710  return Ogre::ColourValue(X, Y, Z, W);
1711  }
1712 
1713  DLLEXPORT inline operator Ogre::Vector4() const
1714  {
1715  return Ogre::Vector4(X, Y, Z, W);
1716  }
1717 
1718  DLLEXPORT inline Float4(const btQuaternion& colour)
1719  {
1720  // copy values //
1721  X = colour.x();
1722  Y = colour.y();
1723  Z = colour.z();
1724  W = colour.w();
1725  DO_NAN_CHECK;
1726  }
1727 
1728  DLLEXPORT inline operator btQuaternion() const
1729  {
1730  return btQuaternion(X, Y, Z, W);
1731  }
1732 
1733 #endif // LEVIATHAN_USING_OGRE
1734 
1735  // ----------------- Quaternions ------------------- //
1736  DLLEXPORT static inline Float4 CreateQuaternionFromAngles(const Float3& angles)
1737  {
1738  // multiplied by 0.5 to get double the value //
1739  const float cosx = cosf(0.5f * angles.X);
1740  const float cosy = cosf(0.5f * angles.Y);
1741  const float cosz = cosf(0.5f * angles.Z);
1742 
1743  const float sinx = sinf(0.5f * angles.X);
1744  const float siny = sinf(0.5f * angles.Y);
1745  const float sinz = sinf(0.5f * angles.Z);
1746 
1747  return Float4(
1748  // compute quaternion //
1749  // X
1750  cosz * cosy * sinx - sinz * siny * cosx,
1751  // Y
1752  cosz * siny * cosx + sinz * cosy * sinx,
1753  // Z
1754  sinz * cosy * cosx - cosz * siny * sinx,
1755  // W
1756  cosz * cosy * cosx * sinz * siny * sinx);
1757  }
1758 
1762  DLLEXPORT inline Float3 QuaternionToEuler() const noexcept
1763  {
1764  const float test = X * Y + Z * W;
1765 
1766  if(test > 0.499) {
1767  // Singularity at north pole
1768  return Float3(2 * atan2(X, W), PI / 2, 0);
1769  }
1770 
1771  if(test < -0.499) {
1772  // Singularity at south pole
1773  return Float3(-2 * atan2(X, W), -PI / 2, 0);
1774  }
1775 
1776  const float sqx = X * X;
1777  const float sqy = Y * Y;
1778  const float sqz = Z * Z;
1779 
1780  return Float3(atan2(2 * Y * W - 2 * X * Z, 1 - 2 * sqy - 2 * sqz), asin(2 * test),
1781  atan2(2 * X * W - 2 * Y * Z, 1 - 2 * sqx - 2 * sqz));
1782  }
1783 
1784  DLLEXPORT inline Float4 QuaternionMultiply(const Float4& other) const noexcept
1785  {
1786  return Float4(X * other.X + X * other.W + Y * other.Z - Z * other.Y,
1787  W * other.Y - X * other.Z + Y * other.W + Z * other.X,
1788  W * other.Z + X * other.Y - Y * other.X + Z * other.W,
1789  W * other.W - X * other.X - Y * other.Y - Z * other.Z);
1790  }
1791 
1792  DLLEXPORT inline Float4 QuaternionReverse() const noexcept
1793  {
1794  // reverse vector //
1795  return Float4(-X, -Y, -Z, W);
1796  }
1797 
1798  DLLEXPORT static inline Float4 IdentityQuaternion() noexcept
1799  {
1800  return Float4(0.f, 0.f, 0.f, 1.f);
1801  }
1802 
1803  // Math from here: https://stackoverflow.com/questions/12435671/quaternion-lookat-function
1805  const Float3& sourcepoint, const Float3& target)
1806  {
1807  const auto forward = (target - sourcepoint).NormalizeSafe();
1808  const float dot = Float3::UnitVForward.Dot(forward);
1809 
1810  if(std::abs(dot - (-1.0f)) < 0.000001f) {
1811  // Assumes up is Float3(0, 1, 0)
1812  return Float4(Float3::UnitVUp, 3.1415926535897932f);
1813  }
1814 
1815  if(std::abs(dot - 1.0f) < 0.000001f) {
1816  return Float4::IdentityQuaternion();
1817  }
1818 
1819  const float rotAngle = std::acos(dot);
1820  const Float3 rotAxis = Float3::UnitVForward.Cross(forward).Normalize();
1821  return CreateQuaternionFromAxisAngle(rotAxis, rotAngle);
1822  }
1823 
1829  const Float3& axis, float angle) noexcept
1830  {
1831  const float s = static_cast<float>(std::sin(angle / 2.0));
1832  const float w = static_cast<float>(std::cos(angle / 2.0));
1833  return Float4(axis * s, w);
1834  }
1835 
1836  // TODO: Implement this (Float4::CreateAxisAngleFromEuler)
1837  DLLEXPORT static inline Float4 CreateAxisAngleFromEuler(const Float3& angles)
1838  {
1839  throw std::exception();
1840  // return Float4();
1841  }
1842 
1843  VALUE_TYPE(Float4);
1844 
1845  float X = 0;
1846  float Y = 0;
1847  float Z = 0;
1848  float W = 0;
1849 
1850  // specific colours //
1851  static const Float4 ColourBlack;
1852  static const Float4 ColourWhite;
1854 
1855  // Use these from other libraries/executables to avoid linker errors //
1856  DLLEXPORT static const Float4& GetColourBlack();
1857  DLLEXPORT static const Float4& GetColourWhite();
1858  DLLEXPORT static const Float4& GetColourTransparent();
1859 };
1860 
1861 // Stream operators //
1862 DLLEXPORT std::ostream& operator<<(std::ostream& stream, const Leviathan::Float4& value);
1863 
1864 DLLEXPORT std::ostream& operator<<(std::ostream& stream, const Leviathan::Float3& value);
1865 
1866 DLLEXPORT std::ostream& operator<<(std::ostream& stream, const Leviathan::Float2& value);
1867 
1868 DLLEXPORT std::ostream& operator<<(
1869  std::ostream& stream, const Leviathan::StartEndIndex& value);
1870 
1871 DLLEXPORT std::ostream& operator<<(
1872  std::ostream& stream, const Leviathan::PotentiallySetIndex& value);
1873 
1874 #ifdef LEVIATHAN_USING_OGRE
1875 void ThrowIfMatrixIsNotOrthogonal(const Ogre::Matrix4& matrix, float tol = 1.0e-4f);
1882 #endif
1883 
1884 } // namespace Leviathan
1885 
1886 #ifdef LEAK_INTO_GLOBAL
1887 using Leviathan::Float2;
1888 using Leviathan::Float3;
1889 using Leviathan::Float4;
1890 using Leviathan::Int2;
1891 using Leviathan::Int3;
1892 #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:1265
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:1259
DLLEXPORT Float3 QuaternionToEuler() const noexcept
Definition: Types.h:1762
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:1481
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:1291
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:1320
DLLEXPORT Float3 operator+() const noexcept
Definition: Types.h:965
DLLEXPORT Float4 Normalize() const
Definition: Types.h:1550
DLLEXPORT float GetZ() const noexcept
Definition: Types.h:1464
DLLEXPORT bool operator>(const Float2 &other) const noexcept
Definition: Types.h:730
static const Float4 ColourTransparent
Definition: Types.h:1853
DLLEXPORT float GetX() const noexcept
Definition: Types.h:1454
DLLEXPORT Float4 operator*(float val) const noexcept
Definition: Types.h:1389
DLLEXPORT bool IsNormalized() const noexcept
Definition: Types.h:1575
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
DLLEXPORT Float4(float f1, float f2, float f3, float f4)
Definition: Types.h:1253
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:1804
static const Float3 UnitVUp
Definition: Types.h:1245
DLLEXPORT Float3 DegreesToRadians() const noexcept
Definition: Types.h:1130
DLLEXPORT bool operator>(const Float4 &other) const noexcept
Definition: Types.h:1432
DLLEXPORT Float4(const btQuaternion &colour)
Definition: Types.h:1718
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:1422
static DLLEXPORT Float4 CreateQuaternionFromAngles(const Float3 &angles)
Definition: Types.h:1736
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:1506
DLLEXPORT constexpr Int2 MinElements(const Int2 &other) const noexcept
Definition: Types.h:305
DLLEXPORT bool operator!=(const Float4 &other) const noexcept
Definition: Types.h:1447
DLLEXPORT bool operator==(const Float2 &other) const noexcept
Definition: Types.h:740
static DLLEXPORT const Float4 & GetColourBlack()
Definition: Types.cpp:30
DLLEXPORT Float4 & operator/=(const Float4 &other)
Definition: Types.h:1410
DLLEXPORT Float4(float data)
Definition: Types.h:1271
DLLEXPORT constexpr Int3(Int2 ints, int z)
Definition: Types.h:346
DLLEXPORT float GetW() const noexcept
Definition: Types.h:1469
DLLEXPORT constexpr Int2 operator+() const noexcept
Definition: Types.h:180
DLLEXPORT bool operator==(const Float4 &other) const noexcept
Definition: Types.h:1442
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:1427
DLLEXPORT Float2 & operator-=(const Float2 &other) noexcept
Definition: Types.h:643
DLLEXPORT Float4 & operator*=(float val) noexcept
Definition: Types.h:1394
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:1617
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:1590
static const Float3 UnitVForward
Definition: Types.h:1244
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:1563
static const Float4 ColourWhite
Definition: Types.h:1852
DLLEXPORT Float2 MaxElements(const Float2 &other) const noexcept
Definition: Types.h:793
DLLEXPORT Float4 operator+(const Float4 &other) const noexcept
Definition: Types.h:1315
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:1459
DLLEXPORT bool HasInvalidValues() const noexcept
Definition: Types.h:903
DLLEXPORT void SetZ(float val)
Definition: Types.h:1487
DLLEXPORT Float4 operator/(float val) const
Definition: Types.h:1373
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:1784
DLLEXPORT Float2(float data)
Definition: Types.h:592
DLLEXPORT Float3(const Ogre::Vector3 &vec)
Definition: Types.h:1211
DLLEXPORT Float3(Float2 floats, float z)
Definition: Types.h:886
DLLEXPORT Float4 operator-(const Float4 &other) const noexcept
Definition: Types.h:1330
#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:1351
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
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:1657
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:1345
static const Float3 Zeroed
Definition: Types.h:1246
DLLEXPORT Float4 MinElements(const Float4 &other) const noexcept
Definition: Types.h:1512
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:1583
DLLEXPORT Float3 Normalize() const
Definition: Types.h:1160
DLLEXPORT Float4 QuaternionReverse() const noexcept
Definition: Types.h:1792
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:1500
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:1539
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:1362
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:1437
DLLEXPORT void SetW(float val)
Definition: Types.h:1493
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:40
DLLEXPORT float LengthSquared() const noexcept
Definition: Types.h:818
DLLEXPORT Float3(const btVector3 &vec)
Definition: Types.h:1223
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:1837
DLLEXPORT constexpr bool operator<=(const Int2 &other) const noexcept
Definition: Types.h:244
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:92
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
static const Float4 ColourBlack
Definition: Types.h:1851
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:1533
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:1335
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:1544
DLLEXPORT Float3(const Int3 &values) noexcept
Definition: Types.h:896
DLLEXPORT Float3 operator/(float val) const
Definition: Types.h:986
DLLEXPORT void SetX(float val)
Definition: Types.h:1080
DLLEXPORT Float4 Clamp(const Float4 &min, const Float4 &max) const noexcept
Definition: Types.h:1525
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:1276
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
DLLEXPORT unsigned int HAddAbs() const noexcept
Definition: Types.h:531
static DLLEXPORT const Float4 & GetColourWhite()
Definition: Types.cpp:35
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:1378
DLLEXPORT void SetX(float val)
Definition: Types.h:1475
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:1357
DLLEXPORT void CheckForNans() const
Definition: Types.h:1282
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:1405
DLLEXPORT constexpr bool operator>(const Int3 &other) const noexcept
Definition: Types.h:471
void ThrowIfMatrixIsNotOrthogonal(const Ogre::Matrix4 &matrix, float tol)
Newton compatible matrix orthogonal check.
Definition: Types.cpp:46
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
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:1625
DLLEXPORT Float4(const Ogre::ColourValue &colour)
Definition: Types.h:1692
DLLEXPORT constexpr Int2 operator-() const noexcept
Definition: Types.h:174
DLLEXPORT float ToAngle() const noexcept
Definition: Types.h:1638
static DLLEXPORT Float4 IdentityQuaternion() noexcept
Definition: Types.h:1798
DLLEXPORT Float4 MaxElements(const Float4 &other) const noexcept
Definition: Types.h:1518
DLLEXPORT Float4 Inverse() const noexcept
Inverts a quaternion.
Definition: Types.h:1644
static DLLEXPORT Float4 CreateQuaternionFromAxisAngle(const Float3 &axis, float angle) noexcept
Definition: Types.h:1828
DLLEXPORT Float4(const Ogre::Quaternion &quat)
Definition: Types.h:1682