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

matrix_reflection.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_MATRIX_REFLECTION_HPP
9 #define EAGINE_MATH_MATRIX_REFLECTION_HPP
10 
11 #include "matrix_ctr.hpp"
12 #include <cmath>
13 
14 namespace eagine::math {
15 
16 // reflection_I
17 template <typename X, int I>
18 class reflection_I;
19 
20 // is_matrix_constructor<reflection_I>
21 template <typename T, int N, bool RM, bool V, int I>
22 struct is_matrix_constructor<reflection_I<matrix<T, N, N, RM, V>, I>>
23  : std::true_type {};
24 
33 template <typename T, bool RM, bool V, int I>
34 class reflection_I<matrix<T, 4, 4, RM, V>, I> {
35 public:
38  constexpr reflection_I(bool r = true) noexcept
39  : _v(r ? T(-1) : T(1)) {}
40 
41  constexpr auto v(int i) const noexcept -> T {
42  return (I == i) ? _v : T(1);
43  }
44 
46  constexpr auto operator()() const noexcept {
48  {{v(0), T(0), T(0), T(0)},
49  {T(0), v(1), T(0), T(0)},
50  {T(0), T(0), v(2), T(0)},
51  {T(0), T(0), T(0), T(1)}}};
52  }
53 
54 private:
55  T _v;
56 };
57 
58 // multiply
59 template <typename T, int N, bool RM1, bool RM2, bool V, int I>
60 static constexpr auto multiply(
61  const reflection_I<matrix<T, N, N, RM1, V>, I>& a,
62  const reflection_I<matrix<T, N, N, RM2, V>, I>& b) noexcept
63  -> reflection_I<matrix<T, N, N, RM1, V>, I> {
64  return {(a._v < b._v) || (a._v > b._v)};
65 }
66 
67 // reorder_mat_ctr(reflection_I)
68 template <typename T, int N, bool RM, bool V, int I>
69 static constexpr auto
70 reorder_mat_ctr(const reflection_I<matrix<T, N, N, RM, V>, I>& c) noexcept
71  -> reflection_I<matrix<T, N, N, !RM, V>, I> {
72  return {c._v < T(0)};
73 }
74 
77 template <typename M>
78 using reflection_x = reflection_I<M, 0>;
79 
82 template <typename M>
83 using reflection_y = reflection_I<M, 1>;
84 
87 template <typename M>
88 using reflection_z = reflection_I<M, 2>;
89 
100 template <typename T, bool V>
101 using matrix_reflection_x =
103 
114 template <typename T, bool V>
115 using matrix_reflection_y =
117 
128 template <typename T, bool V>
129 using matrix_reflection_z =
131 
132 } // namespace eagine::math
133 
134 #endif // EAGINE_MATH_MATRIX_REFLECTION_HPP
reflection_I< M, 1 > reflection_y
Alias for implementation of constructor of reflection along y-axis matrix.
Definition: matrix_reflection.hpp:83
reflection_I< M, 2 > reflection_z
Alias for implementation of constructor of reflection along z-axis matrix.
Definition: matrix_reflection.hpp:88
Math-related code is placed in this namespace.
Definition: eagine.hpp:48
constexpr reflection_I(bool r=true) noexcept
Initializes the matrix constructor.
Definition: matrix_reflection.hpp:38
Helper class used in matrix constructor implementation.
Definition: matrix_ctr.hpp:74
constexpr auto operator()() const noexcept
Returns the constructed matrix.
Definition: matrix_reflection.hpp:46
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
reflection_I< M, 0 > reflection_x
Alias for implementation of constructor of reflection along x-axis matrix.
Definition: matrix_reflection.hpp:78
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).