Wayverb
scene.h
1 #pragma once
2 
3 #include "core/az_el.h"
4 
5 #include "utilities/event.h"
6 
7 #include "glm/glm.hpp"
8 
9 #include <experimental/optional>
10 
11 namespace wayverb {
12 namespace combined {
13 namespace model {
14 
18 class view_state final {
19 public:
20  explicit view_state(const glm::vec3& origin = {0, 0, 0},
21  float eye_distance = 1,
22  const wayverb::core::az_el& az_el = {0, 0});
23 
24  void set_origin(const glm::vec3 & origin);
25  glm::vec3 get_origin() const;
26 
27  void set_eye_distance(float distance);
28  float get_eye_distance() const;
29 
30  void set_rotation(const wayverb::core::az_el& az_el);
31  wayverb::core::az_el get_rotation() const;
32 
33 private:
34  glm::vec3 origin_{0, 0, 0};
35  float eye_distance_ = 1;
36  wayverb::core::az_el az_el_{0, 0};
37 };
38 
39 glm::mat4 get_view_matrix(const view_state& view_state);
40 
41 template <typename T>
42 constexpr auto ease(const T& from, const T& to, float speed) {
43  return from + (to - from) * speed;
44 }
45 
46 view_state ease(const view_state& from, const view_state& to, float speed);
47 
49 
51 class scene final {
52 public:
53  // interactive data actions
54 
55  void set_visible_surface(std::experimental::optional<size_t> visible);
56  std::experimental::optional<size_t> get_visible_surface() const;
57 
58  void set_visualise(bool visualise);
59  bool get_visualise() const;
60 
61  // view actions - affect the modelview matrix
62 
63  void set_origin(const glm::vec3& origin);
64  glm::vec3 get_origin() const;
65 
66  void set_eye_distance(float distance);
67  float get_eye_distance() const;
68 
69  void set_rotation(const wayverb::core::az_el& az_el);
70  wayverb::core::az_el get_rotation() const;
71 
72  view_state get_view_state() const;
73 
74  // display stuff - not sure if this should really be here...
75 
76  void set_viewport(const glm::vec2& viewport);
77  glm::vec2 get_viewport() const;
78  float get_aspect() const;
79 
80  float get_item_radius() const;
81 
82  // query actions
83 
84  glm::mat4 get_projection_matrix() const;
85  glm::mat4 get_inverse_projection_matrix() const;
86 
87  glm::vec3 compute_world_camera_position() const;
88  glm::vec3 compute_world_camera_direction() const;
89  glm::vec3 compute_world_mouse_direction(const glm::vec2& pos) const;
90 
93  visible_surface_changed::connection connect_visible_surface_changed(
94  visible_surface_changed::callback_type callback);
95 
97  visualise_changed::connection connect_visualise_changed(
98  visualise_changed::callback_type callback);
99 
101  view_state_changed::connection connect_view_state_changed(
102  view_state_changed::callback_type callback);
103 
105  projection_matrix_changed::connection connect_projection_matrix_changed(
106  projection_matrix_changed::callback_type callback);
107 
108 private:
109  static constexpr float item_radius = 0.4;
110 
111  glm::mat4 compute_projection_matrix() const;
112 
113  void recompute_view_matrices();
114 
115  // data
116 
117  std::experimental::optional<size_t> visible_surface_;
118 
119  bool visualise_ = true;
120 
121  view_state view_state_;
122 
123  glm::vec2 viewport_;
124 
125  glm::mat4 view_matrix_;
126  glm::mat4 inverse_view_matrix_;
127 
128  glm::mat4 projection_matrix_;
129  glm::mat4 inverse_projection_matrix_;
130 
131  // events
132 
133  visible_surface_changed visible_surface_changed_;
134  visualise_changed visualise_changed_;
135  view_state_changed view_state_changed_;
136  projection_matrix_changed projection_matrix_changed_;
137 };
138 
139 } // namespace model
140 } // namespace combined
141 } // namespace wayverb
This stuff won&#39;t get sent to file, so it&#39;s fine to keep it here I think.
Definition: scene.h:51
Definition: capsule_base.h:9
Definition: az_el.h:10
Definition: event.h:10
Definition: event.h:28