Kajetan Johannes Hammerle 3 years ago
parent
commit
bbca8fff63
4 changed files with 199 additions and 286 deletions
  1. 3 285
      Game.cpp
  2. 183 0
      MarchingCubes.cpp
  3. 11 0
      MarchingCubes.h
  4. 2 1
      meson.build

+ 3 - 285
Game.cpp

@@ -2,6 +2,7 @@
 #include <iostream>
 
 #include "Game.h"
+#include "MarchingCubes.h"
 #include "gaming-core/utils/Array.h"
 #include "gaming-core/utils/List.h"
 #include "gaming-core/utils/Random.h"
@@ -10,14 +11,6 @@
 // static GLuint texture3d;
 static List<Vector3, 122880> list;
 static float tData[16][16][16];
-static Array<List<Array<Vector3, 3>, 4>, 256> table;
-static List<Vector3, 50> points;
-
-static int known[15] = {0b00000000, 0b10000000, 0b11000000, 0b10000100,
-                        0b01110000, 0b11110000, 0b01111000, 0b10100101,
-                        0b10110001, 0b01110001, 0b10000010, 0b11000010,
-                        0b01001010, 0b10101010, 0b10110010};
-static Array<List<Array<Vector3, 3>, 4>, 15> knownTable;
 
 static void addCube(int x, int y, int z) {
     bool b1 = tData[x][y][z] < 0.5f;
@@ -34,267 +27,11 @@ static void addCube(int x, int y, int z) {
 
     Vector3 v(static_cast<float>(x), static_cast<float>(y),
               static_cast<float>(z));
-
-    for(int i = 0; i < table[index].getLength(); i++) {
-        list.add(table[index][i][0] + v);
-        list.add(table[index][i][1] + v);
-        list.add(table[index][i][2] + v);
-    }
-
-    // if(b1) {
-    //    list.add(Vector3(x - 0.1f, y + 0.0f, z + 0.0f));
-    //    list.add(Vector3(x + 0.0f, y - 0.1f, z + 0.0f));
-    //    list.add(Vector3(x + 0.0f, y + 0.0f, z - 0.1f));
-    //}
-}
-
-static void addKnownTable(int index, const Vector3& a, const Vector3& b,
-                          const Vector3& c) {
-    Array<Vector3, 3> array;
-    array[0] = a;
-    array[1] = b;
-    array[2] = c;
-    knownTable[index].add(array);
-}
-
-static int swapBits(int index, int a, int b) {
-    int bitA = (index & (1 << a)) != 0;
-    int bitB = (index & (1 << b)) != 0;
-    index &= ~((1 << a) | (1 << b));
-    index |= bitA << b;
-    index |= bitB << a;
-    return index;
-}
-
-static int flipYZ(int index) {
-    index = swapBits(index, 0, 1);
-    index = swapBits(index, 3, 2);
-    index = swapBits(index, 4, 5);
-    index = swapBits(index, 7, 6);
-    return index;
-}
-
-static int flipXY(int index) {
-    index = swapBits(index, 0, 3);
-    index = swapBits(index, 1, 2);
-    index = swapBits(index, 4, 7);
-    index = swapBits(index, 5, 6);
-    return index;
-}
-
-static int rotateY(int index) {
-    index = swapBits(index, 0, 1);
-    index = swapBits(index, 0, 3);
-    index = swapBits(index, 3, 2);
-    index = swapBits(index, 4, 5);
-    index = swapBits(index, 4, 7);
-    index = swapBits(index, 7, 6);
-    return index;
-}
-
-static int rotateZ(int index) {
-    index = swapBits(index, 0, 1);
-    index = swapBits(index, 0, 4);
-    index = swapBits(index, 4, 5);
-    index = swapBits(index, 3, 2);
-    index = swapBits(index, 3, 7);
-    index = swapBits(index, 7, 6);
-    return index;
-}
-
-static int rotateX(int index) {
-    index = swapBits(index, 2, 1);
-    index = swapBits(index, 1, 5);
-    index = swapBits(index, 5, 6);
-    index = swapBits(index, 3, 0);
-    index = swapBits(index, 0, 4);
-    index = swapBits(index, 4, 7);
-    return index;
-}
-
-static void flipYZ(List<Array<Vector3, 3>, 4>& perm) {
-    Matrix m;
-    m.translateX(-0.5f);
-    m.scale(Vector3(-1.0f, 1.0f, 1.0f));
-    m.translateX(0.5f);
-    for(int i = 0; i < perm.getLength(); i++) {
-        perm[i][0] = m * perm[i][0];
-        perm[i][1] = m * perm[i][1];
-        perm[i][2] = m * perm[i][2];
-    }
-}
-
-static void flipXY(List<Array<Vector3, 3>, 4>& perm) {
-    Matrix m;
-    m.translateZ(-0.5f);
-    m.scale(Vector3(1.0f, 1.0f, -1.0f));
-    m.translateZ(0.5f);
-    for(int i = 0; i < perm.getLength(); i++) {
-        perm[i][0] = m * perm[i][0];
-        perm[i][1] = m * perm[i][1];
-        perm[i][2] = m * perm[i][2];
-    }
-}
-
-static void applyMatrix(List<Array<Vector3, 3>, 4>& perm, Matrix& m) {
-    for(int i = 0; i < perm.getLength(); i++) {
-        perm[i][0] = m * perm[i][0];
-        perm[i][1] = m * perm[i][1];
-        perm[i][2] = m * perm[i][2];
+    for(int i = 0; i < 12; i++) {
+        list.add(MarchingCubes::getVector(index, i) + v);
     }
 }
 
-static bool check(int index) {
-    Matrix m;
-    for(int i = 0; i < 15; i++) {
-        List<Array<Vector3, 3>, 4> perm = knownTable[i];
-        int normal = index;
-        for(int h = 0; h < 4; h++) {
-            for(int w = 0; w < 4; w++) {
-                for(int k = 0; k < 4; k++) {
-                    for(int l = 0; l < 2; l++) {
-                        /*if(known[i] == flipXY(flipYZ((normal)))) {
-                            flipYZ(perm);
-                            flipXY(perm);
-                            table[index] = perm;
-                            return false;
-                        } else*/
-                        if(known[i] == normal) {
-                            Matrix m2;
-                            m2.translate(Vector3(-0.5f, -0.5f, -0.5f));
-                            m *= m2;
-                            m.translate(Vector3(0.5f, 0.5f, 0.5f));
-                            applyMatrix(perm, m);
-                            table[index] = perm;
-                            return false;
-                        }
-                        normal = ((~normal) & 0xFF);
-                    }
-                    normal = rotateY(normal);
-                    Matrix m2;
-                    m2.rotateY(-90.0f);
-                    m *= m2;
-                }
-                normal = rotateZ(normal);
-                Matrix m2;
-                m2.rotateZ(90.0f);
-                m *= m2;
-            }
-            normal = rotateX(normal);
-            Matrix m2;
-            m2.rotateX(90.0f);
-            m *= m2;
-        }
-    }
-    return true;
-}
-
-static void generateTable() {
-    addKnownTable(1, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.5f, 0.0f),
-                  Vector3(0.0f, 0.0f, 0.5f));
-
-    addKnownTable(2, Vector3(0.0f, 0.0f, 0.5f), Vector3(1.0f, 0.0f, 0.5f),
-                  Vector3(0.0f, 0.5f, 0.0f));
-    addKnownTable(2, Vector3(1.0f, 0.0f, 0.5f), Vector3(0.0f, 0.5f, 0.0f),
-                  Vector3(1.0f, 0.5f, 0.0f));
-
-    addKnownTable(3, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.5f, 0.0f),
-                  Vector3(0.0f, 0.0f, 0.5f));
-    addKnownTable(3, Vector3(0.5f, 1.0f, 0.0f), Vector3(1.0f, 0.5f, 0.0f),
-                  Vector3(1.0f, 1.0f, 0.5f));
-
-    addKnownTable(4, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 0.5f),
-                  Vector3(1.0f, 0.5f, 0.0f));
-    addKnownTable(4, Vector3(0.0f, 0.5f, 1.0f), Vector3(0.0f, 0.0f, 0.5f),
-                  Vector3(1.0f, 0.5f, 0.0f));
-    addKnownTable(4, Vector3(0.0f, 0.5f, 1.0f), Vector3(1.0f, 0.5f, 0.0f),
-                  Vector3(1.0f, 0.5f, 1.0f));
-
-    addKnownTable(5, Vector3(0.0f, 0.5f, 0.0f), Vector3(1.0f, 0.5f, 0.0f),
-                  Vector3(0.0f, 0.5f, 1.0f));
-    addKnownTable(5, Vector3(1.0f, 0.5f, 1.0f), Vector3(1.0f, 0.5f, 0.0f),
-                  Vector3(0.0f, 0.5f, 1.0f));
-
-    addKnownTable(6, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 0.5f),
-                  Vector3(1.0f, 0.5f, 0.0f));
-    addKnownTable(6, Vector3(0.0f, 0.5f, 1.0f), Vector3(0.0f, 0.0f, 0.5f),
-                  Vector3(1.0f, 0.5f, 0.0f));
-    addKnownTable(6, Vector3(0.0f, 0.5f, 1.0f), Vector3(0.0f, 0.0f, 0.5f),
-                  Vector3(1.0f, 0.5f, 1.0f));
-    addKnownTable(6, Vector3(0.5f, 1.0f, 0.0f), Vector3(0.0f, 0.5f, 0.0f),
-                  Vector3(0.0f, 1.0f, 0.5f));
-
-    addKnownTable(7, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.5f, 0.0f),
-                  Vector3(0.0f, 0.0f, 0.5f));
-    addKnownTable(7, Vector3(0.5f, 1.0f, 0.0f), Vector3(1.0f, 0.5f, 0.0f),
-                  Vector3(1.0f, 1.0f, 0.5f));
-    addKnownTable(7, Vector3(0.5f, 1.0f, 1.0f), Vector3(0.0f, 0.5f, 1.0f),
-                  Vector3(0.0f, 1.0f, 0.5f));
-    addKnownTable(7, Vector3(0.5f, 1.0f, 0.0f), Vector3(1.0f, 0.5f, 0.0f),
-                  Vector3(1.0f, 1.0f, 0.5f));
-
-    addKnownTable(8, Vector3(0.0f, 0.5f, 0.0f), Vector3(0.0f, 1.0f, 0.5f),
-                  Vector3(0.5f, 1.0f, 1.0f));
-    addKnownTable(8, Vector3(0.0f, 0.5f, 0.0f), Vector3(0.5f, 0.0f, 0.0f),
-                  Vector3(0.5f, 1.0f, 1.0f));
-    addKnownTable(8, Vector3(1.0f, 0.5f, 1.0f), Vector3(0.5f, 0.0f, 0.0f),
-                  Vector3(0.5f, 1.0f, 1.0f));
-    addKnownTable(8, Vector3(1.0f, 0.5f, 1.0f), Vector3(0.5f, 0.0f, 0.0f),
-                  Vector3(1.0f, 0.0f, 0.5f));
-
-    addKnownTable(9, Vector3(0.5f, 0.0f, 0.0f), Vector3(1.0f, 0.5f, 1.0f),
-                  Vector3(0.0f, 1.0f, 0.5f));
-    addKnownTable(9, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 0.5f),
-                  Vector3(0.0f, 1.0f, 0.5f));
-    addKnownTable(9, Vector3(0.5f, 1.0f, 1.0f), Vector3(1.0f, 0.5f, 1.0f),
-                  Vector3(0.0f, 1.0f, 0.5f));
-    addKnownTable(9, Vector3(0.5f, 0.0f, 0.0f), Vector3(1.0f, 0.5f, 1.0f),
-                  Vector3(1.0f, 0.5f, 0.0f));
-
-    addKnownTable(10, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.5f, 0.0f),
-                  Vector3(0.0f, 0.0f, 0.5f));
-    addKnownTable(10, Vector3(0.5f, 1.0f, 1.0f), Vector3(1.0f, 0.5f, 1.0f),
-                  Vector3(1.0f, 1.0f, 0.5f));
-
-    addKnownTable(11, Vector3(0.0f, 0.0f, 0.5f), Vector3(1.0f, 0.0f, 0.5f),
-                  Vector3(0.0f, 0.5f, 0.0f));
-    addKnownTable(11, Vector3(1.0f, 0.0f, 0.5f), Vector3(0.0f, 0.5f, 0.0f),
-                  Vector3(1.0f, 0.5f, 0.0f));
-    addKnownTable(11, Vector3(0.5f, 1.0f, 1.0f), Vector3(1.0f, 0.5f, 1.0f),
-                  Vector3(1.0f, 1.0f, 0.5f));
-
-    addKnownTable(12, Vector3(0.5f, 1.0f, 1.0f), Vector3(1.0f, 0.5f, 1.0f),
-                  Vector3(1.0f, 1.0f, 0.5f));
-    addKnownTable(12, Vector3(0.5f, 0.0f, 0.0f), Vector3(1.0f, 0.5f, 0.0f),
-                  Vector3(1.0f, 0.0f, 0.5f));
-    addKnownTable(12, Vector3(0.5f, 1.0f, 0.0f), Vector3(0.0f, 0.5f, 0.0f),
-                  Vector3(0.0f, 1.0f, 0.5f));
-
-    addKnownTable(13, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 0.5f),
-                  Vector3(0.0f, 1.0f, 0.5f));
-    addKnownTable(13, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 1.0f, 0.5f),
-                  Vector3(0.0f, 1.0f, 0.5f));
-    addKnownTable(13, Vector3(1.0f, 0.0f, 0.5f), Vector3(0.5f, 0.0f, 1.0f),
-                  Vector3(0.5f, 1.0f, 1.0f));
-    addKnownTable(13, Vector3(1.0f, 0.0f, 0.5f), Vector3(0.5f, 1.0f, 1.0f),
-                  Vector3(0.5f, 1.0f, 1.0f));
-
-    addKnownTable(14, Vector3(0.0f, 0.5f, 0.0f), Vector3(0.5f, 0.0f, 0.0f),
-                  Vector3(0.0f, 0.5f, 1.0f));
-    addKnownTable(14, Vector3(1.0f, 1.0f, 0.5f), Vector3(0.5f, 0.0f, 0.0f),
-                  Vector3(0.0f, 0.5f, 1.0f));
-    addKnownTable(14, Vector3(1.0f, 1.0f, 0.5f), Vector3(0.5f, 0.0f, 0.0f),
-                  Vector3(1.0f, 0.0f, 0.5f));
-    addKnownTable(14, Vector3(1.0f, 1.0f, 0.5f), Vector3(0.5f, 1.0f, 1.0f),
-                  Vector3(0.0f, 0.5f, 1.0f));
-
-    int counter = 0;
-    for(int i = 0; i < 256; i++) {
-        counter += check(i);
-    }
-    std::cout << "Unsupported: " << counter << "\n";
-}
-
 Game::Game(Shader& shader, Buttons& buttons, const Size& size)
     : shader(shader), buttons(buttons), size(size),
       frustum(60, 0.1f, 1000.0f, size), up(buttons.add(GLFW_KEY_SPACE, "Up")),
