3#include <cgv/signal/rebind.h>
4#include <cgv/base/register.h>
5#include <cgv/math/ftransform.h>
8#include <cgv/utils/file.h>
9#include <cgv/gui/dialog.h>
10#include <cgv/gui/file_dialog.h>
11#include <cgv/render/attribute_array_binding.h>
12#include <cgv_gl/sphere_renderer.h>
13#include <cgv/media/mesh/simple_mesh.h>
14#include <cg_vr/vr_events.h>
19#include "intersection.h"
29 for (
int i = 0; i < nr_cameras; ++i) {
30 std::cout <<
"camera " << i <<
"(" << nr_cameras <<
"):" << std::endl;
33 std::cout <<
" fx=" << focal_lengths[i][0] <<
", fy=" << focal_lengths[i][1] <<
", center=[" << camera_centers[i] <<
"]" << std::endl;
34 std::cout <<
" fx=" << focal_lengths[2+i][0] <<
", fy=" << focal_lengths[2+i][1] <<
", center=[" << camera_centers[2+i] <<
"]" << std::endl;
35 float camera_to_head[12];
39 std::cout <<
" C2H=" << camera_to_head_matrix[i] << std::endl;
42 std::cout <<
" dP=" << camera_projection_matrix[i] << std::endl;
43 std::cout <<
" uP=" << camera_projection_matrix[2+i] << std::endl;
48void vr_test::start_camera()
58 if (!camera_ptr->
start())
62void vr_test::stop_camera()
72 if (!camera_ptr->
stop())
79 for (
size_t i = 0; i < movable_boxes.size(); ++i) {
80 vec3 origin_box_i = origin - movable_box_translations[i];
81 movable_box_rotations[i].inverse_rotate(origin_box_i);
82 vec3 direction_box_i = direction;
83 movable_box_rotations[i].inverse_rotate(direction_box_i);
87 if (cgv::media::ray_axis_aligned_box_intersection(
88 origin_box_i, direction_box_i,
90 t_result, p_result, n_result, 0.000001f)) {
93 movable_box_rotations[i].rotate(p_result);
94 p_result += movable_box_translations[i];
95 movable_box_rotations[i].rotate(n_result);
98 intersection_points.push_back(p_result);
99 intersection_colors.push_back(color);
100 intersection_box_indices.push_back((
int)i);
101 intersection_controller_indices.push_back(ci);
116 for (
int ii = 0; ii < (int)left_inp_cfg.size(); ++ii)
122 left_inp_cfg.clear();
131 if (last_kit_handle == 0) {
133 init_cameras(kit_ptr);
135 last_kit_handle = kit_handle;
138 for (
int ii = 0; ii < (int)left_inp_cfg.size(); ++ii)
145 if (kit_handle == last_kit_handle) {
155 rgb table_clr(0.3f, 0.2f, 0.0f);
156 boxes.push_back(
box3(
157 vec3(-0.5f*tw, th - tW, -0.5f*td),
158 vec3(0.5f*tw, th, 0.5f*td)));
159 box_colors.push_back(table_clr);
161 boxes.push_back(
box3(
vec3(-0.5f*tw + 2*tW, 0, -0.5f*td+2*tW),
vec3(-0.5f*tw+tW, th - tW, -0.5f*td + tW)));
162 boxes.push_back(
box3(
vec3(-0.5f*tw + 2*tW, 0, 0.5f*td-2*tW),
vec3(-0.5f*tw + tW, th - tW, 0.5f*td - tW)));
163 boxes.push_back(
box3(
vec3(0.5f*tw-2*tW, 0, -0.5f*td+tW),
vec3(0.5f*tw - tW, th - tW, -0.5f*td +2* tW)));
164 boxes.push_back(
box3(
vec3(0.5f*tw-2*tW, 0, 0.5f*td-2*tW),
vec3(0.5f*tw - tW, th - tW, 0.5f*td - tW)));
165 box_colors.push_back(table_clr);
166 box_colors.push_back(table_clr);
167 box_colors.push_back(table_clr);
168 box_colors.push_back(table_clr);
174 boxes.push_back(
box3(
vec3(-0.5f*w, -W, -0.5f*d),
vec3(0.5f*w, 0, 0.5f*d)));
175 box_colors.push_back(
rgb(0.2f, 0.2f, 0.2f));
179 boxes.push_back(
box3(
vec3(-0.5f*w, -W, -0.5f*d - W),
vec3(0.5f*w, h, -0.5f*d)));
180 box_colors.push_back(
rgb(0.8f, 0.5f, 0.5f));
181 boxes.push_back(
box3(
vec3(-0.5f*w, -W, 0.5f*d),
vec3(0.5f*w, h, 0.5f*d + W)));
182 box_colors.push_back(
rgb(0.8f, 0.5f, 0.5f));
184 boxes.push_back(
box3(
vec3(0.5f*w, -W, -0.5f*d - W),
vec3(0.5f*w + W, h, 0.5f*d + W)));
185 box_colors.push_back(
rgb(0.5f, 0.8f, 0.5f));
189 boxes.push_back(
box3(
vec3(-0.5f*w - W, h, -0.5f*d - W),
vec3(0.5f*w + W, h + W, 0.5f*d + W)));
190 box_colors.push_back(
rgb(0.5f, 0.5f, 0.8f));
196 std::default_random_engine generator;
197 std::uniform_real_distribution<float> distribution(0, 1);
198 unsigned n = unsigned(ew / s);
199 unsigned m = unsigned(ed / s);
200 float ox = 0.5f*float(n)*s;
201 float oz = 0.5f*float(m)*s;
202 for(
unsigned i = 0; i < n; ++i) {
203 float x = i * s - ox;
204 for(
unsigned j = 0; j < m; ++j) {
205 float z = j * s - oz;
206 if(fabsf(x) < 0.5f*w && fabsf(x + s) < 0.5f*w && fabsf(z) < 0.5f*d && fabsf(z + s) < 0.5f*d)
208 float h = 0.2f*(std::max(abs(x) - 0.5f*w, 0.0f) + std::max(abs(z) - 0.5f*d, 0.0f))*distribution(generator) + 0.1f;
209 boxes.push_back(
box3(
vec3(x, 0.0f, z),
vec3(x + s, h, z + s)));
211 box_colors.push_back(color);
229 std::default_random_engine generator;
230 std::uniform_real_distribution<float> distribution(0, 1);
231 std::uniform_real_distribution<float> signed_distribution(-1, 1);
232 for(
size_t i = 0; i < nr; ++i) {
233 float x = distribution(generator);
234 float y = distribution(generator);
235 vec3 extent(distribution(generator), distribution(generator), distribution(generator));
237 extent *= std::min(tw, td)*0.1f;
239 vec3 center(-0.5f*tw + x * tw, th + tW, -0.5f*td + y * td);
240 movable_boxes.push_back(
box3(-0.5f*extent, 0.5f*extent));
241 movable_box_colors.push_back(
rgb(distribution(generator), distribution(generator), distribution(generator)));
242 movable_box_translations.push_back(center);
243 quat rot(signed_distribution(generator), signed_distribution(generator), signed_distribution(generator), signed_distribution(generator));
245 movable_box_rotations.push_back(rot);
262 extent_texcrd = vec2(0.5f, 0.5f);
263 center_left = vec2(0.5f,0.25f);
264 center_right = vec2(0.5f,0.25f);
265 seethrough_gamma = 0.33f;
266 frame_width = frame_height = 0;
267 background_distance = 2;
268 background_extent = 2;
270 shared_texture =
true;
271 max_rectangle =
false;
276 show_seethrough =
false;
278 build_scene(5, 7, 3, 0.2f, 0.8f, 0.8f, 0.72f, 0.03f);
285 mesh_scale = 0.0005f;
286 mesh_location = dvec3(0, 0.85f, 0);
287 mesh_orientation = dquat(1, 0, 0, 0);
291 label_outofdate =
true;
292 label_text =
"Info Board";
294 label_upright =
true;
295 label_face_type = cgv::media::font::FFA_BOLD;
296 label_resolution = 256;
298 label_color = rgb(1, 1, 1);
300 state[0] = state[1] = state[2] = state[3] = IS_NONE;
304 os <<
"vr_test: no shortcuts defined" << std::endl;
309 if (member_ptr == &label_face_type || member_ptr == &label_font_idx) {
311 label_outofdate =
true;
313 if ((member_ptr >= &label_color && member_ptr < &label_color + 1) ||
314 member_ptr == &label_size || member_ptr == &label_text) {
315 label_outofdate =
true;
320 for (
int ii = 0; ii < (int)left_inp_cfg.size(); ++ii)
321 if (member_ptr >= &left_inp_cfg[ii] && member_ptr < &left_inp_cfg[ii] + 1)
341 std::cout <<
"grip button " << (vrke.
get_controller_index() == 0 ?
"left":
"right") <<
" controller pressed" << std::endl;
344 std::cout <<
"touch pad of " << (vrke.
get_controller_index() == 0 ?
"left" :
"right") <<
" controller pressed at right direction" << std::endl;
374 <<
" at " << vrse.
get_x() <<
", " << vrse.
get_y() << std::endl;
383 <<
" to " << vrse.
get_x() <<
", " << vrse.
get_y() << std::endl;
393 if (state[ci] == IS_GRAB) {
405 for (
size_t i = 0; i < intersection_points.size(); ++i) {
406 if (intersection_controller_indices[i] != ci)
409 unsigned bi = intersection_box_indices[i];
411 movable_box_translations[bi] =
412 rotation * (movable_box_translations[bi] - last_pos) + pos;
416 movable_box_rotations[bi] =
quat(rotation) * movable_box_rotations[bi];
418 intersection_points[i] = rotation * (intersection_points[i] - last_pos) + pos;
424 while (i < intersection_points.size()) {
425 if (intersection_controller_indices[i] == ci) {
426 intersection_points.erase(intersection_points.begin() + i);
427 intersection_colors.erase(intersection_colors.begin() + i);
428 intersection_box_indices.erase(intersection_box_indices.begin() + i);
429 intersection_controller_indices.erase(intersection_controller_indices.begin() + i);
436 vec3 origin, direction;
439 label_outofdate =
true;
444 if (intersection_points.size() == i)
447 if (state[ci] == IS_NONE)
460 font_enum_decl =
"enums='";
461 for (
unsigned i = 0; i < font_names.size(); ++i) {
463 font_enum_decl +=
";";
464 std::string fn(font_names[i]);
469 font_enum_decl += std::string(fn);
471 font_enum_decl +=
"'";
478 if (M.
read(
"D:/data/surface/meshes/obj/Max-Planck_lowres.obj")) {
490 view_ptr->set_eye_keep_view_angle(
dvec3(0, 4, -4));
534 if (label_fbo.
get_width() != label_resolution) {
539 label_tex.
create(ctx, cgv::render::TT_2D, label_resolution, label_resolution);
540 label_fbo.
create(ctx, label_resolution, label_resolution);
543 label_fbo.
attach(ctx, label_tex);
544 label_outofdate =
true;
546 if (label_outofdate && label_fbo.
is_complete(ctx)) {
547 glPushAttrib(GL_COLOR_BUFFER_BIT);
551 glClearColor(0.5f,0.5f,0.5f,1.0f);
552 glClear(GL_COLOR_BUFFER_BIT);
554 glColor4f(label_color[0], label_color[1], label_color[2], 1);
555 ctx.
set_cursor(20, (
int)ceil(label_size) + 20);
561 for (
size_t i = 0; i < intersection_points.size(); ++i) {
563 <<
"box " << intersection_box_indices[i]
564 <<
" at (" << intersection_points[i]
565 <<
") with controller " << intersection_controller_indices[i] <<
"\n";
573 label_outofdate =
false;
581 if (camera_ptr && camera_ptr->
get_state() == vr::CS_STARTED) {
582 uint32_t width = frame_width, height = frame_height, split = frame_split;
583 if (shared_texture) {
586 camera_aspect = (float)width / height;
589 case vr::CFS_VERTICAL:
592 case vr::CFS_HORIZONTAL:
593 camera_aspect *= 0.5f;
601 std::vector<uint8_t> frame_data;
602 if (camera_ptr->
get_frame(frame_data, width, height, undistorted, max_rectangle)) {
603 camera_aspect = (float)width / height;
606 case vr::CFS_VERTICAL:
609 case vr::CFS_HORIZONTAL:
610 camera_aspect *= 0.5f;
619 camera_tex.
replace(ctx, 0, 0, dv);
622 camera_tex.
create(ctx, dv);
627 if (frame_width != width || frame_height != height) {
629 frame_height = height;
631 center_left(0) = camera_centers[2](0) / frame_width;
632 center_left(1) = camera_centers[2](1) / frame_height;
633 center_right(0) = camera_centers[3](0) / frame_width;
634 center_right(1) = camera_centers[3](1) / frame_height;
643 if (split != frame_split) {
659 cgv::math::translate4<double>(mesh_location)*
660 cgv::math::scale4<double>(mesh_scale, mesh_scale, mesh_scale) *
666 if ((!shared_texture && camera_tex.
is_created()) || (shared_texture && camera_tex_id != -1)) {
673 dvec3 x = normalize(cross(vd, y));
674 y = normalize(cross(x, vd));
675 x *= camera_aspect * background_extent * background_distance;
676 y *= background_extent * background_distance;
677 vd *= background_distance;
681 P.push_back(eye_pos + vd - x - y);
682 P.push_back(eye_pos + vd + x - y);
683 P.push_back(eye_pos + vd - x + y);
684 P.push_back(eye_pos + vd + x + y);
685 double v_offset = 0.5 * (1 - eye);
686 T.push_back(
dvec2(0.0, 0.5 + v_offset));
687 T.push_back(
dvec2(1.0, 0.5 + v_offset));
688 T.push_back(
dvec2(0.0, v_offset));
689 T.push_back(
dvec2(1.0, v_offset));
697 GLint active_texture, texture_binding;
698 if (shared_texture) {
699 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
700 glGetIntegerv(GL_TEXTURE_BINDING_2D, &texture_binding);
701 glActiveTexture(GL_TEXTURE0);
702 glBindTexture(GL_TEXTURE_2D, camera_tex_id);
705 camera_tex.
enable(ctx, 0);
707 prog.
set_uniform(ctx,
"seethrough_gamma", seethrough_gamma);
713 0.01f, 2 * background_distance, eye, undistorted);
728 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
733 if (shared_texture) {
734 glActiveTexture(active_texture);
735 glBindTexture(GL_TEXTURE_2D, texture_binding);
746 std::vector<float> R;
750 for (
int ci = 0; ci < 2; ++ci)
752 vec3 ray_origin, ray_direction;
754 P.push_back(ray_origin);
756 P.push_back(ray_origin + ray_length * ray_direction);
758 rgb c(
float(1 - ci), 0.5f * (
int)state[ci],
float(ci));
765 cr.set_render_style(cone_style);
767 cr.set_position_array(ctx, P);
768 cr.set_color_array(ctx, C);
769 cr.set_radius_array(ctx, R);
770 if (!cr.render(ctx, 0, P.size())) {
772 int pi = prog.get_position_index();
773 int ci = prog.get_color_index();
780 glDrawArrays(GL_LINES, 0, (GLsizei)P.size());
792 if (!frame_boxes.empty()) {
799 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
800 renderer.
draw(ctx, 0, frame_boxes.size());
801 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
807 if (!movable_boxes.empty()) {
814 if (show_seethrough) {
815 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
816 renderer.
draw(ctx, 0, 3);
817 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
818 renderer.
draw(ctx, 3, movable_boxes.size() - 3);
821 renderer.
draw(ctx, 0, movable_boxes.size());
826 if (!boxes.empty()) {
830 renderer.
render(ctx, 0, boxes.size());
833 if (!intersection_points.empty()) {
835 sr.set_position_array(ctx, intersection_points);
836 sr.set_color_array(ctx, intersection_colors);
837 sr.set_render_style(srs);
838 sr.render(ctx, 0, intersection_points.size());
844 int pi = prog.get_position_index();
845 int ti = prog.get_texcoord_index();
849 float w = 0.5f, h = 0.5f;
852 P.push_back(p - 0.5f * w * x - 0.5f * h * y); T.push_back(
vec2(0.0f, 0.0f));
853 P.push_back(p + 0.5f * w * x - 0.5f * h * y); T.push_back(
vec2(1.0f, 0.0f));
854 P.push_back(p - 0.5f * w * x + 0.5f * h * y); T.push_back(
vec2(0.0f, 1.0f));
855 P.push_back(p + 0.5f * w * x + 0.5f * h * y); T.push_back(
vec2(1.0f, 1.0f));
863 glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)P.size());
874 if ((!shared_texture && camera_tex.
is_created()) || (shared_texture && camera_tex_id != -1)) {
877 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
878 GLint active_texture, texture_binding;
879 if (shared_texture) {
880 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
881 glGetIntegerv(GL_TEXTURE_BINDING_2D, &texture_binding);
882 glActiveTexture(GL_TEXTURE0);
883 glBindTexture(GL_TEXTURE_2D, camera_tex_id);
886 camera_tex.
enable(ctx, 0);
895 if (shared_texture) {
896 glActiveTexture(active_texture);
897 glBindTexture(GL_TEXTURE_2D, texture_binding);
909 add_member_control(
this,
"mesh_scale", mesh_scale,
"value_slider",
"min=0.1;max=10;log=true;ticks=true");
910 add_gui(
"mesh_location", mesh_location,
"vector",
"options='min=-3;max=3;ticks=true");
911 add_gui(
"mesh_orientation",
static_cast<cgv::dvec4&
>(mesh_orientation),
"direction",
"options='min=-1;max=1;ticks=true");
912 add_member_control(
this,
"ray_length", ray_length,
"value_slider",
"min=0.1;max=10;log=true;ticks=true");
914 if(last_kit_handle) {
918 connect_copy(
add_button(
"start")->click, cgv::signal::rebind(
this, &vr_test::start_camera));
919 connect_copy(
add_button(
"stop")->click, cgv::signal::rebind(
this, &vr_test::stop_camera));
920 add_view(
"frame_width", frame_width,
"",
"w=20",
" ");
921 add_view(
"height", frame_height,
"",
"w=20",
" ");
922 add_view(
"split", frame_split,
"",
"w=50");
927 add_member_control(
this,
"gamma", seethrough_gamma,
"value_slider",
"min=0.1;max=10;log=true;ticks=true");
928 add_member_control(
this,
"extent_x", extent_texcrd[0],
"value_slider",
"min=0.2;max=2;ticks=true");
929 add_member_control(
this,
"extent_y", extent_texcrd[1],
"value_slider",
"min=0.2;max=2;ticks=true");
930 add_member_control(
this,
"center_left_x", center_left[0],
"value_slider",
"min=0.2;max=0.8;ticks=true");
931 add_member_control(
this,
"center_left_y", center_left[1],
"value_slider",
"min=0.2;max=0.8;ticks=true");
932 add_member_control(
this,
"center_right_x", center_right[0],
"value_slider",
"min=0.2;max=0.8;ticks=true");
933 add_member_control(
this,
"center_right_y", center_right[1],
"value_slider",
"min=0.2;max=0.8;ticks=true");
934 add_member_control(
this,
"background_distance", background_distance,
"value_slider",
"min=0.1;max=10;log=true;ticks=true");
935 add_member_control(
this,
"background_extent", background_extent,
"value_slider",
"min=0.01;max=10;log=true;ticks=true");
939 add_decorator(
"controller input configs",
"heading",
"level=3");
940 int ti = 0, si = 0, pi = 0;
942 for (
int ii = 0; ii < (int)left_inp_cfg.size(); ++ii) {
944 switch (CI.input_type[ii]) {
950 add_member_control(
this, prefix +
".dead_zone", left_inp_cfg[ii].dead_zone,
"value_slider",
"min=0;max=1;ticks=true;log=true");
951 add_member_control(
this, prefix +
".precision", left_inp_cfg[ii].precision,
"value_slider",
"min=0;max=1;ticks=true;log=true");
952 add_member_control(
this, prefix +
".threshold", left_inp_cfg[ii].threshold,
"value_slider",
"min=0;max=1;ticks=true");
958 connect_copy(
add_button(
"save boxes")->click, rebind(
this, &vr_test::on_save_movable_boxes_cb));
959 connect_copy(
add_button(
"load boxes")->click, rebind(
this, &vr_test::on_load_movable_boxes_cb));
960 connect_copy(
add_button(
"load target")->click, rebind(
this, &vr_test::on_load_wireframe_boxes_cb));
971 add_gui(
"cone style", cone_style);
977 add_gui(
"movable box style", movable_style);
989 add_member_control(
this,
"scale", mesh_scale,
"value_slider",
"min=0.0001;step=0.0000001;max=100;log=true;ticks=true");
990 add_gui(
"location", mesh_location,
"",
"main_label='';long_label=true;gui_type='value_slider';options='min=-2;max=2;step=0.001;ticks=true'");
991 add_gui(
"orientation",
static_cast<cgv::dvec4&
>(mesh_orientation),
"direction",
"main_label='';long_label=true;gui_type='value_slider';options='min=-1;max=1;step=0.001;ticks=true'");
1002 add_member_control(
this,
"size", label_size,
"value_slider",
"min=8;max=64;ticks=true");
1010bool vr_test::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)
1012 std::stringstream data;
1015 if (boxes.size() != box_colors.size() || boxes.size() != box_translations.size() || boxes.size() != box_rotations.size()) {
1016 std::cerr <<
"vr_test::save_boxes: passed vectors have different sizes!";
1020 for (
int i = 0; i < movable_boxes.size(); ++i) {
1022 const vec3& box_translation = box_translations[i];
1023 const quat& box_rotation = box_rotations[i];
1024 const rgb& box_color = box_colors[i];
1026 << boxes[i].get_min_pnt() <<
" "
1027 << boxes[i].get_max_pnt() <<
" "
1028 << box_translation <<
" "
1029 << box_rotation <<
" "
1033 std::string s = data.str();
1034 if (!cgv::utils::file::write(fn, s.data(), s.size())) {
1035 std::cerr <<
"vr_test::save_boxes: failed writing data to file: " << fn;
1040bool vr_test::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)
1043 if (!cgv::utils::file::read(fn, data)) {
1044 std::cerr <<
"vr_test::load_boxes: failed reading data from file: " << fn <<
'\n';
1047 std::istringstream f(data);
1051 std::getline(f, line);
1052 std::istringstream l(line);
1058 getline(l, sym,
' ');
1060 vec3 minp,maxp,trans;
1069 boxes.emplace_back(minp, maxp);
1070 box_translations.emplace_back(trans);
1071 box_rotations.emplace_back(rot);
1072 box_colors.emplace_back(col);
1079void vr_test::on_save_movable_boxes_cb()
1085 save_boxes(fn, movable_boxes, movable_box_colors, movable_box_translations, movable_box_rotations);
1088void vr_test::on_load_movable_boxes_cb()
1091 if (!cgv::utils::file::exists(fn)) {
1092 std::cerr <<
"vr_test::on_load_movable_boxes_cb: file does not exist!\n";
1095 clear_movable_boxes();
1096 if (!
load_boxes(fn, movable_boxes, movable_box_colors, movable_box_translations, movable_box_rotations)) {
1097 std::cerr <<
"vr_test::on_load_movable_boxes_cb: failed to parse file!\n";
1098 clear_movable_boxes();
1102void vr_test::on_load_wireframe_boxes_cb()
1105 if (!cgv::utils::file::exists(fn)) {
1106 std::cerr <<
"vr_test::on_load_movable_boxes_cb: file does not exist!\n";
1109 clear_frame_boxes();
1110 if (!
load_boxes(fn, frame_boxes, frame_box_colors, frame_box_translations, frame_box_rotations)) {
1111 std::cerr <<
"vr_test::on_load_wireframe_boxes_cb: failed to parse file!\n";
1112 clear_frame_boxes();
1116void vr_test::clear_movable_boxes()
1118 movable_boxes.clear();
1119 movable_box_translations.clear();
1120 movable_box_rotations.clear();
1121 movable_box_colors.clear();
1124void vr_test::clear_frame_boxes()
1126 frame_boxes.clear();
1127 frame_box_translations.clear();
1128 frame_box_rotations.clear();
1129 frame_box_colors.clear();
1132#include <cgv/base/register.h>
1136#ifdef CGV_FORCE_STATIC
void set_name(const std::string &_name)
set a new parent node
complete implementation of method actions that only call one method when entering a node
the data view gives access to a data array of one, two, three or four dimensions.
unsigned get_kind() const
return, what kind of event this is, typically a value from the EventId enum
unsigned get_flags() const
return the event flags
unsigned short get_key() const
return the key being a capital letter, digit or a value from the Keys enum
KeyAction get_action() const
return the key event action
const vec3 & get_last_position() const
return last position
const vec3 & get_position() const
return current position
mat3 get_rotation_matrix() const
return rotation matrix between from the last to current orientation
int get_trackable_index() const
return trackable index
bool add_gui(const std::string &label, T &value, const std::string &gui_type="", const std::string &options="")
Add a composed gui of the given gui_type for the given value.
cgv::base::base_ptr add_decorator(const std::string &label, const std::string &decorator_type, const std::string &options="", const std::string &align="\n")
add a newly created decorator to the group
void align(const std::string &_align)
send pure alignment information
bool begin_tree_node(const std::string &label, const T &value, bool initial_visibility=false, const std::string &options="", gui_group_ptr ggp=gui_group_ptr())
Begin a sub tree of a tree structured gui.
virtual void update_member(void *member_ptr)
call this to update all views and controls of a member
data::ref_ptr< control< T > > add_member_control(cgv::base::base *base_ptr, const std::string &label, T &value, const std::string &gui_type="", const std::string &options="", const std::string &align="\n")
add control with callback to cgv::base::on_set method on cgv::gui::control::value_change
void end_tree_node(const T &value)
template specialization that allows to specify value reference plus node_instance by using the result...
virtual void post_recreate_gui()
delayed recreation of gui
data::ref_ptr< view< T > > add_view(const std::string &label, const T &value, const std::string &gui_type="", const std::string &options="", const std::string &align="\n")
use this to add a new view to the gui with a given value type, gui type and init options
button_ptr add_button(const std::string &label, const std::string &options="", const std::string &align="\n")
use the current gui driver to append a new button with the given label
unsigned get_stick_index() const
return stick index
float get_last_x() const
return the last x value of the stick
float get_y() const
return the current y value of the stick
float get_last_y() const
return the last y value of the stick
unsigned get_controller_index() const
return controller index
StickAction get_action() const
return the stick action
float get_x() const
return the current x value of the stick
float get_last_value() const
return the last value of the throttle
float get_value() const
return the current value of the throttle
unsigned get_controller_index() const
return controller index
unsigned get_throttle_index() const
return throttle index
const vr::vr_kit_state & get_state() const
return the state of vr kit
vr key events use the key codes defined in vr::VRKeys
unsigned get_controller_index() const
return controller index (0 .. vr::max_nr_controllers-1), controllers with left and right hand role ar...
vr extension of pose events
vr extension of stick event
vr extension of throttle event
void put_homogeneous_matrix(hmat_type &M) const
compute equivalent homogeneous 4x4 rotation matrix
static bool enable_global_array(const context &ctx, int loc)
enable attribute array of given location
static bool set_global_attribute_array(const context &ctx, int loc, const vertex_buffer &vbo, type_descriptor td, size_t size, size_t offset, unsigned stride=0)
point array of vertex attribute at location loc to vertex buffer array array stored in CPU memory; in...
static bool disable_global_array(const context &ctx, int loc)
disable attribute array of given location
renderer that supports point splatting
bool disable(context &ctx)
disable renderer
void set_translation_array(const context &ctx, const std::vector< T > &translations)
template method to set the translations from a vector of vectors of type T, which should have 3 compo...
void set_rotation_array(const context &ctx, const std::vector< T > &rotations)
template method to set the rotation from a vector of quaternions of type T, which should have 4 compo...
void draw(context &ctx, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1)
Draw a range of vertices or indexed elements.
void set_box_array(const context &ctx, const std::vector< cgv::media::axis_aligned_box< T, 3 > > &boxes)
specify box array directly. This sets position_is_center to false as well as position and extent arra...
base class for all drawables, which is independent of the used rendering API.
virtual std::ostream & output_stream()
returns an output stream whose output is printed at the current cursor location, which is managed by ...
virtual void mul_modelview_matrix(const dmat4 &MV)
multiply given matrix from right to current modelview matrix
virtual void set_color(const rgba &clr)
set the current color
virtual shader_program & ref_default_shader_program(bool texture_support=false)=0
return a reference to a shader program used to render without illumination
virtual void enable_font_face(media::font::font_face_ptr font_face, float font_size)
enable the given font face with the given size in pixels
virtual void push_pixel_coords()=0
use this to push new modelview and new projection matrices onto the transformation stacks such that x...
virtual void set_cursor(int x, int y)
flush the output_stream and set a new cursor position given in opengl coordinates with (0,...
void set_gamma(float _gamma)
set the current per channel gamma values to single value
void pop_modelview_matrix()
see push_V for an explanation
void push_modelview_matrix()
push the current viewing matrix onto a matrix stack for viewing matrices.
virtual void pop_pixel_coords()=0
pop previously pushed transformation matrices from modelview and projection stacks
void tesselate_unit_square(bool flip_normals=false, bool edges=false)
tesselate a unit square in the xy-plane with texture coordinates
virtual shader_program & ref_surface_shader_program(bool texture_support=false)=0
return a reference to the default shader program used to render surfaces
view * find_view_as_node(size_t view_idx=0) const
convenience function to find the view control in the current hierarchy
void post_redraw()
posts a redraw event to the current context if one is available
bool create(const context &ctx, int _width=-1, int _height=-1)
create framebuffer if extension is supported, otherwise return false.
void push_viewport(context &ctx, const dvec2 &depth_range=dvec2(0, 1))
push a new window transformation to cover the fbo onto the window transformation stack
bool is_complete(const context &ctx) const
check for completeness, if not complete, get the reason in last_error
int get_width() const
return the width
void pop_viewport(context &ctx)
recover the window transformation array active before the last call to push_viewport
void destruct(const context &ctx)
destruct the framebuffer objext
bool attach(const context &ctx, const render_buffer &rb, int i=0)
attach render buffer to depth buffer if it is a depth buffer, to stencil if it is a stencil buffer or...
bool enable(context &ctx, int i0=-1, int i1=-1, int i2=-1, int i3=-1, int i4=-1, int i5=-1, int i6=-1, int i7=-1, int i8=-1, int i9=-1, int i10=-1, int i11=-1, int i12=-1, int i13=-1, int i14=-1, int i15=-1)
enable the framebuffer either with all color attachments if no arguments are given or if arguments ar...
bool disable(context &ctx)
disable the framebuffer object
bool bind(context &ctx, shader_program &prog, bool force_success, int aa_index=-1)
override to restrict bind function to first aa as second is used for wireframe rendering
void construct(cgv::render::context &ctx, cgv::media::mesh::simple_mesh< T > &mesh, std::vector< idx_type > *tuple_pos_indices=nullptr, std::vector< idx_type > *tuple_normal_indices=nullptr, int *num_floats_in_vertex=nullptr)
Construct mesh render info from a given simple mesh and store all vertex attributes in interleaved in...
bool is_constructed() const
check whether vbos are constructed
virtual bool is_created() const
return whether component has been created
void draw_all(context &ctx, bool skip_opaque=false, bool skip_blended=false, bool use_materials=true)
execute all draw calls
bool validate_and_enable(context &ctx)
validate attributes and if successful, enable renderer
void set_render_style(const render_style &rs)
reference given render style
void set_color_array(const context &ctx, const std::vector< T > &colors)
template method to set the color attribute from a vector of colors of type T
virtual bool render(context &ctx, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1)
Convenience function that draws vertex or indexed element with this renderer.
a shader program combines several shader code fragments to a complete definition of the shading pipel...
bool enable(context &ctx)
enable the shader program
bool disable(context &ctx)
disable shader program and restore fixed functionality
bool set_uniform(const context &ctx, const std::string &name, const T &value, bool generate_error=false)
Set the value of a uniform by name, where the type can be any of int, unsigned, float,...
bool is_linked() const
return whether program is linked
bool build_program(const context &ctx, const std::string &file_name, bool show_error=false, const shader_define_map &defines=shader_define_map())
successively calls create, attach_program and link.
bool generate_mipmaps(const context &ctx)
generate mipmaps automatically, only supported if framebuffer objects are supported by the GPU
void set_mag_filter(TextureFilter _mag_filter)
set the magnification filter
bool create(const context &ctx, TextureType _tt=TT_UNDEF, unsigned width=-1, unsigned height=-1, unsigned depth=-1)
create the texture of dimension and resolution specified in the data format base class.
bool disable(const context &ctx)
disable texture and restore state from before last enable call
bool enable(const context &ctx, int tex_unit=-1)
enable this texture in the given texture unit, -1 corresponds to the current unit.
bool destruct(const context &ctx)
destruct the texture and free texture memory and handle
bool replace(const context &ctx, int x, const cgv::data::const_data_view &data, int level=-1, const std::vector< cgv::data::data_view > *palettes=0)
replace a block within a 1d texture with the given data.
void set_min_filter(TextureFilter _min_filter, float _anisotropy=2.0f)
set the minification filters, if minification is set to TF_ANISOTROP, the second floating point param...
interface for mono or stereo cameras in VR headsets
bool start()
start streaming of frames
const std::string & get_last_error() const
return last error, if no error has occured, the function returns an empty string
CameraState get_state() const
return the camera state
virtual bool put_projection_matrix(int camera_index, bool undistorted, float z_near, float z_far, float *projection_matrix) const =0
access to 4x4 matrix in column major format for perspective transformation of camera (0....
bool stop()
stop streaming of frames
virtual bool put_camera_intrinsics(int camera_index, bool undistorted, float *focal_length_2d_ptr, float *center_2d_ptr) const =0
write the focal lengths in x- and y-direction to access to focal_length_2d_ptr[0|1] and the texture c...
bool has_error() const
check for error
bool get_gl_texture_id(uint32_t &tex_id, uint32_t &width, uint32_t &height, bool undistorted, float max_valid_texcoord_range[4])
query id of shared opengl texture id
CameraFrameSplit get_frame_split() const
query stereo frame layout
virtual bool put_camera_to_head_matrix(int camera_index, float *pose_matrix) const =0
access to 3x4 matrix in column major format for transformation from camera (0 .. left,...
uint8_t get_nr_cameras() const
return number of cameras in the headset (1 for mono and 2 for stereo)
bool get_frame(std::vector< uint8_t > &frame_data, uint32_t &width, uint32_t &height, bool undistorted, bool maximum_valid_rectangle)
check for a new frame, return false if not available. Otherwise copy frame to provided buffer that is...
a vr kit is composed of headset, two controllers, and two trackers, where all devices can be attached...
vr_camera * get_camera() const
return camera or nullptr if not available
const controller_input_config & get_controller_input_config(int controller_index, int input_index) const
query the configuration of a controller input
const vr_kit_info & get_device_info() const
return information on the currently attached devices
virtual void set_controller_input_config(int controller_index, int input_index, const controller_input_config &cic)
set the configuration of a controller input
virtual void put_eye_to_head_matrix(int eye, float *pose_matrix) const =0
access to 3x4 matrix in column major format for transformation from eye (0..left, 1....
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
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
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...
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
void clear(cgv::render::context &ctx)
clear all objects living in the context like textures or display lists
void init_frame(cgv::render::context &ctx)
this method is called in one pass over all drawables before the draw method
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
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
void on_status_change(void *kit_handle, int ci, vr::VRStatus old_status, vr::VRStatus new_status)
keep track of status changes
void construct_environment(float s, float ew, float ed, float w, float d, float h)
construct boxes for environment
void stream_help(std::ostream &os)
overload to stream help information to the given output stream
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
void on_device_change(void *kit_handle, bool attach)
register on device change events
void draw(cgv::render::context &ctx)
overload to draw the content of this drawable
bool handle(cgv::gui::event &e)
overload and implement this method to handle events
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...
void create_gui()
you must overload this for gui creation
bool init(cgv::render::context &ctx)
this method is called after creation or recreation of the context, return whether all necessary funct...
void compute_intersections(const vec3 &origin, const vec3 &direction, int ci, const rgb &color)
compute intersection points of controller ray with movable boxes
extends the stereo view interactor for vr support
int get_rendered_eye() const
return the currently rendered eye
cgv::dvec3 get_view_dir_of_kit(int vr_kit_idx=-1) const
query view direction of a vr kit
void set_blit_vr_view_width(int width)
set the width with which vr views are blit
void draw_vr_kits(bool do_draw)
set whether to draw vr kits
vr::vr_kit * get_current_vr_kit() const
return a pointer to the current vr kit
void enable_vr_event_debugging(bool enable=true)
set whether vr events should be printed to the console window
cgv::dvec3 get_view_up_dir_of_kit(int vr_kit_idx=-1) const
query view up direction of a vr kit
vr::vr_kit * get_rendered_vr_kit() const
return pointer to rendered vr kit or nullptr if birds eye view is rendered
cgv::dvec3 get_eye_of_kit(int eye=0, int vr_kit_idx=-1) const
query the eye position of a vr kit.
void enable_blit_vr_views(bool enable)
enable vr view blitting
void draw_action_zone(bool do_draw)
whether to draw action zone
void set_event_type_flags(cgv::gui::VREventTypeFlags flags)
set the event type flags of to be emitted events
const vr::vr_kit_state * get_current_vr_state() const
return a pointer to the state of the current vr kit
@ CF_RGBA
color format with components R, G and B
std::string get_stick_action_string(StickAction action)
convert a key action into a readable string
std::string file_open_dialog(const std::string &title, const std::string &filter, const std::string &path)
ask the user for a file name to open a file.
void message(const std::string &_message)
tell the user something with a message box
vr_server & ref_vr_server()
return a reference to gamepad server singleton
@ KA_RELEASE
key release action
@ SA_DRAG
stick moved in pressed state
@ SA_RELEASE
stick release action
@ SA_PRESS
stick press action
@ SA_TOUCH
stick touch action
@ SA_UNPRESS
stick unpress repeated press action
@ SA_MOVE
stick moved with respect to last event
@ EID_POSE
id for a 6D pose change events
@ EID_STICK
id of a stick event describing a two axis controller that optionally can be touched and pressed
@ EID_KEY
id for key event
@ EID_THROTTLE
id of throttle event describing a one axis controller
std::string file_save_dialog(const std::string &title, const std::string &filter, const std::string &path)
ask the user for a file name to save a file.
VREventTypeFlags
flags to define which events should be generated by server
@ VRE_ONE_AXIS_GENERATES_KEY
whether one axis events should generate a key event when passing inputs threshold value
@ VRE_TWO_AXES
pad / stick events
@ VRE_ONE_AXIS
trigger / throttle / pedal events
@ VRE_STATUS
status change events
@ VRE_TWO_AXES_GENERATES_DPAD
whether two axes input generates direction pad keys when presses
@ VRE_DEVICE
device change events
void connect_vr_server(bool connect_device_change_only_to_animation_trigger, cgv::gui::window_ptr w)
connect the gamepad server to the given window or the first window of the application,...
@ EF_VR
whether event is from VR kit
cone_renderer & ref_cone_renderer(context &ctx, int ref_count_change)
reference to a singleton cone renderer that is shared among drawables
box_renderer & ref_box_renderer(context &ctx, int ref_count_change)
reference to a singleton box renderer that is shared among drawables
sphere_renderer & ref_sphere_renderer(context &ctx, int ref_count_change)
reference to a singleton sphere renderer that can be shared among drawables
@ TI_UINT8
signed integer stored in 64 bits
DummyEnum
some enum to mark an integral parameter to be of enum type
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
char to_lower(char c)
convert char to lower case
bool has_option(const std::string &option)
check whether the system variable CGV_OPTIONS contains the given option (the comparison is case insen...
vr_kit * get_vr_kit(void *handle)
query a pointer to a vr kit by its device handle, function can return null pointer in case that no vr...
bool configure_seethrough_shader_program(cgv::render::context &ctx, cgv::render::shader_program &prog, uint32_t frame_width, uint32_t frame_height, const vr_kit *vr_kit_ptr, const vr_kit_state &state, float z_near, float z_far, int eye, bool undistorted)
set all uniforms of seethrough shader program for a given camera (0 ... left or mono,...
cgv::mat4 get_mat4_from_pose(const float pose_matrix[12])
convert pose to mat4
VRStatus
different status values for a trackable
@ VRS_TRACKED
trackable is connected and tracked
@ VRS_DETACHED
trackable is not reachable via wireless
@ VR_DPAD_RIGHT
direction pad right
Helper functions to access cgv options provided in the CGV_OPTIONS environment variable.
Helper functions to process strings.
helper class whose constructor calls the define_registration_order() function
float radius
default value assigned to radius attribute in enable method of sphere renderer, set to 1 in construct...
int32_t nr_inputs
number of used inputs
void put_ray(float *ray_origin, float *ray_direction) const
place the 3d ray origin and the 3d ray direction into the given arrays which must provide space for 3...
vr_controller_info controller[max_nr_controllers]
information for attached controllers and trackers
structure that stores all information describing the state of a VR kit
vr_controller_state controller[max_nr_controllers]
status, pose, button, axes, and vibration information of up to vr::max_nr_controllers controller and ...
VRStatus status
whether trackable is currently tracked, only in case of true, the pose member contains useful informa...
example plugin for vr usage