Clouds WIP clouds
authorLuke Lau <luke_lau@icloud.com>
Fri, 20 Mar 2020 22:46:31 +0000 (22:46 +0000)
committerLuke Lau <luke_lau@icloud.com>
Fri, 20 Mar 2020 22:46:31 +0000 (22:46 +0000)
clouds.cpp [new file with mode: 0644]
clouds.hpp [new file with mode: 0644]

diff --git a/clouds.cpp b/clouds.cpp
new file mode 100644 (file)
index 0000000..5fe2bb8
--- /dev/null
@@ -0,0 +1,52 @@
+#include "clouds.hpp"
+#include <cmath>
+#include <GL/glew.h>
+
+float w(int i, int j, int k) { return 1; }
+
+const float metaballR = 1;
+float metaballField(float r) {
+       if (r > metaballR) return 0;
+       const float a = r / metaballR;
+       return (-4.f/9.f * powf(a, 6)) + (17.f/9.f * powf(a, 4)) - (22.f/9.f * powf(a, 2)) + 1;
+}
+
+const float normalizationFactor = 748.f / 405.f * M_PI * metaballR;
+
+void calcContDist(Clouds *clds, float t) {
+       const int i0 = 2, j0 = 2, k0 = 2, t0 = 2;
+       const float divisor = 1.f / 
+                                       ((2 * t0 + 1) *
+                                        (2 * k0 + 1) *
+                                        (2 * j0 + 1) *
+                                        (2 * i0 + 1));
+       float sum = 0;
+       for (int i = 0; i < CLOUD_DIM; i++) {
+               for (int j = 0; j < CLOUD_DIM; j++) {
+                       for (int k = 0; k < CLOUD_DIM; k++) {
+
+
+                               // inner sums
+                               /* for (int tp = -t0, tp < t0; tp++) { */
+                                       for (int ip = -i0; ip < i0; ip++) {
+                                               for (int jp = -j0; jp < j0; jp++) {
+                                                       for (int kp = -k0; kp < k0; kp++) {
+
+
+                                                               sum += w(ip, jp, kp) * (float)clds->cld[i + ip][j + jp][k + kp];
+
+                                                       }
+                                               }
+                                       }
+                               /* } */
+
+                               clds->contDist[i][j][k] = sum / divisor;
+
+                       }
+               }
+       }
+}
+
+void renderBillboard() {
+       
+}
diff --git a/clouds.hpp b/clouds.hpp
new file mode 100644 (file)
index 0000000..1a8496d
--- /dev/null
@@ -0,0 +1,9 @@
+static const int CLOUD_DIM = 16;
+struct Clouds {
+       char cld[CLOUD_DIM][CLOUD_DIM][CLOUD_DIM];
+       float contDist[CLOUD_DIM][CLOUD_DIM][CLOUD_DIM];
+};
+
+
+// calculate continuous distribution
+void calcContDist(Clouds *clds);