diff --git a/grafika_projekt/src/Engine.cpp b/grafika_projekt/src/Engine.cpp index a732beb..4c1ec1d 100644 --- a/grafika_projekt/src/Engine.cpp +++ b/grafika_projekt/src/Engine.cpp @@ -40,7 +40,7 @@ void Core::Engine::loadTextures() { this->plant1Texture = LoadTexture("textures/plant1.png"); this->plant2Texture = LoadTexture("textures/plant2.png"); this->plant3Texture = LoadTexture("textures/plant3.png"); - this->rocktowerTexture = LoadTexture("textures/rocktower1.png"); + this->rocktower1Texture = LoadTexture("textures/rocktower1.png"); this->skyboxTexture = loadCubemap(); } @@ -97,11 +97,12 @@ void Core::Engine::generateBubbleArray() { } } -void Core::Engine::generateGrassArray() { +void Core::Engine::generateObjectArray() { for (int i = 0; i < 200; i++) { - float random1 = this->distr(this->gen); - float random2 = this->distr(this->gen); - grassArray[i] = glm::vec3(random1, -skyboxVerticeParameter + 10, random2); + int random1 = this->distr(this->gen); + int random2 = this->distr(this->gen); + float height = -this->skyboxVerticeParameter + this->terrain.heightTable[random1][random2] + 15; + this->objectArray[i] = glm::vec3(random1, height, random2); } } diff --git a/grafika_projekt/src/Engine.h b/grafika_projekt/src/Engine.h index af19383..c0191f2 100644 --- a/grafika_projekt/src/Engine.h +++ b/grafika_projekt/src/Engine.h @@ -15,30 +15,30 @@ namespace Core { class Engine { public: GLuint textureShader, skyboxShader, bubbleShader; - GLuint submarineTexture, bubbleTexture, fishTexture, terrainTexture, skyboxTexture, plant1Texture, plant2Texture, plant3Texture, coral1Texture, rocktowerTexture, archTexture ; + GLuint submarineTexture, bubbleTexture, fishTexture, terrainTexture, skyboxTexture, plant1Texture, plant2Texture, plant3Texture, coral1Texture, rocktower1Texture, archTexture ; GLuint skyboxVAO; Core::RenderContext submarineContext, fishContext, bubbleContext, terrainContext, plant1Context, plant2Context, plant3Context, coral1Context, rocktower1Context, archContext; std::vector bubbleArray[300]; - glm::vec3 grassArray[200]; + glm::vec3 objectArray[200]; void initShaderPrograms(); void shutdownShaderPrograms(); void initRenderContexts(); void loadTextures(); void initSkybox(); void initBubbles(); + void generateObjectArray(); + Terrain terrain; void initRandomGenerator(std::default_random_engine gen, std::uniform_int_distribution<> distr); static const float skyboxVerticeParameter; private: HeightGenerator heightGenerator; GLuint skyboxVBO; - Terrain terrain; Shader_Loader shaderLoader; static const float cubeVertices[216], skyboxVertices[108]; std::uniform_int_distribution<> distr; std::default_random_engine gen; void initCube(); void generateBubbleArray(); - void generateGrassArray(); std::vector genBubbleKeyPoints(); }; diff --git a/grafika_projekt/src/Terrain.cpp b/grafika_projekt/src/Terrain.cpp index ca68ae9..b00d346 100644 --- a/grafika_projekt/src/Terrain.cpp +++ b/grafika_projekt/src/Terrain.cpp @@ -19,7 +19,8 @@ obj::Model Terrain::generateTerrain() { for (int i = 0; i < VERTEX_COUNT; i++) { for (int j = 0; j < VERTEX_COUNT; j++) { vertices[vertexPointer * 3] = float(j) / float(VERTEX_COUNT - 1) * SIZE; - vertices[vertexPointer * 3 + 1] = getHeight(j, i); + float height = getHeight(j, i); + vertices[vertexPointer * 3 + 1] = height; vertices[vertexPointer * 3 + 2] = float(i) / float(VERTEX_COUNT - 1) * SIZE; glm::vec3 normal = calculateNormal(j, i); normals[vertexPointer * 3] = normal.x; @@ -28,6 +29,8 @@ obj::Model Terrain::generateTerrain() { textureCoords[vertexPointer * 2] = float(j) / float(VERTEX_COUNT - 1) * 40; textureCoords[vertexPointer * 2 + 1] = float(i) / float(VERTEX_COUNT - 1) * 40; vertexPointer++; + heightTable[j][i] = height; + std::cout << heightTable[j][i] << std::endl; } } int pointer = 0; diff --git a/grafika_projekt/src/Terrain.h b/grafika_projekt/src/Terrain.h index 01fcc12..d209221 100644 --- a/grafika_projekt/src/Terrain.h +++ b/grafika_projekt/src/Terrain.h @@ -12,6 +12,7 @@ public: Terrain() = default; Terrain(HeightGenerator heightGenerator); obj::Model generateTerrain(); + float heightTable[64][64]; private: static const float SIZE; static const int VERTEX_COUNT; diff --git a/grafika_projekt/src/main.cpp b/grafika_projekt/src/main.cpp index 1cc77c9..5e9bb1f 100644 --- a/grafika_projekt/src/main.cpp +++ b/grafika_projekt/src/main.cpp @@ -232,6 +232,7 @@ void renderScene() Core::drawObjectTexture(engine.fishContext, animationMatrix(time + 15, change2, fishKeyPoints, glm::vec3(0.25f), 1.f), engine.fishTexture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); Core::drawObjectTexture(engine.fishContext, animationMatrix(time + 15, change3, fishKeyPoints, glm::vec3(0.25f), 1.f), engine.fishTexture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); Core::drawObjectTexture(engine.fishContext, animationMatrix(time + 15, change4, fishKeyPoints, glm::vec3(0.25f), 1.f), engine.fishTexture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + time -= 6; } } @@ -241,6 +242,31 @@ void renderScene() glm::mat4 terrainTransformation = glm::translate(glm::vec3(200, -185, 200)) * glm::rotate(glm::radians(180.f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(8.f)); Core::drawObjectTexture(engine.terrainContext, terrainTransformation, engine.terrainTexture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + + + for (int j = 0; j < 25; j++) { + glm::mat4 objectTransformation = glm::translate(engine.objectArray[j]) * glm::rotate(glm::radians(0.f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.3f)); + + drawObjectTexture(engine.plant1Context, objectTransformation, engine.plant1Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + + objectTransformation = glm::translate(engine.objectArray[25+j]) * glm::rotate(glm::radians(0.f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.3f)); + drawObjectTexture(engine.plant2Context, objectTransformation, engine.plant2Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + + objectTransformation = glm::translate(engine.objectArray[50+j]) * glm::rotate(glm::radians(0.f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.3f)); + drawObjectTexture(engine.plant3Context, objectTransformation, engine.plant3Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + + objectTransformation = glm::translate(engine.objectArray[75+j]) * glm::rotate(glm::radians(0.f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.3f)); + drawObjectTexture(engine.coral1Context, objectTransformation, engine.coral1Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + + objectTransformation = glm::translate(engine.objectArray[100+j]) * glm::rotate(glm::radians(0.f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.3f)); + drawObjectTexture(engine.archContext, objectTransformation, engine.archTexture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + } + + for (int i = 0; i < 5; i++) { + glm::mat4 objectTransformation = glm::translate(engine.objectArray[125 + i]) * glm::rotate(glm::radians(0.f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.3f)); + drawObjectTexture(engine.rocktower1Context, objectTransformation, engine.rocktower1Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + } + glutSwapBuffers(); } @@ -274,6 +300,7 @@ void init() engine.loadTextures(); engine.initSkybox(); engine.initBubbles(); + engine.generateObjectArray(); initKeyRotation(); }