+static double prev_x, prev_y;
+static int bnstate[8];
+
+static void motion_clbk(GLFWwindow *win, double x, double y)
+{
+ int dx = x - prev_x;
+ int dy = y - prev_y;
+
+ prev_x = x;
+ prev_y = y;
+
+ if(!dx && !dy) return;
+
+ if(bnstate[0]) {
+ camera->theta += dx * 0.5;
+ camera->phi += dy * 0.5;
+
+ if(camera->phi < -90) camera->phi = -90;
+ if(camera->phi > 90) camera->phi = 90;
+ }
+ if(bnstate[2]) {
+ camera->distance += dy * 0.1;
+ if(camera->distance < 0.0) camera->distance = 0.0;
+ }
+}
+
+static void mouse_clbk(GLFWwindow *win, int bn, int action, int mods)
+{
+ bnstate[bn - GLFW_MOUSE_BUTTON_LEFT] = action == GLFW_PRESS ? 1 : 0;
+ glfwGetCursorPos(win, &prev_x, &prev_y);
+}
+