+ 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]->rotation);
+
+ 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;
+ exslot[i]->rotation = sel.ex->node->get_rotation();
+ debug_log("Grabbing with rot: %f %f %f %f\n", exslot[i]->rotation.x,
+ exslot[i]->rotation.y, exslot[i]->rotation.z, exslot[i]->rotation.w);
+ 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) {
+ ex->node->set_rotation(exslot[i]->node.get_rotation());
+ 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;
+ }
+ }