Mathter
A configurable 3D math library for game developers.
IdentityBuilder.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 
4 #include "../Matrix/MatrixImpl.hpp"
5 #include "../Quaternion/QuaternionImpl.hpp"
6 #include "ZeroBuilder.hpp"
7 
8 
9 namespace mathter {
10 
11 
13 public:
14  IdentityBuilder() = default;
15  IdentityBuilder& operator=(const IdentityBuilder&) = delete;
16 
17  template <class T, int Rows, int Columns, eMatrixOrder Order, eMatrixLayout Layout, bool Packed>
20  Set(m);
21  return m;
22  }
23 
24  template <class T, bool Packed>
25  operator Quaternion<T, Packed>() const {
26  return Quaternion<T, Packed>{ 1, 0, 0, 0 };
27  }
28 
29 private:
30  template <class T, int Rows, int Columns, eMatrixOrder Order, eMatrixLayout Layout, bool Packed>
32  m = Zero();
33  for (int i = 0; i < std::min(Rows, Columns); ++i) {
34  m(i, i) = T(1);
35  }
36  }
37 };
38 
39 
42 inline auto Identity() {
43  return IdentityBuilder{};
44 }
45 
46 
47 } // namespace mathter
auto Identity()
Creates an identity matrix or identity quaternion.
Definition: IdentityBuilder.hpp:42
Allows you to do quaternion math and represent rotation in a compact way.
Definition: Definitions.hpp:69
Definition: Approx.hpp:11
Definition: IdentityBuilder.hpp:12
IdentityBuilder & operator=(const IdentityBuilder &)=delete
Definition: Definitions.hpp:63
auto Zero()
Creates a matrix with all elements zero.
Definition: ZeroBuilder.hpp:34