|
@@ -12,11 +12,14 @@
|
|
Game::Game(Shader& shader, Shader& noiceShader, LayeredFramebuffer& buffer,
|
|
Game::Game(Shader& shader, Shader& noiceShader, LayeredFramebuffer& buffer,
|
|
Buttons& buttons, const Size& size)
|
|
Buttons& buttons, const Size& size)
|
|
: shader(shader), noiceShader(noiceShader), noiceBuffer(buffer),
|
|
: shader(shader), noiceShader(noiceShader), noiceBuffer(buffer),
|
|
- buttons(buttons), size(size), frustum(60, 0.1f, 1000.0f, size),
|
|
+ bricks("resources/bricks.png"), bricksBump("resources/bricks_bump.png"),
|
|
- up(GLFW_KEY_SPACE, "Up"), down(GLFW_KEY_LEFT_SHIFT, "Down"),
|
|
+ bricksNormal("resources/bricks_normal.png"), buttons(buttons), size(size),
|
|
- left(GLFW_KEY_A, "left"), right(GLFW_KEY_D, "right"),
|
|
+ frustum(60, 0.1f, 1000.0f, size), up(GLFW_KEY_SPACE, "Up"),
|
|
- front(GLFW_KEY_W, "front"), back(GLFW_KEY_S, "back"),
|
|
+ down(GLFW_KEY_LEFT_SHIFT, "Down"), left(GLFW_KEY_A, "left"),
|
|
- toggle(GLFW_KEY_T, "toggle"), oldHeight(0.0f), height(0.0f) {
|
|
+ right(GLFW_KEY_D, "right"), front(GLFW_KEY_W, "front"),
|
|
|
|
+ back(GLFW_KEY_S, "back"), toggle(GLFW_KEY_T, "toggle"),
|
|
|
|
+ scaleUp(GLFW_KEY_G, "scale up"), scaleDown(GLFW_KEY_H, "scale down"),
|
|
|
|
+ oldHeight(0.0f), height(0.0f), heightScale(0.0f) {
|
|
buttons.add(up);
|
|
buttons.add(up);
|
|
buttons.add(down);
|
|
buttons.add(down);
|
|
buttons.add(left);
|
|
buttons.add(left);
|
|
@@ -24,60 +27,16 @@ Game::Game(Shader& shader, Shader& noiceShader, LayeredFramebuffer& buffer,
|
|
buttons.add(front);
|
|
buttons.add(front);
|
|
buttons.add(back);
|
|
buttons.add(back);
|
|
buttons.add(toggle);
|
|
buttons.add(toggle);
|
|
|
|
+ buttons.add(scaleUp);
|
|
|
|
+ buttons.add(scaleDown);
|
|
|
|
+
|
|
|
|
+ position = Vector3(0.0f, 0.0f, -40.0f);
|
|
|
|
|
|
rectangleBuffer.setAttributes(Attributes().addFloat(2));
|
|
rectangleBuffer.setAttributes(Attributes().addFloat(2));
|
|
float recData[6][2] = {{-1.0f, -1.0f}, {-1.0, 1.0}, {1.0, -1.0},
|
|
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}};
|
|
{1.0f, 1.0f}, {-1.0, 1.0}, {1.0, -1.0}};
|
|
rectangleBuffer.setStaticData(sizeof(recData), recData);
|
|
rectangleBuffer.setStaticData(sizeof(recData), recData);
|
|
noiceBuffer.bindTextureTo(0);
|
|
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) {
|
|
void Game::render(float lag) {
|
|
@@ -100,17 +59,21 @@ void Game::render(float lag) {
|
|
|
|
|
|
Matrix m;
|
|
Matrix m;
|
|
m.translate(Utils::interpolate(oldPosition, position, lag));
|
|
m.translate(Utils::interpolate(oldPosition, position, lag));
|
|
- m.translateZ(-32.0f);
|
|
|
|
m.translateY(-32.0f + (oldHeight - height) * lag);
|
|
m.translateY(-32.0f + (oldHeight - height) * lag);
|
|
- m.translateX(-32.0f);
|
|
|
|
shader.setMatrix("view", m.getValues());
|
|
shader.setMatrix("view", m.getValues());
|
|
shader.setFloat("height", oldHeight * step * 0.5f);
|
|
shader.setFloat("height", oldHeight * step * 0.5f);
|
|
|
|
|
|
|
|
+ shader.setVector("viewPos", -position + Vector3(0.0f, 32.0f, 0.0f));
|
|
|
|
+ shader.setVector("lightPos", Vector3());
|
|
|
|
+ shader.setFloat("heightScale", heightScale);
|
|
|
|
+
|
|
if(toggle.isDown()) {
|
|
if(toggle.isDown()) {
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
}
|
|
}
|
|
noiceBuffer.bindTextureTo(0);
|
|
noiceBuffer.bindTextureTo(0);
|
|
- texture.bindTo(1);
|
|
+ bricks.bindTo(1);
|
|
|
|
+ bricksBump.bindTo(2);
|
|
|
|
+ bricksNormal.bindTo(3);
|
|
emptyBuffer.drawPoints(64 * 64 * 64);
|
|
emptyBuffer.drawPoints(64 * 64 * 64);
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
}
|
|
}
|
|
@@ -124,7 +87,7 @@ void Game::tick() {
|
|
if(down.isDown()) {
|
|
if(down.isDown()) {
|
|
height -= 1.0f;
|
|
height -= 1.0f;
|
|
}
|
|
}
|
|
- const float speed = 2.5f;
|
|
+ const float speed = 1.15f;
|
|
if(left.isDown()) {
|
|
if(left.isDown()) {
|
|
position += Vector3(speed, 0.0f, 0.0f);
|
|
position += Vector3(speed, 0.0f, 0.0f);
|
|
}
|
|
}
|
|
@@ -137,6 +100,16 @@ void Game::tick() {
|
|
if(back.isDown()) {
|
|
if(back.isDown()) {
|
|
position -= Vector3(0.0f, 0.0f, speed);
|
|
position -= Vector3(0.0f, 0.0f, speed);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if(scaleUp.isDown()) {
|
|
|
|
+ heightScale += 0.005f;
|
|
|
|
+ }
|
|
|
|
+ if(scaleDown.isDown()) {
|
|
|
|
+ heightScale -= 0.005f;
|
|
|
|
+ if(heightScale < 0.0f) {
|
|
|
|
+ heightScale = 0.0f;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
bool Game::isRunning() const {
|
|
bool Game::isRunning() const {
|