Mathter
A configurable 3D math library for game developers.
ScaleBuilder.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 
4 #include "../Matrix/MatrixImpl.hpp"
5 #include "../Vector.hpp"
6 #include "IdentityBuilder.hpp"
7 
8 
9 namespace mathter {
10 
11 
12 template <class T, int Dim, bool Packed>
13 class ScaleBuilder {
14 public:
15  ScaleBuilder(const Vector<T, Dim, Packed>& scale) : scale(scale) {}
16  ScaleBuilder& operator=(const ScaleBuilder&) = delete;
17 
18  template <class U, eMatrixOrder Order, eMatrixLayout Layout, bool MPacked>
21  Set(m);
22  return m;
23  }
24 
25  template <class U, eMatrixOrder Order, eMatrixLayout Layout, bool MPacked>
28  Set(m);
29  return m;
30  }
31 
32  template <class U, eMatrixLayout Layout, bool MPacked>
35  Set(m);
36  return m;
37  }
38 
39  template <class U, eMatrixLayout Layout, bool MPacked>
42  Set(m);
43  return m;
44  }
45 
46 
47 private:
48  template <class U, int Rows, int Columns, eMatrixOrder Order, eMatrixLayout Layout, bool MPacked>
50  m = Identity();
51  int i;
52  for (i = 0; i < scale.Dimension(); ++i) {
53  m(i, i) = std::move(scale(i));
54  }
55  for (; i < std::min(Rows, Columns); ++i) {
56  m(i, i) = T(1);
57  }
58  }
59 
60  const Vector<T, Dim, Packed> scale;
61 };
62 
63 
67 template <class Vt, int Vdim, bool Vpacked>
68 auto Scale(const Vector<Vt, Vdim, Vpacked>& scale) {
69  return ScaleBuilder{ scale };
70 }
71 
72 
76 template <class... Args, typename std::enable_if<(traits::All<traits::IsScalar, typename std::decay<Args>::type...>::value), int>::type = 0>
77 auto Scale(Args&&... scales) {
78  using PromotedT = decltype((0 + ... + scales));
79  return ScaleBuilder{ Vector<PromotedT, sizeof...(scales)>(scales...) };
80 }
81 
82 
83 
84 } // namespace mathter
auto Identity()
Creates an identity matrix or identity quaternion.
Definition: IdentityBuilder.hpp:42
Represents a vector in N-dimensional space.
Definition: Definitions.hpp:57
Definition: ScaleBuilder.hpp:13
Definition: Approx.hpp:11
Definition: Definitions.hpp:63
ScaleBuilder & operator=(const ScaleBuilder &)=delete
auto Scale(const Vector< Vt, Vdim, Vpacked > &scale)
Creates a scaling matrix.
Definition: ScaleBuilder.hpp:68
ScaleBuilder(const Vector< T, Dim, Packed > &scale)
Definition: ScaleBuilder.hpp:15