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

matrix_translation.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_MATRIX_TRANSLATION_HPP
9 #define EAGINE_MATH_MATRIX_TRANSLATION_HPP
10 
11 #include "matrix_ctr.hpp"
12 
13 namespace eagine::math {
14 
15 // translation
16 template <typename X>
17 class translation;
18 
19 // is_matrix_constructor<translation>
20 template <typename T, int N, bool RM, bool V>
21 struct is_matrix_constructor<translation<matrix<T, N, N, RM, V>>>
22  : std::true_type {};
23 
29 template <typename T, bool RM, bool V>
30 class translation<matrix<T, 4, 4, RM, V>> {
31 public:
32  constexpr translation(vect::data_t<T, 3, V> v) noexcept
33  : _v(v) {}
34 
39  constexpr translation(T vx, T vy, T vz) noexcept
40  : _v{vx, vy, vz} {}
41 
43  constexpr auto operator()() const noexcept {
44  return _make(bool_constant<RM>());
45  }
46 
47  friend constexpr auto
48  reorder_mat_ctr(const translation<matrix<T, 4, 4, RM, V>>& c) noexcept
49  -> translation<matrix<T, 4, 4, !RM, V>> {
50  return {c._v};
51  }
52 
53 private:
54  constexpr auto _make(std::true_type) const noexcept {
55  return matrix<T, 4, 4, true, V>{
56  {{T(1), T(0), T(0), _v[0]},
57  {T(0), T(1), T(0), _v[1]},
58  {T(0), T(0), T(1), _v[2]},
59  {T(0), T(0), T(0), T(1)}}};
60  }
61 
62  constexpr auto _make(std::false_type) const noexcept {
63  return matrix<T, 4, 4, false, V>{
64  {{T(1), T(0), T(0), T(0)},
65  {T(0), T(1), T(0), T(0)},
66  {T(0), T(0), T(1), T(0)},
67  {_v[0], _v[1], _v[2], T(1)}}};
68  }
69 
70  vect::data_t<T, 3, V> _v;
71 };
72 
73 // multiply
74 template <typename T, int N, bool RM1, bool RM2, bool V>
75 static constexpr auto multiply(
76  const translation<matrix<T, N, N, RM1, V>>& a,
77  const translation<matrix<T, N, N, RM2, V>>& b) noexcept
78  -> translation<matrix<T, N, N, RM1, V>> {
79  return {a._v + b._v};
80 }
81 
93 template <typename T, bool V>
94 using matrix_translation =
96 
97 } // namespace eagine::math
98 
99 #endif // EAGINE_MATH_MATRIX_TRANSLATION_HPP
constexpr auto operator()() const noexcept
Returns the constructed matrix.
Definition: matrix_translation.hpp:43
convertible_matrix_constructor< translation< matrix< T, 4, 4, true, V > >> matrix_translation
Alias for constructor of uniform translation transformation matrix.
Definition: matrix_translation.hpp:95
constexpr translation(T vx, T vy, T vz) noexcept
Initializes the matrix constructor.
Definition: matrix_translation.hpp:39
std::integral_constant< bool, B > bool_constant
Alias for boolean constant type.
Definition: int_constant.hpp:20
Math-related code is placed in this namespace.
Definition: eagine.hpp:48
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
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).