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

camera.hpp
Go to the documentation of this file.
1 #ifndef OGLPLUS_CAMERA_HPP
9 #define OGLPLUS_CAMERA_HPP
10 
11 #include "math/interpolate.hpp"
12 #include "math/matrix_ctrs.hpp"
13 #include "math/primitives.hpp"
14 #include "math/sign.hpp"
15 #include "math/vector.hpp"
16 #include <eagine/units/common.hpp>
18 
19 namespace eagine::oglp {
20 
24 public:
26  auto set_target(vec3 target) noexcept -> auto& {
27  _target = target;
28  return *this;
29  }
30 
32  auto set_fov(radians_t<float> angle) noexcept -> auto& {
33  _fov = angle;
34  return *this;
35  }
36 
38  auto set_near(valid_if_positive<float> dist) noexcept -> auto& {
39  _near = dist.value();
40  return *this;
41  }
42 
44  auto set_far(valid_if_positive<float> dist) noexcept -> auto& {
45  _far = dist.value();
46  return *this;
47  }
48 
50  auto set_orbit_min(valid_if_positive<float> orbit) noexcept -> auto& {
51  _orbit_min = orbit.value();
52  return *this;
53  }
54 
56  auto set_orbit_max(valid_if_positive<float> orbit) noexcept -> auto& {
57  _orbit_max = orbit.value();
58  return *this;
59  }
60 
62  auto fov() const noexcept -> radians_t<float> {
63  return _fov;
64  }
65 
69  auto orbit() const noexcept -> float {
70  return smooth_lerp(_orbit_min, _orbit_max, _orbit_factor);
71  }
72 
76  auto azimuth() const noexcept -> radians_t<float> {
77  return _turns;
78  }
79 
83  auto elevation() const noexcept -> radians_t<float> {
84  return _pitch;
85  }
86 
89  auto target() const noexcept -> vec3 {
90  return _target;
91  }
92 
95  auto target_to_camera_direction() const noexcept -> vec3;
96 
99  auto camera_to_target_direction() const noexcept -> vec3 {
100  return -target_to_camera_direction();
101  }
102 
105  auto position() const noexcept -> vec3 {
106  return target() + target_to_camera_direction() * orbit();
107  }
108 
109  auto perspective_matrix_ctr(float aspect) const noexcept {
110  return matrix_perspective::y(_fov, aspect, _near, _far);
111  }
112 
114  auto perspective_matrix(float aspect) const noexcept {
115  return perspective_matrix_ctr(aspect)();
116  }
117 
118  auto transform_matrix_ctr() const noexcept {
119  return matrix_orbiting_y_up(_target, orbit(), azimuth(), elevation());
120  }
121 
123  auto transform_matrix() const noexcept {
124  return transform_matrix_ctr()();
125  }
126 
128  auto matrix(float aspect) const noexcept {
129  return perspective_matrix_ctr(aspect) * transform_matrix_ctr();
130  }
131 
133  auto target_plane_point(float ndcx, float ndcy, float aspect) const noexcept
135 
137  auto pointer_ray(float ndcx, float ndcy, float aspect) const noexcept
139 
140  auto grab_sphere_radius() const noexcept -> float;
141  auto grab_sphere() const noexcept -> sphere;
142 
143 private:
144  vec3 _target{};
146 
147  float _near{0.5F};
148  float _far{10.F};
149 
150 protected:
151  radians_t<float> _turns{};
152  radians_t<float> _pitch{};
153 
154  float _orbit_min{1.5F};
155  float _orbit_max{5.5F};
156  float _orbit_factor = 0.50F;
157 };
158 
159 } // namespace eagine::oglp
160 
161 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
162 #include <oglplus/camera.inl>
163 #endif
164 
165 #endif
166 
auto set_orbit_max(valid_if_positive< float > orbit) noexcept -> auto &
Set maximal orbit value.
Definition: camera.hpp:56
auto perspective_matrix(float aspect) const noexcept
Returns the perspective matrix for the given aspect ratio.
Definition: camera.hpp:114
auto transform_matrix() const noexcept
Returns the camera transformation matrix.
Definition: camera.hpp:123
Basic template for spheres in N-dimensional space.
Definition: primitives.hpp:122
auto set_target(vec3 target) noexcept -> auto &
Sets the target position.
Definition: camera.hpp:26
auto target_to_camera_direction() const noexcept -> vec3
Returns the target-to-camera direction vector.
Primary template for conditionally valid values.
Definition: decl.hpp:49
static auto smooth_lerp(const T &a, const T &b, C coef)
Linear interpolation with coef transformed by sine_sigmoid01.
Definition: interpolate.hpp:42
auto set_far(valid_if_positive< float > dist) noexcept -> auto &
Sets the distance of the far plane.
Definition: camera.hpp:44
auto target() const noexcept -> vec3
Returns the target position.
Definition: camera.hpp:89
Class representing a camera orbiting around its target.
Definition: camera.hpp:23
auto target_plane_point(float ndcx, float ndcy, float aspect) const noexcept -> optionally_valid< vec3 >
Returns the 3D position of a point (in NDC) on the target plane.
auto position() const noexcept -> vec3
Returns the position of the camera.
Definition: camera.hpp:105
auto set_fov(radians_t< float > angle) noexcept -> auto &
Sets the y-axis FOV angle.
Definition: camera.hpp:32
auto camera_to_target_direction() const noexcept -> vec3
Returns the camera-to-target direction vector.
Definition: camera.hpp:99
auto pointer_ray(float ndcx, float ndcy, float aspect) const noexcept -> optionally_valid< line >
Returns a ray from the camera through a point on the target plane.
auto set_orbit_min(valid_if_positive< float > orbit) noexcept -> auto &
Set minimal orbit value.
Definition: camera.hpp:50
auto elevation() const noexcept -> radians_t< float >
Returns the elevation angle (latitude).
Definition: camera.hpp:83
auto fov() const noexcept -> radians_t< float >
Returns the y-axis FOV angle.
Definition: camera.hpp:62
auto azimuth() const noexcept -> radians_t< float >
Returns the azimuth angle (longitude).
Definition: camera.hpp:76
tvec< gl_types::float_type, 3 > vec3
Alias for a 3D vector type.
Definition: vector.hpp:32
auto matrix(float aspect) const noexcept
Returns the camera matrix (perspective * projection).
Definition: camera.hpp:128
auto orbit() const noexcept -> float
Returns the orbit altitude value.
Definition: camera.hpp:69
auto set_near(valid_if_positive< float > dist) noexcept -> auto &
Sets the distance of the near plane.
Definition: camera.hpp:38
Value of type T with a specified unit or tag type U.
Definition: tagged_quantity.hpp:27
static constexpr auto right_angle_() noexcept
Creates a tagged quantity a right angle value.
Definition: quantities.hpp:71
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).