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

matrix_looking_at.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_MATRIX_LOOKING_AT_HPP
9 #define EAGINE_MATH_MATRIX_LOOKING_AT_HPP
10 
11 #include "../quantities.hpp"
12 #include "matrix_ctr.hpp"
13 
14 namespace eagine::math {
15 
16 // looking_at_y_up
17 template <typename X>
18 class looking_at_y_up;
19 
20 // is_matrix_constructor<looking_at_y_up>
21 template <typename T, int N, bool RM, bool V>
22 struct is_matrix_constructor<looking_at_y_up<matrix<T, N, N, RM, V>>>
23  : std::true_type {};
24 
31 template <typename T, bool RM, bool V>
32 class looking_at_y_up<matrix<T, 4, 4, RM, V>> {
33 public:
37  constexpr looking_at_y_up(
38  const vector<T, 3, V>& eye,
39  const vector<T, 3, V>& target) noexcept
40  : _e(eye)
41  , _t(target) {}
42 
44  constexpr auto operator()() const noexcept {
45  return _make(bool_constant<RM>());
46  }
47 
48 private:
49  using _dT = vector<T, 3, V>;
50 
51  vector<T, 3, V> _e, _t;
52 
53  static constexpr auto
54  _make(const _dT& x, const _dT& y, const _dT& z, const _dT& t) noexcept {
56  {{x[0], x[1], x[2], -dot(x, t)},
57  {y[0], y[1], y[2], -dot(y, t)},
58  {z[0], z[1], z[2], -dot(z, t)},
59  {T(0), T(0), T(0), T(1)}}};
60  }
61 
62  static constexpr auto
63  _make(const _dT& y, const _dT& z, const _dT& t) noexcept {
64  return _make(cross(y, z), y, z, t);
65  }
66 
67  static constexpr auto _make(const _dT& z, const _dT& t) noexcept {
68  return _make(normalized(cross(z, t)), z, t);
69  }
70 
71  static constexpr auto _make(const _dT& z) noexcept {
72  return _make(z, _dT::make(z.z(), T(0), -z.x()));
73  }
74 
75  constexpr auto _make(std::true_type) const noexcept {
76  return _make(normalized(_e - _t));
77  }
78 
79  constexpr auto _make(std::false_type) const noexcept {
80  return reorder(_make(std::true_type()));
81  }
82 };
83 
84 // reorder_mat_ctr(looking_at_y_up)
85 template <typename T, int N, bool RM, bool V>
86 static constexpr auto
87 reorder_mat_ctr(const looking_at_y_up<matrix<T, N, N, RM, V>>& c) noexcept
88  -> looking_at_y_up<matrix<T, N, N, !RM, V>> {
89  return {c._e, c._t};
90 }
91 
94 template <typename T, bool V>
97 
98 } // namespace eagine::math
99 
100 #endif // EAGINE_MATH_MATRIX_LOOKING_AT_HPP
static auto normalized(const vector< T, N, V > &a) noexcept
Returns normalized argument.
Definition: vector.hpp:379
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
constexpr auto operator()() const noexcept
Returns the constructed matrix.
Definition: matrix_looking_at.hpp:44
std::integral_constant< bool, B > bool_constant
Alias for boolean constant type.
Definition: int_constant.hpp:20
constexpr looking_at_y_up(const vector< T, 3, V > &eye, const vector< T, 3, V > &target) noexcept
Initializes the matrix constructor.
Definition: matrix_looking_at.hpp:37
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
convertible_matrix_constructor< looking_at_y_up< matrix< T, 4, 4, true, V > >> matrix_looking_at_y_up
Alias for constructor of look-at matrix used for camera transformations.
Definition: matrix_looking_at.hpp:96
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

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