Diligent Engine  v.2.4.g
BasicMath.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
50 
51 #include <cmath>
52 #include <algorithm>
53 #include <iostream>
54 
55 #include "HashUtils.hpp"
56 
57 #ifdef _MSC_VER
58 # pragma warning(push)
59 # pragma warning(disable : 4201) // nonstandard extension used: nameless struct/union
60 #endif
61 
62 namespace Diligent
63 {
64 
65 static constexpr double PI = 3.14159265358979323846;
66 static constexpr float PI_F = 3.1415927f;
67 
68 // Template Vector & Matrix Classes
69 template <class T> struct Matrix2x2;
70 template <class T> struct Matrix3x3;
71 template <class T> struct Matrix4x4;
72 template <class T> struct Vector4;
73 
74 template <class T> struct Vector2
75 {
76  union
77  {
78  struct
79  {
80  T x;
81  T y;
82  };
83  struct
84  {
85  T r;
86  T g;
87  };
88  struct
89  {
90  T u;
91  T v;
92  };
93  };
94 
95 
96  Vector2 operator-(const Vector2<T>& right) const
97  {
98  return Vector2{x - right.x, y - right.y};
99  }
100 
102  {
103  x -= right.x;
104  y -= right.y;
105  return *this;
106  }
107 
109  {
110  return Vector2{-x, -y};
111  }
112 
113  Vector2 operator+(const Vector2<T>& right) const
114  {
115  return Vector2{x + right.x, y + right.y};
116  }
117 
119  {
120  x += right.x;
121  y += right.y;
122  return *this;
123  }
124 
125  Vector2 operator*(T s) const
126  {
127  return Vector2{x * s, y * s};
128  }
129 
130  Vector2 operator*(const Vector2& right) const
131  {
132  return Vector2{x * right.x, y * right.y};
133  }
134 
135  Vector2& operator*=(const Vector2& right)
136  {
137  x *= right.x;
138  y *= right.y;
139  return *this;
140  }
141 
143  {
144  x *= s;
145  y *= s;
146  return *this;
147  }
148 
150  {
151  Vector2 out;
152  out[0] = x * m[0][0] + y * m[1][0];
153  out[1] = x * m[0][1] + y * m[1][1];
154  return out;
155  }
156 
157  Vector2 operator/(const Vector2& right) const
158  {
159  return Vector2{x / right.x, y / right.y};
160  }
161 
162  Vector2& operator/=(const Vector2& right)
163  {
164  x /= right.x;
165  y /= right.y;
166  return *this;
167  }
168 
169  Vector2 operator/(T s) const
170  {
171  return Vector2{x / s, y / s};
172  }
173 
175  {
176  x /= s;
177  y /= s;
178  return *this;
179  }
180 
181  bool operator==(const Vector2& right) const
182  {
183  return x == right.x && y == right.y;
184  }
185 
186  bool operator!=(const Vector2& right) const
187  {
188  return !(*this == right);
189  }
190 
191  Vector2 operator<(const Vector2& right) const
192  {
193  return Vector2{x < right.x ? static_cast<T>(1) : static_cast<T>(0),
194  y < right.y ? static_cast<T>(1) : static_cast<T>(0)};
195  }
196 
197  Vector2 operator>(const Vector2& right) const
198  {
199  return Vector2{x > right.x ? static_cast<T>(1) : static_cast<T>(0),
200  y > right.y ? static_cast<T>(1) : static_cast<T>(0)};
201  }
202 
203  Vector2 operator<=(const Vector2& right) const
204  {
205  return Vector2{x <= right.x ? static_cast<T>(1) : static_cast<T>(0),
206  y <= right.y ? static_cast<T>(1) : static_cast<T>(0)};
207  }
208 
209  Vector2 operator>=(const Vector2& right) const
210  {
211  return Vector2{x >= right.x ? static_cast<T>(1) : static_cast<T>(0),
212  y >= right.y ? static_cast<T>(1) : static_cast<T>(0)};
213  }
214 
215  T* Data() { return reinterpret_cast<T*>(this); }
216 
217  const T* Data() const { return reinterpret_cast<const T*>(this); }
218 
219  T& operator[](size_t index)
220  {
221  return Data()[index];
222  }
223 
224  const T& operator[](size_t index) const
225  {
226  return Data()[index];
227  }
228 
230  x{0}, y{0} {}
231  Vector2(T _x, T _y) :
232  x{_x}, y{_y} {}
233 
234  template <typename Y>
235  static Vector2 MakeVector(const Y& vals)
236  {
237  return Vector2 //
238  {
239  static_cast<T>(vals[0]),
240  static_cast<T>(vals[1]) //
241  };
242  }
243 
244  template <typename Y>
246  {
247  return Vector2<Y>{static_cast<Y>(x),
248  static_cast<Y>(y)};
249  }
250 };
251 
252 template <class T>
254 {
255  return a * s;
256 }
257 
258 
259 template <class T> struct Vector3
260 {
261  union
262  {
263  struct
264  {
265  T x;
266  T y;
267  T z;
268  };
269  struct
270  {
271  T r;
272  T g;
273  T b;
274  };
275  struct
276  {
277  T u;
278  T v;
279  T w;
280  };
281  };
282 
283 
284  Vector3 operator-(const Vector3& right) const
285  {
286  return Vector3{x - right.x, y - right.y, z - right.z};
287  }
288 
290  {
291  return Vector3{-x, -y, -z};
292  }
293 
295  {
296  x -= right.x;
297  y -= right.y;
298  z -= right.z;
299  return *this;
300  }
301 
302  Vector3 operator+(const Vector3& right) const
303  {
304  return Vector3{x + right.x, y + right.y, z + right.z};
305  }
306 
308  {
309  x += right.x;
310  y += right.y;
311  z += right.z;
312  return *this;
313  }
314 
315  Vector3 operator*(T s) const
316  {
317  return Vector3{x * s, y * s, z * s};
318  }
319 
321  {
322  x *= s;
323  y *= s;
324  z *= s;
325  return *this;
326  }
327 
328  Vector3 operator*(const Vector3& right) const
329  {
330  return Vector3{x * right.x, y * right.y, z * right.z};
331  }
332 
334  {
335  Vector4<T> out4 = Vector4<T>(x, y, z, 1) * m;
336  return Vector3{out4.x / out4.w, out4.y / out4.w, out4.z / out4.w};
337  }
338 
339  Vector3& operator*=(const Vector3& right)
340  {
341  x *= right.x;
342  y *= right.y;
343  z *= right.z;
344  return *this;
345  }
346 
348  {
349  Vector3 out;
350  out[0] = x * m[0][0] + y * m[1][0] + z * m[2][0];
351  out[1] = x * m[0][1] + y * m[1][1] + z * m[2][1];
352  out[2] = x * m[0][2] + y * m[1][2] + z * m[2][2];
353  return out;
354  }
355 
356  Vector3 operator/(T s) const
357  {
358  return Vector3{x / s, y / s, z / s};
359  }
360 
362  {
363  x /= s;
364  y /= s;
365  z /= s;
366  return *this;
367  }
368 
369  Vector3 operator/(const Vector3& right) const
370  {
371  return Vector3{x / right.x, y / right.y, z / right.z};
372  }
373 
374  Vector3& operator/=(const Vector3& right)
375  {
376  x /= right.x;
377  y /= right.y;
378  z /= right.z;
379  return *this;
380  }
381 
382  bool operator==(const Vector3& right) const
383  {
384  return x == right.x && y == right.y && z == right.z;
385  }
386 
387  bool operator!=(const Vector3& right) const
388  {
389  return !(*this == right);
390  }
391 
392  Vector3 operator<(const Vector3& right) const
393  {
394  return Vector3{x < right.x ? static_cast<T>(1) : static_cast<T>(0),
395  y < right.y ? static_cast<T>(1) : static_cast<T>(0),
396  z < right.z ? static_cast<T>(1) : static_cast<T>(0)};
397  }
398 
399  Vector3 operator>(const Vector3& right) const
400  {
401  return Vector3{x > right.x ? static_cast<T>(1) : static_cast<T>(0),
402  y > right.y ? static_cast<T>(1) : static_cast<T>(0),
403  z > right.z ? static_cast<T>(1) : static_cast<T>(0)};
404  }
405 
406  Vector3 operator<=(const Vector3& right) const
407  {
408  return Vector3{x <= right.x ? static_cast<T>(1) : static_cast<T>(0),
409  y <= right.y ? static_cast<T>(1) : static_cast<T>(0),
410  z <= right.z ? static_cast<T>(1) : static_cast<T>(0)};
411  }
412 
413  Vector3 operator>=(const Vector3& right) const
414  {
415  return Vector3{x >= right.x ? static_cast<T>(1) : static_cast<T>(0),
416  y >= right.y ? static_cast<T>(1) : static_cast<T>(0),
417  z >= right.z ? static_cast<T>(1) : static_cast<T>(0)};
418  }
419 
420  T* Data() { return reinterpret_cast<T*>(this); }
421 
422  const T* Data() const { return reinterpret_cast<const T*>(this); }
423 
424  T& operator[](size_t index)
425  {
426  return Data()[index];
427  }
428 
429  const T& operator[](size_t index) const
430  {
431  return Data()[index];
432  }
433 
435  x{0}, y{0}, z{0} {}
436  Vector3(T _x, T _y, T _z) :
437  x{_x}, y{_y}, z{_z} {}
438 
439  template <typename Y>
440  static Vector3 MakeVector(const Y& vals)
441  {
442  return Vector3 //
443  {
444  static_cast<T>(vals[0]),
445  static_cast<T>(vals[1]),
446  static_cast<T>(vals[2]) //
447  };
448  }
449 
450  template <typename Y>
452  {
453  return Vector3<Y>{static_cast<Y>(x),
454  static_cast<Y>(y),
455  static_cast<Y>(z)};
456  }
457 
458  operator Vector2<T>() const { return Vector2<T>(x, y); }
459 };
460 
461 template <class T>
463 {
464  return a * s;
465 }
466 
467 
468 template <class T> struct Vector4
469 {
470  union
471  {
472  struct
473  {
474  T x;
475  T y;
476  T z;
477  T w;
478  };
479  struct
480  {
481  T r;
482  T g;
483  T b;
484  T a;
485  };
486  };
487 
488  Vector4 operator-(const Vector4& right) const
489  {
490  return Vector4{x - right.x, y - right.y, z - right.z, w - right.w};
491  }
492 
494  {
495  return Vector4{-x, -y, -z, -w};
496  }
497 
499  {
500  x -= right.x;
501  y -= right.y;
502  z -= right.z;
503  w -= right.w;
504  return *this;
505  }
506 
507  Vector4 operator+(const Vector4& right) const
508  {
509  return Vector4{x + right.x, y + right.y, z + right.z, w + right.w};
510  }
511 
513  {
514  x += right.x;
515  y += right.y;
516  z += right.z;
517  w += right.w;
518  return *this;
519  }
520 
521  Vector4 operator*(T s) const
522  {
523  return Vector4{x * s, y * s, z * s, w * s};
524  }
525 
527  {
528  x *= s;
529  y *= s;
530  z *= s;
531  w *= s;
532  return *this;
533  }
534 
535  Vector4 operator*(const Vector4& right) const
536  {
537  return Vector4{x * right.x, y * right.y, z * right.z, w * right.w};
538  }
539 
540  Vector4& operator*=(const Vector4& right)
541  {
542  x *= right.x;
543  y *= right.y;
544  z *= right.z;
545  w *= right.w;
546  return *this;
547  }
548 
549  Vector4 operator/(T s) const
550  {
551  return Vector4{x / s, y / s, z / s, w / s};
552  }
553 
555  {
556  x /= s;
557  y /= s;
558  z /= s;
559  w /= s;
560  return *this;
561  }
562 
563  Vector4 operator/(const Vector4& right) const
564  {
565  return Vector4{x / right.x, y / right.y, z / right.z, w / right.w};
566  }
567 
568  Vector4& operator/=(const Vector4& right)
569  {
570  x /= right.x;
571  y /= right.y;
572  z /= right.z;
573  w /= right.w;
574  return *this;
575  }
576 
577  bool operator==(const Vector4& right) const
578  {
579  return x == right.x && y == right.y && z == right.z && w == right.w;
580  }
581 
582  bool operator!=(const Vector4& right) const
583  {
584  return !(*this == right);
585  }
586 
588  {
589  Vector4 out;
590  out[0] = x * m[0][0] + y * m[1][0] + z * m[2][0] + w * m[3][0];
591  out[1] = x * m[0][1] + y * m[1][1] + z * m[2][1] + w * m[3][1];
592  out[2] = x * m[0][2] + y * m[1][2] + z * m[2][2] + w * m[3][2];
593  out[3] = x * m[0][3] + y * m[1][3] + z * m[2][3] + w * m[3][3];
594  return out;
595  }
596 
598  {
599  x = v3.x;
600  y = v3.y;
601  z = v3.z;
602  w = 1;
603  return *this;
604  }
605  Vector4& operator=(const Vector4&) = default;
606 
607  Vector4 operator<(const Vector4& right) const
608  {
609  return Vector4{x < right.x ? static_cast<T>(1) : static_cast<T>(0),
610  y < right.y ? static_cast<T>(1) : static_cast<T>(0),
611  z < right.z ? static_cast<T>(1) : static_cast<T>(0),
612  w < right.w ? static_cast<T>(1) : static_cast<T>(0)};
613  }
614 
615  Vector4 operator>(const Vector4& right) const
616  {
617  return Vector4{x > right.x ? static_cast<T>(1) : static_cast<T>(0),
618  y > right.y ? static_cast<T>(1) : static_cast<T>(0),
619  z > right.z ? static_cast<T>(1) : static_cast<T>(0),
620  w > right.w ? static_cast<T>(1) : static_cast<T>(0)};
621  }
622 
623  Vector4 operator<=(const Vector4& right) const
624  {
625  return Vector4{x <= right.x ? static_cast<T>(1) : static_cast<T>(0),
626  y <= right.y ? static_cast<T>(1) : static_cast<T>(0),
627  z <= right.z ? static_cast<T>(1) : static_cast<T>(0),
628  w <= right.w ? static_cast<T>(1) : static_cast<T>(0)};
629  }
630 
631  Vector4 operator>=(const Vector4& right) const
632  {
633  return Vector4{x >= right.x ? static_cast<T>(1) : static_cast<T>(0),
634  y >= right.y ? static_cast<T>(1) : static_cast<T>(0),
635  z >= right.z ? static_cast<T>(1) : static_cast<T>(0),
636  w >= right.w ? static_cast<T>(1) : static_cast<T>(0)};
637  }
638 
639  T* Data() { return reinterpret_cast<T*>(this); }
640 
641  const T* Data() const { return reinterpret_cast<const T*>(this); }
642 
643  T& operator[](size_t index)
644  {
645  return Data()[index];
646  }
647 
648  const T& operator[](size_t index) const
649  {
650  return Data()[index];
651  }
652 
654  x{0}, y{0}, z{0}, w{0} {}
655  Vector4(T _x, T _y, T _z, T _w) :
656  x{_x}, y{_y}, z{_z}, w{_w} {}
657  Vector4(const Vector3<T>& v3, T _w) :
658  x{v3.x}, y{v3.y}, z{v3.z}, w{_w} {}
659 
660  template <typename Y>
661  static Vector4 MakeVector(const Y& vals)
662  {
663  return Vector4 //
664  {
665  static_cast<T>(vals[0]),
666  static_cast<T>(vals[1]),
667  static_cast<T>(vals[2]),
668  static_cast<T>(vals[3]) //
669  };
670  }
671 
672  template <typename Y>
674  {
675  return Vector4<Y>{static_cast<Y>(x),
676  static_cast<Y>(y),
677  static_cast<Y>(z),
678  static_cast<Y>(w)};
679  }
680 
681  operator Vector3<T>() const
682  {
683  return Vector3<T>(x, y, z);
684  }
685 };
686 
687 
688 template <class T>
690 {
691  return a * s;
692 }
693 
694 
695 template <class T> struct Matrix2x2
696 {
697  union
698  {
699  struct
700  {
701  T _11;
702  T _12;
703  T _21;
704  T _22;
705  };
706  struct
707  {
708  T m00;
709  T m01;
710  T m10;
711  T m11;
712  };
713  T m[2][2];
714  };
715 
716  explicit Matrix2x2(T value) :
717  // clang-format off
718  _11{value}, _12{value},
719  _21{value}, _22{value}
720  // clang-format on
721  {
722  }
723 
725  Matrix2x2{0} {}
726 
727  // clang-format off
728  Matrix2x2(T i11, T i12,
729  T i21, T i22) :
730  _11{i11}, _12{i12},
731  _21{i21}, _22{i22}
732  // clang-format on
733  {
734  }
735 
736  template <typename Y>
737  static Matrix2x2 MakeMatrix(const Y& vals)
738  {
739  return Matrix2x2 //
740  {
741  static_cast<T>(vals[0]), static_cast<T>(vals[1]),
742  static_cast<T>(vals[2]), static_cast<T>(vals[3]) //
743  };
744  }
745 
746  bool operator==(const Matrix2x2& r) const
747  {
748  for (int i = 0; i < 2; ++i)
749  for (int j = 0; j < 2; ++j)
750  if ((*this)[i][j] != r[i][j])
751  return false;
752 
753  return true;
754  }
755 
756  bool operator!=(const Matrix2x2& r) const
757  {
758  return !(*this == r);
759  }
760 
761  T* operator[](size_t row)
762  {
763  return m[row];
764  }
765 
766  const T* operator[](size_t row) const
767  {
768  return m[row];
769  }
770 
771  T* Data() { return (*this)[0]; }
772 
773  const T* Data() const { return (*this)[0]; }
774 
775 
777  {
778  for (int i = 0; i < 4; ++i)
779  (reinterpret_cast<T*>(this))[i] *= s;
780 
781  return *this;
782  }
783 
785  {
786  *this = Mul(*this, right);
787  return *this;
788  }
789 
791  {
792  return Matrix2x2{
793  _11, _21,
794  _12, _22};
795  }
796 
798  {
799  return Matrix2x2{
800  1, 0,
801  0, 1};
802  }
803 
804  static Matrix2x2 Mul(const Matrix2x2& m1, const Matrix2x2& m2)
805  {
806  Matrix2x2 mOut;
807  for (int i = 0; i < 2; i++)
808  {
809  for (int j = 0; j < 2; j++)
810  {
811  for (int k = 0; k < 2; k++)
812  {
813  mOut.m[i][j] += m1.m[i][k] * m2.m[k][j];
814  }
815  }
816  }
817  return mOut;
818  }
819 
820  static Matrix2x2 Rotation(T angleInRadians)
821  {
822  auto s = std::sin(angleInRadians);
823  auto c = std::cos(angleInRadians);
824 
825  return Matrix2x2 //
826  {
827  c, s,
828  -s, c //
829  };
830  }
831 
832  T Determinant() const
833  {
834  return _11 * _22 - _12 * _21;
835  }
836 
838  {
839  Matrix2x2 Inv //
840  {
841  +_22, -_12,
842  -_21, +_11 //
843  };
844 
845  Inv *= static_cast<T>(1) / Determinant();
846  return Inv;
847  }
848 };
849 
850 
851 template <class T> struct Matrix3x3
852 {
853  union
854  {
855  struct
856  {
857  T _11;
858  T _12;
859  T _13;
860  T _21;
861  T _22;
862  T _23;
863  T _31;
864  T _32;
865  T _33;
866  };
867  struct
868  {
869  T m00;
870  T m01;
871  T m02;
872  T m10;
873  T m11;
874  T m12;
875  T m20;
876  T m21;
877  T m22;
878  };
879  T m[3][3];
880  };
881 
882  explicit Matrix3x3(T value) :
883  // clang-format off
884  _11{value}, _12{value}, _13{value},
885  _21{value}, _22{value}, _23{value},
886  _31{value}, _32{value}, _33{value}
887  // clang-format on
888  {
889  }
890 
892  Matrix3x3{0} {}
893 
894  // clang-format off
895  Matrix3x3(T i11, T i12, T i13,
896  T i21, T i22, T i23,
897  T i31, T i32, T i33) :
898  _11{i11}, _12{i12}, _13{i13},
899  _21{i21}, _22{i22}, _23{i23},
900  _31{i31}, _32{i32}, _33{i33}
901  // clang-format on
902  {
903  }
904 
905  template <typename Y>
906  static Matrix3x3 MakeMatrix(const Y& vals)
907  {
908  return Matrix3x3 //
909  {
910  static_cast<T>(vals[0]), static_cast<T>(vals[1]), static_cast<T>(vals[2]),
911  static_cast<T>(vals[3]), static_cast<T>(vals[4]), static_cast<T>(vals[5]),
912  static_cast<T>(vals[6]), static_cast<T>(vals[7]), static_cast<T>(vals[8]) //
913  };
914  }
915 
916  bool operator==(const Matrix3x3& r) const
917  {
918  for (int i = 0; i < 3; ++i)
919  for (int j = 0; j < 3; ++j)
920  if ((*this)[i][j] != r[i][j])
921  return false;
922 
923  return true;
924  }
925 
926  bool operator!=(const Matrix3x3& r) const
927  {
928  return !(*this == r);
929  }
930 
931  T* operator[](size_t row)
932  {
933  return m[row];
934  }
935 
936  const T* operator[](size_t row) const
937  {
938  return m[row];
939  }
940 
941  T* Data() { return (*this)[0]; }
942 
943  const T* Data() const { return (*this)[0]; }
944 
946  {
947  for (int i = 0; i < 9; ++i)
948  (reinterpret_cast<T*>(this))[i] *= s;
949 
950  return *this;
951  }
952 
954  {
955  *this = Mul(*this, right);
956  return *this;
957  }
958 
960  {
961  return Matrix3x3 //
962  {
963  _11, _21, _31,
964  _12, _22, _32,
965  _13, _23, _33 //
966  };
967  }
968 
970  {
971  return Matrix3x3 //
972  {
973  1, 0, 0,
974  0, 1, 0,
975  0, 0, 1 //
976  };
977  }
978 
979  static Matrix3x3 Scale(T x, T y, T z)
980  {
981  return Matrix3x3 //
982  {
983  x, 0, 0,
984  0, y, 0,
985  0, 0, z //
986  };
987  }
988 
989  // D3D-style left-handed matrix that rotates a point around the x axis. Angle (in radians)
990  // is measured clockwise when looking along the rotation axis toward the origin:
991  // (x' y' z') = (x y z) * RotationX
992  static Matrix3x3 RotationX(T angleInRadians)
993  {
994  auto s = std::sin(angleInRadians);
995  auto c = std::cos(angleInRadians);
996 
997  return Matrix3x3 // clang-format off
998  {
999  1, 0, 0,
1000  0, c, s,
1001  0, -s, c // clang-format on
1002  };
1003  }
1004 
1005  // D3D-style left-handed matrix that rotates a point around the y axis. Angle (in radians)
1006  // is measured clockwise when looking along the rotation axis toward the origin:
1007  // (x' y' z' 1) = (x y z 1) * RotationY
1008  static Matrix3x3 RotationY(T angleInRadians)
1009  {
1010  auto s = std::sin(angleInRadians);
1011  auto c = std::cos(angleInRadians);
1012 
1013  return Matrix3x3 // clang-format off
1014  {
1015  c, 0, -s,
1016  0, 1, 0,
1017  s, 0, c // clang-format on
1018  };
1019  }
1020 
1021  // D3D-style left-handed matrix that rotates a point around the z axis. Angle (in radians)
1022  // is measured clockwise when looking along the rotation axis toward the origin:
1023  // (x' y' z' 1) = (x y z 1) * RotationZ
1024  static Matrix3x3 RotationZ(T angleInRadians)
1025  {
1026  auto s = std::sin(angleInRadians);
1027  auto c = std::cos(angleInRadians);
1028 
1029  return Matrix3x3 // clang-format off
1030  {
1031  c, s, 0,
1032  -s, c, 0,
1033  0, 0, 1 // clang-format on
1034  };
1035  }
1036 
1037  static Matrix3x3 Mul(const Matrix3x3& m1, const Matrix3x3& m2)
1038  {
1039  Matrix3x3 mOut;
1040  for (int i = 0; i < 3; i++)
1041  {
1042  for (int j = 0; j < 3; j++)
1043  {
1044  for (int k = 0; k < 3; k++)
1045  {
1046  mOut.m[i][j] += m1.m[i][k] * m2.m[k][j];
1047  }
1048  }
1049  }
1050 
1051  return mOut;
1052  }
1053 
1054  T Determinant() const
1055  {
1056  T det = 0;
1057  det += _11 * (_22 * _33 - _32 * _23);
1058  det -= _12 * (_21 * _33 - _31 * _23);
1059  det += _13 * (_21 * _32 - _31 * _22);
1060  return det;
1061  }
1062 };
1063 
1064 template <class T> struct Matrix4x4
1065 {
1066  union
1067  {
1068  struct
1069  {
1070  T _11;
1071  T _12;
1072  T _13;
1073  T _14;
1074  T _21;
1075  T _22;
1076  T _23;
1077  T _24;
1078  T _31;
1079  T _32;
1080  T _33;
1081  T _34;
1082  T _41;
1083  T _42;
1084  T _43;
1085  T _44;
1086  };
1087  struct
1088  {
1089  T m00;
1090  T m01;
1091  T m02;
1092  T m03;
1093  T m10;
1094  T m11;
1095  T m12;
1096  T m13;
1097  T m20;
1098  T m21;
1099  T m22;
1100  T m23;
1101  T m30;
1102  T m31;
1103  T m32;
1104  T m33;
1105  };
1106  T m[4][4];
1107  };
1108 
1109  explicit Matrix4x4(T value) :
1110  // clang-format off
1111  _11{value}, _12{value}, _13{value}, _14{value},
1112  _21{value}, _22{value}, _23{value}, _24{value},
1113  _31{value}, _32{value}, _33{value}, _34{value},
1114  _41{value}, _42{value}, _43{value}, _44{value}
1115  // clang-format on
1116  {
1117  }
1118 
1120  Matrix4x4{0} {}
1121 
1122  // clang-format off
1123  Matrix4x4(T i11, T i12, T i13, T i14,
1124  T i21, T i22, T i23, T i24,
1125  T i31, T i32, T i33, T i34,
1126  T i41, T i42, T i43, T i44) :
1127  _11{i11}, _12{i12}, _13{i13}, _14{i14},
1128  _21{i21}, _22{i22}, _23{i23}, _24{i24},
1129  _31{i31}, _32{i32}, _33{i33}, _34{i34},
1130  _41{i41}, _42{i42}, _43{i43}, _44{i44}
1131  {
1132  }
1133  // clang-format on
1134 
1135  // clang-format off
1136  Matrix4x4(const Vector4<T>& Row0,
1137  const Vector4<T>& Row1,
1138  const Vector4<T>& Row2,
1139  const Vector4<T>& Row3) :
1140  _11{Row0.x}, _12{Row0.y}, _13{Row0.z}, _14{Row0.w},
1141  _21{Row1.x}, _22{Row1.y}, _23{Row1.z}, _24{Row1.w},
1142  _31{Row2.x}, _32{Row2.y}, _33{Row2.z}, _34{Row2.w},
1143  _41{Row3.x}, _42{Row3.y}, _43{Row3.z}, _44{Row3.w}
1144  {
1145  }
1146  // clang-format on
1147 
1148  template <typename Y>
1149  static Matrix4x4 MakeMatrix(const Y& vals)
1150  {
1151  // clang-format off
1152  return Matrix4x4
1153  {
1154  static_cast<T>(vals[ 0]), static_cast<T>(vals[ 1]), static_cast<T>(vals[ 2]), static_cast<T>(vals[ 3]),
1155  static_cast<T>(vals[ 4]), static_cast<T>(vals[ 5]), static_cast<T>(vals[ 6]), static_cast<T>(vals[ 7]),
1156  static_cast<T>(vals[ 8]), static_cast<T>(vals[ 9]), static_cast<T>(vals[10]), static_cast<T>(vals[11]),
1157  static_cast<T>(vals[12]), static_cast<T>(vals[13]), static_cast<T>(vals[14]), static_cast<T>(vals[15])
1158  };
1159  // clang-format on
1160  }
1161 
1162  bool operator==(const Matrix4x4& r) const
1163  {
1164  for (int i = 0; i < 4; ++i)
1165  for (int j = 0; j < 4; ++j)
1166  if ((*this)[i][j] != r[i][j])
1167  return false;
1168 
1169  return true;
1170  }
1171 
1172  bool operator!=(const Matrix4x4& r) const
1173  {
1174  return !(*this == r);
1175  }
1176 
1177  T* operator[](size_t row)
1178  {
1179  return m[row];
1180  }
1181 
1182  const T* operator[](size_t row) const
1183  {
1184  return m[row];
1185  }
1186 
1187  T* Data() { return (*this)[0]; }
1188 
1189  const T* Data() const { return (*this)[0]; }
1190 
1192  {
1193  for (int i = 0; i < 16; ++i)
1194  (reinterpret_cast<T*>(this))[i] *= s;
1195 
1196  return *this;
1197  }
1198 
1200  {
1201  *this = Mul(*this, right);
1202  return *this;
1203  }
1204 
1206  {
1207  return Matrix4x4 //
1208  {
1209  _11, _21, _31, _41,
1210  _12, _22, _32, _42,
1211  _13, _23, _33, _43,
1212  _14, _24, _34, _44 //
1213  };
1214  }
1215 
1217  {
1218  return Matrix4x4 //
1219  {
1220  1, 0, 0, 0,
1221  0, 1, 0, 0,
1222  0, 0, 1, 0,
1223  0, 0, 0, 1 //
1224  };
1225  }
1226 
1227  static Matrix4x4 Translation(T x, T y, T z)
1228  {
1229  return Matrix4x4 //
1230  {
1231  1, 0, 0, 0,
1232  0, 1, 0, 0,
1233  0, 0, 1, 0,
1234  x, y, z, 1 //
1235  };
1236  }
1237 
1239  {
1240  return Translation(v.x, v.y, v.z);
1241  }
1242 
1243  static Matrix4x4 Scale(T x, T y, T z)
1244  {
1245  return Matrix4x4 //
1246  {
1247  x, 0, 0, 0,
1248  0, y, 0, 0,
1249  0, 0, z, 0,
1250  0, 0, 0, 1 //
1251  };
1252  }
1253 
1254  static Matrix4x4 Scale(const Vector3<T>& v)
1255  {
1256  return Scale(v.x, v.y, v.z);
1257  }
1258 
1259  static Matrix4x4 Scale(T s)
1260  {
1261  return Scale(s, s, s);
1262  }
1263 
1264 
1265  // D3D-style left-handed matrix that rotates a point around the x axis. Angle (in radians)
1266  // is measured clockwise when looking along the rotation axis toward the origin:
1267  // (x' y' z' 1) = (x y z 1) * RotationX
1268  static Matrix4x4 RotationX(T angleInRadians)
1269  {
1270  auto s = std::sin(angleInRadians);
1271  auto c = std::cos(angleInRadians);
1272 
1273  return Matrix4x4 // clang-format off
1274  {
1275  1, 0, 0, 0,
1276  0, c, s, 0,
1277  0, -s, c, 0,
1278  0, 0, 0, 1 // clang-format on
1279  };
1280  }
1281 
1282  // D3D-style left-handed matrix that rotates a point around the y axis. Angle (in radians)
1283  // is measured clockwise when looking along the rotation axis toward the origin:
1284  // (x' y' z' 1) = (x y z 1) * RotationY
1285  static Matrix4x4 RotationY(T angleInRadians)
1286  {
1287  auto s = std::sin(angleInRadians);
1288  auto c = std::cos(angleInRadians);
1289 
1290  return Matrix4x4 // clang-format off
1291  {
1292  c, 0, -s, 0,
1293  0, 1, 0, 0,
1294  s, 0, c, 0,
1295  0, 0, 0, 1 // clang-format on
1296  };
1297  }
1298 
1299  // D3D-style left-handed matrix that rotates a point around the z axis. Angle (in radians)
1300  // is measured clockwise when looking along the rotation axis toward the origin:
1301  // (x' y' z' 1) = (x y z 1) * RotationZ
1302  static Matrix4x4 RotationZ(T angleInRadians)
1303  {
1304  auto s = std::sin(angleInRadians);
1305  auto c = std::cos(angleInRadians);
1306 
1307  return Matrix4x4 // clang-format off
1308  {
1309  c, s, 0, 0,
1310  -s, c, 0, 0,
1311  0, 0, 1, 0,
1312  0, 0, 0, 1 // clang-format on
1313  };
1314  }
1315 
1316  // 3D Rotation matrix for an arbitrary axis specified by x, y and z
1317  static Matrix4x4 RotationArbitrary(Vector3<T> axis, T angleInRadians)
1318  {
1319  axis = normalize(axis);
1320 
1321  auto sinAngle = std::sin(angleInRadians);
1322  auto cosAngle = std::cos(angleInRadians);
1323  auto oneMinusCosAngle = 1 - cosAngle;
1324 
1325  Matrix4x4 mOut;
1326 
1327  mOut._11 = 1 + oneMinusCosAngle * (axis.x * axis.x - 1);
1328  mOut._12 = axis.z * sinAngle + oneMinusCosAngle * axis.x * axis.y;
1329  mOut._13 = -axis.y * sinAngle + oneMinusCosAngle * axis.x * axis.z;
1330  mOut._41 = 0;
1331 
1332  mOut._21 = -axis.z * sinAngle + oneMinusCosAngle * axis.y * axis.x;
1333  mOut._22 = 1 + oneMinusCosAngle * (axis.y * axis.y - 1);
1334  mOut._23 = axis.x * sinAngle + oneMinusCosAngle * axis.y * axis.z;
1335  mOut._24 = 0;
1336 
1337  mOut._31 = axis.y * sinAngle + oneMinusCosAngle * axis.z * axis.x;
1338  mOut._32 = -axis.x * sinAngle + oneMinusCosAngle * axis.z * axis.y;
1339  mOut._33 = 1 + oneMinusCosAngle * (axis.z * axis.z - 1);
1340  mOut._34 = 0;
1341 
1342  mOut._41 = 0;
1343  mOut._42 = 0;
1344  mOut._43 = 0;
1345  mOut._44 = 1;
1346 
1347  return mOut;
1348  }
1349 
1350  static Matrix4x4 ViewFromBasis(const Vector3<T>& f3X, const Vector3<T>& f3Y, const Vector3<T>& f3Z)
1351  {
1352  return Matrix4x4 // clang-format off
1353  {
1354  f3X.x, f3Y.x, f3Z.x, 0,
1355  f3X.y, f3Y.y, f3Z.y, 0,
1356  f3X.z, f3Y.z, f3Z.z, 0,
1357  0, 0, 0, 1 // clang-format on
1358  };
1359  }
1360 
1361 
1362  void SetNearFarClipPlanes(T zNear, T zFar, T bIsGL)
1363  {
1364  if (bIsGL)
1365  {
1366  // https://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml
1367  // http://www.terathon.com/gdc07_lengyel.pdf
1368  // Note that OpenGL uses right-handed coordinate system, where
1369  // camera is looking in negative z direction:
1370  // OO
1371  // |__|<--------------------
1372  // -z +z
1373  // Consequently, OpenGL projection matrix given by these two
1374  // references inverts z axis.
1375 
1376  // We do not need to do this, because we use DX coordinate
1377  // system for the camera space. Thus we need to invert the
1378  // sign of the values in the third column in the matrix
1379  // from the references:
1380 
1381  _33 = -(-(zFar + zNear) / (zFar - zNear));
1382  _43 = -2 * zNear * zFar / (zFar - zNear);
1383  _34 = -(-1);
1384  }
1385  else
1386  {
1387  _33 = zFar / (zFar - zNear);
1388  _43 = -zNear * zFar / (zFar - zNear);
1389  _34 = 1;
1390  }
1391  }
1392 
1393  void GetNearFarClipPlanes(T& zNear, T& zFar, bool bIsGL) const
1394  {
1395  if (bIsGL)
1396  {
1397  zNear = _43 / (-1 - _33);
1398  zFar = _43 / (+1 - _33);
1399  }
1400  else
1401  {
1402  zNear = -_43 / _33;
1403  zFar = _33 / (_33 - 1) * zNear;
1404  }
1405  }
1406 
1407  static Matrix4x4 Projection(T fov, T aspectRatio, T zNear, T zFar, bool bIsGL) // Left-handed projection
1408  {
1409  Matrix4x4 mOut;
1410  auto yScale = static_cast<T>(1) / std::tan(fov / static_cast<T>(2));
1411  auto xScale = yScale / aspectRatio;
1412  mOut._11 = xScale;
1413  mOut._22 = yScale;
1414 
1415  mOut.SetNearFarClipPlanes(zNear, zFar, bIsGL);
1416 
1417  return mOut;
1418  }
1419 
1420  static Matrix4x4 OrthoOffCenter(T left, T right, T bottom, T top, T zNear, T zFar, bool bIsGL) // Left-handed ortho projection
1421  {
1422  auto _22 = (bIsGL ? 2 : 1) / (zFar - zNear);
1423  auto _32 = (bIsGL ? zNear + zFar : zNear) / (zNear - zFar);
1424  // clang-format off
1425  return Matrix4x4
1426  {
1427  2 / (right - left), 0, 0, 0,
1428  0, 2 / (top - bottom), 0, 0,
1429  0, 0, _22, 0,
1430  (left + right)/(left - right), (top + bottom) / (bottom - top), _32, 1
1431  };
1432  // clang-format on
1433  }
1434 
1435  static Matrix4x4 Ortho(T width, T height, T zNear, T zFar, bool bIsGL) // Left-handed ortho projection
1436  {
1437  return OrthoOffCenter(
1438  -width * static_cast<T>(0.5),
1439  +width * static_cast<T>(0.5),
1440  -height * static_cast<T>(0.5),
1441  +height * static_cast<T>(0.5),
1442  zNear, zFar, bIsGL);
1443  }
1444 
1445  static Matrix4x4 Mul(const Matrix4x4& m1, const Matrix4x4& m2)
1446  {
1447  Matrix4x4 mOut;
1448  for (int i = 0; i < 4; i++)
1449  {
1450  for (int j = 0; j < 4; j++)
1451  {
1452  for (int k = 0; k < 4; k++)
1453  {
1454  mOut.m[i][j] += m1.m[i][k] * m2.m[k][j];
1455  }
1456  }
1457  }
1458  return mOut;
1459  }
1460 
1461 
1462  T Determinant() const
1463  {
1464  T det = 0.f;
1465 
1466  det += _11 *
1467  Matrix3x3<T>(_22, _23, _24,
1468  _32, _33, _34,
1469  _42, _43, _44)
1470  .Determinant();
1471 
1472  det -= _12 *
1473  Matrix3x3<T>(_21, _23, _24,
1474  _31, _33, _34,
1475  _41, _43, _44)
1476  .Determinant();
1477 
1478  det += _13 *
1479  Matrix3x3<T>(_21, _22, _24,
1480  _31, _32, _34,
1481  _41, _42, _44)
1482  .Determinant();
1483 
1484  det -= _14 *
1485  Matrix3x3<T>(_21, _22, _23,
1486  _31, _32, _33,
1487  _41, _42, _43)
1488  .Determinant();
1489 
1490  return det;
1491  }
1492 
1494  {
1495  Matrix4x4 inv;
1496 
1497  // row 1
1498  inv._11 =
1499  Matrix3x3<T>(_22, _23, _24,
1500  _32, _33, _34,
1501  _42, _43, _44)
1502  .Determinant();
1503 
1504  inv._12 =
1505  -Matrix3x3<T>(_21, _23, _24,
1506  _31, _33, _34,
1507  _41, _43, _44)
1508  .Determinant();
1509 
1510  inv._13 =
1511  Matrix3x3<T>(_21, _22, _24,
1512  _31, _32, _34,
1513  _41, _42, _44)
1514  .Determinant();
1515 
1516  inv._14 =
1517  -Matrix3x3<T>(_21, _22, _23,
1518  _31, _32, _33,
1519  _41, _42, _43)
1520  .Determinant();
1521 
1522 
1523  // row 2
1524  inv._21 =
1525  -Matrix3x3<T>(_12, _13, _14,
1526  _32, _33, _34,
1527  _42, _43, _44)
1528  .Determinant();
1529 
1530  inv._22 =
1531  Matrix3x3<T>(_11, _13, _14,
1532  _31, _33, _34,
1533  _41, _43, _44)
1534  .Determinant();
1535 
1536  inv._23 =
1537  -Matrix3x3<T>(_11, _12, _14,
1538  _31, _32, _34,
1539  _41, _42, _44)
1540  .Determinant();
1541 
1542  inv._24 =
1543  Matrix3x3<T>(_11, _12, _13,
1544  _31, _32, _33,
1545  _41, _42, _43)
1546  .Determinant();
1547 
1548 
1549  // row 3
1550  inv._31 =
1551  Matrix3x3<T>(_12, _13, _14,
1552  _22, _23, _24,
1553  _42, _43, _44)
1554  .Determinant();
1555 
1556  inv._32 =
1557  -Matrix3x3<T>(_11, _13, _14,
1558  _21, _23, _24,
1559  _41, _43, _44)
1560  .Determinant();
1561 
1562  inv._33 =
1563  Matrix3x3<T>(_11, _12, _14,
1564  _21, _22, _24,
1565  _41, _42, _44)
1566  .Determinant();
1567 
1568  inv._34 =
1569  -Matrix3x3<T>(_11, _12, _13,
1570  _21, _22, _23,
1571  _41, _42, _43)
1572  .Determinant();
1573 
1574 
1575  // row 4
1576  inv._41 =
1577  -Matrix3x3<T>(_12, _13, _14,
1578  _22, _23, _24,
1579  _32, _33, _34)
1580  .Determinant();
1581 
1582  inv._42 =
1583  Matrix3x3<T>(_11, _13, _14,
1584  _21, _23, _24,
1585  _31, _33, _34)
1586  .Determinant();
1587 
1588  inv._43 =
1589  -Matrix3x3<T>(_11, _12, _14,
1590  _21, _22, _24,
1591  _31, _32, _34)
1592  .Determinant();
1593 
1594  inv._44 =
1595  Matrix3x3<T>(_11, _12, _13,
1596  _21, _22, _23,
1597  _31, _32, _33)
1598  .Determinant();
1599 
1600  auto det = _11 * inv._11 + _12 * inv._12 + _13 * inv._13 + _14 * inv._14;
1601  inv = inv.Transpose();
1602  inv *= static_cast<T>(1) / det;
1603 
1604  return inv;
1605  }
1606 
1608  {
1609  return Matrix4x4 // clang-format off
1610  {
1611  _11, _12, _13, _14,
1612  _21, _22, _23, _24,
1613  _31, _32, _33, _34,
1614  0, 0, 0, _44 // clang-format on
1615  };
1616  }
1617 };
1618 
1619 // Template Vector Operations
1620 
1621 
1622 template <class T>
1623 T dot(const Vector2<T>& a, const Vector2<T>& b)
1624 {
1625  return a.x * b.x + a.y * b.y;
1626 }
1627 
1628 template <class T>
1629 T dot(const Vector3<T>& a, const Vector3<T>& b)
1630 {
1631  return a.x * b.x + a.y * b.y + a.z * b.z;
1632 }
1633 
1634 template <class T>
1635 T dot(const Vector4<T>& a, const Vector4<T>& b)
1636 {
1637  return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
1638 }
1639 
1640 template <class VectorType>
1641 auto length(const VectorType& a) -> decltype(dot(a, a))
1642 {
1643  return sqrt(dot(a, a));
1644 }
1645 
1646 
1647 template <class T>
1649 {
1650  return Vector3<T>(std::min(a.x, b.x), std::min(a.y, b.y), std::min(a.z, b.z));
1651 }
1652 
1653 template <class T>
1655 {
1656  return Vector4<T>(std::min(a.x, b.x), std::min(a.y, b.y), std::min(a.z, b.z), std::min(a.w, b.w));
1657 }
1658 
1659 template <class T>
1661 {
1662  return Vector3<T>(std::max(a.x, b.x), std::max(a.y, b.y), std::max(a.z, b.z));
1663 }
1664 
1665 template <class T>
1667 {
1668  return Vector4<T>(std::max(a.x, b.x), std::max(a.y, b.y), std::max(a.z, b.z), std::max(a.w, b.w));
1669 }
1670 
1671 template <class T>
1673 {
1674  // WARNING: abs() on gcc is for integers only!
1675  return Vector2<T>(a.x < 0 ? -a.x : a.x,
1676  a.y < 0 ? -a.y : a.y);
1677 }
1678 
1679 template <class T>
1681 {
1682  // WARNING: abs() on gcc is for integers only!
1683  return Vector3<T>(a.x < 0 ? -a.x : a.x,
1684  a.y < 0 ? -a.y : a.y,
1685  a.z < 0 ? -a.z : a.z);
1686 }
1687 
1688 template <class T>
1690 {
1691  // WARNING: abs() on gcc is for integers only!
1692  return Vector4<T>(a.x < 0 ? -a.x : a.x,
1693  a.y < 0 ? -a.y : a.y,
1694  a.z < 0 ? -a.z : a.z,
1695  a.w < 0 ? -a.w : a.w);
1696 }
1697 
1698 
1699 template <typename T>
1700 T clamp(T val, T _min, T _max)
1701 {
1702  return val < _min ? _min : (val > _max ? _max : val);
1703 }
1704 
1705 template <class T>
1706 Vector2<T> clamp(const Vector2<T>& a, const Vector2<T>& _min, const Vector2<T>& _max)
1707 {
1708  return Vector2<T>(clamp(a.x, _min.x, _max.x),
1709  clamp(a.y, _min.y, _max.y));
1710 }
1711 
1712 template <class T>
1713 Vector3<T> clamp(const Vector3<T>& a, const Vector3<T>& _min, const Vector3<T>& _max)
1714 {
1715  return Vector3<T>(clamp(a.x, _min.x, _max.x),
1716  clamp(a.y, _min.y, _max.y),
1717  clamp(a.z, _min.z, _max.z));
1718 }
1719 
1720 template <class T>
1721 Vector4<T> clamp(const Vector4<T>& a, const Vector4<T>& _min, const Vector4<T>& _max)
1722 {
1723  return Vector4<T>(clamp(a.x, _min.x, _max.x),
1724  clamp(a.y, _min.y, _max.y),
1725  clamp(a.z, _min.z, _max.z),
1726  clamp(a.w, _min.w, _max.w));
1727 }
1728 
1729 
1730 template <class T>
1732 {
1733  // | i j k |
1734  // | a.x a.y a.z |
1735  // | b.x b.y b.z |
1736  return Vector3<T>((a.y * b.z) - (a.z * b.y), (a.z * b.x) - (a.x * b.z), (a.x * b.y) - (a.y * b.x));
1737 }
1738 
1739 template <class T, class Y>
1741 {
1742  // | i j k |
1743  // | a.x a.y a.z |
1744  // | b.x b.y b.z |
1745  return Vector3<T> //
1746  {
1747  static_cast<T>(Y{a.y} * Y{b.z} - Y{a.z} * Y{b.y}),
1748  static_cast<T>(Y{a.z} * Y{b.x} - Y{a.x} * Y{b.z}),
1749  static_cast<T>(Y{a.x} * Y{b.y} - Y{a.y} * Y{b.x}) //
1750  };
1751 }
1752 
1754 {
1755  return cross<float, double>(a, b);
1756 }
1757 
1759 {
1760  return cross<int32_t, int64_t>(a, b);
1761 }
1762 
1763 template <class VectorType>
1764 VectorType normalize(const VectorType& a)
1765 {
1766  auto len = length(a);
1767  return a / len;
1768 }
1769 
1770 
1771 // Template Matrix-Matrix multiplications
1772 
1773 template <class T>
1775 {
1776  return Matrix4x4<T>::Mul(m1, m2);
1777 }
1778 
1779 template <class T>
1781 {
1782  return Matrix3x3<T>::Mul(m1, m2);
1783 }
1784 
1785 template <class T>
1787 {
1788  return Matrix2x2<T>::Mul(m1, m2);
1789 }
1790 
1791 
1792 // Template Matrix-Vector multiplications
1793 
1794 template <class T>
1796 {
1797  Vector4<T> out;
1798  out[0] = m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] * v.w;
1799  out[1] = m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] * v.w;
1800  out[2] = m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] * v.w;
1801  out[3] = m[3][0] * v.x + m[3][1] * v.y + m[3][2] * v.z + m[3][3] * v.w;
1802  return out;
1803 }
1804 
1805 template <class T>
1807 {
1808  Vector3<T> out;
1809  out[0] = m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z;
1810  out[1] = m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z;
1811  out[2] = m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z;
1812  return out;
1813 }
1814 
1815 template <class T>
1817 {
1818  Vector2<T> out;
1819  out[0] = m[0][0] * v.x + m[0][1] * v.y;
1820  out[1] = m[1][0] * v.x + m[1][1] * v.y;
1821  return out;
1822 }
1823 
1824 // Common HLSL-compatible vector typedefs
1825 
1826 using uint = uint32_t;
1830 
1834 
1838 
1842 
1846 
1850 
1851 
1853 {
1855 
1856  Quaternion(const float4& _q) noexcept :
1857  q{_q}
1858  {}
1859  Quaternion(float x, float y, float z, float w) noexcept :
1860  q{x, y, z, w}
1861  {
1862  }
1863  Quaternion() noexcept {}
1864 
1865  bool operator==(const Quaternion& right) const
1866  {
1867  return q == right.q;
1868  }
1869 
1870  template <typename Y>
1871  static Quaternion MakeQuaternion(const Y& vals)
1872  {
1873  return Quaternion{float4::MakeVector(vals)};
1874  }
1875 
1876  static Quaternion RotationFromAxisAngle(const float3& axis, float angle)
1877  {
1878  Quaternion out{0, 0, 0, 1};
1879  float norm = length(axis);
1880  if (norm != 0)
1881  {
1882  float sina2 = sin(0.5f * angle);
1883  out.q[0] = sina2 * axis[0] / norm;
1884  out.q[1] = sina2 * axis[1] / norm;
1885  out.q[2] = sina2 * axis[2] / norm;
1886  out.q[3] = cos(0.5f * angle);
1887  }
1888  return out;
1889  }
1890 
1891  void GetAxisAngle(float3& outAxis, float& outAngle) const
1892  {
1893  float sina2 = sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2]);
1894  outAngle = 2.0f * atan2(sina2, q[3]);
1895  float r = (sina2 > 0) ? (1.0f / sina2) : 0;
1896  outAxis[0] = r * q[0];
1897  outAxis[1] = r * q[1];
1898  outAxis[2] = r * q[2];
1899  }
1900 
1902  {
1903  float4x4 out;
1904  float yy2 = 2.0f * q[1] * q[1];
1905  float xy2 = 2.0f * q[0] * q[1];
1906  float xz2 = 2.0f * q[0] * q[2];
1907  float yz2 = 2.0f * q[1] * q[2];
1908  float zz2 = 2.0f * q[2] * q[2];
1909  float wz2 = 2.0f * q[3] * q[2];
1910  float wy2 = 2.0f * q[3] * q[1];
1911  float wx2 = 2.0f * q[3] * q[0];
1912  float xx2 = 2.0f * q[0] * q[0];
1913  out[0][0] = -yy2 - zz2 + 1.0f;
1914  out[0][1] = xy2 + wz2;
1915  out[0][2] = xz2 - wy2;
1916  out[0][3] = 0;
1917  out[1][0] = xy2 - wz2;
1918  out[1][1] = -xx2 - zz2 + 1.0f;
1919  out[1][2] = yz2 + wx2;
1920  out[1][3] = 0;
1921  out[2][0] = xz2 + wy2;
1922  out[2][1] = yz2 - wx2;
1923  out[2][2] = -xx2 - yy2 + 1.0f;
1924  out[2][3] = 0;
1925  out[3][0] = out[3][1] = out[3][2] = 0;
1926  out[3][3] = 1;
1927  return out;
1928  }
1929 
1930  static Quaternion Mul(const Quaternion& q1, const Quaternion& q2)
1931  {
1932  Quaternion q1_q2;
1933  q1_q2.q.x = +q1.q.x * q2.q.w + q1.q.y * q2.q.z - q1.q.z * q2.q.y + q1.q.w * q2.q.x;
1934  q1_q2.q.y = -q1.q.x * q2.q.z + q1.q.y * q2.q.w + q1.q.z * q2.q.x + q1.q.w * q2.q.y;
1935  q1_q2.q.z = +q1.q.x * q2.q.y - q1.q.y * q2.q.x + q1.q.z * q2.q.w + q1.q.w * q2.q.z;
1936  q1_q2.q.w = -q1.q.x * q2.q.x - q1.q.y * q2.q.y - q1.q.z * q2.q.z + q1.q.w * q2.q.w;
1937  return q1_q2;
1938  }
1939 
1941  {
1942  q = rhs.q;
1943  return *this;
1944  }
1945 
1947  {
1948  *this = Mul(*this, rhs);
1949  return *this;
1950  }
1951 
1952  float3 RotateVector(const float3& v) const
1953  {
1954  const float3 axis(q.x, q.y, q.z);
1955  return v + 2.f * cross(axis, cross(axis, v) + q.w * v);
1956  }
1957 };
1958 
1959 inline Quaternion operator*(const Quaternion& q1, const Quaternion& q2)
1960 {
1961  return Quaternion::Mul(q1, q2);
1962 }
1963 
1965 {
1966  return Quaternion{normalize(q.q)};
1967 }
1968 
1969 // https://en.wikipedia.org/wiki/Slerp
1970 inline Quaternion slerp(Quaternion v0, Quaternion v1, float t, bool DoNotNormalize = false)
1971 {
1972  // Only unit quaternions are valid rotations.
1973  // Normalize to avoid undefined behavior.
1974  if (!DoNotNormalize)
1975  {
1976  v0 = normalize(v0);
1977  v1 = normalize(v1);
1978  }
1979 
1980  // Compute the cosine of the angle between the two vectors.
1981  auto dp = dot(v0.q, v1.q);
1982 
1983  // If the dot product is negative, slerp won't take
1984  // the shorter path. Note that v1 and -v1 are equivalent when
1985  // the negation is applied to all four components. Fix by
1986  // reversing one quaternion.
1987  if (dp < 0)
1988  {
1989  v1.q = -v1.q;
1990  dp = -dp;
1991  }
1992 
1993  const double DOT_THRESHOLD = 0.9995;
1994  if (dp > DOT_THRESHOLD)
1995  {
1996  // If the inputs are too close for comfort, linearly interpolate
1997  // and normalize the result.
1998 
1999  Quaternion result = Quaternion{v0.q + t * (v1.q - v0.q)};
2000  result.q = normalize(result.q);
2001  return result;
2002  }
2003 
2004  // Since dot is in range [0, DOT_THRESHOLD], acos is safe
2005  auto theta_0 = std::acos(dp); // theta_0 = angle between input vectors
2006  auto theta = theta_0 * t; // theta = angle between v0 and result
2007  auto sin_theta = std::sin(theta); // compute this value only once
2008  auto sin_theta_0 = std::sin(theta_0); // compute this value only once
2009 
2010  auto s0 = cos(theta) - dp * sin_theta / sin_theta_0; // == sin(theta_0 - theta) / sin(theta_0)
2011  auto s1 = sin_theta / sin_theta_0;
2012 
2013  auto v = Quaternion{v0.q * s0 + v1.q * s1};
2014  if (!DoNotNormalize)
2015  {
2016  v = normalize(v);
2017  }
2018  return v;
2019 }
2020 
2021 
2022 template <typename T>
2023 T lerp(const T& Left, const T& Right, float w)
2024 {
2025  return Left * (1.f - w) + Right * w;
2026 }
2027 
2028 template <typename T>
2029 T SmoothStep(T Left, T Right, T w)
2030 {
2031  auto t = clamp((w - Left) / (Right - Left), static_cast<T>(0), static_cast<T>(1));
2032  return t * t * (static_cast<T>(3) - static_cast<T>(2) * t);
2033 }
2034 
2035 template <typename T>
2036 T max3(const T& x, const T& y, const T& z)
2037 {
2038  return std::max(std::max(x, y), z);
2039 }
2040 
2041 template <typename T>
2042 T min3(const T& x, const T& y, const T& z)
2043 {
2044  return std::min(std::min(x, y), z);
2045 }
2046 
2048 {
2049  // clang-format off
2050  return float4
2051  {
2052  static_cast<float>((RGBA8 >> 0u) & 0xFF) / 255.f,
2053  static_cast<float>((RGBA8 >> 8u) & 0xFF) / 255.f,
2054  static_cast<float>((RGBA8 >> 16u) & 0xFF) / 255.f,
2055  static_cast<float>((RGBA8 >> 24u) & 0xFF) / 255.f
2056  };
2057  // clang-format on
2058 }
2059 
2060 inline Uint32 F4Color_To_RGBA8Unorm(const float4& f4Color)
2061 {
2062  Uint32 RGBA8U = 0;
2063  RGBA8U |= static_cast<Uint32>(clamp(f4Color.r, 0.f, 1.f) * 255.f) << 0u;
2064  RGBA8U |= static_cast<Uint32>(clamp(f4Color.g, 0.f, 1.f) * 255.f) << 8u;
2065  RGBA8U |= static_cast<Uint32>(clamp(f4Color.b, 0.f, 1.f) * 255.f) << 16u;
2066  RGBA8U |= static_cast<Uint32>(clamp(f4Color.a, 0.f, 1.f) * 255.f) << 24u;
2067  return RGBA8U;
2068 }
2069 
2070 template <typename T>
2072 {
2073 };
2074 
2075 template <>
2077 {
2078  // All floats that have fractional part are representable as 32-bit int
2079  using Type = Int32;
2080 };
2081 
2082 template <>
2084 {
2085  // All doubles that have fractional part are representable as 64-bit int
2086  using Type = Int64;
2087 };
2088 
2089 // At least on MSVC std::floor is an actual function call into ucrtbase.dll.
2090 // All floats/doubles that have fractional parts also fit into integer
2091 // representable range, so we can do much better.
2092 template <typename T>
2094 {
2095  auto i = static_cast<typename _FastFloatIntermediateType<T>::Type>(x);
2096  auto flr = static_cast<T>(i);
2097  // x flr floor(x) flr <= x
2098  // +1.0 -> 1.0 1.0 true
2099  // +0.5 -> 0.0 0.0 true
2100  // 0.0 -> 0.0 0.0 true
2101  // -0.5 -> 0.0 -1.0 false
2102  // -1.0 -> -1.0 -1.0 true
2103 
2104  return flr <= x ? flr : flr - 1;
2105 }
2106 
2107 template <typename T>
2108 T FastCeil(T x)
2109 {
2110  return -FastFloor(-x);
2111 }
2112 
2113 
2114 template <typename T>
2116 {
2117  return Diligent::Vector2<T>{
2118  FastFloor(vec.x),
2119  FastFloor(vec.y)};
2120 }
2121 
2122 template <typename T>
2124 {
2125  return Diligent::Vector3<T>{
2126  FastFloor(vec.x),
2127  FastFloor(vec.y),
2128  FastFloor(vec.z)};
2129 }
2130 
2131 template <typename T>
2133 {
2134  return Diligent::Vector4<T>{
2135  FastFloor(vec.x),
2136  FastFloor(vec.y),
2137  FastFloor(vec.z),
2138  FastFloor(vec.w)};
2139 }
2140 
2141 
2142 template <typename T>
2144 {
2145  return Diligent::Vector2<T>{
2146  FastCeil(vec.x),
2147  FastCeil(vec.y)};
2148 }
2149 
2150 template <typename T>
2152 {
2153  return Diligent::Vector3<T>{
2154  FastCeil(vec.x),
2155  FastCeil(vec.y),
2156  FastCeil(vec.z)};
2157 }
2158 
2159 template <typename T>
2161 {
2162  return Diligent::Vector4<T>{
2163  FastCeil(vec.x),
2164  FastCeil(vec.y),
2165  FastCeil(vec.z),
2166  FastCeil(vec.w)};
2167 }
2168 
2170 {
2171  // https://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN
2172 
2173  // Interleave lower 16 bits of x and y, so the bits of x
2174  // are in the even positions and bits from y in the odd;
2175  // x | (y << 1) gets the resulting 32-bit Morton Number.
2176  // x and y must initially be less than 65536.
2177  Uint32 x = _x;
2178  Uint32 y = _y;
2179 
2180  x = (x | (x << 8u)) & 0x00FF00FFu;
2181  x = (x | (x << 4u)) & 0x0F0F0F0Fu;
2182  x = (x | (x << 2u)) & 0x33333333u;
2183  x = (x | (x << 1u)) & 0x55555555u;
2184 
2185  y = (y | (y << 8u)) & 0x00FF00FFu;
2186  y = (y | (y << 4u)) & 0x0F0F0F0Fu;
2187  y = (y | (y << 2u)) & 0x33333333u;
2188  y = (y | (y << 1u)) & 0x55555555u;
2189 
2190  return x | (y << 1u);
2191 }
2192 
2194 template <typename T>
2195 typename std::enable_if<std::is_integral<T>::value, T>::type ExtractLSB(T& bits)
2196 {
2197  if (bits == T{0})
2198  return 0;
2199 
2200  const T bit = bits & ~(bits - T{1});
2201  bits &= ~bit;
2202 
2203  return bit;
2204 }
2205 
2207 template <typename T>
2208 typename std::enable_if<std::is_enum<T>::value, T>::type ExtractLSB(T& bits)
2209 {
2210  return static_cast<T>(ExtractLSB(reinterpret_cast<typename std::underlying_type<T>::type&>(bits)));
2211 }
2212 
2213 
2214 inline std::ostream& operator<<(std::ostream& os, const float4& vec)
2215 {
2216  return os << "float4(" << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w << ')';
2217 }
2218 inline std::ostream& operator<<(std::ostream& os, const float3& vec)
2219 {
2220  return os << "float3(" << vec.x << ", " << vec.y << ", " << vec.z << ')';
2221 }
2222 inline std::ostream& operator<<(std::ostream& os, const float2& vec)
2223 {
2224  return os << "float2(" << vec.x << ", " << vec.y << ')';
2225 }
2226 
2227 inline std::ostream& operator<<(std::ostream& os, const int4& vec)
2228 {
2229  return os << "int4(" << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w << ')';
2230 }
2231 inline std::ostream& operator<<(std::ostream& os, const int3& vec)
2232 {
2233  return os << "int3(" << vec.x << ", " << vec.y << ", " << vec.z << ')';
2234 }
2235 inline std::ostream& operator<<(std::ostream& os, const int2& vec)
2236 {
2237  return os << "int2(" << vec.x << ", " << vec.y << ')';
2238 }
2239 
2240 
2241 inline std::ostream& operator<<(std::ostream& os, const uint4& vec)
2242 {
2243  return os << "uint4(" << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w << ')';
2244 }
2245 inline std::ostream& operator<<(std::ostream& os, const uint3& vec)
2246 {
2247  return os << "uint3(" << vec.x << ", " << vec.y << ", " << vec.z << ')';
2248 }
2249 inline std::ostream& operator<<(std::ostream& os, const uint2& vec)
2250 {
2251  return os << "uint2(" << vec.x << ", " << vec.y << ')';
2252 }
2253 
2254 } // namespace Diligent
2255 
2256 
2257 
2258 namespace std
2259 {
2260 template <typename T>
2262 {
2263  return Diligent::Vector2<T>(
2264  std::max(Left.x, Right.x),
2265  std::max(Left.y, Right.y));
2266 }
2267 
2268 template <typename T>
2270 {
2271  return Diligent::Vector3<T>(
2272  std::max(Left.x, Right.x),
2273  std::max(Left.y, Right.y),
2274  std::max(Left.z, Right.z));
2275 }
2276 
2277 template <typename T>
2279 {
2280  return Diligent::Vector4<T>(
2281  std::max(Left.x, Right.x),
2282  std::max(Left.y, Right.y),
2283  std::max(Left.z, Right.z),
2284  std::max(Left.w, Right.w));
2285 }
2286 
2287 
2288 template <typename T>
2290 {
2291  return Diligent::Vector2<T>(
2292  std::min(Left.x, Right.x),
2293  std::min(Left.y, Right.y));
2294 }
2295 
2296 template <typename T>
2298 {
2299  return Diligent::Vector3<T>(
2300  std::min(Left.x, Right.x),
2301  std::min(Left.y, Right.y),
2302  std::min(Left.z, Right.z));
2303 }
2304 
2305 template <typename T>
2307 {
2308  return Diligent::Vector4<T>(
2309  std::min(Left.x, Right.x),
2310  std::min(Left.y, Right.y),
2311  std::min(Left.z, Right.z),
2312  std::min(Left.w, Right.w));
2313 }
2314 
2315 template <typename T>
2317 {
2318  return Diligent::Vector2<T>(
2319  std::floor(vec.x),
2320  std::floor(vec.y));
2321 }
2322 
2323 template <typename T>
2325 {
2326  return Diligent::Vector3<T>(
2327  std::floor(vec.x),
2328  std::floor(vec.y),
2329  std::floor(vec.z));
2330 }
2331 
2332 template <typename T>
2334 {
2335  return Diligent::Vector4<T>(
2336  std::floor(vec.x),
2337  std::floor(vec.y),
2338  std::floor(vec.z),
2339  std::floor(vec.w));
2340 }
2341 
2342 
2343 template <typename T>
2345 {
2346  return Diligent::Vector2<T>(
2347  std::ceil(vec.x),
2348  std::ceil(vec.y));
2349 }
2350 
2351 template <typename T>
2353 {
2354  return Diligent::Vector3<T>(
2355  std::ceil(vec.x),
2356  std::ceil(vec.y),
2357  std::ceil(vec.z));
2358 }
2359 
2360 template <typename T>
2362 {
2363  return Diligent::Vector4<T>(
2364  std::ceil(vec.x),
2365  std::ceil(vec.y),
2366  std::ceil(vec.z),
2367  std::ceil(vec.w));
2368 }
2369 
2370 
2371 template <typename T>
2372 struct hash<Diligent::Vector2<T>>
2373 {
2374  size_t operator()(const Diligent::Vector2<T>& v2) const
2375  {
2376  return Diligent::ComputeHash(v2.x, v2.y);
2377  }
2378 };
2379 
2380 template <typename T>
2381 struct hash<Diligent::Vector3<T>>
2382 {
2383  size_t operator()(const Diligent::Vector3<T>& v3) const
2384  {
2385  return Diligent::ComputeHash(v3.x, v3.y, v3.z);
2386  }
2387 };
2388 
2389 template <typename T>
2390 struct hash<Diligent::Vector4<T>>
2391 {
2392  size_t operator()(const Diligent::Vector4<T>& v4) const
2393  {
2394  return Diligent::ComputeHash(v4.x, v4.y, v4.z, v4.w);
2395  }
2396 };
2397 
2398 template <typename T>
2399 struct hash<Diligent::Matrix2x2<T>>
2400 {
2401  size_t operator()(const Diligent::Matrix2x2<T>& m) const
2402  {
2403  return Diligent::ComputeHash(
2404  m.m00, m.m01,
2405  m.m10, m.m11);
2406  }
2407 };
2408 
2409 template <typename T>
2410 struct hash<Diligent::Matrix3x3<T>>
2411 {
2412  size_t operator()(const Diligent::Matrix3x3<T>& m) const
2413  {
2414  return Diligent::ComputeHash(
2415  m.m00, m.m01, m.m02,
2416  m.m10, m.m11, m.m12,
2417  m.m20, m.m21, m.m22);
2418  }
2419 };
2420 
2421 template <typename T>
2422 struct hash<Diligent::Matrix4x4<T>>
2423 {
2424  size_t operator()(const Diligent::Matrix4x4<T>& m) const
2425  {
2426  return Diligent::ComputeHash(
2427  m.m00, m.m01, m.m02, m.m03,
2428  m.m10, m.m11, m.m12, m.m13,
2429  m.m20, m.m21, m.m22, m.m23,
2430  m.m30, m.m31, m.m32, m.m33);
2431  }
2432 };
2433 } // namespace std
2434 
2435 #ifdef _MSC_VER
2436 # pragma warning(pop)
2437 #endif
Diligent::Matrix3x3::RotationY
static Matrix3x3 RotationY(T angleInRadians)
Definition: BasicMath.hpp:1008
Diligent::Matrix2x2::Matrix2x2
Matrix2x2(T value)
Definition: BasicMath.hpp:716
Diligent::Matrix4x4::Data
T * Data()
Definition: BasicMath.hpp:1187
Diligent::Matrix4x4::operator*=
Matrix4x4 & operator*=(T s)
Definition: BasicMath.hpp:1191
Diligent::uint
uint32_t uint
Definition: BasicMath.hpp:1826
Diligent::Vector4::x
T x
Definition: BasicMath.hpp:474
Diligent::Vector4::MakeVector
static Vector4 MakeVector(const Y &vals)
Definition: BasicMath.hpp:661
Diligent::Vector4::operator/
Vector4 operator/(const Vector4 &right) const
Definition: BasicMath.hpp:563
Diligent::Vector4::Data
const T * Data() const
Definition: BasicMath.hpp:641
Diligent::Vector3::operator!=
bool operator!=(const Vector3 &right) const
Definition: BasicMath.hpp:387
Diligent::Matrix3x3::_21
T _21
Definition: BasicMath.hpp:860
Diligent::Vector2::operator*
Vector2 operator*(const Matrix2x2< T > &m) const
Definition: BasicMath.hpp:149
Diligent::Vector3::operator+
Vector3 operator+(const Vector3 &right) const
Definition: BasicMath.hpp:302
Diligent::Matrix3x3::_11
T _11
Definition: BasicMath.hpp:857
Diligent::Matrix4x4::m03
T m03
Definition: BasicMath.hpp:1092
std::hash< Diligent::Matrix3x3< T > >::operator()
size_t operator()(const Diligent::Matrix3x3< T > &m) const
Definition: BasicMath.hpp:2412
Diligent::Vector2::MakeVector
static Vector2 MakeVector(const Y &vals)
Definition: BasicMath.hpp:235
Diligent::Matrix3x3::Scale
static Matrix3x3 Scale(T x, T y, T z)
Definition: BasicMath.hpp:979
Diligent::Matrix4x4::Identity
static Matrix4x4 Identity()
Definition: BasicMath.hpp:1216
Diligent::_FastFloatIntermediateType
Definition: BasicMath.hpp:2071
Diligent::Matrix4x4::Matrix4x4
Matrix4x4()
Definition: BasicMath.hpp:1119
Diligent::Vector2::operator[]
const T & operator[](size_t index) const
Definition: BasicMath.hpp:224
Diligent::Matrix4x4::_14
T _14
Definition: BasicMath.hpp:1073
Diligent::Vector4::Vector4
Vector4(const Vector3< T > &v3, T _w)
Definition: BasicMath.hpp:657
Diligent::Matrix2x2::MakeMatrix
static Matrix2x2 MakeMatrix(const Y &vals)
Definition: BasicMath.hpp:737
Diligent::ExtractLSB
std::enable_if< std::is_integral< T >::value, T >::type ExtractLSB(T &bits)
Returns the least-signficant bit and clears it in the input argument.
Definition: BasicMath.hpp:2195
Diligent::Vector2::operator-
Vector2 operator-(const Vector2< T > &right) const
Definition: BasicMath.hpp:96
Diligent::Matrix3x3::MakeMatrix
static Matrix3x3 MakeMatrix(const Y &vals)
Definition: BasicMath.hpp:906
Diligent::high_precision_cross
Vector3< float > high_precision_cross(const Vector3< float > &a, const Vector3< float > &b)
Definition: BasicMath.hpp:1753
Diligent::Vector2::operator>=
Vector2 operator>=(const Vector2 &right) const
Definition: BasicMath.hpp:209
Diligent::Vector3::operator/=
Vector3 & operator/=(const Vector3 &right)
Definition: BasicMath.hpp:374
Diligent::Matrix4x4::m01
T m01
Definition: BasicMath.hpp:1090
Diligent::Vector4::a
T a
Definition: BasicMath.hpp:484
Diligent::Vector2::operator/
Vector2 operator/(const Vector2 &right) const
Definition: BasicMath.hpp:157
Diligent::Matrix3x3::operator==
bool operator==(const Matrix3x3 &r) const
Definition: BasicMath.hpp:916
Diligent::Vector4::Vector4
Vector4(T _x, T _y, T _z, T _w)
Definition: BasicMath.hpp:655
Diligent::Matrix4x4::Matrix4x4
Matrix4x4(T i11, T i12, T i13, T i14, T i21, T i22, T i23, T i24, T i31, T i32, T i33, T i34, T i41, T i42, T i43, T i44)
Definition: BasicMath.hpp:1123
Diligent::Matrix4x4::m10
T m10
Definition: BasicMath.hpp:1093
Diligent::Matrix3x3::Matrix3x3
Matrix3x3()
Definition: BasicMath.hpp:891
Diligent::Vector4::operator>=
Vector4 operator>=(const Vector4 &right) const
Definition: BasicMath.hpp:631
Diligent::cross
Vector3< T > cross(const Vector3< T > &a, const Vector3< T > &b)
Definition: BasicMath.hpp:1731
Diligent::Vector3::Data
T * Data()
Definition: BasicMath.hpp:420
Diligent::Vector2::x
T x
Definition: BasicMath.hpp:80
Diligent::Matrix4x4::_34
T _34
Definition: BasicMath.hpp:1081
Diligent::Vector3::z
T z
Definition: BasicMath.hpp:267
Diligent::min
Vector3< T > min(const Vector3< T > &a, const Vector3< T > &b)
Definition: BasicMath.hpp:1648
Diligent::Vector2::operator-=
Vector2 & operator-=(const Vector2< T > &right)
Definition: BasicMath.hpp:101
Diligent::_FastFloatIntermediateType< double >::Type
Int64 Type
Definition: BasicMath.hpp:2086
Diligent::Vector3::w
T w
Definition: BasicMath.hpp:279
Diligent::Vector2::operator/=
Vector2 & operator/=(T s)
Definition: BasicMath.hpp:174
Diligent::Vector3::MakeVector
static Vector3 MakeVector(const Y &vals)
Definition: BasicMath.hpp:440
Diligent::Matrix3x3::m10
T m10
Definition: BasicMath.hpp:872
Diligent::Matrix2x2::operator*=
Matrix2x2 & operator*=(T s)
Definition: BasicMath.hpp:776
Diligent::Vector4::operator-
Vector4 operator-(const Vector4 &right) const
Definition: BasicMath.hpp:488
Diligent::Matrix3x3::operator[]
T * operator[](size_t row)
Definition: BasicMath.hpp:931
Diligent::Matrix3x3::operator!=
bool operator!=(const Matrix3x3 &r) const
Definition: BasicMath.hpp:926
Diligent::Vector2::Vector2
Vector2(T _x, T _y)
Definition: BasicMath.hpp:231
Diligent::Vector3::Recast
Vector3< Y > Recast() const
Definition: BasicMath.hpp:451
Diligent::Vector2::operator+
Vector2 operator+(const Vector2< T > &right) const
Definition: BasicMath.hpp:113
Diligent::Matrix4x4::_11
T _11
Definition: BasicMath.hpp:1070
Diligent::Matrix4x4::_21
T _21
Definition: BasicMath.hpp:1074
Diligent::Matrix4x4::_44
T _44
Definition: BasicMath.hpp:1085
Diligent::Vector3::operator>=
Vector3 operator>=(const Vector3 &right) const
Definition: BasicMath.hpp:413
Diligent::abs
Vector2< T > abs(const Vector2< T > &a)
Definition: BasicMath.hpp:1672
Diligent::Vector4::b
T b
Definition: BasicMath.hpp:483
Diligent::Vector2::operator/
Vector2 operator/(T s) const
Definition: BasicMath.hpp:169
Diligent::Matrix4x4::operator[]
T * operator[](size_t row)
Definition: BasicMath.hpp:1177
Diligent::Vector2::operator-
Vector2 operator-() const
Definition: BasicMath.hpp:108
Diligent::operator*
Vector2< T > operator*(T s, const Vector2< T > &a)
Definition: BasicMath.hpp:253
Diligent::Matrix4x4::Inverse
Matrix4x4 Inverse() const
Definition: BasicMath.hpp:1493
Diligent::Vector2::Data
const T * Data() const
Definition: BasicMath.hpp:217
Diligent::Vector4::operator+
Vector4 operator+(const Vector4 &right) const
Definition: BasicMath.hpp:507
Diligent::Matrix4x4::ViewFromBasis
static Matrix4x4 ViewFromBasis(const Vector3< T > &f3X, const Vector3< T > &f3Y, const Vector3< T > &f3Z)
Definition: BasicMath.hpp:1350
Diligent::length
auto length(const VectorType &a) -> decltype(dot(a, a))
Definition: BasicMath.hpp:1641
Diligent::Matrix4x4::OrthoOffCenter
static Matrix4x4 OrthoOffCenter(T left, T right, T bottom, T top, T zNear, T zFar, bool bIsGL)
Definition: BasicMath.hpp:1420
Diligent::RGBA8Unorm_To_F4Color
float4 RGBA8Unorm_To_F4Color(Uint32 RGBA8)
Definition: BasicMath.hpp:2047
Diligent::Matrix4x4::m20
T m20
Definition: BasicMath.hpp:1097
Diligent::Matrix4x4::Determinant
T Determinant() const
Definition: BasicMath.hpp:1462
Diligent::Matrix3x3::_23
T _23
Definition: BasicMath.hpp:862
Diligent::Vector4::operator/=
Vector4 & operator/=(T s)
Definition: BasicMath.hpp:554
Diligent::Matrix4x4
Definition: BasicMath.hpp:71
Diligent::Matrix4x4::RotationZ
static Matrix4x4 RotationZ(T angleInRadians)
Definition: BasicMath.hpp:1302
Diligent::Matrix3x3::Data
T * Data()
Definition: BasicMath.hpp:941
Diligent::Vector3::Data
const T * Data() const
Definition: BasicMath.hpp:422
Diligent::Matrix4x4::_23
T _23
Definition: BasicMath.hpp:1076
Diligent::max
Vector3< T > max(const Vector3< T > &a, const Vector3< T > &b)
Definition: BasicMath.hpp:1660
Diligent::Matrix4x4::MakeMatrix
static Matrix4x4 MakeMatrix(const Y &vals)
Definition: BasicMath.hpp:1149
Diligent::Matrix4x4::m22
T m22
Definition: BasicMath.hpp:1099
Diligent::Matrix2x2::operator[]
const T * operator[](size_t row) const
Definition: BasicMath.hpp:766
Diligent::Vector4::operator=
Vector4 & operator=(const Vector3< T > &v3)
Definition: BasicMath.hpp:597
Diligent::Vector4::operator[]
const T & operator[](size_t index) const
Definition: BasicMath.hpp:648
Diligent::Vector2::u
T u
Definition: BasicMath.hpp:90
std::hash< Diligent::Vector4< T > >::operator()
size_t operator()(const Diligent::Vector4< T > &v4) const
Definition: BasicMath.hpp:2392
Diligent::Vector3::operator*=
Vector3 & operator*=(T s)
Definition: BasicMath.hpp:320
Diligent::Vector4::operator<
Vector4 operator<(const Vector4 &right) const
Definition: BasicMath.hpp:607
Diligent::clamp
T clamp(T val, T _min, T _max)
Definition: BasicMath.hpp:1700
Diligent::Matrix3x3::_33
T _33
Definition: BasicMath.hpp:865
std::min
Diligent::Vector2< T > min(const Diligent::Vector2< T > &Left, const Diligent::Vector2< T > &Right)
Definition: BasicMath.hpp:2289
Diligent::Matrix3x3::m00
T m00
Definition: BasicMath.hpp:869
Diligent::Vector4::operator*
Vector4 operator*(const Matrix4x4< T > &m) const
Definition: BasicMath.hpp:587
Diligent::Quaternion::MakeQuaternion
static Quaternion MakeQuaternion(const Y &vals)
Definition: BasicMath.hpp:1871
Diligent::Matrix2x2::Inverse
Matrix2x2 Inverse() const
Definition: BasicMath.hpp:837
Diligent::Matrix2x2::Transpose
Matrix2x2 Transpose() const
Definition: BasicMath.hpp:790
Diligent::Vector3::Vector3
Vector3(T _x, T _y, T _z)
Definition: BasicMath.hpp:436
Diligent::Vector2::Vector2
Vector2()
Definition: BasicMath.hpp:229
Diligent::Matrix4x4::m
T m[4][4]
Definition: BasicMath.hpp:1106
Diligent::Matrix2x2::_11
T _11
Definition: BasicMath.hpp:701
Diligent::Matrix2x2::Data
const T * Data() const
Definition: BasicMath.hpp:773
Diligent::Quaternion::operator=
Quaternion & operator=(const Quaternion &rhs)
Definition: BasicMath.hpp:1940
Diligent::Vector3::r
T r
Definition: BasicMath.hpp:271
std::hash< Diligent::Matrix4x4< T > >::operator()
size_t operator()(const Diligent::Matrix4x4< T > &m) const
Definition: BasicMath.hpp:2424
Diligent::Matrix4x4::RemoveTranslation
Matrix4x4 RemoveTranslation() const
Definition: BasicMath.hpp:1607
Diligent::Vector3
Definition: BasicMath.hpp:259
Diligent::Matrix4x4::Projection
static Matrix4x4 Projection(T fov, T aspectRatio, T zNear, T zFar, bool bIsGL)
Definition: BasicMath.hpp:1407
Diligent::Int32
int32_t Int32
32-bit signed integer
Definition: BasicTypes.h:46
Diligent::Matrix4x4::SetNearFarClipPlanes
void SetNearFarClipPlanes(T zNear, T zFar, T bIsGL)
Definition: BasicMath.hpp:1362
Diligent::Matrix4x4::_33
T _33
Definition: BasicMath.hpp:1080
Diligent::Matrix4x4::Scale
static Matrix4x4 Scale(const Vector3< T > &v)
Definition: BasicMath.hpp:1254
Diligent::Vector4::operator-=
Vector4 & operator-=(const Vector4< T > &right)
Definition: BasicMath.hpp:498
Diligent::Matrix3x3::_22
T _22
Definition: BasicMath.hpp:861
Diligent::Matrix2x2::Determinant
T Determinant() const
Definition: BasicMath.hpp:832
Diligent::Matrix4x4::Mul
static Matrix4x4 Mul(const Matrix4x4 &m1, const Matrix4x4 &m2)
Definition: BasicMath.hpp:1445
Diligent::Matrix3x3::RotationZ
static Matrix3x3 RotationZ(T angleInRadians)
Definition: BasicMath.hpp:1024
Diligent::Matrix4x4::Matrix4x4
Matrix4x4(const Vector4< T > &Row0, const Vector4< T > &Row1, const Vector4< T > &Row2, const Vector4< T > &Row3)
Definition: BasicMath.hpp:1136
Diligent::Vector4::operator*
Vector4 operator*(T s) const
Definition: BasicMath.hpp:521
Diligent::max3
T max3(const T &x, const T &y, const T &z)
Definition: BasicMath.hpp:2036
Diligent::Vector3::operator*
Vector3 operator*(const Matrix4x4< T > &m) const
Definition: BasicMath.hpp:333
Diligent::Quaternion::Quaternion
Quaternion() noexcept
Definition: BasicMath.hpp:1863
Diligent::Vector3::u
T u
Definition: BasicMath.hpp:277
Diligent::Matrix3x3::m
T m[3][3]
Definition: BasicMath.hpp:879
Diligent::Matrix2x2::Matrix2x2
Matrix2x2(T i11, T i12, T i21, T i22)
Definition: BasicMath.hpp:728
Diligent::Matrix2x2::_12
T _12
Definition: BasicMath.hpp:702
Diligent::Matrix4x4::_32
T _32
Definition: BasicMath.hpp:1079
Diligent::Matrix4x4::m02
T m02
Definition: BasicMath.hpp:1091
Diligent::Int64
int64_t Int64
64-bit signed integer
Definition: BasicTypes.h:45
Diligent::Matrix2x2::Rotation
static Matrix2x2 Rotation(T angleInRadians)
Definition: BasicMath.hpp:820
Diligent::Vector4::operator<=
Vector4 operator<=(const Vector4 &right) const
Definition: BasicMath.hpp:623
Diligent::Quaternion::RotateVector
float3 RotateVector(const float3 &v) const
Definition: BasicMath.hpp:1952
Diligent::Matrix3x3::Data
const T * Data() const
Definition: BasicMath.hpp:943
Diligent::Matrix3x3::Matrix3x3
Matrix3x3(T value)
Definition: BasicMath.hpp:882
Diligent::Matrix3x3
Definition: BasicMath.hpp:70
Diligent::Matrix4x4::_31
T _31
Definition: BasicMath.hpp:1078
Diligent::Matrix4x4::m30
T m30
Definition: BasicMath.hpp:1101
Diligent::F4Color_To_RGBA8Unorm
Uint32 F4Color_To_RGBA8Unorm(const float4 &f4Color)
Definition: BasicMath.hpp:2060
Diligent::Matrix3x3::_32
T _32
Definition: BasicMath.hpp:864
Diligent::Matrix4x4::operator==
bool operator==(const Matrix4x4 &r) const
Definition: BasicMath.hpp:1162
Diligent::Vector2::operator*=
Vector2 & operator*=(T s)
Definition: BasicMath.hpp:142
Diligent::Vector4::operator*=
Vector4 & operator*=(T s)
Definition: BasicMath.hpp:526
std::floor
Diligent::Vector2< T > floor(const Diligent::Vector2< T > &vec)
Definition: BasicMath.hpp:2316
Diligent::Vector3::y
T y
Definition: BasicMath.hpp:266
Diligent::Vector2::operator*=
Vector2 & operator*=(const Vector2 &right)
Definition: BasicMath.hpp:135
Diligent::Matrix4x4::m32
T m32
Definition: BasicMath.hpp:1103
Diligent::Matrix2x2::Matrix2x2
Matrix2x2()
Definition: BasicMath.hpp:724
Diligent::Matrix4x4::Scale
static Matrix4x4 Scale(T s)
Definition: BasicMath.hpp:1259
Diligent::Matrix2x2::operator[]
T * operator[](size_t row)
Definition: BasicMath.hpp:761
Diligent::Matrix3x3::RotationX
static Matrix3x3 RotationX(T angleInRadians)
Definition: BasicMath.hpp:992
Diligent::Matrix4x4::m33
T m33
Definition: BasicMath.hpp:1104
Diligent::Vector4::operator!=
bool operator!=(const Vector4 &right) const
Definition: BasicMath.hpp:582
Diligent::Vector4::y
T y
Definition: BasicMath.hpp:475
Diligent::Vector3::v
T v
Definition: BasicMath.hpp:278
Diligent::Matrix2x2
Definition: BasicMath.hpp:69
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::Matrix2x2::Identity
static Matrix2x2 Identity()
Definition: BasicMath.hpp:797
Diligent::ComputeHash
std::size_t ComputeHash(const ArgsType &... Args)
Definition: HashUtils.hpp:57
Diligent::Vector2
Definition: BasicMath.hpp:74
Diligent::Matrix4x4::Scale
static Matrix4x4 Scale(T x, T y, T z)
Definition: BasicMath.hpp:1243
Diligent::Matrix3x3::operator*=
Matrix3x3 & operator*=(const Matrix3x3 &right)
Definition: BasicMath.hpp:953
Diligent::Matrix4x4::_12
T _12
Definition: BasicMath.hpp:1071
Diligent::Vector2::operator<
Vector2 operator<(const Vector2 &right) const
Definition: BasicMath.hpp:191
Diligent::Matrix2x2::m11
T m11
Definition: BasicMath.hpp:711
Diligent::Vector4::operator[]
T & operator[](size_t index)
Definition: BasicMath.hpp:643
Diligent::lerp
T lerp(const T &Left, const T &Right, float w)
Definition: BasicMath.hpp:2023
Diligent::Vector4
Definition: BasicMath.hpp:72
Diligent::Matrix2x2::m
T m[2][2]
Definition: BasicMath.hpp:713
Diligent::normalize
VectorType normalize(const VectorType &a)
Definition: BasicMath.hpp:1764
Diligent::Vector3::operator*
Vector3 operator*(const Matrix3x3< T > &m) const
Definition: BasicMath.hpp:347
Diligent::Quaternion::Quaternion
Quaternion(const float4 &_q) noexcept
Definition: BasicMath.hpp:1856
Diligent::Vector2::operator+=
Vector2 & operator+=(const Vector2< T > &right)
Definition: BasicMath.hpp:118
Diligent::Matrix4x4::m21
T m21
Definition: BasicMath.hpp:1098
Diligent::BitInterleave16
Uint32 BitInterleave16(Uint16 _x, Uint16 _y)
Definition: BasicMath.hpp:2169
std::ceil
Diligent::Vector2< T > ceil(const Diligent::Vector2< T > &vec)
Definition: BasicMath.hpp:2344
Diligent::Quaternion::operator==
bool operator==(const Quaternion &right) const
Definition: BasicMath.hpp:1865
Diligent::SmoothStep
T SmoothStep(T Left, T Right, T w)
Definition: BasicMath.hpp:2029
Diligent::min3
T min3(const T &x, const T &y, const T &z)
Definition: BasicMath.hpp:2042
Diligent::Matrix4x4::m12
T m12
Definition: BasicMath.hpp:1095
Diligent::Matrix4x4::Translation
static Matrix4x4 Translation(T x, T y, T z)
Definition: BasicMath.hpp:1227
Diligent::Vector4::operator>
Vector4 operator>(const Vector4 &right) const
Definition: BasicMath.hpp:615
Diligent::Matrix3x3::m22
T m22
Definition: BasicMath.hpp:877
Diligent::Vector2::operator<=
Vector2 operator<=(const Vector2 &right) const
Definition: BasicMath.hpp:203
Diligent::Vector2::operator/=
Vector2 & operator/=(const Vector2 &right)
Definition: BasicMath.hpp:162
Diligent::Vector3::Vector3
Vector3()
Definition: BasicMath.hpp:434
Diligent::Vector2::Recast
Vector2< Y > Recast() const
Definition: BasicMath.hpp:245
Diligent::Vector4::operator-
Vector4 operator-() const
Definition: BasicMath.hpp:493
Diligent::Matrix4x4::RotationArbitrary
static Matrix4x4 RotationArbitrary(Vector3< T > axis, T angleInRadians)
Definition: BasicMath.hpp:1317
Diligent::Matrix2x2::_21
T _21
Definition: BasicMath.hpp:703
Diligent::Matrix2x2::operator==
bool operator==(const Matrix2x2 &r) const
Definition: BasicMath.hpp:746
Diligent::Quaternion::ToMatrix
float4x4 ToMatrix() const
Definition: BasicMath.hpp:1901
Diligent::Matrix2x2::m00
T m00
Definition: BasicMath.hpp:708
Diligent::Matrix3x3::Mul
static Matrix3x3 Mul(const Matrix3x3 &m1, const Matrix3x3 &m2)
Definition: BasicMath.hpp:1037
Diligent::Matrix4x4::_42
T _42
Definition: BasicMath.hpp:1083
Diligent::Quaternion::operator*=
Quaternion & operator*=(const Quaternion &rhs)
Definition: BasicMath.hpp:1946
Diligent::Matrix4x4::m31
T m31
Definition: BasicMath.hpp:1102
Diligent::Vector4::Vector4
Vector4()
Definition: BasicMath.hpp:653
Diligent::Matrix3x3::m01
T m01
Definition: BasicMath.hpp:870
Diligent::FastFloor
T FastFloor(T x)
Definition: BasicMath.hpp:2093
Diligent::Matrix3x3::Transpose
Matrix3x3 Transpose() const
Definition: BasicMath.hpp:959
Diligent::Matrix3x3::Identity
static Matrix3x3 Identity()
Definition: BasicMath.hpp:969
Diligent::Matrix3x3::operator*=
Matrix3x3 & operator*=(T s)
Definition: BasicMath.hpp:945
Diligent::Vector3::operator-
Vector3 operator-() const
Definition: BasicMath.hpp:289
HashUtils.hpp
Diligent::Matrix4x4::m00
T m00
Definition: BasicMath.hpp:1089
Diligent::Matrix4x4::m13
T m13
Definition: BasicMath.hpp:1096
Diligent::Matrix4x4::operator[]
const T * operator[](size_t row) const
Definition: BasicMath.hpp:1182
Diligent::Matrix3x3::_12
T _12
Definition: BasicMath.hpp:858
Diligent::Vector4::Data
T * Data()
Definition: BasicMath.hpp:639
Diligent::Vector3::operator+=
Vector3 & operator+=(const Vector3< T > &right)
Definition: BasicMath.hpp:307
Diligent::Vector4::g
T g
Definition: BasicMath.hpp:482
Diligent::Matrix4x4::operator*=
Matrix4x4 & operator*=(const Matrix4x4 &right)
Definition: BasicMath.hpp:1199
std
Definition: AdvancedMath.hpp:979
Diligent::Vector4::operator/
Vector4 operator/(T s) const
Definition: BasicMath.hpp:549
Diligent::Vector3::g
T g
Definition: BasicMath.hpp:272
Diligent::Vector2::v
T v
Definition: BasicMath.hpp:91
Diligent::Vector2::operator*
Vector2 operator*(T s) const
Definition: BasicMath.hpp:125
Diligent::Matrix2x2::m10
T m10
Definition: BasicMath.hpp:710
Diligent::Uint16
uint16_t Uint16
16-bit unsigned integer
Definition: BasicTypes.h:52
Diligent::Matrix4x4::Ortho
static Matrix4x4 Ortho(T width, T height, T zNear, T zFar, bool bIsGL)
Definition: BasicMath.hpp:1435
std::max
Diligent::Vector2< T > max(const Diligent::Vector2< T > &Left, const Diligent::Vector2< T > &Right)
Definition: BasicMath.hpp:2261
Diligent::Vector3::operator>
Vector3 operator>(const Vector3 &right) const
Definition: BasicMath.hpp:399
Diligent::Vector4::z
T z
Definition: BasicMath.hpp:476
Diligent::Vector2::operator>
Vector2 operator>(const Vector2 &right) const
Definition: BasicMath.hpp:197
Diligent::Matrix2x2::Data
T * Data()
Definition: BasicMath.hpp:771
Diligent::Matrix2x2::_22
T _22
Definition: BasicMath.hpp:704
Diligent::Vector4::Recast
Vector4< Y > Recast() const
Definition: BasicMath.hpp:673
Diligent::Matrix2x2::Mul
static Matrix2x2 Mul(const Matrix2x2 &m1, const Matrix2x2 &m2)
Definition: BasicMath.hpp:804
Diligent::Matrix4x4::_24
T _24
Definition: BasicMath.hpp:1077
Diligent::Quaternion::q
float4 q
Definition: BasicMath.hpp:1854
Diligent::Matrix3x3::Determinant
T Determinant() const
Definition: BasicMath.hpp:1054
Diligent::Vector3::operator*=
Vector3 & operator*=(const Vector3 &right)
Definition: BasicMath.hpp:339
Diligent::Matrix4x4::m23
T m23
Definition: BasicMath.hpp:1100
Diligent::Matrix4x4::Translation
static Matrix4x4 Translation(const Vector3< T > &v)
Definition: BasicMath.hpp:1238
Diligent::Matrix4x4::_22
T _22
Definition: BasicMath.hpp:1075
Diligent::Matrix4x4::_43
T _43
Definition: BasicMath.hpp:1084
Diligent::Vector3::operator-=
Vector3 & operator-=(const Vector3< T > &right)
Definition: BasicMath.hpp:294
Diligent::Vector2::r
T r
Definition: BasicMath.hpp:85
Diligent::Matrix3x3::m21
T m21
Definition: BasicMath.hpp:876
Diligent::Matrix4x4::GetNearFarClipPlanes
void GetNearFarClipPlanes(T &zNear, T &zFar, bool bIsGL) const
Definition: BasicMath.hpp:1393
Diligent::Vector4::operator*=
Vector4 & operator*=(const Vector4 &right)
Definition: BasicMath.hpp:540
Diligent::Vector4::operator==
bool operator==(const Vector4 &right) const
Definition: BasicMath.hpp:577
Diligent::Matrix4x4::Data
const T * Data() const
Definition: BasicMath.hpp:1189
Diligent::Quaternion::RotationFromAxisAngle
static Quaternion RotationFromAxisAngle(const float3 &axis, float angle)
Definition: BasicMath.hpp:1876
std::hash< Diligent::Vector2< T > >::operator()
size_t operator()(const Diligent::Vector2< T > &v2) const
Definition: BasicMath.hpp:2374
Diligent::Vector4::operator*
Vector4 operator*(const Vector4 &right) const
Definition: BasicMath.hpp:535
Diligent::Vector2::operator==
bool operator==(const Vector2 &right) const
Definition: BasicMath.hpp:181
Diligent::Quaternion::GetAxisAngle
void GetAxisAngle(float3 &outAxis, float &outAngle) const
Definition: BasicMath.hpp:1891
Diligent::Matrix3x3::_31
T _31
Definition: BasicMath.hpp:863
Diligent::Matrix4x4::operator!=
bool operator!=(const Matrix4x4 &r) const
Definition: BasicMath.hpp:1172
Diligent::Vector3::operator[]
T & operator[](size_t index)
Definition: BasicMath.hpp:424
Diligent::Vector4::operator+=
Vector4 & operator+=(const Vector4< T > &right)
Definition: BasicMath.hpp:512
Diligent::Vector4::r
T r
Definition: BasicMath.hpp:481
Diligent::Vector3::operator*
Vector3 operator*(T s) const
Definition: BasicMath.hpp:315
Diligent::_FastFloatIntermediateType< float >::Type
Int32 Type
Definition: BasicMath.hpp:2079
Diligent::Vector3::operator/
Vector3 operator/(const Vector3 &right) const
Definition: BasicMath.hpp:369
Diligent::Quaternion
Definition: BasicMath.hpp:1852
Diligent::Matrix2x2::operator*=
Matrix2x2 & operator*=(const Matrix2x2 &right)
Definition: BasicMath.hpp:784
atan2
#define atan2
Definition: GLSLDefinitions.h:101
Diligent::Matrix2x2::m01
T m01
Definition: BasicMath.hpp:709
Diligent::Matrix3x3::m11
T m11
Definition: BasicMath.hpp:873
Diligent::Vector3::b
T b
Definition: BasicMath.hpp:273
Diligent::Matrix4x4::_41
T _41
Definition: BasicMath.hpp:1082
Diligent::Matrix3x3::m02
T m02
Definition: BasicMath.hpp:871
Diligent::Matrix3x3::_13
T _13
Definition: BasicMath.hpp:859
Diligent::Matrix2x2::operator!=
bool operator!=(const Matrix2x2 &r) const
Definition: BasicMath.hpp:756
Diligent::Vector3::operator[]
const T & operator[](size_t index) const
Definition: BasicMath.hpp:429
Diligent::Vector3::operator<=
Vector3 operator<=(const Vector3 &right) const
Definition: BasicMath.hpp:406
Diligent::FastCeil
T FastCeil(T x)
Definition: BasicMath.hpp:2108
Diligent::Vector3::operator==
bool operator==(const Vector3 &right) const
Definition: BasicMath.hpp:382
Diligent::Quaternion::Mul
static Quaternion Mul(const Quaternion &q1, const Quaternion &q2)
Definition: BasicMath.hpp:1930
Diligent::Vector2::g
T g
Definition: BasicMath.hpp:86
Diligent::Vector4::w
T w
Definition: BasicMath.hpp:477
Diligent::Matrix4x4::RotationX
static Matrix4x4 RotationX(T angleInRadians)
Definition: BasicMath.hpp:1268
Diligent::Vector3::operator-
Vector3 operator-(const Vector3 &right) const
Definition: BasicMath.hpp:284
Diligent::Matrix4x4::m11
T m11
Definition: BasicMath.hpp:1094
Diligent::Vector3::x
T x
Definition: BasicMath.hpp:265
std::hash< Diligent::Matrix2x2< T > >::operator()
size_t operator()(const Diligent::Matrix2x2< T > &m) const
Definition: BasicMath.hpp:2401
Diligent::Vector2::operator[]
T & operator[](size_t index)
Definition: BasicMath.hpp:219
Diligent::Vector2::Data
T * Data()
Definition: BasicMath.hpp:215
Diligent::Vector3::operator*
Vector3 operator*(const Vector3 &right) const
Definition: BasicMath.hpp:328
Diligent::dot
T dot(const Vector2< T > &a, const Vector2< T > &b)
Definition: BasicMath.hpp:1623
Diligent::Matrix3x3::m20
T m20
Definition: BasicMath.hpp:875
Diligent::operator<<
std::ostream & operator<<(std::ostream &os, const float4 &vec)
Definition: BasicMath.hpp:2214
std::hash< Diligent::Vector3< T > >::operator()
size_t operator()(const Diligent::Vector3< T > &v3) const
Definition: BasicMath.hpp:2383
Diligent::Vector2::operator!=
bool operator!=(const Vector2 &right) const
Definition: BasicMath.hpp:186
Diligent::Matrix4x4::Matrix4x4
Matrix4x4(T value)
Definition: BasicMath.hpp:1109
Diligent::Matrix4x4::RotationY
static Matrix4x4 RotationY(T angleInRadians)
Definition: BasicMath.hpp:1285
Diligent::Vector2::operator*
Vector2 operator*(const Vector2 &right) const
Definition: BasicMath.hpp:130
Diligent::Matrix4x4::_13
T _13
Definition: BasicMath.hpp:1072
Diligent::Vector3::operator/
Vector3 operator/(T s) const
Definition: BasicMath.hpp:356
Diligent::Vector3::operator/=
Vector3 & operator/=(T s)
Definition: BasicMath.hpp:361
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
Diligent::Matrix4x4::Transpose
Matrix4x4 Transpose() const
Definition: BasicMath.hpp:1205
Diligent::Matrix3x3::m12
T m12
Definition: BasicMath.hpp:874
Diligent::Vector2::y
T y
Definition: BasicMath.hpp:81
Diligent::Vector4::operator/=
Vector4 & operator/=(const Vector4 &right)
Definition: BasicMath.hpp:568
Diligent::Vector3::operator<
Vector3 operator<(const Vector3 &right) const
Definition: BasicMath.hpp:392
Diligent::slerp
Quaternion slerp(Quaternion v0, Quaternion v1, float t, bool DoNotNormalize=false)
Definition: BasicMath.hpp:1970
Diligent::Matrix3x3::Matrix3x3
Matrix3x3(T i11, T i12, T i13, T i21, T i22, T i23, T i31, T i32, T i33)
Definition: BasicMath.hpp:895
PI_F
#define PI_F
Definition: GraphicsUtilities.cpp:36
Diligent::Quaternion::Quaternion
Quaternion(float x, float y, float z, float w) noexcept
Definition: BasicMath.hpp:1859
Diligent::Matrix3x3::operator[]
const T * operator[](size_t row) const
Definition: BasicMath.hpp:936