+static double prev_x, prev_y;
+static int button;
+
+static void motion_clbk(GLFWwindow *win, double x, double y)
+{
+ switch(button) {
+ case GLFW_MOUSE_BUTTON_LEFT:
+ theta += x - prev_x;
+ phi += y - prev_y;
+
+ if(phi < -90)
+ phi = -90;
+ if(phi > 90)
+ phi = 90;
+
+ break;
+
+ case GLFW_MOUSE_BUTTON_RIGHT:
+ dist *= (y - prev_y) * 0.01 + 1;
+ if(dist < 0.0) {
+ dist = 0.0;
+ }
+ break;
+ }
+
+ prev_x = x;
+ prev_y = y;
+}
+
+static void mouse_clbk(GLFWwindow *win, int bn, int action, int mods)
+{
+ button = bn;
+ glfwGetCursorPos(win, &prev_x, &prev_y);
+}
+