@@ -306,23 +43,6 @@ Game::Game(Shader& shader, Buttons& buttons, const Size& size)
     shader.use();
     vertexBuffer.setAttributes(Attributes().addFloat(3));
 
-    generateTable();
-
-    /*Matrix m;
-    m.translate(Vector3(-0.5f, -0.5f, -0.5f));
-    m.rotateX(-90);
-    m.translate(Vector3(0.5f, 0.5f, 0.5f));
-
-    Vector3 v(0.5f, 0.0f, 0.0f);
-    v = m * v;
-    std::cout << v[0] << " " << v[1] << " " << v[2] << "\n";
-    v = m * v;
-    std::cout << v[0] << " " << v[1] << " " << v[2] << "\n";
-    v = m * v;
-    std::cout << v[0] << " " << v[1] << " " << v[2] << "\n";
-    v = m * v;
-    std::cout << v[0] << " " << v[1] << " " << v[2] << "\n";*/
-
     Random r(0);
     for(int x = 0; x < 16; x++) {
         for(int y = 0; y < 16; y++) {
@@ -373,8 +93,6 @@ void Game::render(float lag) {
     m.translate(interPos);
     m.translateZ(-30.0f);
     m.translateX(-8.0f);
-    // m.rotateY(-30.0f);
-    // m.scale(Vector3(0.05f, 0.05f, 1.0f));
     shader.setMatrix("view", m.getValues());
 
     vertexBuffer.draw(list.getLength());

+ 183 - 0
MarchingCubes.cpp

@@ -0,0 +1,183 @@
+#include "MarchingCubes.h"
+
+static Vector3 vectors[13] = {
+    Vector3(0.0f, 0.0f, 0.0f), Vector3(0.5f, 1.0f, 1.0f),
+    Vector3(0.0f, 0.5f, 1.0f), Vector3(0.0f, 1.0f, 0.5f),
+    Vector3(1.0f, 0.5f, 1.0f), Vector3(1.0f, 1.0f, 0.5f),
+    Vector3(0.5f, 1.0f, 0.0f), Vector3(1.0f, 0.5f, 0.0f),
+    Vector3(0.0f, 0.5f, 0.0f), Vector3(0.0f, 0.0f, 0.5f),
+    Vector3(0.5f, 0.0f, 1.0f), Vector3(1.0f, 0.0f, 0.5f),
+    Vector3(0.5f, 0.0f, 0.0f)};
+
+static int table[3072] = {
+    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  2,  3,  0,  0,  0,  0,
+    0,  0,  0,  0,  0,  4,  1,  5,  0,  0,  0,  0,  0,  0,  0,  0,  0,  3,  5,
+    2,  5,  2,  4,  0,  0,  0,  0,  0,  0,  5,  6,  7,  0,  0,  0,  0,  0,  0,
+    0,  0,  0,  5,  6,  7,  3,  1,  2,  0,  0,  0,  0,  0,  0,  7,  4,  6,  4,
+    6,  1,  0,  0,  0,  0,  0,  0,  3,  6,  2,  7,  6,  2,  7,  2,  4,  0,  0,
+    0,  3,  8,  6,  0,  0,  0,  0,  0,  0,  0,  0,  0,  6,  1,  8,  1,  8,  2,
+    0,  0,  0,  0,  0,  0,  6,  3,  8,  1,  5,  4,  0,  0,  0,  0,  0,  0,  6,
+    5,  8,  4,  5,  8,  4,  8,  2,  0,  0,  0,  5,  3,  7,  3,  7,  8,  0,  0,
+    0,  0,  0,  0,  5,  1,  7,  2,  1,  7,  2,  7,  8,  0,  0,  0,  1,  3,  4,
+    8,  3,  4,  8,  4,  7,  0,  0,  0,  8,  7,  2,  4,  7,  2,  0,  0,  0,  0,
+    0,  0,  9,  2,  10, 0,  0,  0,  0,  0,  0,  0,  0,  0,  9,  3,  10, 3,  10,
+    1,  0,  0,  0,  0,  0,  0,  4,  1,  5,  2,  10, 9,  0,  0,  0,  0,  0,  0,
+    4,  10, 5,  9,  10, 5,  9,  5,  3,  0,  0,  0,  9,  2,  10, 5,  7,  6,  0,
+    0,  0,  0,  0,  0,  9,  3,  10, 3,  10, 1,  7,  6,  5,  0,  0,  0,  7,  4,
+    6,  4,  6,  1,  9,  10, 2,  0,  0,  0,  4,  10, 7,  3,  10, 7,  3,  10, 9,
+    3,  6,  7,  9,  2,  10, 3,  8,  6,  0,  0,  0,  0,  0,  0,  9,  8,  10, 6,
+    8,  10, 6,  10, 1,  0,  0,  0,  6,  8,  3,  10, 2,  9,  1,  4,  5,  0,  0,
+    0,  4,  5,  6,  4,  10, 6,  8,  10, 6,  8,  10, 9,  5,  3,  7,  3,  7,  8,
+    10, 2,  9,  0,  0,  0,  9,  7,  1,  9,  10, 1,  5,  7,  1,  9,  7,  8,  9,
+    10, 8,  4,  10, 8,  4,  10, 7,  3,  2,  1,  9,  10, 8,  4,  10, 8,  4,  8,
+    7,  0,  0,  0,  10, 4,  11, 0,  0,  0,  0,  0,  0,  0,  0,  0,  10, 4,  11,
+    1,  2,  3,  0,  0,  0,  0,  0,  0,  5,  11, 1,  11, 1,  10, 0,  0,  0,  0,
+    0,  0,  10, 2,  11, 3,  2,  11, 3,  11, 5,  0,  0,  0,  7,  5,  6,  4,  11,
+    10, 0,  0,  0,  0,  0,  0,  3,  2,  1,  11, 4,  10, 5,  7,  6,  0,  0,  0,
+    7,  11, 6,  10, 11, 6,  10, 6,  1,  0,  0,  0,  7,  6,  3,  7,  11, 3,  2,
+    11, 3,  2,  11, 10, 10, 4,  11, 6,  8,  3,  0,  0,  0,  0,  0,  0,  6,  1,
+    8,  1,  8,  2,  11, 4,  10, 0,  0,  0,  10, 1,  11, 1,  11, 5,  8,  3,  6,
+    0,  0,  0,  10, 8,  5,  10, 11, 5,  6,  8,  5,  10, 8,  2,  8,  7,  3,  7,
+    3,  5,  10, 11, 4,  0,  0,  0,  10, 11, 2,  7,  11, 2,  7,  11, 8,  1,  4,
+    5,  7,  11, 8,  1,  11, 8,  1,  11, 10, 1,  3,  8,  10, 11, 2,  7,  11, 2,
+    7,  2,  8,  0,  0,  0,  11, 9,  4,  9,  4,  2,  0,  0,  0,  0,  0,  0,  1,
+    4,  3,  11, 4,  3,  11, 3,  9,  0,  0,  0,  2,  1,  9,  5,  1,  9,  5,  9,
+    11, 0,  0,  0,  3,  5,  9,  11, 5,  9,  0,  0,  0,  0,  0,  0,  2,  4,  9,
+    4,  9,  11, 6,  5,  7,  0,  0,  0,  7,  6,  11, 3,  6,  11, 3,  6,  9,  4,
+    5,  1,  7,  1,  9,  7,  11, 9,  2,  1,  9,  7,  1,  6,  7,  6,  11, 3,  6,
+    11, 3,  11, 9,  0,  0,  0,  11, 9,  4,  9,  4,  2,  6,  8,  3,  0,  0,  0,
+    1,  4,  6,  9,  4,  6,  9,  4,  11, 9,  8,  6,  6,  8,  5,  9,  8,  5,  9,
+    8,  11, 1,  3,  2,  6,  8,  5,  9,  8,  5,  9,  5,  11, 0,  0,  0,  7,  11,
+    9,  7,  9,  9,  5,  4,  2,  5,  2,  2,  9,  11, 8,  11, 8,  7,  1,  4,  5,
+    0,  0,  0,  7,  8,  11, 8,  11, 9,  1,  3,  2,  0,  0,  0,  9,  11, 8,  11,
+    8,  7,  0,  0,  0,  0,  0,  0,  11, 7,  12, 0,  0,  0,  0,  0,  0,  0,  0,
+    0,  11, 7,  12, 3,  2,  1,  0,  0,  0,  0,  0,  0,  11, 7,  12, 5,  4,  1,
+    0,  0,  0,  0,  0,  0,  3,  5,  2,  5,  2,  4,  12, 7,  11, 0,  0,  0,  11,
+    5,  12, 5,  12, 6,  0,  0,  0,  0,  0,  0,  11, 5,  12, 5,  12, 6,  2,  1,
+    3,  0,  0,  0,  11, 4,  12, 1,  4,  12, 1,  12, 6,  0,  0,  0,  11, 2,  6,
+    11, 12, 6,  3,  2,  6,  11, 2,  4,  7,  12, 11, 8,  6,  3,  0,  0,  0,  0,
+    0,  0,  2,  8,  1,  8,  1,  6,  11, 12, 7,  0,  0,  0,  1,  4,  5,  12, 7,
+    11, 6,  8,  3,  0,  0,  0,  11, 12, 4,  8,  12, 4,  8,  12, 2,  5,  7,  6,
+    8,  12, 3,  11, 12, 3,  11, 3,  5,  0,  0,  0,  8,  12, 2,  5,  12, 2,  5,
+    12, 11, 5,  1,  2,  8,  3,  1,  8,  12, 1,  4,  12, 1,  4,  12, 11, 11, 12,
+    4,  8,  12, 4,  8,  4,  2,  0,  0,  0,  12, 11, 7,  10, 9,  2,  0,  0,  0,
+    0,  0,  0,  1,  10, 3,  10, 3,  9,  7,  11, 12, 0,  0,  0,  12, 7,  11, 1,
+    4,  5,  10, 2,  9,  0,  0,  0,  12, 7,  9,  5,  7,  9,  5,  7,  3,  10, 11,
+    4,  6,  12, 5,  12, 5,  11, 2,  9,  10, 0,  0,  0,  12, 9,  3,  12, 3,  3,
+    11, 10, 1,  11, 1,  1,  11, 4,  12, 1,  4,  12, 1,  4,  6,  9,  10, 2,  3,
+    9,  6,  9,  6,  12, 4,  10, 11, 0,  0,  0,  3,  6,  8,  11, 12, 7,  9,  10,
+    2,  0,  0,  0,  7,  11, 6,  10, 11, 6,  10, 11, 1,  8,  12, 9,  12, 8,  9,
+    6,  7,  5,  1,  2,  3,  6,  7,  5,  9,  8,  12, 5,  7,  6,  11, 4,  10, 0,
+    0,  0,  8,  12, 3,  11, 12, 3,  11, 12, 5,  2,  9,  10, 5,  11, 1,  11, 1,
+    10, 8,  12, 9,  0,  0,  0,  8,  12, 9,  4,  10, 11, 2,  1,  3,  0,  0,  0,
+    11, 10, 4,  9,  12, 8,  0,  0,  0,  0,  0,  0,  12, 10, 7,  10, 7,  4,  0,
+    0,  0,  0,  0,  0,  12, 10, 7,  10, 7,  4,  3,  2,  1,  0,  0,  0,  5,  7,
+    1,  12, 7,  1,  12, 1,  10, 0,  0,  0,  12, 7,  10, 3,  7,  10, 3,  7,  5,
+    3,  2,  10, 4,  5,  10, 6,  5,  10, 6,  10, 12, 0,  0,  0,  4,  5,  10, 6,
+    5,  10, 6,  5,  12, 2,  1,  3,  12, 6,  10, 1,  6,  10, 0,  0,  0,  0,  0,
+    0,  3,  2,  6,  10, 2,  6,  10, 6,  12, 0,  0,  0,  4,  7,  10, 7,  10, 12,
+    3,  6,  8,  0,  0,  0,  6,  8,  2,  6,  2,  2,  7,  12, 10, 7,  10, 10, 5,
+    7,  1,  12, 7,  1,  12, 7,  10, 3,  6,  8,  10, 12, 2,  12, 2,  8,  5,  7,
+    6,  0,  0,  0,  4,  12, 3,  4,  5,  3,  8,  12, 3,  4,  12, 10, 8,  2,  12,
+    2,  12, 10, 5,  1,  4,  0,  0,  0,  8,  3,  12, 1,  3,  12, 1,  12, 10, 0,
+    0,  0,  10, 12, 2,  12, 2,  8,  0,  0,  0,  0,  0,  0,  12, 9,  7,  2,  9,
+    7,  2,  7,  4,  0,  0,  0,  12, 4,  3,  12, 9,  3,  1,  4,  3,  12, 4,  7,
+    2,  1,  5,  2,  9,  5,  7,  9,  5,  7,  9,  12, 12, 7,  9,  5,  7,  9,  5,
+    9,  3,  0,  0,  0,  2,  9,  4,  6,  9,  4,  6,  9,  12, 6,  5,  4,  12, 6,
+    9,  6,  9,  3,  4,  5,  1,  0,  0,  0,  2,  9,  1,  12, 9,  1,  12, 1,  6,
+    0,  0,  0,  3,  9,  6,  9,  6,  12, 0,  0,  0,  0,  0,  0,  12, 9,  7,  2,
+    9,  7,  2,  9,  4,  6,  8,  3,  1,  6,  4,  6,  4,  7,  9,  8,  12, 0,  0,
+    0,  5,  7,  6,  9,  8,  12, 3,  2,  1,  0,  0,  0,  12, 8,  9,  6,  7,  5,
+    0,  0,  0,  0,  0,  0,  4,  2,  5,  2,  5,  3,  12, 9,  8,  0,  0,  0,  12,
+    8,  9,  1,  4,  5,  0,  0,  0,  0,  0,  0,  8,  9,  12, 2,  3,  1,  0,  0,
+    0,  0,  0,  0,  12, 8,  9,  0,  0,  0,  0,  0,  0,  0,  0,  0,  12, 8,  9,
+    0,  0,  0,  0,  0,  0,  0,  0,  0,  8,  9,  12, 2,  3,  1,  0,  0,  0,  0,
+    0,  0,  12, 8,  9,  1,  4,  5,  0,  0,  0,  0,  0,  0,  4,  2,  5,  2,  5,
+    3,  12, 9,  8,  0,  0,  0,  12, 8,  9,  6,  7,  5,  0,  0,  0,  0,  0,  0,
+    5,  7,  6,  9,  8,  12, 3,  2,  1,  0,  0,  0,  1,  6,  4,  6,  4,  7,  9,
+    8,  12, 0,  0,  0,  12, 9,  7,  2,  9,  7,  2,  9,  4,  6,  8,  3,  3,  9,
+    6,  9,  6,  12, 0,  0,  0,  0,  0,  0,  2,  9,  1,  12, 9,  1,  12, 1,  6,
+    0,  0,  0,  12, 6,  9,  6,  9,  3,  4,  5,  1,  0,  0,  0,  2,  9,  4,  6,
+    9,  4,  6,  9,  12, 6,  5,  4,  12, 7,  9,  5,  7,  9,  5,  9,  3,  0,  0,
+    0,  2,  1,  5,  2,  9,  5,  7,  9,  5,  7,  9,  12, 12, 4,  3,  12, 9,  3,
+    1,  4,  3,  12, 4,  7,  12, 9,  7,  2,  9,  7,  2,  7,  4,  0,  0,  0,  10,
+    12, 2,  12, 2,  8,  0,  0,  0,  0,  0,  0,  8,  3,  12, 1,  3,  12, 1,  12,
+    10, 0,  0,  0,  8,  2,  12, 2,  12, 10, 5,  1,  4,  0,  0,  0,  4,  12, 3,
+    4,  5,  3,  8,  12, 3,  4,  12, 10, 10, 12, 2,  12, 2,  8,  5,  7,  6,  0,
+    0,  0,  5,  7,  1,  12, 7,  1,  12, 7,  10, 3,  6,  8,  6,  8,  2,  6,  2,
+    2,  7,  12, 10, 7,  10, 10, 4,  7,  10, 7,  10, 12, 3,  6,  8,  0,  0,  0,
+    3,  2,  6,  10, 2,  6,  10, 6,  12, 0,  0,  0,  12, 6,  10, 1,  6,  10, 0,
+    0,  0,  0,  0,  0,  4,  5,  10, 6,  5,  10, 6,  5,  12, 2,  1,  3,  4,  5,
+    10, 6,  5,  10, 6,  10, 12, 0,  0,  0,  12, 7,  10, 3,  7,  10, 3,  7,  5,
+    3,  2,  10, 5,  7,  1,  12, 7,  1,  12, 1,  10, 0,  0,  0,  12, 10, 7,  10,
+    7,  4,  3,  2,  1,  0,  0,  0,  12, 10, 7,  10, 7,  4,  0,  0,  0,  0,  0,
+    0,  11, 10, 4,  9,  12, 8,  0,  0,  0,  0,  0,  0,  8,  12, 9,  4,  10, 11,
+    2,  1,  3,  0,  0,  0,  5,  11, 1,  11, 1,  10, 8,  12, 9,  0,  0,  0,  8,
+    12, 3,  11, 12, 3,  11, 12, 5,  2,  9,  10, 9,  8,  12, 5,  7,  6,  11, 4,
+    10, 0,  0,  0,  12, 8,  9,  6,  7,  5,  1,  2,  3,  6,  7,  5,  7,  11, 6,
+    10, 11, 6,  10, 11, 1,  8,  12, 9,  3,  6,  8,  11, 12, 7,  9,  10, 2,  0,
+    0,  0,  3,  9,  6,  9,  6,  12, 4,  10, 11, 0,  0,  0,  11, 4,  12, 1,  4,
+    12, 1,  4,  6,  9,  10, 2,  12, 9,  3,  12, 3,  3,  11, 10, 1,  11, 1,  1,
+    6,  12, 5,  12, 5,  11, 2,  9,  10, 0,  0,  0,  12, 7,  9,  5,  7,  9,  5,
+    7,  3,  10, 11, 4,  12, 7,  11, 1,  4,  5,  10, 2,  9,  0,  0,  0,  1,  10,
+    3,  10, 3,  9,  7,  11, 12, 0,  0,  0,  12, 11, 7,  10, 9,  2,  0,  0,  0,
+    0,  0,  0,  11, 12, 4,  8,  12, 4,  8,  4,  2,  0,  0,  0,  8,  3,  1,  8,
+    12, 1,  4,  12, 1,  4,  12, 11, 8,  12, 2,  5,  12, 2,  5,  12, 11, 5,  1,
+    2,  8,  12, 3,  11, 12, 3,  11, 3,  5,  0,  0,  0,  11, 12, 4,  8,  12, 4,
+    8,  12, 2,  5,  7,  6,  1,  4,  5,  12, 7,  11, 6,  8,  3,  0,  0,  0,  2,
+    8,  1,  8,  1,  6,  11, 12, 7,  0,  0,  0,  7,  12, 11, 8,  6,  3,  0,  0,
+    0,  0,  0,  0,  11, 2,  6,  11, 12, 6,  3,  2,  6,  11, 2,  4,  11, 4,  12,
+    1,  4,  12, 1,  12, 6,  0,  0,  0,  11, 5,  12, 5,  12, 6,  2,  1,  3,  0,
+    0,  0,  11, 5,  12, 5,  12, 6,  0,  0,  0,  0,  0,  0,  3,  5,  2,  5,  2,
+    4,  12, 7,  11, 0,  0,  0,  11, 7,  12, 5,  4,  1,  0,  0,  0,  0,  0,  0,
+    11, 7,  12, 3,  2,  1,  0,  0,  0,  0,  0,  0,  11, 7,  12, 0,  0,  0,  0,
+    0,  0,  0,  0,  0,  9,  11, 8,  11, 8,  7,  0,  0,  0,  0,  0,  0,  7,  8,
+    11, 8,  11, 9,  1,  3,  2,  0,  0,  0,  9,  11, 8,  11, 8,  7,  1,  4,  5,
+    0,  0,  0,  7,  11, 9,  7,  9,  9,  5,  4,  2,  5,  2,  2,  6,  8,  5,  9,
+    8,  5,  9,  5,  11, 0,  0,  0,  6,  8,  5,  9,  8,  5,  9,  8,  11, 1,  3,
+    2,  1,  4,  6,  9,  4,  6,  9,  4,  11, 9,  8,  6,  11, 9,  4,  9,  4,  2,
+    6,  8,  3,  0,  0,  0,  7,  6,  11, 3,  6,  11, 3,  11, 9,  0,  0,  0,  7,
+    1,  9,  7,  11, 9,  2,  1,  9,  7,  1,  6,  7,  6,  11, 3,  6,  11, 3,  6,
+    9,  4,  5,  1,  2,  4,  9,  4,  9,  11, 6,  5,  7,  0,  0,  0,  3,  5,  9,
+    11, 5,  9,  0,  0,  0,  0,  0,  0,  2,  1,  9,  5,  1,  9,  5,  9,  11, 0,
+    0,  0,  1,  4,  3,  11, 4,  3,  11, 3,  9,  0,  0,  0,  11, 9,  4,  9,  4,
+    2,  0,  0,  0,  0,  0,  0,  10, 11, 2,  7,  11, 2,  7,  2,  8,  0,  0,  0,
+    7,  11, 8,  1,  11, 8,  1,  11, 10, 1,  3,  8,  10, 11, 2,  7,  11, 2,  7,
+    11, 8,  1,  4,  5,  8,  7,  3,  7,  3,  5,  10, 11, 4,  0,  0,  0,  10, 8,
+    5,  10, 11, 5,  6,  8,  5,  10, 8,  2,  10, 1,  11, 1,  11, 5,  8,  3,  6,
+    0,  0,  0,  6,  1,  8,  1,  8,  2,  11, 4,  10, 0,  0,  0,  10, 4,  11, 6,
+    8,  3,  0,  0,  0,  0,  0,  0,  7,  6,  3,  7,  11, 3,  2,  11, 3,  2,  11,
+    10, 7,  11, 6,  10, 11, 6,  10, 6,  1,  0,  0,  0,  3,  2,  1,  11, 4,  10,
+    5,  7,  6,  0,  0,  0,  7,  5,  6,  4,  11, 10, 0,  0,  0,  0,  0,  0,  10,
+    2,  11, 3,  2,  11, 3,  11, 5,  0,  0,  0,  5,  11, 1,  11, 1,  10, 0,  0,
+    0,  0,  0,  0,  10, 4,  11, 1,  2,  3,  0,  0,  0,  0,  0,  0,  10, 4,  11,
+    0,  0,  0,  0,  0,  0,  0,  0,  0,  9,  10, 8,  4,  10, 8,  4,  8,  7,  0,
+    0,  0,  9,  10, 8,  4,  10, 8,  4,  10, 7,  3,  2,  1,  9,  7,  1,  9,  10,
+    1,  5,  7,  1,  9,  7,  8,  5,  3,  7,  3,  7,  8,  10, 2,  9,  0,  0,  0,
+    4,  5,  6,  4,  10, 6,  8,  10, 6,  8,  10, 9,  6,  8,  3,  10, 2,  9,  1,
+    4,  5,  0,  0,  0,  9,  8,  10, 6,  8,  10, 6,  10, 1,  0,  0,  0,  9,  2,
+    10, 3,  8,  6,  0,  0,  0,  0,  0,  0,  4,  10, 7,  3,  10, 7,  3,  10, 9,
+    3,  6,  7,  7,  4,  6,  4,  6,  1,  9,  10, 2,  0,  0,  0,  9,  3,  10, 3,
+    10, 1,  7,  6,  5,  0,  0,  0,  9,  2,  10, 5,  7,  6,  0,  0,  0,  0,  0,
+    0,  4,  10, 5,  9,  10, 5,  9,  5,  3,  0,  0,  0,  4,  1,  5,  2,  10, 9,
+    0,  0,  0,  0,  0,  0,  9,  3,  10, 3,  10, 1,  0,  0,  0,  0,  0,  0,  9,
+    2,  10, 0,  0,  0,  0,  0,  0,  0,  0,  0,  8,  7,  2,  4,  7,  2,  0,  0,
+    0,  0,  0,  0,  1,  3,  4,  8,  3,  4,  8,  4,  7,  0,  0,  0,  5,  1,  7,
+    2,  1,  7,  2,  7,  8,  0,  0,  0,  5,  3,  7,  3,  7,  8,  0,  0,  0,  0,
+    0,  0,  6,  5,  8,  4,  5,  8,  4,  8,  2,  0,  0,  0,  6,  3,  8,  1,  5,
+    4,  0,  0,  0,  0,  0,  0,  6,  1,  8,  1,  8,  2,  0,  0,  0,  0,  0,  0,
+    3,  8,  6,  0,  0,  0,  0,  0,  0,  0,  0,  0,  3,  6,  2,  7,  6,  2,  7,
+    2,  4,  0,  0,  0,  7,  4,  6,  4,  6,  1,  0,  0,  0,  0,  0,  0,  5,  6,
+    7,  3,  1,  2,  0,  0,  0,  0,  0,  0,  5,  6,  7,  0,  0,  0,  0,  0,  0,
+    0,  0,  0,  3,  5,  2,  5,  2,  4,  0,  0,  0,  0,  0,  0,  4,  1,  5,  0,
+    0,  0,  0,  0,  0,  0,  0,  0,  1,  2,  3,  0,  0,  0,  0,  0,  0,  0,  0,
+    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+};
+
+int MarchingCubes::getVectorAmount() {
+    return 12;
+}
+
+Vector3 MarchingCubes::getVector(int index, int i) {
+    return vectors[table[index * 12 + i]];
+}

+ 11 - 0
MarchingCubes.h

@@ -0,0 +1,11 @@
+#ifndef MARCHINGCUBES_H
+#define MARCHINGCUBES_H
+
+#include "gaming-core/math/Vector.h"
+
+namespace MarchingCubes {
+    int getVectorAmount();
+    Vector3 getVector(int index, int i);
+}
+
+#endif

+ 2 - 1
meson.build

@@ -2,6 +2,7 @@ project('spg project', 'cpp')
 
 sources = ['Main.cpp',
     'Game.cpp',
+    'MarchingCubes.cpp',
     'gaming-core/utils/Size.cpp',
     'gaming-core/utils/Clock.cpp',
     'gaming-core/utils/Random.cpp',
@@ -30,4 +31,4 @@ executable('demo',
     sources: sources,
     dependencies : [glewDep, glfwDep],
     include_directories : include_directories('gaming-core'),
-    cpp_args: ['-Wall', '-Wextra', '-pedantic', '-Werror', '-Wno-unused-function'])
+    cpp_args: ['-Wall', '-Wextra', '-pedantic', '-Werror'])