-static void set_light(int idx, const Vec3 &pos, const Vec3 &color)
-{
- unsigned int lt = GL_LIGHT0 + idx;
- float posv[] = { pos.x, pos.y, pos.z, 1 };
- float colv[] = { color.x, color.y, color.z, 1 };
-
- glEnable(lt);
- glLightfv(lt, GL_POSITION, posv);
- glLightfv(lt, GL_DIFFUSE, colv);
- glLightfv(lt, GL_SPECULAR, colv);
+ // TODO move to the avatar system
+ // calculate mouselook view matrix
+ mouse_view_matrix = Mat4::identity;
+ mouse_view_matrix.pre_translate(0, 0, -cam_dist);
+ if(!have_headtracking) {
+ mouse_view_matrix.pre_rotate_x(deg_to_rad(avatar.head_alt));
+ }
+ mouse_view_matrix.pre_rotate_y(deg_to_rad(avatar.body_rot));
+ mouse_view_matrix.pre_translate(-avatar.pos.x, -avatar.pos.y, -avatar.pos.z);
+
+
+ // update hand-tracking
+ if(have_handtracking) {
+ update_vrhands(&avatar);
+
+ if(vrhand[0].valid) {
+ exslot_left.node.set_position(vrhand[0].pos);
+ exslot_left.node.set_rotation(vrhand[0].rot);
+
+ // right hand takes precedence for hover
+ if(!exsel_grab_left && !exsel_hover) {
+ exsel_hover = exman->select(Sphere(vrhand[0].pos, 5));
+ }
+ }
+ if(vrhand[1].valid) {
+ exslot_right.node.set_position(vrhand[1].pos);
+ exslot_right.node.set_rotation(vrhand[1].rot);
+
+ if(!exsel_grab_right) {
+ exsel_hover = exman->select(Sphere(vrhand[1].pos, 5));
+ }
+ }
+
+ } else {
+ // check if an exhibit is hovered-over by mouse (only if we don't have one grabbed)
+ if(!exsel_grab_mouse) {
+ Ray ray = calc_pick_ray(prev_mx, prev_my);
+ exsel_hover = exman->select(ray);
+ }
+
+ // TODO do this properly
+ // set the position of the left hand at a suitable position for the exhibit UI
+ dir = rotate(Vec3(-0.46, -0.1, -1), Vec3(0, 1, 0), deg_to_rad(-avatar.body_rot));
+ exslot_left.node.set_position(avatar.pos + dir * 30); // magic: distance in front
+ }
+
+ if(!exslot_right.empty()) exslot_right.node.update(dt);
+ // always update the left slot, because it's the anchor point of the exhibit ui
+ exslot_left.node.update(dt);