Fix ellipsoids in simulation
[clouds.git] / clouds.cpp
index 52b3053812d8f16416361e519270e8df1bd23dfa..baabcba703d4aca0e44e80f142e7eb97a82ed1c7 100644 (file)
 
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
 
-bool debugContDist = false;
+enum Mode {
+  render,
+  debugContDist,
+  debugProbExt,
+  debugProbAct
+};
+Mode curMode = render;
 
 using namespace std;
 using namespace glm;
@@ -85,6 +91,7 @@ void precalculateBillboardTextures() {
 
 struct Metaball {
   vec3 pos;
+  ivec3 coords;
   /** Radius, density */
   float r, d;
   vec4 col;
@@ -109,6 +116,7 @@ void calculateMetaballs() {
       for (int k = 0; k < CLOUD_DIM; k++) {
         Metaball m = {
             {i / (float)CLOUD_DIM, j / (float)CLOUD_DIM, k / (float)CLOUD_DIM},
+            {i, j, k},
             1.f / (float)CLOUD_DIM};
         m.pos = (m.pos * vec3(2)) - vec3(1);
         m.d = cs.q[i][j][k];
@@ -224,7 +232,7 @@ void renderClouds() {
     return distance(camPos, a.pos) > distance(camPos, b.pos);
   });
 
-  glUniform1i(glGetUniformLocation(bbProg, "debugContDist"), debugContDist);
+  glUniform1i(glGetUniformLocation(bbProg, "debug"), curMode != render);
 
   glDisable(GL_DEPTH_TEST);
   glEnable(GL_BLEND);
@@ -258,8 +266,12 @@ void renderClouds() {
     // Don't modulate it -- blend it
     glUniform1i(glGetUniformLocation(bbProg, "modulate"), 0);
 
-    if (debugContDist) {
-      glUniform1f(glGetUniformLocation(bbProg, "density"), k.d);
+    if (curMode != render) {
+      float debugVal = 0;
+      if (curMode == debugContDist) debugVal = k.d;
+      else if (curMode == debugProbAct) debugVal = cs.p_act[k.coords.x][k.coords.y][k.coords.z];
+      else if (curMode == debugProbExt) debugVal = cs.p_ext[k.coords.x][k.coords.y][k.coords.z];
+      glUniform1f(glGetUniformLocation(bbProg, "debugVal"), debugVal);
       glDisable(GL_BLEND);
       model = scale(model, vec3(0.02));
       glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
@@ -301,8 +313,8 @@ void timer(int _) {
   /* calculateMetaballs(); */
   if (needsRedisplay) {
     glutPostRedisplay();
-    needsRedisplay = false;
   }
+  needsRedisplay = false;
   glutTimerFunc(16, timer, 0);
 }
 
@@ -312,8 +324,20 @@ void keyboard(unsigned char key, int x, int y) {
     needsRedisplay = true;
     needsReshading = true;
   }
-  if (key == 'd') {
-    debugContDist = !debugContDist;
+  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;
   }
 }