cgv
Loading...
Searching...
No Matches
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/cone_renderer.h>
10#include <cgv/render/shader_program.h>
11#include <cgv_gl/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 <plugins/crg_vr_view/vr_view_interactor.h>
25#include <plugins/crg_vr_view/vr_render_helpers.h>
26
27class vr_test :
28 public cgv::base::node,
31 public cgv::gui::provider {
32protected:
33 using vec2 = cgv::vec2;
34 using vec3 = cgv::vec3;
35 using dvec2 = cgv::dvec2;
36 using dvec3 = cgv::dvec3;
37 using mat3 = cgv::mat3;
38 using mat4 = cgv::mat4;
39 using rgb = cgv::rgb;
40 using rgba = cgv::rgba;
41 using quat = cgv::quat;
42 using dquat = cgv::dquat;
43 using box3 = cgv::box3;
44
45 // different interaction states for the controllers
46 enum InteractionState {
47 IS_NONE,
48 IS_OVER,
49 IS_GRAB
50 };
51
52
53 // store the scene as colored boxes
54 std::vector<box3> boxes;
55 std::vector<rgb> box_colors;
56
57 // rendering styles
60
61 // sample for rendering a mesh
62 double mesh_scale;
63 dvec3 mesh_location;
64 dquat mesh_orientation;
65
66 // render information for mesh
68
69 // sample for rendering text labels
70 std::string label_text;
71 int label_font_idx;
72 bool label_upright;
73 float label_size;
74 rgb label_color;
75
76private:
77 bool label_outofdate; // whether label texture is out of date
78
79protected:
80 unsigned label_resolution; // resolution of label texture
81 cgv::render::texture label_tex; // texture used for offline rendering of label
82 cgv::render::frame_buffer label_fbo; // fbo used for offline rendering of label
83
84 // general font information
85 std::vector<const char*> font_names;
86 std::string font_enum_decl;
87
88 // current font face used
89 cgv::media::font::font_face_ptr label_font_face;
91
92 // manage controller input configuration for left controller
93 std::vector<vr::controller_input_config> left_inp_cfg;
94
95 // store handle to vr kit of which left deadzone and precision is configured
96 void* last_kit_handle;
97
98 // length of to be rendered rays
99 float ray_length;
100
101 // keep reference to vr_view_interactor
102 vr_view_interactor* vr_view_ptr;
103
104 // store the movable boxes
105 std::vector<box3> movable_boxes;
106 std::vector<rgb> movable_box_colors;
107 std::vector<vec3> movable_box_translations;
108 std::vector<quat> movable_box_rotations;
109
110 // store the wireframe boxes
111 std::vector<box3> frame_boxes;
112 std::vector<rgb> frame_box_colors;
113 std::vector<vec3> frame_box_translations;
114 std::vector<quat> frame_box_rotations;
115
116 // intersection points
117 std::vector<vec3> intersection_points;
118 std::vector<rgb> intersection_colors;
119 std::vector<int> intersection_box_indices;
120 std::vector<int> intersection_controller_indices;
121
122 // state of current interaction with boxes for all controllers
123 InteractionState state[4];
124
125 // render style for interaction
127 cgv::render::box_render_style movable_style;
128 cgv::render::box_render_style wire_frame_style;
129
130 int nr_cameras;
131 int frame_width, frame_height;
132 int frame_split;
133 float seethrough_gamma;
134 mat4 camera_to_head_matrix[2];
135 cgv::math::fmat<float, 4, 4> camera_projection_matrix[4];
136 vec2 focal_lengths[4];
137 vec2 camera_centers[4];
138 cgv::render::texture camera_tex;
140 GLuint camera_tex_id;
141 bool undistorted;
142 bool shared_texture;
143 bool max_rectangle;
144 float camera_aspect;
145 bool show_seethrough;
146 bool use_matrix;
147 float background_distance;
148 float background_extent;
149 vec2 extent_texcrd;
150 vec2 center_left;
151 vec2 center_right;
152
153public:
154 void init_cameras(vr::vr_kit* kit_ptr);
155
156 void start_camera();
157
158 void stop_camera();
159
161 void compute_intersections(const vec3& origin, const vec3& direction, int ci, const rgb& color);
163 void on_status_change(void* kit_handle, int ci, vr::VRStatus old_status, vr::VRStatus new_status);
165 void on_device_change(void* kit_handle, bool attach);
167 void construct_table(float tw, float td, float th, float tW);
169 void construct_room(float w, float d, float h, float W, bool walls, bool ceiling);
171 void construct_environment(float s, float ew, float ed, float w, float d, float h);
173 void construct_movable_boxes(float tw, float td, float th, float tW, size_t nr);
175 void build_scene(float w, float d, float h, float W, float tw, float td, float th, float tW);
176public:
177 vr_test();
178
179 std::string get_type_name() { return "vr_test"; }
180
181 void stream_help(std::ostream& os);
182
183 void on_set(void* member_ptr);
184
185 bool handle(cgv::gui::event& e);
186
187 bool init(cgv::render::context& ctx);
188
189 void clear(cgv::render::context& ctx);
190
192
193 void draw(cgv::render::context& ctx);
194
196
197 void create_gui();
198
200
202 bool save_boxes(const std::string fn, const std::vector<box3>& boxes, const std::vector<rgb>& box_colors, const std::vector<vec3>& box_translations, const std::vector<quat>& box_rotations);
203
205
206 bool load_boxes(const std::string fn, std::vector<box3>& boxes, std::vector<rgb>& box_colors, std::vector<vec3>& box_translations, std::vector<quat>& box_rotations);
207
208 private:
209
210 void on_save_movable_boxes_cb();
211 void on_load_movable_boxes_cb();
212 void on_load_wireframe_boxes_cb();
213 void clear_movable_boxes();
214 void clear_frame_boxes();
215
216};
217
The node class keeps a pointer to its parent.
Definition node.h:19
interface for all classes that want to receive events
derive from this class to provide a gui to the current viewer
Definition provider.h:64
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
base class for all drawables, which is independent of the used rendering API.
Definition drawable.h:15
this class encapsulate frame buffers that live on the GPU and can be used as destination for the rend...
the mesh_render_info structure manages vertex buffer objects for attribute and element buffers as wel...
a shader program combines several shader code fragments to a complete definition of the shading pipel...
the texture class encapsulates all functionality independent of the rendering api.
Definition texture.h:15
a vr kit is composed of headset, two controllers, and two trackers, where all devices can be attached...
Definition vr_kit.h:69
void build_scene(float w, float d, float h, float W, float tw, float td, float th, float tW)
construct a scene with a table
Definition vr_test.cxx:250
bool save_boxes(const std::string fn, const std::vector< box3 > &boxes, const std::vector< rgb > &box_colors, const std::vector< vec3 > &box_translations, const std::vector< quat > &box_rotations)
stores configuration of the movable boxes inside a file
Definition vr_test.cxx:1010
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 vr_test.cxx:307
bool load_boxes(const std::string fn, std::vector< box3 > &boxes, std::vector< rgb > &box_colors, std::vector< vec3 > &box_translations, std::vector< quat > &box_rotations)
loads boxes stored by the save_boxes method from a file
Definition vr_test.cxx:1040
void clear(cgv::render::context &ctx)
clear all objects living in the context like textures or display lists
Definition vr_test.cxx:521
void init_frame(cgv::render::context &ctx)
this method is called in one pass over all drawables before the draw method
Definition vr_test.cxx:528
void construct_movable_boxes(float tw, float td, float th, float tW, size_t nr)
construct boxes that represent a table of dimensions tw,td,th and leg width tW
Definition vr_test.cxx:221
void construct_table(float tw, float td, float th, float tW)
construct boxes that represent a table of dimensions tw,td,th and leg width tW
Definition vr_test.cxx:153
void on_status_change(void *kit_handle, int ci, vr::VRStatus old_status, vr::VRStatus new_status)
keep track of status changes
Definition vr_test.cxx:107
void construct_environment(float s, float ew, float ed, float w, float d, float h)
construct boxes for environment
Definition vr_test.cxx:195
void stream_help(std::ostream &os)
overload to stream help information to the given output stream
Definition vr_test.cxx:303
void construct_room(float w, float d, float h, float W, bool walls, bool ceiling)
construct boxes that represent a room of dimensions w,d,h and wall width W
Definition vr_test.cxx:172
void on_device_change(void *kit_handle, bool attach)
register on device change events
Definition vr_test.cxx:128
void draw(cgv::render::context &ctx)
overload to draw the content of this drawable
Definition vr_test.cxx:652
bool handle(cgv::gui::event &e)
overload and implement this method to handle events
Definition vr_test.cxx:328
void finish_draw(cgv::render::context &ctx)
this method is called when the current drawable is left in a tree traversal that calls the draw metho...
Definition vr_test.cxx:871
void create_gui()
you must overload this for gui creation
Definition vr_test.cxx:907
bool init(cgv::render::context &ctx)
this method is called after creation or recreation of the context, return whether all necessary funct...
Definition vr_test.cxx:457
void compute_intersections(const vec3 &origin, const vec3 &direction, int ci, const rgb &color)
compute intersection points of controller ray with movable boxes
Definition vr_test.cxx:77
extends the stereo view interactor for vr support
FontFaceAttributes
declaration of supported attributes of font faces
Definition font.h:21
cgv::math::quaternion< double > dquat
declare type of double quaternion
Definition quaternion.h:372
cgv::media::color< float, cgv::media::RGB, cgv::media::OPACITY > rgba
declare rgba color type with 32 bit components
Definition color.h:855
cgv::math::quaternion< float > quat
declare type of quaternion
Definition quaternion.h:370
cgv::math::fvec< double, 3 > dvec3
declare type of 3d double precision floating point vectors
Definition fvec.h:676
cgv::media::axis_aligned_box< float, 3 > box3
declare type of 3d single precision floating point axis-aligned boxes
cgv::media::color< float, cgv::media::RGB > rgb
declare rgb color type with 32 bit components
Definition color.h:853
cgv::math::fmat< float, 3, 3 > mat3
declare type of 3x3 matrices
Definition fmat.h:358
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
Definition fvec.h:667
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:669
cgv::math::fvec< double, 2 > dvec2
declare type of 2d double precision floating point vectors
Definition fvec.h:674
cgv::math::fmat< float, 4, 4 > mat4
declare type of 4x4 matrices
Definition fmat.h:360
VRStatus
different status values for a trackable
Definition vr_state.h:85
boxes use surface render styles
render style for sphere rendere
defines the class vr::vr_driver class and gives access to the driver registry with the functions vr::...