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

matrix_orbiting.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_MATRIX_ORBITING_HPP
9 #define EAGINE_MATH_MATRIX_ORBITING_HPP
10 
11 #include "../quantities.hpp"
12 #include "matrix_ctr.hpp"
13 
14 namespace eagine::math {
15 
16 // orbiting_y_up
17 template <typename X>
18 class orbiting_y_up;
19 
20 // is_matrix_constructor<orbiting_y_up>
21 template <typename T, int N, bool RM, bool V>
22 struct is_matrix_constructor<orbiting_y_up<matrix<T, N, N, RM, V>>>
23  : std::true_type {};
24 
33 template <typename T, bool RM, bool V>
34 class orbiting_y_up<matrix<T, 4, 4, RM, V>> {
35 public:
36  constexpr orbiting_y_up(
37  const vector<T, 3, V>& t,
38  const vector<T, 3, V>& x,
39  const vector<T, 3, V>& y,
40  const vector<T, 3, V>& z,
41  T r) noexcept
42  : _t(t)
43  , _x(x)
44  , _z(z)
45  , _y(y)
46  , _r(r) {}
47 
48  constexpr orbiting_y_up(
49  const vector<T, 3, V>& t,
50  const T rs,
51  const T sa,
52  const T ca,
53  const T se,
54  const T ce) noexcept
55  : _t(t)
56  , _x{{-sa, T(0), -ca}}
57  , _z{{ce * ca, se, ce * -sa}}
58  , _y(cross(_z, _x))
59  , _r(rs) {}
60 
66  constexpr orbiting_y_up(
67  const vector<T, 3, V>& target,
68  const T radius,
69  radians_t<T> azimuth,
70  radians_t<T> elevation)
71  : orbiting_y_up(
72  target,
73  radius,
74  sin(azimuth),
75  cos(azimuth),
76  sin(elevation),
77  cos(elevation)) {}
78 
80  constexpr auto operator()() const noexcept {
81  return _make(bool_constant<RM>());
82  }
83 
84  friend constexpr auto
85  reorder_mat_ctr(const orbiting_y_up<matrix<T, 4, 4, RM, V>>& c) noexcept
86  -> orbiting_y_up<matrix<T, 4, 4, !RM, V>> {
87  return {c._t, c._x, c._y, c._z, c._r};
88  }
89 
90 private:
91  constexpr auto _make(std::true_type) const noexcept {
92  return matrix<T, 4, 4, true, V>{
93  {{_x[0], _x[1], _x[2], -_r * dot(_x, _z) - dot(_x, _t)},
94  {_y[0], _y[1], _y[2], -_r * dot(_y, _z) - dot(_y, _t)},
95  {_z[0], _z[1], _z[2], -_r * dot(_z, _z) - dot(_z, _t)},
96  {T(0), T(0), T(0), T(1)}}};
97  }
98 
99  constexpr auto _make(std::false_type) const noexcept {
100  return reorder(_make(std::true_type()));
101  }
102 
103  vector<T, 3, V> _t;
104  vector<T, 3, V> _x, _z, _y;
105  T _r;
106 };
107 
110 template <typename T, bool V>
111 using matrix_orbiting_y_up =
113 
114 } // namespace eagine::math
115 
116 #endif // EAGINE_MATH_MATRIX_ORBITING_HPP
static auto reorder(const matrix< T, C, R, RM, V > &m) noexcept -> matrix< T, C, R, !RM, V >
Returns a matrix reordered (switches row/column major).
Definition: matrix.hpp:314
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
static constexpr auto dot(const vector< T, N, V > &a, const vector< T, N, V > &b) noexcept
Vector dot product.
Definition: vector.hpp:311
Helper class used in matrix constructor implementation.
Definition: matrix_ctr.hpp:74
constexpr orbiting_y_up(const vector< T, 3, V > &target, const T radius, radians_t< T > azimuth, radians_t< T > elevation)
Initalizes the matrix constructor.
Definition: matrix_orbiting.hpp:66
constexpr auto operator()() const noexcept
Returns the constructed matrix.
Definition: matrix_orbiting.hpp:80
Value of type T with a specified unit or tag type U.
Definition: tagged_quantity.hpp:27
static auto cross(const vector< T, 3, V > &a, const vector< T, 3, V > &b) noexcept
3D vector cross product.
Definition: vector.hpp:326
Basic RxC matrix implementation template.
Definition: fwd.hpp:25
convertible_matrix_constructor< orbiting_y_up< matrix< T, 4, 4, true, V > >> matrix_orbiting_y_up
Alias for constructor of orbiting matrix used for camera transformations.
Definition: matrix_orbiting.hpp:112

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