OGLplus  (0.59.0) a C++ wrapper for rendering APIs

matrix_scale.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_MATRIX_SCALE_HPP
9 #define EAGINE_MATH_MATRIX_SCALE_HPP
10 
11 #include "matrix_ctr.hpp"
12 
13 namespace eagine::math {
14 
15 // scale
16 template <typename X>
17 class scale;
18 
19 // is_matrix_constructor<scale>
20 template <typename T, int N, bool RM, bool V>
21 struct is_matrix_constructor<scale<matrix<T, N, N, RM, V>>> : std::true_type {};
22 
28 template <typename T, bool RM, bool V>
29 class scale<matrix<T, 4, 4, RM, V>> {
30 public:
31  constexpr scale(vect::data_t<T, 3, V> v) noexcept
32  : _v(v) {}
33 
38  constexpr scale(T vx, T vy, T vz) noexcept
39  : _v{vx, vy, vz} {}
40 
42  constexpr auto operator()() const noexcept {
44  {{_v[0], T(0), T(0), T(0)},
45  {T(0), _v[1], T(0), T(0)},
46  {T(0), T(0), _v[2], T(0)},
47  {T(0), T(0), T(0), T(1)}}};
48  }
49 
50  friend constexpr auto
51  reorder_mat_ctr(const scale<matrix<T, 4, 4, RM, V>>& c) noexcept
52  -> scale<matrix<T, 4, 4, !RM, V>> {
53  return {c._v};
54  }
55 
56 private:
57  vect::data_t<T, 3, V> _v;
58 };
59 
60 // multiply
61 template <typename T, int N, bool RM1, bool RM2, bool V>
62 static constexpr auto multiply(
63  const scale<matrix<T, N, N, RM1, V>>& a,
64  const scale<matrix<T, N, N, RM2, V>>& b) noexcept
65  -> scale<matrix<T, N, N, RM1, V>> {
66  return {a._v * b._v};
67 }
68 
69 // uniform_scale
70 template <typename X>
71 class uniform_scale;
72 
73 // is_matrix_constructor<uniform_scale>
74 template <typename T, int N, bool RM, bool V>
75 struct is_matrix_constructor<uniform_scale<matrix<T, N, N, RM, V>>>
76  : std::true_type {};
77 
83 template <typename T, bool RM, bool V>
84 class uniform_scale<matrix<T, 4, 4, RM, V>> {
85 public:
88  constexpr uniform_scale(T v) noexcept
89  : _v(v) {}
90 
92  constexpr auto operator()() const noexcept {
94  {{_v, T(0), T(0), T(0)},
95  {T(0), _v, T(0), T(0)},
96  {T(0), T(0), _v, T(0)},
97  {T(0), T(0), T(0), T(1)}}};
98  }
99 
100  friend constexpr auto
101  reorder_mat_ctr(const uniform_scale<matrix<T, 4, 4, RM, V>>& c) noexcept
102  -> uniform_scale<matrix<T, 4, 4, !RM, V>> {
103  return {c._v};
104  }
105 
106 private:
107  T _v;
108 };
109 
110 // multiply
111 template <typename T, int N, bool RM1, bool RM2, bool V>
112 static constexpr auto multiply(
113  const uniform_scale<matrix<T, N, N, RM1, V>>& a,
114  const uniform_scale<matrix<T, N, N, RM2, V>>& b) noexcept
115  -> uniform_scale<matrix<T, N, N, RM1, V>> {
116  return {a._v * b._v};
117 }
118 
126 template <typename T, bool V>
127 using matrix_scale =
129 
140 template <typename T, bool V>
141 using matrix_uniform_scale =
143 
144 } // namespace eagine::math
145 
146 #endif // EAGINE_MATH_MATRIX_SCALE_HPP
convertible_matrix_constructor< scale< matrix< T, 4, 4, true, V > >> matrix_scale
Alias for constructor of scale transformation matrix.
Definition: matrix_scale.hpp:128
constexpr uniform_scale(T v) noexcept
Initializes the matrix constructor.
Definition: matrix_scale.hpp:88
constexpr auto operator()() const noexcept
Returns the constructed matrix.
Definition: matrix_scale.hpp:92
static auto scale(std::shared_ptr< generator > gen, std::array< float, 3 > s) noexcept
Constructs instances of scaled_gen modifier.
Definition: scaled.hpp:41
Math-related code is placed in this namespace.
Definition: eagine.hpp:48
constexpr scale(T vx, T vy, T vz) noexcept
Initializes the matrix constructor.
Definition: matrix_scale.hpp:38
Helper class used in matrix constructor implementation.
Definition: matrix_ctr.hpp:74
static auto multiply(const matrix< T, K, M, RM1, V > &m1, const matrix< T, N, K, RM2, V > &m2) noexcept -> matrix< T, N, M, RM1, V >
Matrix multiplication function.
Definition: matrix.hpp:529
constexpr auto operator()() const noexcept
Returns the constructed matrix.
Definition: matrix_scale.hpp:42
Basic RxC matrix implementation template.
Definition: fwd.hpp:25

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).