select and move exhibits
[laserbrain_demo] / src / app.cc
index 25c59b3..59d713c 100644 (file)
@@ -72,7 +72,7 @@ static ExhibitManager *exman;
 static BlobExhibit *blobs;
 static bool show_blobs;
 
-static ExSelection ex_sel;
+ExSelection exsel_grab, exsel_hover;
 
 static Renderer *rend;
 
@@ -343,6 +343,13 @@ static void update(float dt)
        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);
 
+       // check if an exhibit is hovered-over by mouse or 6dof
+       // XXX note: using previous view/proj matrix lattency shouldn't be an issue but
+       //           make sure state-creep doesn't get us
+       // XXX also this mouse-picking probably should only be active in non-VR mode
+       Ray ray = calc_pick_ray(prev_mx, prev_my);
+       exsel_hover = exman->select(ray);
+
        // update hand-tracking
        if(have_handtracking) {
                update_vrhands(&avatar);
@@ -605,11 +612,11 @@ void app_mouse_button(int bn, bool pressed, int x, int y)
 
        if(bn == 0) {
                if(!pressed) {
-                       if(ex_sel.ex) {
-                               ex_sel.ex = 0;
+                       if(exsel_grab.ex) {
+                               exsel_grab.ex = 0;
                        } else {
                                Ray ray = calc_pick_ray(x, y);
-                               ex_sel = exman->select(ray);
+                               exsel_grab = exman->select(ray);
                        }
                }
        }
@@ -645,11 +652,11 @@ void app_mouse_motion(int x, int y)
 
        if(!dx && !dy) return;
 
-       if(ex_sel.ex) {
-               Vec3 pos = ex_sel.ex->node->get_node_position();
+       if(exsel_grab.ex) {
+               Vec3 pos = exsel_grab.ex->node->get_node_position();
                Vec3 dir = transpose(view_matrix.upper3x3()) * Vec3(dx * 1.0, dy * -1.0, 0);
 
-               ex_sel.ex->node->set_position(pos + dir);
+               exsel_grab.ex->node->set_position(pos + dir);
        }
 
        if(bnstate[2]) {