cgv
Loading...
Searching...
No Matches
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 <plugins/crg_stereo_view/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
28
30
68class CGV_API vr_view_interactor : public stereo_view_interactor, public vr::vr_calibration_base
69{
70protected:
71 cgv::ivec4 cgv_viewport;
72 void* fbo_handle;
73
81
112 void calibrate_driver();
115public:
116 void set_tracking_rotation(float tr) {
117 tracking_rotation = tr;
118 calibrate_driver();
119 }
120 float get_tracking_rotation() {
121 return tracking_rotation;
122 }
123 void set_tracking_origin(cgv::vec3 ori) {
124 tracking_origin = ori;
125 calibrate_driver();
126 }
127 cgv::vec3 get_tracking_origin() {
128 return tracking_origin;
129 }
131private:
132 cgv::mat3x4 start_pose;
133protected:
140 // extent of blitting
141 int blit_width;
146 int head_tracker;
149 vr::gl_vr_display* rendered_display_ptr;
150 int rendered_display_index;
151
152 cgv::gui::VREventTypeFlags event_flags;
153
154 // debugging of vr events on console
155 bool debug_vr_events;
156
157 // visualization of kits and action zone
158 VRkitVisType vis_type, hmd_vis_type, controller_vis_type, tracker_vis_type, base_vis_type;
159 bool show_action_zone;
160 cgv::rgb fence_color1, fence_color2;
161 float fence_frequency;
162 float fence_line_width;
163
164 // current vr kit handle is selected by an integer cast into an enum whos names correspond to the vr kit names
165 void* current_vr_handle;
166 int current_vr_handle_index;
167 std::string kit_enum_definition;
168 // list of vr kit states
169 std::vector<vr::vr_kit_state> kit_states;
170 // list of to be initialized vr kits
171 std::vector<void*> new_kits;
172 // list of vr kits
173 std::vector<void*> kits;
174 // list of to be destructed vr kits
175 std::vector<void*> old_kits;
178
179 // render objects
183
184 // helper members to allow change of mesh file names
185 std::string hmd_mesh_file_name, controller_mesh_file_name, tracker_mesh_file_name, base_mesh_file_name;
186 // for each mesh type a scale
187 float mesh_scales[4];
189 vr::vr_kit* get_vr_kit_from_index(int i) const;
190 //
191 void configure_kits();
193 void on_status_change(void* handle, int controller_index, vr::VRStatus old_status, vr::VRStatus new_status);
195 virtual void on_device_change(void* handle, bool attach);
197 void add_trackable_spheres(const float* pose, int i, std::vector<cgv::vec4>& spheres, std::vector<cgv::rgb>& sphere_colors);
198public:
200 vr_view_interactor(const char* name);
202 std::string get_type_name() const;
203
207 cgv::gui::VREventTypeFlags get_event_type_flags() const;
209 void set_event_type_flags(cgv::gui::VREventTypeFlags flags);
211 bool vr_event_debugging_enabled() const { return debug_vr_events; }
213 void enable_vr_event_debugging(bool enable = true);
215 const vr::vr_kit_state* get_current_vr_state() const;
217 vr::vr_kit* get_current_vr_kit() const;
218 // query vr state
219 void query_vr_states();
221
225
228 cgv::dvec3 get_view_dir_of_kit(int vr_kit_idx = -1) const;
230
233 cgv::dvec3 get_view_up_dir_of_kit(int vr_kit_idx = -1) const;
235
242 cgv::dvec3 get_eye_of_kit(int eye = 0, int vr_kit_idx = -1) const;
244
248 bool seperate_view_drawn() const { return separate_view; }
250 void draw_separate_view(bool do_draw);
252 bool vr_kits_drawn() const { return vis_type != VVT_NONE; }
254 void draw_vr_kits(bool do_draw);
256 void draw_vr_controllers(bool do_draw);
258 bool action_zone_drawn() const { return show_action_zone; }
260 void draw_action_zone(bool do_draw);
262 bool blit_vr_views_enabled() const { return blit_vr_views; }
264 void enable_blit_vr_views(bool enable);
266 int get_blit_vr_view_width() const { return blit_width; }
268 void set_blit_vr_view_width(int width);
270
274 int get_rendered_eye() const { return rendered_eye; }
277 vr::gl_vr_display* get_rendered_display() const { return rendered_display_ptr; }
279 vr::vr_kit* get_rendered_vr_kit() const { return static_cast<vr::vr_kit*>(rendered_display_ptr); }
281 int get_rendered_vr_kit_index() const { return rendered_display_index; }
283
284 void on_set(void* member_ptr);
286 void stream_stats(std::ostream&);
288 bool init(cgv::render::context& ctx);
290 void clear(cgv::render::context& ctx);
292 bool handle_vr_events(cgv::gui::event& e);
294 bool handle(cgv::gui::event& e);
296 void stream_help(std::ostream& os);
297 // render the views for the kits in nested render passes
298 void render_vr_kits(cgv::render::context& ctx);
300 void init_frame(cgv::render::context&);
302 void draw_vr_kits(cgv::render::context& ctx);
304 void draw_action_zone(cgv::render::context& ctx);
306 void draw(cgv::render::context&);
308 void finish_frame(cgv::render::context&);
310 void after_finish(cgv::render::context& ctx);
312 bool self_reflect(cgv::reflect::reflection_handler& srh);
314 void create_gui();
315};
317
318#include <cgv/config/lib_end.h>
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
renderer that supports point splatting
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
implements offscreen rendering
base class with write access to driver calibration matrix
Definition vr_driver.h:37
a vr kit is composed of headset, two controllers, and two trackers, where all devices can be attached...
Definition vr_kit.h:69
extends the stereo view interactor for vr support
int get_rendered_eye() const
return the currently rendered eye
bool blit_vr_views_enabled() const
check whether vr views are blitted
vr::gl_vr_display * get_rendered_display() const
return the vr kit currently rendered return a pointer to the current vr kit
cgv::vec3 head_tracker_position
head position from tracker location
float tracking_rotation
rotation angle around the y-axis
vr::vr_kit * get_rendered_vr_kit() const
return pointer to rendered vr kit or nullptr if birds eye view is rendered
bool separate_view
whether the window shows a separate view onto the scene or the one of the current vr kit
int pose_query
type of pose query according to vr::vr_kit::query_state function's 2nd parameter
int get_rendered_vr_kit_index() const
return index of rendered vr kit or -1 if birds eye view is rendered
float blit_aspect_scale
scale of aspect ratio used for blitting
cgv::vec3 tracking_rotation_origin
location in tracking coordinate system around which rotation is defined
std::string calibration_file_path
path to calibration file
cgv::mat3 head_tracker_orientation
head orientation from tracker orientation
bool vr_event_debugging_enabled() const
check whether vr events are printed to the console window
cgv::vec3 tracking_origin
origin of tracking coordinate system given in world coordinates
bool action_zone_drawn() const
check whether action zone is drawn
int get_blit_vr_view_width() const
return width of vr view blitting
bool blit_vr_views
whether to blit in the views of the vr kits
bool seperate_view_drawn() const
check whether separate view is rendered
int none_separate_view
selection of view of current hmd used in case of no separate view (1 ... left, 2 ....
int rendered_eye
rendered_eye: 0...monitor,1...left eye,2...right eye
bool dont_render_kits
whether to not render for kits
bool vr_kits_drawn() const
check whether vr kits are drawn
CGV_API cgv::reflect::enum_reflection_traits< VRkitVisType > get_reflection_traits(const VRkitVisType &gm)
support reflection of enum names
VREventTypeFlags
flags to define which events should be generated by server
Definition vr_server.h:27
VRStatus
different status values for a trackable
Definition vr_state.h:85
this type specific reflection traits class is used by the reflect_enum function to reflect enum types
render style for sphere rendere
structure that stores all information describing the state of a VR kit
Definition vr_state.h:139
defines the class vr::vr_driver class and gives access to the driver registry with the functions vr::...