|
@@ -5,6 +5,7 @@
|
|
|
#include "MarchingCubes.h"
|
|
|
#include "gaming-core/utils/Array.h"
|
|
|
#include "gaming-core/utils/List.h"
|
|
|
+#include "gaming-core/utils/Random.h"
|
|
|
#include "gaming-core/utils/Utils.h"
|
|
|
#include "gaming-core/wrapper/GL.h"
|
|
|
|
|
@@ -25,10 +26,58 @@ Game::Game(Shader& shader, Shader& noiceShader, LayeredFramebuffer& buffer,
|
|
|
buttons.add(toggle);
|
|
|
|
|
|
rectangleBuffer.setAttributes(Attributes().addFloat(2));
|
|
|
- float data[6][2] = {{-1.0f, -1.0f}, {-1.0, 1.0}, {1.0, -1.0},
|
|
|
- {1.0f, 1.0f}, {-1.0, 1.0}, {1.0, -1.0}};
|
|
|
- rectangleBuffer.setStaticData(sizeof(data), data);
|
|
|
+ float recData[6][2] = {{-1.0f, -1.0f}, {-1.0, 1.0}, {1.0, -1.0},
|
|
|
+ {1.0f, 1.0f}, {-1.0, 1.0}, {1.0, -1.0}};
|
|
|
+ rectangleBuffer.setStaticData(sizeof(recData), recData);
|
|
|
noiceBuffer.bindTextureTo(0);
|
|
|
+
|
|
|
+ Random r;
|
|
|
+ const int textureSize = 64;
|
|
|
+ float tData[textureSize][textureSize][textureSize][3];
|
|
|
+ for(int x = 0; x < textureSize; x++) {
|
|
|
+ for(int y = 0; y < textureSize; y++) {
|
|
|
+ for(int z = 0; z < textureSize; z++) {
|
|
|
+ tData[x][y][z][0] = r.nextFloat();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(int k = 1; k < 3; k++) {
|
|
|
+ int factor = (k * 2 + 1) * (k * 2 + 1) * (k * 2 + 1);
|
|
|
+ for(int x = 0; x < textureSize; x++) {
|
|
|
+ for(int y = 0; y < textureSize; y++) {
|
|
|
+ for(int z = 0; z < textureSize; z++) {
|
|
|
+ float sum = 0.0f;
|
|
|
+ for(int mx = -k; mx <= k; mx++) {
|
|
|
+ for(int my = -k; my <= k; my++) {
|
|
|
+ for(int mz = -k; mz <= k; mz++) {
|
|
|
+ int rx = std::abs(x + mx);
|
|
|
+ int ry = std::abs(y + my);
|
|
|
+ int rz = std::abs(z + mz);
|
|
|
+ rx = rx >= 64 ? 127 - rx : rx;
|
|
|
+ ry = ry >= 64 ? 127 - ry : ry;
|
|
|
+ rz = rz >= 64 ? 127 - rz : rz;
|
|
|
+ sum += tData[rx][ry][rz][0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tData[x][y][z][0] = sum / factor;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(int x = 0; x < textureSize; x++) {
|
|
|
+ for(int y = 0; y < textureSize; y++) {
|
|
|
+ for(int z = 0; z < textureSize; z++) {
|
|
|
+ float v = tData[x][y][z][0];
|
|
|
+ float vvv = v * v * v;
|
|
|
+ v = 6.0f * vvv * v * v - 15.0f * vvv * v + 10.0f * vvv;
|
|
|
+ tData[x][y][z][0] = v;
|
|
|
+ tData[x][y][z][1] = v;
|
|
|
+ tData[x][y][z][2] = v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ texture.setData(textureSize, textureSize, textureSize, tData);
|
|
|
}
|
|
|
|
|
|
void Game::render(float lag) {
|
|
@@ -55,11 +104,13 @@ void Game::render(float lag) {
|
|
|
m.translateY(-32.0f + (oldHeight - height) * lag);
|
|
|
m.translateX(-32.0f);
|
|
|
shader.setMatrix("view", m.getValues());
|
|
|
+ shader.setFloat("height", oldHeight * step * 0.5f);
|
|
|
|
|
|
if(toggle.isDown()) {
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
|
}
|
|
|
noiceBuffer.bindTextureTo(0);
|
|
|
+ texture.bindTo(1);
|
|
|
emptyBuffer.drawPoints(64 * 64 * 64);
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
|
}
|