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

matrix_rotation.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_MATRIX_ROTATION_HPP
9 #define EAGINE_MATH_MATRIX_ROTATION_HPP
10 
11 #include "../quantities.hpp"
12 #include "matrix_ctr.hpp"
13 #include <cmath>
14 
15 #ifdef __clang__
16 EAGINE_DIAG_PUSH()
17 EAGINE_DIAG_OFF(double-promotion)
18 #endif
19 
20 namespace eagine::math {
21 
22 // rotation_I
23 template <typename X, int I>
24 class rotation_I;
25 
26 // is_matrix_constructor<rotation_I>
27 template <typename T, int N, bool RM, bool V, int I>
28 struct is_matrix_constructor<rotation_I<matrix<T, N, N, RM, V>, I>>
29  : std::true_type {};
30 
39 template <typename T, bool RM, bool V, int I>
40 class rotation_I<matrix<T, 4, 4, RM, V>, I> {
41 public:
44  constexpr rotation_I(radians_t<T> v) noexcept
45  : _v(v) {}
46 
48  constexpr auto operator()() const {
49  using _axis = int_constant<I>;
50  return _make(cos(_v), sin(_v) * (RM ? 1 : -1), _axis());
51  }
52 
53  friend constexpr auto
54  reorder_mat_ctr(const rotation_I<matrix<T, 4, 4, RM, V>, I>& c) noexcept
55  -> rotation_I<matrix<T, 4, 4, !RM, V>, I> {
56  return {c._v};
57  }
58 
59 private:
60  using _x = int_constant<0>;
61  using _y = int_constant<1>;
62  using _z = int_constant<2>;
63 
64  static constexpr auto _make(T cx, T sx, _x) noexcept {
65  return matrix<T, 4, 4, RM, V>{
66  {{T(1), T(0), T(0), T(0)},
67  {T(0), cx, -sx, T(0)},
68  {T(0), sx, cx, T(0)},
69  {T(0), T(0), T(0), T(1)}}};
70  }
71 
72  static constexpr auto _make(T cx, T sx, _y) noexcept {
73  return matrix<T, 4, 4, RM, V>{
74  {{cx, T(0), sx, T(0)},
75  {T(0), T(1), T(0), T(0)},
76  {-sx, T(0), cx, T(0)},
77  {T(0), T(0), T(0), T(1)}}};
78  }
79 
80  static constexpr auto _make(T cx, T sx, _z) noexcept {
81  return matrix<T, 4, 4, RM, V>{
82  {{cx, -sx, T(0), T(0)},
83  {sx, cx, T(0), T(0)},
84  {T(0), T(0), T(1), T(0)},
85  {T(0), T(0), T(0), T(1)}}};
86  }
87 
88  radians_t<T> _v;
89 };
90 
91 // multiply
92 template <typename T, int N, bool RM1, bool RM2, bool V, int I>
93 static constexpr auto multiply(
94  const rotation_I<matrix<T, N, N, RM1, V>, I>& a,
95  const rotation_I<matrix<T, N, N, RM2, V>, I>& b) noexcept
96  -> rotation_I<matrix<T, N, N, RM1, V>, I> {
97  return {radians_t<T>{T(a._v) + T(b._v)}};
98 }
99 
102 template <typename M>
103 using rotation_x = rotation_I<M, 0>;
104 
107 template <typename M>
108 using rotation_y = rotation_I<M, 1>;
109 
112 template <typename M>
113 using rotation_z = rotation_I<M, 2>;
114 
122 template <typename T, bool V>
123 using matrix_rotation_x =
125 
136 template <typename T, bool V>
137 using matrix_rotation_y =
139 
150 template <typename T, bool V>
151 using matrix_rotation_z =
153 
154 } // namespace eagine::math
155 
156 #ifdef __clang__
157 EAGINE_DIAG_POP()
158 #endif
159 
160 #endif // EAGINE_MATH_MATRIX_ROTATION_HPP
rotation_I< M, 2 > rotation_z
Alias for implementation of constructor of rotation along z-axis matrix.
Definition: matrix_rotation.hpp:113
constexpr auto operator()() const
Returns the constructed matrix.
Definition: matrix_rotation.hpp:48
rotation_I< M, 1 > rotation_y
Alias for implementation of constructor of rotation along y-axis matrix.
Definition: matrix_rotation.hpp:108
Math-related code is placed in this namespace.
Definition: eagine.hpp:48
rotation_I< M, 0 > rotation_x
Alias for implementation of constructor of rotation along x-axis matrix.
Definition: matrix_rotation.hpp:103
Helper class used in matrix constructor implementation.
Definition: matrix_ctr.hpp:74
constexpr rotation_I(radians_t< T > v) noexcept
Initializes the matrix constructor.
Definition: matrix_rotation.hpp:44
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
std::integral_constant< int, I > int_constant
Alias for signed int constant type.
Definition: int_constant.hpp:25
Value of type T with a specified unit or tag type U.
Definition: tagged_quantity.hpp:27
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).