+bool needsRedisplay = false;
+void timer(int _) {
+ /* calculateMetaballs(); */
+ if (needsRedisplay) {
+ glutPostRedisplay();
+ }
+ needsRedisplay = false;
+ glutTimerFunc(16, timer, 0);
+}
+
+void keyboard(unsigned char key, int x, int y) {
+ if (key == ' ') {
+ calculateMetaballs();
+ needsRedisplay = true;
+ needsReshading = true;
+ }
+ if (key == '0') {
+ curMode = render;
+ needsRedisplay = true;
+ }
+ if (key == '1') {
+ curMode = debugContDist;
+ needsRedisplay = true;
+ }
+ if (key == '2') {
+ curMode = debugProbAct;
+ needsRedisplay = true;
+ }
+ if (key == '3') {
+ curMode = debugProbExt;
+ needsRedisplay = true;
+ }
+}
+
+int prevMouseX, prevMouseY;
+bool firstMouse = true;
+void motion(int x, int y) {
+ if (firstMouse) {
+ prevMouseX = x;
+ prevMouseY = y;
+ firstMouse = false;
+ }
+ float dx = x - prevMouseX, dy = y - prevMouseY;
+ prevMouseX = x;
+ prevMouseY = y;
+ const vec3 origin(0, 18, 0);
+ const float sensitivity = 0.003f;
+ auto camMat = translate(mat4(1), origin + camPos);
+ auto rotation = rotate(rotate(mat4(1), -dx * sensitivity, {0, 1, 0}),
+ -dy * sensitivity, {1, 0, 0});
+ auto rotAroundOrig = camMat * rotation * translate(mat4(1), origin - camPos);
+ camPos = rotAroundOrig * glm::vec4(camPos, 0);
+ needsRedisplay = true;
+}
+
+void passiveMotion(int x, int y) {
+ prevMouseX = x;
+ prevMouseY = y;
+}
+