+ if(noclip) {
+ avatar.pos = newpos;
+ } else {
+ if(!constrain_walk_mesh(newpos, &avatar.pos)) {
+ float dtheta = M_PI / 32.0;
+ float theta = dtheta;
+ Vec2 dir2d = newpos.xz() - avatar.pos.xz();
+
+ for(int i=0; i<16; i++) {
+ Vec2 dvec = rotate(dir2d, theta);
+ Vec3 pos = avatar.pos + Vec3(dvec.x, 0, dvec.y);
+ if(constrain_walk_mesh(pos, &avatar.pos)) {
+ break;
+ }
+ dvec = rotate(dir2d, -theta);
+ pos = avatar.pos + Vec3(dvec.x, 0, dvec.y);
+ if(constrain_walk_mesh(pos, &avatar.pos)) {
+ break;
+ }
+ theta += dtheta;
+ }
+ }
+ floor_y = avatar.pos.y - user_eye_height;
+ }
+
+ if(have_headtracking) {
+ Quat qhead;
+ goatvr_head_orientation(&qhead.x);
+ avatar.tracked_head_rotation(qhead);
+ }
+
+ // 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);
+
+ 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();