cgv
vr_test.h
Go to the documentation of this file.
1 #pragma once
2 #include <cgv/base/node.h>
3 #include <cgv/render/drawable.h>
4 #include <cgv/gui/provider.h>
5 #include <cgv/gui/event_handler.h>
6 #include <cgv_gl/box_renderer.h>
7 #include <cgv_gl/gl/mesh_render_info.h>
8 #include <cgv_gl/sphere_renderer.h>
9 #include <cgv_gl/rounded_cone_renderer.h>
10 #include <cgv/render/shader_program.h>
11 #include <cgv_gl/rounded_cone_renderer.h>
12 #include <cgv/render/frame_buffer.h>
13 
16 
21 // these are the vr specific headers
22 #include <vr/vr_driver.h>
23 #include <cg_vr/vr_server.h>
24 #include <vr_view_interactor.h>
25 #include <vr_render_helpers.h>
26 
27 class vr_test :
28  public cgv::base::node,
29  public cgv::render::drawable,
31  public cgv::gui::provider {
32 protected:
33  // different interaction states for the controllers
34  enum InteractionState {
35  IS_NONE,
36  IS_OVER,
37  IS_GRAB
38  };
39 
40 
41  // store the scene as colored boxes
42  std::vector<box3> boxes;
43  std::vector<rgb> box_colors;
44 
45  // rendering styles
47  cgv::render::rounded_cone_render_style cone_style;
48 
49  // sample for rendering a mesh
50  double mesh_scale;
51  dvec3 mesh_location;
52  dquat mesh_orientation;
53 
54  // render information for mesh
56 
57  // sample for rendering text labels
58  std::string label_text;
59  int label_font_idx;
60  bool label_upright;
61  float label_size;
62  rgb label_color;
63 
64 private:
65  bool label_outofdate; // whether label texture is out of date
66 
67 protected:
68  unsigned label_resolution; // resolution of label texture
69  cgv::render::texture label_tex; // texture used for offline rendering of label
70  cgv::render::frame_buffer label_fbo; // fbo used for offline rendering of label
71 
72  // general font information
73  std::vector<const char*> font_names;
74  std::string font_enum_decl;
75 
76  // current font face used
77  cgv::media::font::font_face_ptr label_font_face;
79 
80  // manage controller input configuration for left controller
81  std::vector<vr::controller_input_config> left_inp_cfg;
82 
83  // store handle to vr kit of which left deadzone and precision is configured
84  void* last_kit_handle;
85 
86  // length of to be rendered rays
87  float ray_length;
88 
89  // keep reference to vr_view_interactor
90  vr_view_interactor* vr_view_ptr;
91 
92  // store the movable boxes
93  std::vector<box3> movable_boxes;
94  std::vector<rgb> movable_box_colors;
95  std::vector<vec3> movable_box_translations;
96  std::vector<quat> movable_box_rotations;
97 
98  // intersection points
99  std::vector<vec3> intersection_points;
100  std::vector<rgb> intersection_colors;
101  std::vector<int> intersection_box_indices;
102  std::vector<int> intersection_controller_indices;
103 
104  // state of current interaction with boxes for all controllers
105  InteractionState state[4];
106 
107  // render style for interaction
109  cgv::render::box_render_style movable_style;
110 
111  int nr_cameras;
112  int frame_width, frame_height;
113  int frame_split;
114  float seethrough_gamma;
115  mat4 camera_to_head_matrix[2];
116  cgv::math::fmat<float, 4, 4> camera_projection_matrix[4];
117  vec2 focal_lengths[4];
118  vec2 camera_centers[4];
119  cgv::render::texture camera_tex;
120  cgv::render::shader_program seethrough;
121  GLuint camera_tex_id;
122  bool undistorted;
123  bool shared_texture;
124  bool max_rectangle;
125  float camera_aspect;
126  bool show_seethrough;
127  bool use_matrix;
128  float background_distance;
129  float background_extent;
130  vec2 extent_texcrd;
131  vec2 center_left;
132  vec2 center_right;
133 
134 public:
135  void init_cameras(vr::vr_kit* kit_ptr);
136 
137  void start_camera();
138 
139  void stop_camera();
140 
142  void compute_intersections(const vec3& origin, const vec3& direction, int ci, const rgb& color);
144  void on_status_change(void* kit_handle, int ci, vr::VRStatus old_status, vr::VRStatus new_status);
146  void on_device_change(void* kit_handle, bool attach);
148  void construct_table(float tw, float td, float th, float tW);
150  void construct_room(float w, float d, float h, float W, bool walls, bool ceiling);
152  void construct_environment(float s, float ew, float ed, float w, float d, float h);
154  void construct_movable_boxes(float tw, float td, float th, float tW, size_t nr);
156  void build_scene(float w, float d, float h, float W, float tw, float td, float th, float tW);
157 public:
158  vr_test();
159 
160  std::string get_type_name() { return "vr_test"; }
161 
162  void stream_help(std::ostream& os);
163 
164  void on_set(void* member_ptr);
165 
166  bool handle(cgv::gui::event& e);
167 
168  bool init(cgv::render::context& ctx);
169 
170  void clear(cgv::render::context& ctx);
171 
172  void init_frame(cgv::render::context& ctx);
173 
174  void draw(cgv::render::context& ctx);
175 
177 
178  void create_gui();
179 };
180 
vr_view_interactor
extends the stereo view interactor for vr support
Definition: vr_view_interactor.h:67
cgv::math::fmat< float, 4, 4 >
cgv::base::node::get_type_name
std::string get_type_name() const
overload to return the type name of this object
Definition: node.cxx:47
cgv::render::box_render_style
boxes use surface render styles
Definition: box_renderer.h:19
cgv::gui::event_handler
interface for all classes that want to receive events
Definition: event_handler.h:15
cgv::render::sphere_render_style
Definition: sphere_renderer.h:19
cgv::render::drawable::clear
virtual void clear(context &)
clear all objects living in the context like textures or display lists
Definition: drawable.cxx:129
vr_driver.h
cgv::data::ref_ptr< font_face >
cgv::render::texture
Definition: texture.h:15
cgv::media::font::FontFaceAttributes
FontFaceAttributes
declaration of supported attributes of font faces
Definition: font.h:21
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
cgv::render::drawable::init
virtual bool init(context &)
this method is called after creation or recreation of the context, return whether all necessary funct...
Definition: drawable.cxx:98
cgv::gui::provider
derive from this class to provide a gui to the current viewer
Definition: provider.h:64
cgv::render::drawable::init_frame
virtual void init_frame(context &)
this method is called in one pass over all drawables before the draw method
Definition: drawable.cxx:107
cgv::render::shader_program
Definition: shader_program.h:25
cgv::render::drawable::finish_draw
virtual void finish_draw(context &)
this method is called when the current drawable is left in a tree traversal that calls the draw metho...
Definition: drawable.cxx:115
cgv::gui::event_handler::stream_help
virtual void stream_help(std::ostream &os)=0
overload to stream help information to the given output stream
cgv::gui::event
Definition: event.h:59
cgv::render::drawable::draw
virtual void draw(context &)
overload to draw the content of this drawable
Definition: drawable.cxx:111
cgv::gui::event_handler::handle
virtual bool handle(event &e)=0
overload and implement this method to handle events
cgv::base::base::on_set
virtual void on_set(void *member_ptr)
this callback is called when the set_void method has changed a member and can be overloaded in derive...
Definition: base.cxx:210
cgv::render::drawable
Definition: drawable.h:15
cgv::render::frame_buffer
Definition: frame_buffer.h:17
cgv::render::mesh_render_info
Definition: mesh_render_info.h:16
vr::VRStatus
VRStatus
different status values for a trackable
Definition: vr_state.h:85
cgv::base::node
Definition: node.h:17
cgv::render::context
Definition: context.h:525