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

matrix_ortho.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_MATRIX_ORTHO_HPP
9 #define EAGINE_MATH_MATRIX_ORTHO_HPP
10 
11 #include "matrix_ctr.hpp"
12 
13 namespace eagine::math {
14 
15 // ortho
16 template <typename X>
17 class ortho;
18 
19 // is_matrix_constructor<ortho>
20 template <typename T, int N, bool RM, bool V>
21 struct is_matrix_constructor<ortho<matrix<T, N, N, RM, V>>> : std::true_type {};
22 
28 template <typename T, bool RM, bool V>
29 class ortho<matrix<T, 4, 4, RM, V>> {
30 public:
31  constexpr ortho(const vect::data_t<T, 6, V>& v) noexcept
32  : _v(v) {}
33 
35  constexpr ortho(
36  T x_left,
37  T x_right,
38  T y_bottom,
39  T y_top,
40  T z_near,
41  T z_far) noexcept
42  : _v{x_left, x_right, y_bottom, y_top, z_near, z_far} {}
43 
45  constexpr auto operator()() const noexcept {
46  return _make(bool_constant<RM>());
47  }
48 
49 private:
50  constexpr auto _x_left() const {
51  return _v[0];
52  }
53  constexpr auto _x_right() const {
54  return _v[1];
55  }
56  constexpr auto _y_bottom() const {
57  return _v[2];
58  }
59  constexpr auto _y_top() const {
60  return _v[3];
61  }
62  constexpr auto _z_near() const {
63  return _v[4];
64  }
65  constexpr auto _z_far() const {
66  return _v[5];
67  }
68 
69  constexpr auto _m00() const noexcept {
70  return T(2) / (_x_right() - _x_left());
71  }
72 
73  constexpr auto _m11() const noexcept {
74  return T(2) / (_y_top() - _y_bottom());
75  }
76 
77  constexpr auto _m22() const noexcept {
78  return -T(2) / (_z_far() - _z_near());
79  }
80 
81  constexpr auto _m30() const noexcept {
82  return -(_x_right() + _x_left()) / (_x_right() - _x_left());
83  }
84 
85  constexpr auto _m31() const noexcept {
86  return -(_y_top() + _y_bottom()) / (_y_top() - _y_bottom());
87  }
88 
89  constexpr auto _m32() const noexcept {
90  return -(_z_far() + _z_near()) / (_z_far() - _z_near());
91  }
92 
93  constexpr auto _make(std::true_type) const noexcept {
94  return matrix<T, 4, 4, true, V>{
95  {{_m00(), T(0), T(0), _m30()},
96  {T(0), _m11(), T(0), _m31()},
97  {T(0), T(0), _m22(), _m32()},
98  {T(0), T(0), T(0), T(1)}}};
99  }
100 
101  constexpr auto _make(std::false_type) const noexcept {
102  return matrix<T, 4, 4, false, V>{
103  {{_m00(), T(0), T(0), T(0)},
104  {T(0), _m11(), T(0), T(0)},
105  {T(0), T(0), _m22(), T(0)},
106  {_m30(), _m31(), _m32(), T(1)}}};
107  }
108 
109  using _dT = vect::data_t<T, 6, V>;
110  _dT _v;
111 };
112 
113 // reorder_mat_ctr(ortho)
114 template <typename T, int N, bool RM, bool V>
115 static constexpr auto
116 reorder_mat_ctr(const ortho<matrix<T, N, N, RM, V>>& c) noexcept
117  -> ortho<matrix<T, N, N, !RM, V>> {
118  return {c._v};
119 }
120 
123 template <typename T, bool V>
124 using matrix_ortho =
126 
127 } // namespace eagine::math
128 
129 #endif // EAGINE_MATH_MATRIX_ORTHO_HPP
constexpr auto operator()() const noexcept
Returns the constructed matrix.
Definition: matrix_ortho.hpp:45
constexpr ortho(T x_left, T x_right, T y_bottom, T y_top, T z_near, T z_far) noexcept
Initializes the matrix constructor.
Definition: matrix_ortho.hpp:35
convertible_matrix_constructor< ortho< matrix< T, 4, 4, true, V > >> matrix_ortho
Alias for constructor of orthographic projection matrix.
Definition: matrix_ortho.hpp:125
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
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).