cgv
vr_view_interactor.h
1 #pragma once
2 
3 #include <cgv/base/base.h>
4 #include <vr/vr_kit.h>
5 #include <cg_vr/vr_server.h>
6 #include <vr/vr_driver.h>
7 #include <cgv_gl/box_renderer.h>
8 #include <cgv_gl/sphere_renderer.h>
9 #include <cgv_gl/gl/mesh_render_info.h>
10 #include <stereo_view_interactor.h>
11 
12 #include "lib_begin.h"
13 
16 
19 {
20  VVT_NONE,
21  VVT_SPHERE = 1,
22  VVT_MESH = 2,
23  VVT_BOTH
24 };
25 
26 
28 
66 class CGV_API vr_view_interactor : public stereo_view_interactor, public vr::vr_calibration_base
67 {
68 protected:
69  ivec4 cgv_viewport;
70  void* fbo_handle;
71 
74  mat3 head_tracker_orientation;
79 
103  float tracking_rotation;
110  void calibrate_driver();
113 public:
114  void set_tracking_rotation(float tr) {
115  tracking_rotation = tr;
116  }
117  float get_tracking_rotation() {
118  return tracking_rotation;
119  }
120  void set_tracking_origin(vec3 ori) {
121  tracking_origin = ori;
122  }
123  vec3 get_tracking_origin() {
124  return tracking_origin;
125  }
127 private:
128  mat34 start_pose;
129 public:
130  typedef cgv::math::fmat<float,3,4> mat34;
131 protected:
138  // extent of blitting
139  int blit_width;
144  int head_tracker;
145  int rendered_eye;
146  vr::gl_vr_display* rendered_display_ptr;
147  int rendered_display_index;
148 
149  cgv::gui::VREventTypeFlags event_flags;
150 
151  // debugging of vr events on console
152  bool debug_vr_events;
153 
154  // visualization of kits and action zone
155  VRkitVisType vis_type, hmd_vis_type, controller_vis_type, tracker_vis_type, base_vis_type;
156  bool show_action_zone;
157  rgb fence_color1, fence_color2;
158  float fence_frequency;
159  float fence_line_width;
160 
161  // current vr kit handle is selected by an integer cast into an enum whos names correspond to the vr kit names
162  void* current_vr_handle;
163  int current_vr_handle_index;
164  std::string kit_enum_definition;
165  // list of vr kit states
166  std::vector<vr::vr_kit_state> kit_states;
167  // list of to be initialized vr kits
168  std::vector<void*> new_kits;
169  // list of vr kits
170  std::vector<void*> kits;
171  // list of to be destructed vr kits
172  std::vector<void*> old_kits;
175 
176  // render objects
180 
181  // helper members to allow change of mesh file names
182  std::string hmd_mesh_file_name, controller_mesh_file_name, tracker_mesh_file_name, base_mesh_file_name;
183  // for each mesh type a scale
184  float mesh_scales[4];
186  vr::vr_kit* get_vr_kit_from_index(int i) const;
187  //
188  void configure_kits();
190  void on_status_change(void* handle, int controller_index, vr::VRStatus old_status, vr::VRStatus new_status);
192  virtual void on_device_change(void* handle, bool attach);
194  void add_trackable_spheres(const float* pose, int i, std::vector<vec4>& spheres, std::vector<rgb>& sphere_colors);
195 public:
197  vr_view_interactor(const char* name);
199  std::string get_type_name() const;
200 
203  cgv::gui::VREventTypeFlags get_event_type_flags() const;
206  void set_event_type_flags(cgv::gui::VREventTypeFlags flags);
208  bool vr_event_debugging_enabled() const { return debug_vr_events; }
210  void enable_vr_event_debugging(bool enable = true);
212  const vr::vr_kit_state* get_current_vr_state() const;
214  vr::vr_kit* get_current_vr_kit() const;
215  // query vr state
216  void query_vr_states();
218 
221 
225  dvec3 get_view_dir_of_kit(int vr_kit_idx = -1) const;
227 
230  dvec3 get_view_up_dir_of_kit(int vr_kit_idx = -1) const;
232 
239  dvec3 get_eye_of_kit(int eye = 0, int vr_kit_idx = -1) const;
241 
244  bool seperate_view_drawn() const { return separate_view; }
247  void draw_separate_view(bool do_draw);
249  bool vr_kits_drawn() const { return vis_type != VVT_NONE; }
251  void draw_vr_kits(bool do_draw);
253  bool action_zone_drawn() const { return show_action_zone; }
255  void draw_action_zone(bool do_draw);
257  bool blit_vr_views_enabled() const { return blit_vr_views; }
259  void enable_blit_vr_views(bool enable);
261  int get_blit_vr_view_width() const { return blit_width; }
263  void set_blit_vr_view_width(int width);
265 
268  int get_rendered_eye() const { return rendered_eye; }
272  vr::gl_vr_display* get_rendered_display() const { return rendered_display_ptr; }
274  vr::vr_kit* get_rendered_vr_kit() const { return static_cast<vr::vr_kit*>(rendered_display_ptr); }
276  void on_set(void* member_ptr);
279  void stream_stats(std::ostream&);
281  bool init(cgv::render::context& ctx);
283  void clear(cgv::render::context& ctx);
285  bool handle_vr_events(cgv::gui::event& e);
287  bool handle(cgv::gui::event& e);
289  void stream_help(std::ostream& os);
290  // render the views for the kits in nested render passes
291  void render_vr_kits(cgv::render::context& ctx);
293  void init_frame(cgv::render::context&);
295  void draw_vr_kits(cgv::render::context& ctx);
297  void draw_action_zone(cgv::render::context& ctx);
299  void draw(cgv::render::context&);
301  void finish_frame(cgv::render::context&);
303  void after_finish(cgv::render::context& ctx);
305  bool self_reflect(cgv::reflect::reflection_handler& srh);
307  void create_gui();
308 };
310 
311 #include <cgv/config/lib_end.h>
vr_view_interactor
extends the stereo view interactor for vr support
Definition: vr_view_interactor.h:67
cgv::math::fmat< float, 3, 4 >
cgv::render::sphere_render_style
Definition: sphere_renderer.h:19
cgv::render::box_renderer
renderer that supports point splatting
Definition: box_renderer.h:30
vr::gl_vr_display
implements offscreen rendering
Definition: gl_vr_display.h:25
cgv::render::surface_render_style
Definition: surface_renderer.h:26
vr_view_interactor::vr_event_debugging_enabled
bool vr_event_debugging_enabled() const
check whether vr events are printed to the console window
Definition: vr_view_interactor.h:208
vr_driver.h
vr::vr_calibration_base
base class with write access to driver calibration matrix
Definition: vr_driver.h:37
vr_view_interactor::blit_aspect_scale
float blit_aspect_scale
scale of aspect ratio used for blitting
Definition: vr_view_interactor.h:141
vr_view_interactor::calibration_file_path
std::string calibration_file_path
path to calibration file
Definition: vr_view_interactor.h:112
vr::vr_kit
a vr kit is composed of headset, two controllers, and two trackers, where all devices can be attached...
Definition: vr_kit.h:69
cgv::gui::create_gui
bool create_gui(provider *p, const std::string &label, void *value_ptr, const std::string &value_type, const std::string &gui_type, const std::string &options, bool *toggles)
create the gui for a composed structure
Definition: gui_creator.cxx:21
vr_view_interactor::tracking_origin
vec3 tracking_origin
origin of tracking coordinate system given in world coordinates
Definition: vr_view_interactor.h:108
vr_view_interactor::tracking_rotation_origin
vec3 tracking_rotation_origin
location in tracking coordinate system around which rotation is defined
Definition: vr_view_interactor.h:106
VRkitVisType
VRkitVisType
different visualization types for vr kit components
Definition: vr_view_interactor.h:19
vr_view_interactor::get_rendered_display
vr::gl_vr_display * get_rendered_display() const
Definition: vr_view_interactor.h:272
cgv::reflect::reflection_handler
Definition: reflection_handler.h:63
vr_view_interactor::head_tracker_position
vec3 head_tracker_position
head position from tracker location
Definition: vr_view_interactor.h:77
vr_view_interactor::blit_vr_views
bool blit_vr_views
whether to blit in the views of the vr kits
Definition: vr_view_interactor.h:137
vr_view_interactor::pose_query
int pose_query
type of pose query according to vr::vr_kit::query_state function's 2nd parameter
Definition: vr_view_interactor.h:174
cgv::gui::event
Definition: event.h:59
vr_view_interactor::none_separate_view
int none_separate_view
selection of view of current hmd used in case of no separate view (1 ... left, 2 ....
Definition: vr_view_interactor.h:143
vr_view_interactor::get_blit_vr_view_width
int get_blit_vr_view_width() const
return width of vr view blitting
Definition: vr_view_interactor.h:261
vr_view_interactor::separate_view
bool separate_view
whether the window shows a separate view onto the scene or the one of the current vr kit
Definition: vr_view_interactor.h:133
vr_view_interactor::vr_kits_drawn
bool vr_kits_drawn() const
check whether vr kits are drawn
Definition: vr_view_interactor.h:249
vr_view_interactor::dont_render_kits
bool dont_render_kits
whether to not render for kits
Definition: vr_view_interactor.h:135
vr::vr_kit_state
structure that stores all information describing the state of a VR kit
Definition: vr_state.h:139
cgv::gui::VREventTypeFlags
VREventTypeFlags
flags to define which events should be generated by server
Definition: vr_server.h:27
cgv::type::info::get_type_name
const char * get_type_name(TypeId tid)
function that returns the name of a type specified through TypeId
Definition: type_id.cxx:117
vr::VRStatus
VRStatus
different status values for a trackable
Definition: vr_state.h:85
cgv::render::context
Definition: context.h:525
vr_view_interactor::action_zone_drawn
bool action_zone_drawn() const
check whether action zone is drawn
Definition: vr_view_interactor.h:253
vr_view_interactor::blit_vr_views_enabled
bool blit_vr_views_enabled() const
check whether vr views are blitted
Definition: vr_view_interactor.h:257