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

camera.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_APPLICATION_CAMERA_HPP
10 #define EAGINE_APPLICATION_CAMERA_HPP
11 
12 #include "context.hpp"
13 #include <oglplus/camera.hpp>
14 #include <oglplus/math/sign.hpp>
15 
16 namespace eagine::application {
17 //------------------------------------------------------------------------------
21 
22 public:
24  using base::matrix;
25 
27  auto matrix(video_context& vc) const noexcept {
28  return base::matrix(vc.surface_aspect());
29  }
30 
32  auto has_changed() noexcept {
33  return std::exchange(_changed, false);
34  }
35 
37  auto update_orbit(float inc) noexcept -> orbiting_camera&;
38 
40  auto update_turns(float inc) noexcept -> orbiting_camera&;
41 
43  auto update_pitch(float inc) noexcept -> orbiting_camera&;
44 
49  auto idle_update(
50  const context_state_view&,
51  const valid_if_positive<float>& divisor = 2.F) noexcept
52  -> orbiting_camera&;
53 
58  auto idle_update(
59  const execution_context&,
60  const valid_if_positive<float>& divisor = 2.F) noexcept
61  -> orbiting_camera&;
62 
63  constexpr auto pressure_input_id() const noexcept -> message_id {
64  return EAGINE_MSG_ID(Camera, Pressure);
65  }
66 
71  auto pressure_input() noexcept -> input_slot {
72  return {
73  pressure_input_id(),
74  {this, EAGINE_THIS_MEM_FUNC_C(_handle_pressure)}};
75  }
76 
77  constexpr auto dampening_input_id() const noexcept -> message_id {
78  return EAGINE_MSG_ID(Camera, Dampening);
79  }
80 
85  auto dampening_input() noexcept -> input_slot {
86  return {
87  dampening_input_id(),
88  {this, EAGINE_THIS_MEM_FUNC_C(_handle_dampening)}};
89  }
90 
91  constexpr auto altitude_change_input_id() const noexcept -> message_id {
92  return EAGINE_MSG_ID(Camera, Altitude);
93  }
94 
99  auto altitude_change_input() noexcept -> input_slot {
100  return {
101  altitude_change_input_id(),
102  {this, EAGINE_THIS_MEM_FUNC_C(_change_altitude)}};
103  }
104 
105  constexpr auto longitude_change_input_id() const noexcept -> message_id {
106  return EAGINE_MSG_ID(Camera, Longitude);
107  }
108 
113  auto longitude_change_input() noexcept -> input_slot {
114  return {
115  longitude_change_input_id(),
116  input_handler{this, EAGINE_THIS_MEM_FUNC_C(_change_longitude)}};
117  }
118 
119  constexpr auto latitude_change_input_id() const noexcept -> message_id {
120  return EAGINE_MSG_ID(Camera, Latitude);
121  }
122 
127  auto latitude_change_input() noexcept -> input_slot {
128  return {
129  latitude_change_input_id(),
130  {this, EAGINE_THIS_MEM_FUNC_C(_change_latitude)}};
131  }
132 
136 
139  auto basic_input_mapping(execution_context& ec, identifier mapping_id)
140  -> orbiting_camera&;
141 
145  return basic_input_mapping(ec, {});
146  }
147 
148 private:
149  oglp::sign _orbit_dir;
150  oglp::sign _turn_dir;
151  oglp::sign _pitch_dir;
152 
153  bool _changed{true};
154  bool _is_dragging{false};
155  bool _dampen_motion{false};
156 
157  auto _motion_adjust() const noexcept {
158  return _dampen_motion ? 0.2 : 1.0;
159  }
160 
161  void _handle_pressure(const input& i);
162  void _handle_dampening(const input& i);
163  void _change_altitude(const input& i);
164  void _change_longitude(const input& i);
165  void _change_latitude(const input& i);
166 };
167 //------------------------------------------------------------------------------
168 } // namespace eagine::application
169 
170 #if !EAGINE_LINK_LIBRARY || defined(EAGINE_IMPLEMENTING_LIBRARY)
171 #include <eagine/application/camera.inl>
172 #endif
173 
174 #endif
Application harness / wrapper code is placed in this namespace.
Definition: eagine.hpp:72
Declaration of class template storing a reference to a callable object.
Definition: callable_ref.hpp:24
Read-only view of application context state values.
Definition: state_view.hpp:34
auto longitude_change_input() noexcept -> input_slot
Returns the input slot for handling azimuth change input signals. This can be bound for example to le...
Definition: camera.hpp:113
#define EAGINE_MSG_ID(API, NAME)
Macro for instantiating objects of static_message_id.
Definition: message_id.hpp:148
auto dampening_input() noexcept -> input_slot
Returns the input slot for handling motion dampening input signals. This can be bound for example to ...
Definition: camera.hpp:85
auto connect_inputs(execution_context &ec) -> orbiting_camera &
Connects the camera input slots to the execution context.
Primary template for conditionally valid values.
Definition: decl.hpp:49
auto matrix(video_context &vc) const noexcept
Construction from a reference to a video context.
Definition: camera.hpp:27
auto altitude_change_input() noexcept -> input_slot
Returns the input slot for handling orbit change input signals. This can be bound for example to mous...
Definition: camera.hpp:99
auto basic_input_mapping(execution_context &ec) -> auto &
Specifies the default key binding for the camera input slots.
Definition: camera.hpp:144
auto has_changed() noexcept
Inddicates if the camera has changed and resets the flag.
Definition: camera.hpp:32
Class representing a camera orbiting around its target.
Definition: camera.hpp:23
auto update_pitch(float inc) noexcept -> orbiting_camera &
Does a generic elevation update with given increment.
auto latitude_change_input() noexcept -> input_slot
Returns the input slot for handling elevation change input signals. This can be bound for example to ...
Definition: camera.hpp:127
Class that allows binding of a user input device to a handler callable.
Definition: input.hpp:191
auto idle_update(const context_state_view &, const valid_if_positive< float > &divisor=2.F) noexcept -> orbiting_camera &
Does a generic combined update when the user does not provide input.
auto update_turns(float inc) noexcept -> orbiting_camera &
Does a generic azimuth update with given increment.
#define EAGINE_THIS_MEM_FUNC_C(FUNC)
Macro for creating object of member_function_constant in member functions.
Definition: mem_func_const.hpp:206
auto basic_input_mapping(execution_context &ec, identifier mapping_id) -> orbiting_camera &
Specifies a named key binding for the camera input slots.
Extension of orbiting camera wrapper.
Definition: camera.hpp:20
Class holding video rendering-related application support objects.
Definition: context.hpp:34
auto matrix(float aspect) const noexcept
Returns the camera matrix (perspective * projection).
Definition: camera.hpp:128
Class storing two identifier values representing class/method pair.
Definition: message_id.hpp:25
auto update_orbit(float inc) noexcept -> orbiting_camera &
Does a generic orbit update with given increment.
Class holding shared video/audio rendering application support objects.
Definition: context.hpp:166
auto pressure_input() noexcept -> input_slot
Returns the input slot for handling cursor pressure input signals. This can be bound for example to m...
Definition: camera.hpp:71

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