fullscreen, mouse grab, stuff
[laserbrain_demo] / src / app.cc
index 96b3f86..065e581 100644 (file)
@@ -24,7 +24,7 @@ static Vec3 cam_pos;
 static float floor_y;  // last floor height
 static float user_eye_height = 165;
 
-static float walk_speed = 400.0f;
+static float walk_speed = 300.0f;
 static bool show_walk_mesh, noclip = false;
 
 static int prev_mx, prev_my;
@@ -250,6 +250,15 @@ void app_keyboard(int key, bool pressed)
                        app_quit();
                        break;
 
+               case 'f':
+                       app_toggle_fullscreen();
+                       break;
+
+               case '`':
+                       app_toggle_grab_mouse();
+                       show_message("mouse %s", app_is_mouse_grabbed() ? "grabbed" : "released");
+                       break;
+
                case 'w':
                        if(mod & MOD_CTRL) {
                                show_walk_mesh = !show_walk_mesh;
@@ -288,6 +297,21 @@ void app_mouse_button(int bn, bool pressed, int x, int y)
        bnstate[bn] = pressed;
 }
 
+static inline void mouse_look(int dx, int dy)
+{
+       cam_theta += dx * 0.5;
+       cam_phi += dy * 0.5;
+
+       if(cam_phi < -90) cam_phi = -90;
+       if(cam_phi > 90) cam_phi = 90;
+}
+
+static void mouse_zoom(int dx, int dy)
+{
+       cam_dist += dy * 0.1;
+       if(cam_dist < 0.0) cam_dist = 0.0;
+}
+
 void app_mouse_motion(int x, int y)
 {
        int dx = x - prev_mx;
@@ -297,20 +321,19 @@ void app_mouse_motion(int x, int y)
 
        if(!dx && !dy) return;
 
-       app_mouse_delta(dx, dy);
+       if(bnstate[0]) {
+               mouse_look(dx, dy);
+       }
+       if(bnstate[2]) {
+               mouse_zoom(dx, dy);
+       }
 }
 
 void app_mouse_delta(int dx, int dy)
 {
-       if(bnstate[0]) {
-               cam_theta += dx * 0.5;
-               cam_phi += dy * 0.5;
-
-               if(cam_phi < -90) cam_phi = -90;
-               if(cam_phi > 90) cam_phi = 90;
-       }
        if(bnstate[2]) {
-               cam_dist += dy * 0.1;
-               if(cam_dist < 0.0) cam_dist = 0.0;
+               mouse_zoom(dx, dy);
+       } else {
+               mouse_look(dx, dy);
        }
 }