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 <cmath>
8 
9 // Uncomment for debugging and major slow downs
10 // #define CHECK_FOR_NANS
11 
12 #ifdef CHECK_FOR_NANS
13 #define DO_NAN_CHECK \
14  { \
15  CheckForNans(); \
16  }
17 #else
18 #define DO_NAN_CHECK
19 #endif // CHECK_FOR_NANS
20 
21 #ifdef LEVIATHAN_FULL
22 #include "LinearMath/btQuaternion.h"
23 #include "LinearMath/btVector3.h"
24 #include "OgreColourValue.h"
25 #include "OgreQuaternion.h"
26 #include "OgreVector3.h"
27 #include "OgreVector4.h"
28 #endif // LEVIATHAN_FULL
29 
30 namespace Leviathan {
31 
32 
34 
35  inline PotentiallySetIndex(size_t index) : ValueSet(true), Index(index) {}
36  inline PotentiallySetIndex() = default;
37 
38  inline operator bool() const
39  {
40 
41  return ValueSet;
42  }
43 
44  inline operator size_t() const
45  {
46 #ifdef _DEBUG
47  LEVIATHAN_ASSERT(
48  ValueSet, "PotentiallySetIndex size_t() called when ValueSet is false");
49 #endif // _DEBUG
50 
51  return Index;
52  }
53 
54  bool operator==(const PotentiallySetIndex& other) const
55  {
56 
57  if(!ValueSet)
58  return ValueSet == other.ValueSet;
59 
60  return Index == other.Index;
61  }
62 
64  {
65 
66  ValueSet = other.ValueSet;
67  Index = other.Index;
68  return *this;
69  }
70 
71  inline PotentiallySetIndex& operator=(const size_t& value)
72  {
73 
74  ValueSet = true;
75  Index = value;
76  return *this;
77  }
78 
79  inline bool IsSet() const
80  {
81 
82  return ValueSet;
83  }
84 
85  bool ValueSet = false;
86  size_t Index = 0;
87 };
88 
89 struct StartEndIndex {
90 
92 
93  inline StartEndIndex(size_t start, size_t end) : Start(start), End(end) {}
94 
95  inline StartEndIndex(size_t start) : Start(start) {}
96 
97  inline StartEndIndex() = default;
98 
100  inline void Reset()
101  {
102  Start = Index();
103  End = Index();
104  }
105 
108  inline size_t Length() const
109  {
110  if(!Start || !End || static_cast<size_t>(Start) > static_cast<size_t>(End))
111  return 0;
112 
113  return 1 + (static_cast<size_t>(End) - static_cast<size_t>(Start));
114  }
115 
116 
119 };
120 
121 struct Int2 {
122 public:
124  {
125  X = 0;
126  Y = 0;
127  }
128  DLLEXPORT Int2(int x, int y)
129  {
130  X = x;
131  Y = y;
132  }
133  DLLEXPORT explicit Int2(int data)
134  {
135  X = data;
136  Y = data;
137  }
138  DLLEXPORT Int2(const Int2& other)
139  {
140  X = other.X;
141  Y = other.Y;
142  }
143 
144  // ------------------------------------ //
146  {
147  return Int2(X + val.X, Y + val.Y);
148  }
149 
150  DLLEXPORT int operator[](const int nIndex) const
151  {
152  switch(nIndex) {
153  case 0: return X;
154  case 1: return Y;
155  }
156 
157  LEVIATHAN_ASSERT(0, "invalid [] access");
158  return 0;
159  }
160 
161  // ------------------- Operators ----------------- //
162  // add elements //
163  DLLEXPORT inline Int2 operator+(const Int2& val) const
164  {
165  return Int2(X + val.X, Y + val.Y);
166  }
167 
168  DLLEXPORT inline Int2* operator+=(const Int2& val)
169  {
170  X += val.X;
171  Y += val.Y;
172  return this;
173  }
174  // subtracts all elements //
175  DLLEXPORT inline Int2 operator-(const Int2& val) const
176  {
177  return Int2(X - val.X, Y - val.Y);
178  }
179  // negates all elements //
180  DLLEXPORT inline Int2 operator-() const
181  {
182  return Int2(-X, -Y);
183  }
184  // multiplies elements together //
185  DLLEXPORT inline Int2 operator*(const Int2& val) const
186  {
187  return Int2(X * val.X, Y * val.Y);
188  }
189  // multiply by scalar f //
190  DLLEXPORT inline Int2 operator*(int f) const
191  {
192  return Int2(X * f, Y * f);
193  }
194 
195  DLLEXPORT inline Int2* operator*=(int f)
196  {
197  X *= f;
198  Y *= f;
199  return this;
200  }
201  // divides all elements //
202  DLLEXPORT inline Int2 operator/(const Int2& val) const
203  {
204  return Int2(X / val.X, Y / val.Y);
205  }
206  // divides by int //
207  DLLEXPORT inline Int2 operator/(int f) const
208  {
209  return Int2(X / f, Y / f);
210  }
211  // ---- comparison operators ---- //
212  // element by element comparison with operators //
213  DLLEXPORT inline bool operator<(const Int2& other) const
214  {
215  return X < other.X && Y < other.Y;
216  };
217  DLLEXPORT inline bool operator<=(const Int2& other) const
218  {
219  return X <= other.X && Y <= other.Y;
220  };
221  DLLEXPORT inline bool operator>(const Int2& other) const
222  {
223  return X > other.X && Y > other.Y;
224  };
225  DLLEXPORT inline bool operator>=(const Int2& other) const
226  {
227  return X >= other.X && Y >= other.Y;
228  };
229  DLLEXPORT inline bool operator==(const Int2& other) const
230  {
231  return X == other.X && Y == other.Y;
232  };
233  DLLEXPORT inline bool operator!=(const Int2& other) const
234  {
235  return X != other.X && Y != other.Y;
236  };
237 
238  // ------------------------------------ //
239 
240  DLLEXPORT void SetData(const int& data)
241  {
242  X = data;
243  Y = data;
244  };
245  DLLEXPORT void SetData(const int& data1, const int& data2)
246  {
247  X = data1;
248  Y = data2;
249  };
250 
251  VALUE_TYPE(Int2);
252 
253  int X, Y;
254 };
255 
256 struct Int3 {
257 public:
259  {
260  X = 0;
261  Y = 0;
262  Z = 0;
263  }
264  DLLEXPORT Int3(int x, int y, int z)
265  {
266  X = x;
267  Y = y;
268  Z = z;
269  }
270  DLLEXPORT explicit Int3(int data)
271  {
272  // save a bit of space //
273  X = Y = Z = data;
274  }
275 
276  // ------------------------------------ //
277  DLLEXPORT Int3 operator+(const Int3& val) const
278  {
279  return Int3(X + val.X, Y + val.Y, Z + val.Z);
280  }
281 
282  DLLEXPORT Int3 operator*(int val) const
283  {
284  return Int3(X * val, Y * val, Z * val);
285  }
286 
287  DLLEXPORT int operator[](const int nIndex) const
288  {
289  switch(nIndex) {
290  case 0: return X;
291  case 1: return Y;
292  case 2: return Z;
293  }
294 
295  LEVIATHAN_ASSERT(0, "invalid Int3[] access");
296  return 0;
297  }
298  DLLEXPORT Int3 operator-(const Int3& other) const
299  {
300  return Int3(X - other.X, Y - other.Y, Z - other.Z);
301  }
302 
303  DLLEXPORT inline Int3* operator*=(int f)
304  {
305  X *= f;
306  Y *= f;
307  Z *= f;
308  return this;
309  }
310 
312  {
313  return X + Y + Z;
314  }
315 
316  VALUE_TYPE(Int3);
317 
318  // ------------------------------------ //
319 
320  int X, Y, Z;
321 };
322 
323 struct Int4 {
324 public:
326  {
327  X = Y = Z = W = 0;
328  }
329  DLLEXPORT Int4(int x, int y, int z, int w) : X(x), Y(y), Z(z), W(w) {}
330  DLLEXPORT explicit Int4(int data)
331  {
332  X = Y = Z = W = data;
333  }
334 
335  // ------------------------------------ //
337  {
338  X += val.X;
339  Y += val.Y;
340  Z += val.Z;
341  W += val.W;
342  return *this;
343  }
344  DLLEXPORT int operator[](const int nIndex) const
345  {
346  switch(nIndex) {
347  case 0: return X;
348  case 1: return Y;
349  case 2: return Z;
350  case 3: return W;
351  }
352 
353  LEVIATHAN_ASSERT(0, "invalid Int4[] access");
354  return 0;
355  }
357  {
358  X -= val.X;
359  Y -= val.Y;
360  Z -= val.Z;
361  W -= val.W;
362  return *this;
363  }
365  {
366  return X + Y + Z + W;
367  }
368  // ------------------------------------ //
369 
370  int X, Y, Z, W;
371 };
372 
373 // ----------------- Float types ------------------- //
374 // refactored to match declarations in ozz vec_float //
375 
376 // functions inlined just like in ozz, for speed, I guess //
377 // mostly rewritten to match ozz implementation, just in case and not to break anything //
378 
379 struct Float2 {
380 public:
381  DLLEXPORT inline Float2()
382  {
383  X = Y = 0;
384  };
385  DLLEXPORT inline Float2(float x, float y)
386  {
387  X = x;
388  Y = y;
389  DO_NAN_CHECK;
390  }
391  DLLEXPORT inline explicit Float2(float both)
392  {
393  X = Y = both;
394  DO_NAN_CHECK;
395  }
396 
397  DLLEXPORT inline bool HasInvalidValues() const
398  {
399  if(!std::isfinite(X) || !std::isfinite(Y)) {
400  return true;
401  }
402 
403  return false;
404  }
405 
406  DLLEXPORT inline void CheckForNans()
407  {
408  if(HasInvalidValues()) {
409  DEBUG_BREAK;
410  throw std::runtime_error("Float2 has NaNs (or infinites in it) in it!");
411  }
412  }
413 
414  // access operator //
415  DLLEXPORT inline float& operator[](const int& nindex)
416  {
417  switch(nindex) {
418  case 0: return X;
419  case 1: return Y;
420  }
421 
422  LEVIATHAN_ASSERT(0, "invalid [] access");
423  return X;
424  }
425 
426  // ------------------- Operators ----------------- //
427  // add elements //
428  DLLEXPORT inline Float2 operator+(const Float2& val) const
429  {
430  return Float2(X + val.X, Y + val.Y);
431  }
432 
433  DLLEXPORT inline Float2* operator+=(const Float2& val)
434  {
435  X += val.X;
436  Y += val.Y;
437  return this;
438  }
439  // subtracts all elements //
440  DLLEXPORT inline Float2 operator-(const Float2& val) const
441  {
442  return Float2(X - val.X, Y - val.Y);
443  }
444  // negates all elements //
445  DLLEXPORT inline Float2 operator-() const
446  {
447  return Float2(-X, -Y);
448  }
449  // multiplies elements together //
450  DLLEXPORT inline Float2 operator*(const Float2& val) const
451  {
452  return Float2(X * val.X, Y * val.Y);
453  }
454  // multiply by scalar f //
455  DLLEXPORT inline Float2 operator*(float f) const
456  {
457  return Float2(X * f, Y * f);
458  }
459 
460  DLLEXPORT inline Float2& operator*=(float f)
461  {
462  X *= f;
463  Y *= f;
464  DO_NAN_CHECK;
465  return *this;
466  }
467  // divides all elements //
468  DLLEXPORT inline Float2 operator/(const Float2& val) const
469  {
470  return Float2(X / val.X, Y / val.Y);
471  }
472  // divides by float //
473  DLLEXPORT inline Float2 operator/(float f) const
474  {
475  return Float2(X / f, Y / f);
476  }
477  // ---- comparison operators ---- //
478  // element by element comparison with operators //
479  DLLEXPORT inline bool operator<(const Float2& other) const
480  {
481  return X < other.X && Y < other.Y;
482  };
483  DLLEXPORT inline bool operator<=(const Float2& other) const
484  {
485  return X <= other.X && Y <= other.Y;
486  };
487  DLLEXPORT inline bool operator>(const Float2& other) const
488  {
489  return X > other.X && Y > other.Y;
490  };
491  DLLEXPORT inline bool operator>=(const Float2& other) const
492  {
493  return X >= other.X && Y >= other.Y;
494  };
495  DLLEXPORT inline bool operator==(const Float2& other) const
496  {
497  return X == other.X && Y == other.Y;
498  };
499  DLLEXPORT inline bool operator!=(const Float2& other) const
500  {
501  return X != other.X && Y != other.Y;
502  };
503  // ------------------ Functions ------------------ //
504  DLLEXPORT inline float GetX() const
505  {
506  return X;
507  }
508  DLLEXPORT inline float GetY() const
509  {
510  return Y;
511  }
512  DLLEXPORT inline void SetX(const float& val)
513  {
514  X = val;
515  DO_NAN_CHECK;
516  };
517  DLLEXPORT inline void SetY(const float& val)
518  {
519  Y = val;
520  DO_NAN_CHECK;
521  };
522 
523  // add all elements together //
524  DLLEXPORT inline float HAdd() const
525  {
526  return X + Y;
527  }
528  // Add all elements together after abs() is called on each element //
529  DLLEXPORT inline float HAddAbs() const
530  {
531  return std::fabs(X) + std::fabs(Y);
532  }
533  // getting min and max of objects //
534  DLLEXPORT inline Float2 MinElements(const Float2& other) const
535  {
536  return Float2(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y);
537  }
538  DLLEXPORT inline Float2 MaxElements(const Float2& other) const
539  {
540  return Float2(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y);
541  }
542  // value clamping //
543  DLLEXPORT inline Float2 Clamp(const Float2& min, const Float2& max)
544  {
545  const Float2 minval = this->MinElements(max);
546  return min.MaxElements(minval);
547  }
548 
549  // ----------------- Vector math ------------------- //
550  // dot product of the vectors //
551  DLLEXPORT inline float Dot(const Float2& val) const
552  {
553  return X * val.X + Y * val.Y;
554  }
555  // length of the vector //
556  DLLEXPORT inline float Length() const
557  {
558  return sqrt(X * X + Y * Y);
559  }
560  // normalizes the vector //
561  DLLEXPORT inline Float2 Normalize() const
562  {
563  const float length = Length();
564  if(length == 0)
565  return Float2(0, 0);
566  return Float2(X / length, Y / length);
567  }
568  // safe version of normalization //
569  DLLEXPORT inline Float2 NormalizeSafe(const Float2& safer) const
570  {
571  // security //
572  LEVIATHAN_ASSERT(safer.IsNormalized(), "safer not normalized");
573  const float len = X * X + Y * Y;
574  if(len == 0) {
575  return safer;
576  }
577  const float length = sqrt(len);
578  return Float2(X / length, Y / length);
579  }
580  // checks is the vector normalized //
581  DLLEXPORT inline bool IsNormalized() const
582  {
583  // is absolute -1.f under normalization tolerance //
584  return fabs(X * X + Y * Y - 1.0f) < NORMALIZATION_TOLERANCE;
585  }
586  // does linear interpolation between vectors and coefficient f, not limited to range [0,1],
587  // courtesy of ozz-animation //
588  DLLEXPORT inline Float2 Lerp(const Float2& other, float f) const
589  {
590  return Float2((other.X - X) * f + X, (other.Y - Y) * f + Y);
591  }
592  // compares distance between vectors to tolerance, returns true if less //
593  DLLEXPORT inline bool Compare(const Float2& other, float tolerance) const
594  {
595  const Float2 difference = (*this) - other;
596  return difference.Dot(difference) < tolerance * tolerance;
597  }
598  // ------------------------------------ //
599  // static returns //
600  // creates a Float2 with all zeros //
601  DLLEXPORT inline static Float2 zero()
602  {
603  return Float2(0.f, 0.f);
604  }
605  // creates a Float2 with all ones //
606  DLLEXPORT inline static Float2 one()
607  {
608  return Float2(1.f, 1.f);
609  }
610 
611  // unitary vector x, to work with ozz declarations //
612  DLLEXPORT inline static Float2 x_asix()
613  {
614  return Float2(1.f, 0.f);
615  }
616  // unitary vector y //
617  DLLEXPORT inline static Float2 y_axis()
618  {
619  return Float2(0.f, 1.f);
620  }
621  // ----------------- casts ------------------- //
622  // waiting for Microsoft's compilers to add support for "explicit" here //
623  // DLLEXPORT inline operator D3DXVECTOR2(){
624  // return D3DXVECTOR2(X, Y);
625  //}
626 
628 
629  // data //
630  float X, Y;
631 };
632 struct Float3 {
633 public:
634  // Needed for returning from scripts
636  {
637  X = Y = Z = 0;
638  };
639  DLLEXPORT Float3(float x, float y, float z)
640  {
641  X = x;
642  Y = y;
643  Z = z;
644  DO_NAN_CHECK;
645  }
646  DLLEXPORT Float3(Float2 floats, float z)
647  {
648  X = floats.X;
649  Y = floats.Y;
650  Z = z;
651  DO_NAN_CHECK;
652  }
653  DLLEXPORT explicit Float3(float data)
654  {
655  X = Y = Z = data;
656  DO_NAN_CHECK;
657  }
658  DLLEXPORT Float3(const Int3& values)
659  {
660  X = static_cast<float>(values.X);
661  Y = static_cast<float>(values.Y);
662  Z = static_cast<float>(values.Z);
663 
664  DO_NAN_CHECK;
665  }
666  DLLEXPORT Float3(const Float3& other)
667  {
668  // copy values //
669  X = other.X;
670  Y = other.Y;
671  Z = other.Z;
672 
673  DO_NAN_CHECK;
674  }
675 
676  DLLEXPORT inline bool HasInvalidValues() const
677  {
678  if(!std::isfinite(X) || !std::isfinite(Y) || !std::isfinite(Z)) {
679  return true;
680  }
681 
682  return false;
683  }
684 
685  DLLEXPORT inline void CheckForNans()
686  {
687  if(HasInvalidValues()) {
688  DEBUG_BREAK;
689  throw std::runtime_error("Float3 has NaNs (or infinites in it) in it!");
690  }
691  }
692 
693  // access operator //
694  DLLEXPORT inline float& operator[](const int& nindex)
695  {
696  switch(nindex) {
697  case 0: return X;
698  case 1: return Y;
699  case 2: return Z;
700  }
701  LEVIATHAN_ASSERT(0, "invalid [] access");
702  return X;
703  }
704 
705  // ------------------- Operators ----------------- //
706  // add elements //
707  DLLEXPORT inline Float3 operator+(const Float3& val) const
708  {
709  return Float3(X + val.X, Y + val.Y, Z + val.Z);
710  }
711  DLLEXPORT inline Float3& operator+=(const Float3& val)
712  {
713  X += val.X;
714  Y += val.Y;
715  Z += val.Z;
716  return *this;
717  }
718  DLLEXPORT inline Float3& operator-=(const Float3& val)
719  {
720  X -= val.X;
721  Y -= val.Y;
722  Z -= val.Z;
723  return *this;
724  }
725 
726  // subtracts all elements //
727  DLLEXPORT inline Float3 operator-(const Float3& val) const
728  {
729  return Float3(X - val.X, Y - val.Y, Z - val.Z);
730  }
731  // negates all elements //
732  DLLEXPORT inline Float3 operator-() const
733  {
734  return Float3(-X, -Y, -Z);
735  }
736  // multiplies elements together //
737  DLLEXPORT inline Float3 operator*(const Float3& val) const
738  {
739  return Float3(X * val.X, Y * val.Y, Z * val.Z);
740  }
741  // Divides all elements by float //
742  DLLEXPORT inline Float3 operator/(const float& val) const
743  {
744  return Float3(X / val, Y / val, Z / val);
745  }
746  DLLEXPORT inline Float3& operator/=(const float& val)
747  {
748  X /= val;
749  Y /= val;
750  Z /= val;
751  DO_NAN_CHECK;
752  return *this;
753  }
754  // multiply by scalar f //
755  DLLEXPORT inline Float3 operator*(float f) const
756  {
757  return Float3(X * f, Y * f, Z * f);
758  }
759  DLLEXPORT inline Float3& operator*=(float f)
760  {
761  X *= f;
762  Y *= f;
763  Z *= f;
764  DO_NAN_CHECK;
765  return *this;
766  }
767  // divides all elements //
768  DLLEXPORT inline Float3 operator/(const Float3& val) const
769  {
770  return Float3(X / val.X, Y / val.Y, Z / val.Z);
771  }
772  // divides by float //
773  DLLEXPORT inline Float3 operator/(float f) const
774  {
775  return Float3(X / f, Y / f, Z / f);
776  }
777  // ---- comparison operators ---- //
778  // element by element comparison with operators //
779  DLLEXPORT inline bool operator<(const Float3& other) const
780  {
781  return X < other.X && Y < other.Y && Z < other.Z;
782  };
783  DLLEXPORT inline bool operator<=(const Float3& other) const
784  {
785  return X <= other.X && Y <= other.Y && Z <= other.Z;
786  };
787  DLLEXPORT inline bool operator>(const Float3& other) const
788  {
789  return X > other.X && Y > other.Y && Z > other.Z;
790  };
791  DLLEXPORT inline bool operator>=(const Float3& other) const
792  {
793  return X >= other.X && Y >= other.Y && Z > other.Z;
794  };
795  DLLEXPORT inline bool operator==(const Float3& other) const
796  {
797  return X == other.X && Y == other.Y && Z == other.Z;
798  };
799  DLLEXPORT inline bool operator!=(const Float3& other) const
800  {
801  return !(*this == other);
802  };
803  // ------------------ Functions ------------------ //
804  DLLEXPORT inline float GetX() const
805  {
806  return X;
807  };
808  DLLEXPORT inline float GetY() const
809  {
810  return Y;
811  };
812  DLLEXPORT inline float GetZ() const
813  {
814  return Z;
815  };
816  DLLEXPORT inline void SetX(const float& val)
817  {
818  X = val;
819  DO_NAN_CHECK;
820  };
821  DLLEXPORT inline void SetY(const float& val)
822  {
823  Y = val;
824  DO_NAN_CHECK;
825  };
826  DLLEXPORT inline void SetZ(const float& val)
827  {
828  Z = val;
829  DO_NAN_CHECK;
830  };
831 
832  // add all elements together //
833  DLLEXPORT inline float HAdd() const
834  {
835  return X + Y + Z;
836  }
837  // Add all elements together absoluted (abs()) //
838  DLLEXPORT inline float HAddAbs() const
839  {
840  return std::abs(X) + std::abs(Y) + std::abs(Z);
841  }
842  // getting min and max of objects //
843  DLLEXPORT inline Float3 MinElements(const Float3& other) const
844  {
845  return Float3(
846  X < other.X ? X : other.X, Y < other.Y ? Y : other.Y, Z < other.Z ? Z : other.Z);
847  }
848  DLLEXPORT inline Float3 MaxElements(const Float3& other) const
849  {
850  return Float3(
851  X > other.X ? X : other.X, Y > other.Y ? Y : other.Y, Z > other.Z ? Z : other.Z);
852  }
853  // value clamping //
854  DLLEXPORT inline Float3 Clamp(const Float3& min, const Float3& max)
855  {
856  const Float3 minval = this->MinElements(max);
857  return min.MaxElements(minval);
858  }
859 
861  {
862 
864  }
865 
866  // ----------------- Vector math ------------------- //
867  // dot product of the vectors //
868  DLLEXPORT inline float Dot(const Float3& val) const
869  {
870  return X * val.X + Y * val.Y + Z * val.Z;
871  }
872  DLLEXPORT inline Float3 Cross(const Float3& val) const
873  {
874  return Float3(Y * val.Z - val.Y * Z, Z * val.X - val.Z * X, X * val.Y - val.X * Y);
875  }
876  // length of the vector //
877  DLLEXPORT inline float Length() const
878  {
879  return sqrt(X * X + Y * Y + Z * Z);
880  }
881  DLLEXPORT inline float LengthSquared() const
882  {
883  return X * X + Y * Y + Z * Z;
884  }
885  // normalizes the vector //
886  DLLEXPORT inline Float3 Normalize() const
887  {
888  const float length = Length();
889  if(length == 0)
890  return Float3(0, 0, 0);
891  return Float3(X / length, Y / length, Z / length);
892  }
893  // safe version of normalization //
894  DLLEXPORT inline Float3 NormalizeSafe(const Float3& safer = Float3(1, 0, 0)) const
895  {
896  // security //
897  // assert(safer.IsNormalized() && "safer not normalized");
898  const float len = X * X + Y * Y + Z * Z;
899  if(len == 0) {
900  return safer;
901  }
902  const float length = sqrt(len);
903  return Float3(X / length, Y / length, Z / length);
904  }
905  // checks is the vector normalized //
906  DLLEXPORT inline bool IsNormalized() const
907  {
908  // is absolute -1.f under normalization tolerance //
909  return fabs(X * X + Y * Y + Z * Z - 1.0f) < NORMALIZATION_TOLERANCE;
910  }
911  // does linear interpolation between vectors and coefficient f, not limited to range
912  // [0,1], courtesy of ozz-animation //
913  DLLEXPORT inline Float3 Lerp(const Float3& other, float f) const
914  {
915  return Float3((other.X - X) * f + X, (other.Y - Y) * f + Y, (other.Z - Z) * f + Z);
916  }
917  // compares distance between vectors to tolerance, returns true if less //
918  DLLEXPORT inline bool Compare(const Float3& other, float tolerance) const
919  {
920  const Float3 difference = (*this) - other;
921  return difference.Dot(difference) < tolerance * tolerance;
922  }
923 
924  DLLEXPORT static inline Float3 CreateVectorFromAngles(const float& yaw, const float& pitch)
925  {
926  return Float3(-sin(yaw * DEGREES_TO_RADIANS), sin(pitch * DEGREES_TO_RADIANS),
927  -cos(yaw * DEGREES_TO_RADIANS))
928  .NormalizeSafe(Zeroed);
929  }
930  // ------------------------------------ //
931  // functions to be compatible with ozz functions //
932  // all zero values object //
933  DLLEXPORT inline static Float3 zero()
934  {
935  return Float3(0.f, 0.f, 0.f);
936  }
937  // all ones //
938  DLLEXPORT inline static Float3 one()
939  {
940  return Float3(1.f, 1.f, 1.f);
941  }
942  // unitary vectors //
943  // x axis
944  DLLEXPORT inline static Float3 x_axis()
945  {
946  return Float3(1.f, 0.f, 0.f);
947  }
948 
949  // y axis
950  DLLEXPORT inline static Float3 y_axis()
951  {
952  return Float3(0.f, 1.f, 0.f);
953  }
954 
955  // z axis
956  DLLEXPORT inline static Float3 z_axis()
957  {
958  return Float3(0.f, 0.f, 1.f);
959  }
960  // ----------------- casts ------------------- //
961 #ifdef LEVIATHAN_FULL
962  DLLEXPORT Float3(const Ogre::Vector3& vec)
963  {
964  // copy values //
965  X = vec.x;
966  Y = vec.y;
967  Z = vec.z;
968  DO_NAN_CHECK;
969  }
970 
971  DLLEXPORT inline operator Ogre::Vector3() const
972  {
973  return Ogre::Vector3(X, Y, Z);
974  }
975 
976  DLLEXPORT Float3(const btVector3& vec)
977  {
978  // copy values //
979  X = vec.x();
980  Y = vec.y();
981  Z = vec.z();
982  DO_NAN_CHECK;
983  }
984 
985  DLLEXPORT inline operator btVector3() const
986  {
987  return btVector3(X, Y, Z);
988  }
989 #endif // LEVIATHAN_USING_OGRE
990  // ------------------------------------ //
991 
993 
994  float X, Y, Z;
995 
996  static const Float3 UnitVForward;
997  static const Float3 UnitVUp;
998  static const Float3 Zeroed;
999 };
1000 struct Float4 {
1001 public:
1002  // Needed for returning from scripts
1004  {
1005  X = Y = Z = W = 0;
1006  };
1007  DLLEXPORT Float4(float f1, float f2, float f3, float f4)
1008  {
1009  X = f1;
1010  Y = f2;
1011  Z = f3;
1012  W = f4;
1013  DO_NAN_CHECK;
1014  }
1015  DLLEXPORT Float4(Float2 floats, float f3, float f4)
1016  {
1017  X = floats.X;
1018  Y = floats.Y;
1019  Z = f3;
1020  W = f4;
1021  DO_NAN_CHECK;
1022  }
1023  DLLEXPORT Float4(Float3 floats, float f4)
1024  {
1025  X = floats.X;
1026  Y = floats.Y;
1027  Z = floats.Z;
1028  W = f4;
1029  DO_NAN_CHECK;
1030  }
1031  DLLEXPORT explicit Float4(float val)
1032  {
1033  X = Y = Z = W = val;
1034  DO_NAN_CHECK;
1035  }
1036 
1037  DLLEXPORT inline bool HasInvalidValues() const
1038  {
1039  if(!std::isfinite(X) || !std::isfinite(Y) || !std::isfinite(Z) || !std::isfinite(W)) {
1040  return true;
1041  }
1042 
1043  return false;
1044  }
1045 
1046  DLLEXPORT inline void CheckForNans()
1047  {
1048  if(HasInvalidValues()) {
1049  DEBUG_BREAK;
1050  throw std::runtime_error("Float4 has NaNs (or infinites in it) in it!");
1051  }
1052  }
1053 
1054  // access operator //
1055  DLLEXPORT inline float& operator[](const int& nindex)
1056  {
1057  switch(nindex) {
1058  case 0: return X;
1059  case 1: return Y;
1060  case 2: return Z;
1061  case 3: return W;
1062  }
1063 
1064  LEVIATHAN_ASSERT(0, "invalid [] access");
1065  return X;
1066  }
1067 
1069  DLLEXPORT inline operator float*()
1070  {
1071  // this should be always confirmed to work //
1072  return &X;
1073  }
1074 
1075  // ------------------- Operators ----------------- //
1076  // add elements //
1077  DLLEXPORT inline Float4 operator+(const Float4& val) const
1078  {
1079  return Float4(X + val.X, Y + val.Y, Z + val.Z, W + val.W);
1080  }
1081  // subtracts all elements //
1082  DLLEXPORT inline Float4 operator-(const Float4& val) const
1083  {
1084  return Float4(X - val.X, Y - val.Y, Z - val.Z, W - val.W);
1085  }
1086  // negates all elements //
1087  DLLEXPORT inline Float4 operator-() const
1088  {
1089  return Float4(-X, -Y, -Z, -W);
1090  }
1091  // multiplies elements together //
1092  DLLEXPORT inline Float4 operator*(const Float4& val) const
1093  {
1094  return Float4(X * val.X, Y * val.Y, Z * val.Z, W * val.W);
1095  }
1096  // multiply by scalar f //
1097  DLLEXPORT inline Float4 operator*(float f) const
1098  {
1099  return Float4(X * f, Y * f, Z * f, W * f);
1100  }
1101  // divides all elements //
1102  DLLEXPORT inline Float4 operator/(const Float4& val) const
1103  {
1104  return Float4(X / val.X, Y / val.Y, Z / val.Z, W / val.W);
1105  }
1106  // divides by float //
1107  DLLEXPORT inline Float4 operator/(float f) const
1108  {
1109  return Float4(X / f, Y / f, Z / f, W / f);
1110  }
1111  // ---- comparison operators ---- //
1112  // element by element comparison with operators //
1113  DLLEXPORT inline bool operator<(const Float4& other) const
1114  {
1115  return !(*this == other);
1116  };
1117  DLLEXPORT inline bool operator>(const Float4& other) const
1118  {
1119  return !(*this == other);
1120  };
1121  DLLEXPORT inline bool operator==(const Float4& other) const
1122  {
1123  return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
1124  };
1125  DLLEXPORT inline bool operator!=(const Float4& other) const
1126  {
1127  return X != other.X && Y != other.Y && Z != other.Z && W != other.W;
1128  };
1129  // ------------------ Functions ------------------ //
1130  DLLEXPORT inline float GetX() const
1131  {
1132  return X;
1133  };
1134  DLLEXPORT inline float GetY() const
1135  {
1136  return Y;
1137  };
1138  DLLEXPORT inline float GetZ() const
1139  {
1140  return Z;
1141  };
1142  DLLEXPORT inline float GetW() const
1143  {
1144  return W;
1145  };
1146  DLLEXPORT inline void SetX(const float& val)
1147  {
1148  X = val;
1149  DO_NAN_CHECK;
1150  };
1151  DLLEXPORT inline void SetY(const float& val)
1152  {
1153  Y = val;
1154  DO_NAN_CHECK;
1155  };
1156  DLLEXPORT inline void SetZ(const float& val)
1157  {
1158  Z = val;
1159  DO_NAN_CHECK;
1160  };
1161  DLLEXPORT inline void SetW(const float& val)
1162  {
1163  W = val;
1164  DO_NAN_CHECK;
1165  };
1166 
1167  // add all elements together //
1168  DLLEXPORT inline float HAdd() const
1169  {
1170  return X + Y + Z + W;
1171  }
1172  // Add all elements together after abs() is called on each element //
1173  DLLEXPORT inline float HAddAbs() const
1174  {
1175  return std::abs(X) + std::abs(Y) + std::abs(Z) + std::abs(W);
1176  }
1177  // getting min and max of objects //
1178  DLLEXPORT inline Float4 MinElements(const Float4& other) const
1179  {
1180  return Float4(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y,
1181  Z < other.Z ? Z : other.Z, W < other.W ? W : other.W);
1182  }
1183  DLLEXPORT inline Float4 MaxElements(const Float4& other) const
1184  {
1185  return Float4(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y,
1186  Z > other.Z ? Z : other.Z, W > other.W ? W : other.W);
1187  }
1188  // value clamping //
1189  DLLEXPORT inline Float4 Clamp(const Float4& min, const Float4& max)
1190  {
1191  const Float4 minval = this->MinElements(max);
1192  return min.MaxElements(minval);
1193  }
1194 
1195  // ----------------- Vector math ------------------- //
1196  // dot product of the vectors //
1197  DLLEXPORT inline float Dot(const Float4& val) const
1198  {
1199  return X * val.X + Y * val.Y + Z * val.Z + W * val.W;
1200  }
1201 
1202  // length of the vector //
1203  DLLEXPORT inline float Length() const
1204  {
1205  return sqrt(X * X + Y * Y + Z * Z + W * W);
1206  }
1207 
1208  // normalizes the vector //
1209  DLLEXPORT inline Float4 Normalize() const
1210  {
1211  const float length = Length();
1212 
1213  if(length == 0) {
1214  // Returns an identity quaternion
1215  return Float4(0, 0, 0, 1);
1216  }
1217 
1218  return Float4(X / length, Y / length, Z / length, W / length);
1219  }
1220  // safe version of normalization //
1221  DLLEXPORT inline Float4 NormalizeSafe(const Float4& safer = Float4(0, 0, 0, 1)) const
1222  {
1223  // security //
1224  const float len = X * X + Y * Y + Z * Z + W * W;
1225  if(len == 0) {
1226  return safer;
1227  }
1228 
1229  const float length = sqrt(len);
1230  return Float4(X / length, Y / length, Z / length, W / length);
1231  }
1232  // checks is the vector normalized //
1233  DLLEXPORT inline bool IsNormalized() const
1234  {
1235  // is absolute -1.f under normalization tolerance //
1236  return fabs(X * X + Y * Y + Z * Z + W * W - 1.0f) < NORMALIZATION_TOLERANCE;
1237  }
1238  // does linear interpolation between vectors and coefficient f,
1239  // not limited to range [0,1], courtesy of ozz-animation //
1240  DLLEXPORT inline Float4 Lerp(const Float4& other, float f) const
1241  {
1242  return Float4((other.X - X) * f + X, (other.Y - Y) * f + Y, (other.Z - Z) * f + Z,
1243  (other.W - W) * f + W);
1244  }
1245 
1246  // does SPHERICAL interpolation between quaternions //
1247  DLLEXPORT inline Float4 Slerp(const Float4& other, float f) const
1248  {
1249  // extra quaternion for calculations //
1250  Float4 quaternion3;
1251 
1252  // dot product of both //
1253  float dot = this->Dot(other);
1254 
1255  if(dot < 0) {
1256 
1257  dot = -dot;
1258  quaternion3 = -other;
1259  } else {
1260  quaternion3 = other;
1261  }
1262 
1263  if(dot < 0.95f) {
1264 
1265  float angle = acosf(dot);
1266  return ((*this) * sinf(angle * (1 - f)) + quaternion3 * sinf(angle * f)) /
1267  sinf(angle);
1268 
1269  } else {
1270  // small angle, linear interpolation will be fine //
1271  return this->Lerp(quaternion3, f);
1272  }
1273  }
1274 
1275  // compares distance between vectors to tolerance, returns true if less //
1276  DLLEXPORT inline bool Compare(const Float4& other, float tolerance) const
1277  {
1278  const Float4 difference = (*this) - other;
1279  return difference.Dot(difference) < tolerance * tolerance;
1280  }
1281 
1284  DLLEXPORT inline Float3 ToAxis() const
1285  {
1286 
1287  const auto s = std::sqrt(1 - std::pow(W, 2));
1288  // Avoid division by zero (this small axis it can be basically converted directly)
1289  if(s > 0) {
1290  return Float3(X / s, Y / s, Z / s);
1291  } else {
1292  return Float3(X, Y, Z);
1293  }
1294  }
1295 
1298  DLLEXPORT inline float ToAngle() const
1299  {
1300 
1301  return 2 * std::acos(W);
1302  }
1303 
1305  DLLEXPORT inline Float4 Inverse() const
1306  {
1307 
1308  const auto length = Length();
1309  if(length > 0.0f) {
1310 
1311  const auto inverted = 1.0f / length;
1312  return Float4(-X * inverted, -Y * inverted, -Z * inverted, W * inverted);
1313  } else {
1314  // Invalid inversing
1315  return Float4(0);
1316  }
1317  }
1318 
1320  DLLEXPORT inline Float3 RotateVector(const Float3& vector) const
1321  {
1322  // // Alternative from
1323  // //
1324  // https://gamedev.stackexchange.com/questions/28395/rotating-vector3-by-a-quaternion
1325  // const auto u = Float3(X, Y, Z);
1326 
1327  // // Complex math going on
1328  // return u * 2.0f * u.Dot(vector)
1329  // + vector * (W*W - u.Dot(u))
1330  // + u.Cross(vector) * 2.0f * W;
1331 
1332  // Math taken from Ogre::Quaternion
1333  Float3 uv;
1334  Float3 uuv;
1335  Float3 qvec(X, Y, Z);
1336  uv = qvec.Cross(vector);
1337  uuv = qvec.Cross(uv);
1338  uv *= 2.0f * W;
1339  uuv *= 2.0f;
1340 
1341  return vector + uv + uuv;
1342  }
1343 
1344  // ------------------------------------ //
1345  // All zeros //
1346  DLLEXPORT inline static Float4 zero()
1347  {
1348  return Float4(0.f, 0.f, 0.f, 0.f);
1349  }
1350 
1351  // all ones //
1352  DLLEXPORT inline static Float4 one()
1353  {
1354  return Float4(1.f, 1.f, 1.f, 1.f);
1355  }
1356  // unitary vectors for ozz support //
1357  // x
1358  DLLEXPORT inline static Float4 x_axis()
1359  {
1360  return Float4(1.f, 0.f, 0.f, 0.f);
1361  }
1362  // y
1363  DLLEXPORT inline static Float4 y_axis()
1364  {
1365  return Float4(0.f, 1.f, 0.f, 0.f);
1366  }
1367  // z
1368  DLLEXPORT inline static Float4 z_axis()
1369  {
1370  return Float4(0.f, 0.f, 1.f, 0.f);
1371  }
1372  // w
1373  DLLEXPORT inline static Float4 w_axis()
1374  {
1375  return Float4(0.f, 0.f, 0.f, 1.f);
1376  }
1377 
1378 #ifdef LEVIATHAN_FULL
1379  DLLEXPORT Float4(const Ogre::Quaternion& quat)
1380  {
1381  // copy values //
1382  X = quat.x;
1383  Y = quat.y;
1384  Z = quat.z;
1385  W = quat.w;
1386  DO_NAN_CHECK;
1387  }
1388 
1389  DLLEXPORT Float4(const Ogre::ColourValue& colour)
1390  {
1391  // copy values //
1392  X = colour.r;
1393  Y = colour.g;
1394  Z = colour.b;
1395  W = colour.a;
1396  DO_NAN_CHECK;
1397  }
1398 
1399  DLLEXPORT inline operator Ogre::Quaternion() const
1400  {
1401  // Ogre has these in different order
1402  return Ogre::Quaternion(W, X, Y, Z);
1403  }
1404 
1405  DLLEXPORT inline operator Ogre::ColourValue() const
1406  {
1407  return Ogre::ColourValue(X, Y, Z, W);
1408  }
1409 
1410  DLLEXPORT inline operator Ogre::Vector4() const
1411  {
1412  return Ogre::Vector4(X, Y, Z, W);
1413  }
1414 
1415  DLLEXPORT Float4(const btQuaternion& colour)
1416  {
1417  // copy values //
1418  X = colour.x();
1419  Y = colour.y();
1420  Z = colour.z();
1421  W = colour.w();
1422  DO_NAN_CHECK;
1423  }
1424 
1425  DLLEXPORT inline operator btQuaternion() const
1426  {
1427  return btQuaternion(X, Y, Z, W);
1428  }
1429 #endif // LEVIATHAN_USING_OGRE
1430 
1431  // ----------------- Quaternions ------------------- //
1432  DLLEXPORT static inline Float4 CreateQuaternionFromAngles(const Float3& angles)
1433  {
1434  // multiplied by 0.5 to get double the value //
1435  float cosx = cosf(0.5f * angles.X);
1436  float cosy = cosf(0.5f * angles.Y);
1437  float cosz = cosf(0.5f * angles.Z);
1438 
1439  float sinx = sinf(0.5f * angles.X);
1440  float siny = sinf(0.5f * angles.Y);
1441  float sinz = sinf(0.5f * angles.Z);
1442 
1443 
1444  Float4 quaternion((Float4)0);
1445  // compute quaternion //
1446  quaternion.X = cosz * cosy * sinx - sinz * siny * cosx;
1447  quaternion.Y = cosz * siny * cosx + sinz * cosy * sinx;
1448  quaternion.Z = sinz * cosy * cosx - cosz * siny * sinx;
1449  quaternion.W = cosz * cosy * cosx * sinz * siny * sinx;
1450 
1451  return quaternion;
1452  }
1453 
1458  {
1459 
1460  float test = X * Y + Z * W;
1461 
1462  if(test > 0.499) {
1463  // Singularity at north pole
1464  return Float3(2 * atan2(X, W), PI / 2, 0);
1465  }
1466 
1467  if(test < -0.499) {
1468 
1469  // Singularity at south pole
1470  return Float3(-2 * atan2(X, W), -PI / 2, 0);
1471  }
1472 
1473  float sqx = X * X;
1474  float sqy = Y * Y;
1475  float sqz = Z * Z;
1476 
1477  return Float3(atan2(2 * Y * W - 2 * X * Z, 1 - 2 * sqy - 2 * sqz), asin(2 * test),
1478  atan2(2 * X * W - 2 * Y * Z, 1 - 2 * sqx - 2 * sqz));
1479  }
1480 
1481  DLLEXPORT inline Float4 QuaternionMultiply(const Float4& other) const
1482  {
1483 
1484  Float4 result;
1485 
1486  result.X = X * other.X + X * other.W + Y * other.Z - Z * other.Y;
1487  result.Y = W * other.Y - X * other.Z + Y * other.W + Z * other.X;
1488  result.Z = W * other.Z + X * other.Y - Y * other.X + Z * other.W;
1489  result.W = W * other.W - X * other.X - Y * other.Y - Z * other.Z;
1490 
1491  return result;
1492  }
1493 
1495  {
1496  // reverse vector //
1497  return Float4(-X, -Y, -Z, W);
1498  }
1499 
1501  {
1502  return Float4(0, 0, 0, 1);
1503  }
1504 
1505  // Math from here: https://stackoverflow.com/questions/12435671/quaternion-lookat-function
1507  const Float3& sourcepoint, const Float3& target)
1508  {
1509  const auto forward = (target - sourcepoint).NormalizeSafe();
1510  const float dot = Float3::UnitVForward.Dot(forward);
1511 
1512  if(std::abs(dot - (-1.0f)) < 0.000001f) {
1513  // Assumes up is Float3(0, 1, 0)
1514  return Float4(
1515  Float3::UnitVUp.X, Float3::UnitVUp.Y, Float3::UnitVUp.Z, 3.1415926535897932f);
1516  }
1517  if(std::abs(dot - 1.0f) < 0.000001f) {
1518  return Float4::IdentityQuaternion();
1519  }
1520 
1521  const float rotAngle = std::acos(dot);
1522  const Float3 rotAxis = Float3::UnitVForward.Cross(forward).Normalize();
1523  return CreateQuaternionFromAxisAngle(rotAxis, rotAngle);
1524  }
1525 
1531  const Float3& axis, float angle)
1532  {
1533  const auto s = std::sin(angle / 2.0);
1534  const auto x = axis.X * s;
1535  const auto y = axis.Y * s;
1536  const auto z = axis.Z * s;
1537  const auto w = std::cos(angle / 2.0);
1538  return Float4(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z),
1539  static_cast<float>(w));
1540  }
1541 
1542  DLLEXPORT static inline Float4 CreateAxisAngleFromEuler(const Float3& angles)
1543  {
1544 
1545  throw std::exception();
1546  // return Float4();
1547  }
1548 
1549  VALUE_TYPE(Float4);
1550 
1551  // ----------------- casts ------------------- //
1552 
1553  // ------------------------------------ //
1554 
1555  float X, Y, Z, W;
1556 
1557 
1558  // specific colours //
1559  static const Float4 ColourBlack;
1560  static const Float4 ColourWhite;
1562 
1563  // Use these from other libraries/executables to avoid linker errors //
1564  DLLEXPORT static const Float4& GetColourBlack();
1565  DLLEXPORT static const Float4& GetColourWhite();
1566  DLLEXPORT static const Float4& GetColourTransparent();
1567 };
1568 
1569 // Stream operators //
1570 DLLEXPORT std::ostream& operator<<(std::ostream& stream, const Leviathan::Float4& value);
1571 
1572 DLLEXPORT std::ostream& operator<<(std::ostream& stream, const Leviathan::Float3& value);
1573 
1574 DLLEXPORT std::ostream& operator<<(std::ostream& stream, const Leviathan::Float2& value);
1575 
1576 DLLEXPORT std::ostream& operator<<(
1577  std::ostream& stream, const Leviathan::StartEndIndex& value);
1578 
1579 DLLEXPORT std::ostream& operator<<(
1580  std::ostream& stream, const Leviathan::PotentiallySetIndex& value);
1581 
1582 #ifdef LEVIATHAN_USING_OGRE
1583 void ThrowIfMatrixIsNotOrthogonal(const Ogre::Matrix4& matrix, float tol = 1.0e-4f);
1590 #endif
1591 
1592 } // namespace Leviathan
1593 
1594 #ifdef LEAK_INTO_GLOBAL
1595 using Leviathan::Float2;
1596 using Leviathan::Float3;
1597 using Leviathan::Float4;
1598 using Leviathan::Int2;
1599 using Leviathan::Int3;
1600 #endif
DLLEXPORT bool operator==(const Float4 &other) const
Definition: Types.h:1121
DLLEXPORT bool operator<=(const Float2 &other) const
Definition: Types.h:483
DLLEXPORT Float3 operator-(const Float3 &val) const
Definition: Types.h:727
DLLEXPORT Float4(Float3 floats, float f4)
Definition: Types.h:1023
DLLEXPORT Int4(int x, int y, int z, int w)
Definition: Types.h:329
DLLEXPORT Int3()
Definition: Types.h:258
DLLEXPORT Float4(Float2 floats, float f3, float f4)
Definition: Types.h:1015
DLLEXPORT bool IsNormalized() const
Definition: Types.h:581
DLLEXPORT void CheckForNans()
Definition: Types.h:685
DLLEXPORT Float2 Normalize() const
Definition: Types.h:561
DLLEXPORT void SetData(const int &data1, const int &data2)
Definition: Types.h:245
DLLEXPORT Float2()
Definition: Types.h:381
DLLEXPORT Int4 & operator+(const Int4 &val)
Definition: Types.h:336
DLLEXPORT Float2 operator*(float f) const
Definition: Types.h:455
DLLEXPORT Float3 MinElements(const Float3 &other) const
Definition: Types.h:843
DLLEXPORT float Dot(const Float2 &val) const
Definition: Types.h:551
DLLEXPORT void SetX(const float &val)
Definition: Types.h:512
static DLLEXPORT Float4 w_axis()
Definition: Types.h:1373
DLLEXPORT float HAddAbs() const
Definition: Types.h:529
DLLEXPORT Float3 operator+(const Float3 &val) const
Definition: Types.h:707
DLLEXPORT bool operator<(const Float3 &other) const
Definition: Types.h:779
DLLEXPORT Int3 operator-(const Int3 &other) const
Definition: Types.h:298
DLLEXPORT void SetW(const float &val)
Definition: Types.h:1161
DLLEXPORT Float4 Normalize() const
Definition: Types.h:1209
DLLEXPORT float HAddAbs() const
Definition: Types.h:1173
DLLEXPORT Float3 & operator+=(const Float3 &val)
Definition: Types.h:711
static const Float4 ColourTransparent
Definition: Types.h:1561
DLLEXPORT bool operator==(const Float3 &other) const
Definition: Types.h:795
static DLLEXPORT Float2 one()
Definition: Types.h:606
DLLEXPORT float & operator[](const int &nindex)
Definition: Types.h:694
DLLEXPORT int operator[](const int nIndex) const
Definition: Types.h:287
DLLEXPORT Float4(float f1, float f2, float f3, float f4)
Definition: Types.h:1007
DLLEXPORT bool operator>(const Float4 &other) const
Definition: Types.h:1117
static DLLEXPORT Float4 QuaternionLookAt(const Float3 &sourcepoint, const Float3 &target)
Definition: Types.h:1506
static const Float3 UnitVUp
Definition: Types.h:997
DLLEXPORT int operator[](const int nIndex) const
Definition: Types.h:150
DLLEXPORT Float2 operator*(const Float2 &val) const
Definition: Types.h:450
DLLEXPORT float HAdd() const
Definition: Types.h:1168
DLLEXPORT Float3 & operator/=(const float &val)
Definition: Types.h:746
DLLEXPORT Float3 MaxElements(const Float3 &other) const
Definition: Types.h:848
static DLLEXPORT Float3 zero()
Definition: Types.h:933
DLLEXPORT bool IsNormalized() const
Definition: Types.h:1233
DLLEXPORT Float3 Cross(const Float3 &val) const
Definition: Types.h:872
static DLLEXPORT Float4 CreateQuaternionFromAngles(const Float3 &angles)
Definition: Types.h:1432
DLLEXPORT Float3 DegreesToRadians()
Definition: Types.h:860
DLLEXPORT float HAddAbs() const
Definition: Types.h:838
DLLEXPORT Float4 NormalizeSafe(const Float4 &safer=Float4(0, 0, 0, 1)) const
Definition: Types.h:1221
DLLEXPORT bool operator!=(const Float3 &other) const
Definition: Types.h:799
DLLEXPORT Int2 operator+(const Int2 &val) const
Definition: Types.h:163
DLLEXPORT bool operator>(const Int2 &other) const
Definition: Types.h:221
DLLEXPORT void SetY(const float &val)
Definition: Types.h:517
DLLEXPORT Float2(float both)
Definition: Types.h:391
DLLEXPORT Float4 MinElements(const Float4 &other) const
Definition: Types.h:1178
DLLEXPORT Int2(int x, int y)
Definition: Types.h:128
static DLLEXPORT const Float4 & GetColourBlack()
Definition: Types.cpp:30
DLLEXPORT Float3(const Int3 &values)
Definition: Types.h:658
DLLEXPORT Float2 * operator+=(const Float2 &val)
Definition: Types.h:433
DLLEXPORT Float2 operator-(const Float2 &val) const
Definition: Types.h:440
DLLEXPORT Float3 Lerp(const Float3 &other, float f) const
Definition: Types.h:913
DLLEXPORT int operator[](const int nIndex) const
Definition: Types.h:344
DLLEXPORT Int4(int data)
Definition: Types.h:330
DLLEXPORT bool operator!=(const Float2 &other) const
Definition: Types.h:499
DLLEXPORT Float2(float x, float y)
Definition: Types.h:385
DLLEXPORT Float2 operator-() const
Definition: Types.h:445
DLLEXPORT float GetZ() const
Definition: Types.h:1138
DLLEXPORT Int2 operator-() const
Definition: Types.h:180
DLLEXPORT void SetX(const float &val)
Definition: Types.h:1146
DLLEXPORT Float4 Slerp(const Float4 &other, float f) const
Definition: Types.h:1247
DLLEXPORT Float3 operator/(const Float3 &val) const
Definition: Types.h:768
static const Float3 UnitVForward
Definition: Types.h:996
DLLEXPORT Float3(float x, float y, float z)
Definition: Types.h:639
static const Float4 ColourWhite
Definition: Types.h:1560
DLLEXPORT bool operator!=(const Float4 &other) const
Definition: Types.h:1125
static DLLEXPORT Float4 zero()
Definition: Types.h:1346
DLLEXPORT Float4 operator*(float f) const
Definition: Types.h:1097
DLLEXPORT Int2 * operator*=(int f)
Definition: Types.h:195
DLLEXPORT bool Compare(const Float3 &other, float tolerance) const
Definition: Types.h:918
static DLLEXPORT Float3 one()
Definition: Types.h:938
static DLLEXPORT Float3 y_axis()
Definition: Types.h:950
DLLEXPORT bool operator>=(const Float2 &other) const
Definition: Types.h:491
DLLEXPORT float Length() const
Definition: Types.h:877
DLLEXPORT float GetX() const
Definition: Types.h:1130
DLLEXPORT Int3 operator*(int val) const
Definition: Types.h:282
DLLEXPORT Float2 NormalizeSafe(const Float2 &safer) const
Definition: Types.h:569
DLLEXPORT float & operator[](const int &nindex)
Definition: Types.h:1055
DLLEXPORT Float3(Float2 floats, float z)
Definition: Types.h:646
DLLEXPORT Float2 Lerp(const Float2 &other, float f) const
Definition: Types.h:588
#define DO_NAN_CHECK
Definition: Types.h:18
DLLEXPORT bool operator<(const Int2 &other) const
Definition: Types.h:213
DLLEXPORT void SetData(const int &data)
Definition: Types.h:240
DLLEXPORT Float3 & operator*=(float f)
Definition: Types.h:759
DLLEXPORT int AddAllTogether() const
Definition: Types.h:311
StartEndIndex(size_t start, size_t end)
Definition: Types.h:93
DLLEXPORT Int2 operator/(const Int2 &val) const
Definition: Types.h:202
DLLEXPORT Float4 operator/(float f) const
Definition: Types.h:1107
DLLEXPORT Float3 RotateVector(const Float3 &vector) const
Rotates a vector by this quaternion.
Definition: Types.h:1320
bool operator==(const PotentiallySetIndex &other) const
Definition: Types.h:54
DLLEXPORT bool operator!=(const Int2 &other) const
Definition: Types.h:233
#define isfinite
Definition: jsoncpp.cpp:4247
static DLLEXPORT Float2 y_axis()
Definition: Types.h:617
DLLEXPORT void CheckForNans()
Definition: Types.h:1046
DLLEXPORT Float4 Lerp(const Float4 &other, float f) const
Definition: Types.h:1240
static const Float3 Zeroed
Definition: Types.h:998
DLLEXPORT Int2 operator*(int f) const
Definition: Types.h:190
DLLEXPORT Int2 operator/(int f) const
Definition: Types.h:207
PotentiallySetIndex Index
Definition: Types.h:91
DLLEXPORT Int2 operator*(const Int2 &val) const
Definition: Types.h:185
DLLEXPORT float GetZ() const
Definition: Types.h:812
PotentiallySetIndex & operator=(const PotentiallySetIndex &other)
Definition: Types.h:63
static DLLEXPORT Float3 x_axis()
Definition: Types.h:944
DLLEXPORT Float3 Normalize() const
Definition: Types.h:886
DLLEXPORT bool operator>=(const Int2 &other) const
Definition: Types.h:225
DLLEXPORT Float3 operator/(const float &val) const
Definition: Types.h:742
static DLLEXPORT Float2 x_asix()
Definition: Types.h:612
DLLEXPORT Float3()
Definition: Types.h:635
static DLLEXPORT Float4 x_axis()
Definition: Types.h:1358
DLLEXPORT void SetZ(const float &val)
Definition: Types.h:826
DLLEXPORT bool HasInvalidValues() const
Definition: Types.h:1037
DLLEXPORT Float4 MaxElements(const Float4 &other) const
Definition: Types.h:1183
DLLEXPORT Int4 & operator-(const Int4 &val)
Definition: Types.h:356
DLLEXPORT Float3 NormalizeSafe(const Float3 &safer=Float3(1, 0, 0)) const
Definition: Types.h:894
DLLEXPORT Float3 operator-() const
Definition: Types.h:732
DLLEXPORT bool Compare(const Float4 &other, float tolerance) const
Definition: Types.h:1276
DLLEXPORT Float3 & operator-=(const Float3 &val)
Definition: Types.h:718
DLLEXPORT Float3(const Float3 &other)
Definition: Types.h:666
DLLEXPORT Float4 operator-(const Float4 &val) const
Definition: Types.h:1082
DLLEXPORT Int3(int x, int y, int z)
Definition: Types.h:264
static DLLEXPORT const Float4 & GetColourTransparent()
Definition: Types.cpp:40
DLLEXPORT Int2 * operator+=(const Int2 &val)
Definition: Types.h:168
size_t Length() const
Definition: Types.h:108
DLLEXPORT float GetY() const
Definition: Types.h:508
static DLLEXPORT Float4 CreateAxisAngleFromEuler(const Float3 &angles)
Definition: Types.h:1542
DLLEXPORT float GetW() const
Definition: Types.h:1142
DLLEXPORT Float3 QuaternionToEuler() const
Definition: Types.h:1457
DLLEXPORT float HAdd() const
Definition: Types.h:524
DLLEXPORT bool operator>(const Float3 &other) const
Definition: Types.h:787
static const Float4 ColourBlack
Definition: Types.h:1559
DLLEXPORT Float4 QuaternionReverse() const
Definition: Types.h:1494
DLLEXPORT Float4 Clamp(const Float4 &min, const Float4 &max)
Definition: Types.h:1189
static DLLEXPORT Float3 CreateVectorFromAngles(const float &yaw, const float &pitch)
Definition: Types.h:924
DLLEXPORT Float3 Clamp(const Float3 &min, const Float3 &max)
Definition: Types.h:854
DLLEXPORT int AddAllTogether() const
Definition: Types.h:364
DLLEXPORT bool operator<=(const Float3 &other) const
Definition: Types.h:783
DLLEXPORT void SetY(const float &val)
Definition: Types.h:821
DLLEXPORT Int2 operator-(const Int2 &val) const
Definition: Types.h:175
DLLEXPORT Float2 Clamp(const Float2 &min, const Float2 &max)
Definition: Types.h:543
DLLEXPORT Float4 operator-() const
Definition: Types.h:1087
DLLEXPORT Float2 MinElements(const Float2 &other) const
Definition: Types.h:534
DLLEXPORT Int2()
Definition: Types.h:123
DLLEXPORT float GetY() const
Definition: Types.h:1134
DLLEXPORT Float3(float data)
Definition: Types.h:653
DLLEXPORT bool operator<=(const Int2 &other) const
Definition: Types.h:217
DLLEXPORT float Dot(const Float3 &val) const
Definition: Types.h:868
DLLEXPORT Int3 operator+(const Int3 &val) const
Definition: Types.h:277
DLLEXPORT bool operator==(const Int2 &other) const
Definition: Types.h:229
DLLEXPORT void SetX(const float &val)
Definition: Types.h:816
DLLEXPORT float Dot(const Float4 &val) const
Definition: Types.h:1197
static DLLEXPORT Float3 z_axis()
Definition: Types.h:956
DLLEXPORT float HAdd() const
Definition: Types.h:833
constexpr float PI
Definition: Define.h:58
PotentiallySetIndex(size_t index)
Definition: Types.h:35
PotentiallySetIndex & operator=(const size_t &value)
Definition: Types.h:71
constexpr float DEGREES_TO_RADIANS
Definition: Define.h:60
DLLEXPORT bool operator>(const Float2 &other) const
Definition: Types.h:487
static DLLEXPORT const Float4 & GetColourWhite()
Definition: Types.cpp:35
static DLLEXPORT Float2 zero()
Definition: Types.h:601
DLLEXPORT Float3 operator/(float f) const
Definition: Types.h:773
DLLEXPORT Float4 operator*(const Float4 &val) const
Definition: Types.h:1092
DLLEXPORT float GetX() const
Definition: Types.h:804
DLLEXPORT float Length() const
Definition: Types.h:556
DLLEXPORT bool Compare(const Float2 &other, float tolerance) const
Definition: Types.h:593
DLLEXPORT Int2 operator+(const Int2 &val)
Definition: Types.h:145
#define DLLEXPORT
Definition: Include.h:115
DLLEXPORT float & operator[](const int &nindex)
Definition: Types.h:415
DLLEXPORT Float4 operator+(const Float4 &val) const
Definition: Types.h:1077
DLLEXPORT Float2 MaxElements(const Float2 &other) const
Definition: Types.h:538
DLLEXPORT Float2 operator/(const Float2 &val) const
Definition: Types.h:468
DLLEXPORT Float4()
Definition: Types.h:1003
DLLEXPORT void SetY(const float &val)
Definition: Types.h:1151
DLLEXPORT void CheckForNans()
Definition: Types.h:406
constexpr float NORMALIZATION_TOLERANCE
For checking vector normalization.
Definition: Define.h:43
DLLEXPORT Float3 operator*(const Float3 &val) const
Definition: Types.h:737
DLLEXPORT float Length() const
Definition: Types.h:1203
StartEndIndex(size_t start)
Definition: Types.h:95
DLLEXPORT bool operator==(const Float2 &other) const
Definition: Types.h:495
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
DLLEXPORT bool HasInvalidValues() const
Definition: Types.h:397
void ThrowIfMatrixIsNotOrthogonal(const Ogre::Matrix4 &matrix, float tol)
Newton compatible matrix orthogonal check.
Definition: Types.cpp:46
DLLEXPORT bool operator<(const Float4 &other) const
Definition: Types.h:1113
DLLEXPORT bool IsNormalized() const
Definition: Types.h:906
static DLLEXPORT Float4 one()
Definition: Types.h:1352
DLLEXPORT Float4 Inverse() const
Inverts a quaternion.
Definition: Types.h:1305
static DLLEXPORT Float4 IdentityQuaternion()
Definition: Types.h:1500
DLLEXPORT float ToAngle() const
Definition: Types.h:1298
void Reset()
Reset the Start and End to unset.
Definition: Types.h:100
DLLEXPORT bool HasInvalidValues() const
Definition: Types.h:676
DLLEXPORT Int2(const Int2 &other)
Definition: Types.h:138
DLLEXPORT Int2(int data)
Definition: Types.h:133
DLLEXPORT Float3 operator*(float f) const
Definition: Types.h:755
DLLEXPORT Float2 operator/(float f) const
Definition: Types.h:473
static DLLEXPORT Float4 CreateQuaternionFromAxisAngle(const Float3 &axis, float angle)
Definition: Types.h:1530
DLLEXPORT void SetZ(const float &val)
Definition: Types.h:1156
DLLEXPORT std::ostream & operator<<(std::ostream &stream, const VariableBlock &value)
Definition: DataBlock.cpp:284
DLLEXPORT Float3 ToAxis() const
Definition: Types.h:1284
DLLEXPORT Float4 operator/(const Float4 &val) const
Definition: Types.h:1102
static DLLEXPORT Float4 y_axis()
Definition: Types.h:1363
DLLEXPORT bool operator<(const Float2 &other) const
Definition: Types.h:479
DLLEXPORT Int3 * operator*=(int f)
Definition: Types.h:303
DLLEXPORT Float4 QuaternionMultiply(const Float4 &other) const
Definition: Types.h:1481
DLLEXPORT Float2 operator+(const Float2 &val) const
Definition: Types.h:428
DLLEXPORT float GetY() const
Definition: Types.h:808
DLLEXPORT Float4(float val)
Definition: Types.h:1031
DLLEXPORT bool operator>=(const Float3 &other) const
Definition: Types.h:791
DLLEXPORT Int3(int data)
Definition: Types.h:270
DLLEXPORT Float2 & operator*=(float f)
Definition: Types.h:460
DLLEXPORT float GetX() const
Definition: Types.h:504
DLLEXPORT Int4()
Definition: Types.h:325
static DLLEXPORT Float4 z_axis()
Definition: Types.h:1368
DLLEXPORT float LengthSquared() const
Definition: Types.h:881