-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);
+ // update hand-tracking
+ if(have_handtracking) {
+ update_vrhands(&avatar);
+
+ ExSelection *exsel_grab[] = { &exsel_grab_left, &exsel_grab_right };
+ ExhibitSlot *exslot[] = { &exslot_left, &exslot_right };
+
+ for(int i=0; i<2; i++) {
+ if(vrhand[i].valid) {
+ exslot[i]->node.set_position(vrhand[i].pos);
+ exslot[i]->node.set_rotation(vrhand[i].rot * exslot[i]->grab_rot);
+
+ bool act_grab = goatvr_action(i, GOATVR_ACTION_GRAB) != 0;
+
+ ExSelection sel;
+ sel = exman->select(Sphere(vrhand[i].pos, 10));
+
+ if(!*exsel_grab[i]) {
+ // we don't have an exhibit grabbed
+ if(act_grab) {
+ // grab an exhibit
+ *exsel_grab[i] = sel;
+ //SceneNode *objnode = sel.ex->node->find_object_node();
+ //exslot[i]->rotation = normalize(sel.ex->node->get_rotation());
+ exslot[i]->grab_rot = inverse(vrhand[i].rot);
+ exslot[i]->attach_exhibit(sel.ex, EXSLOT_ATTACH_TRANSIENT);
+ if(exsel_active) {
+ exsel_active = ExSelection::null; // cancel active on grab
+ }
+ } else {
+ // just hover
+ exsel_hover = sel;
+ }
+ } else {
+ // we have an exhibit grabbed
+ if(!act_grab) {
+ // drop it
+ Exhibit *ex = exsel_grab[i]->ex;
+ exslot[i]->detach_exhibit();
+
+ ExhibitSlot *slot = exman->nearest_empty_slot(vrhand[i].pos, 100);
+ if(!slot) {
+ debug_log("no empty slot nearby\n");
+ if(ex->prev_slot && ex->prev_slot->empty()) {
+ slot = ex->prev_slot;
+ debug_log("using previous slot\n");
+ }
+ }
+
+ if(slot) {
+ Quat rot = normalize(exslot[i]->node.get_rotation());
+ ex->node->set_rotation(rot);
+ slot->attach_exhibit(ex);
+ } else {
+ // nowhere to put it, stash it for later
+ exman->stash_exhibit(ex);
+ debug_log("no slots available, stashing\n");
+ }
+
+ *exsel_grab[i] = ExSelection::null;
+ exslot[i]->grab_rot = Quat::identity;
+ }
+ }
+ }
+ }
+
+ // if there are no grabs, and we're pointing with the right finger, override active
+ if(!exsel_grab_left && !exsel_grab_right) {
+ if(goatvr_action(1, GOATVR_ACTION_POINT)) {
+ Ray ray;
+ ray.origin = vrhand[1].pos;
+ ray.dir = rotate(Vec3(0, 0, -1), vrhand[1].rot);
+ exsel_active = exman->select(ray);
+ pointing = true;
+ } else {
+ exsel_active = ExSelection::null;
+ pointing = false;
+ }
+ }
+
+ } 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
+ Quat rot;
+ rot.set_rotation(Vec3(0, 1, 0), deg_to_rad(-avatar.body_rot));
+ exslot_left.node.set_rotation(rot);
+ }
+
+ 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);
+
+ // need to call this *after* we have updated the active exhibit (if any)
+ exui_update(dt);