From a0ac366237bfff3b7e2dedd3ad2a43758e45f47e Mon Sep 17 00:00:00 2001 From: Matraf Date: Wed, 26 Jan 2022 12:23:51 +0100 Subject: [PATCH] add random values for rotation/size objects --- grafika_projekt/grafika_projekt.vcxproj | 2 +- grafika_projekt/grafika_projekt.vcxproj.user | 2 +- grafika_projekt/src/Engine.cpp | 16 ++++++++ grafika_projekt/src/Engine.h | 4 ++ grafika_projekt/src/Terrain.cpp | 2 +- grafika_projekt/src/main.cpp | 39 ++++++++++++-------- 6 files changed, 46 insertions(+), 19 deletions(-) diff --git a/grafika_projekt/grafika_projekt.vcxproj b/grafika_projekt/grafika_projekt.vcxproj index caf784f..ecb7ffb 100644 --- a/grafika_projekt/grafika_projekt.vcxproj +++ b/grafika_projekt/grafika_projekt.vcxproj @@ -29,7 +29,7 @@ Application true - v142 + v143 Unicode diff --git a/grafika_projekt/grafika_projekt.vcxproj.user b/grafika_projekt/grafika_projekt.vcxproj.user index 5df420f..966b4ff 100644 --- a/grafika_projekt/grafika_projekt.vcxproj.user +++ b/grafika_projekt/grafika_projekt.vcxproj.user @@ -1,6 +1,6 @@  - false + true \ No newline at end of file diff --git a/grafika_projekt/src/Engine.cpp b/grafika_projekt/src/Engine.cpp index b214aa4..f2a3179 100644 --- a/grafika_projekt/src/Engine.cpp +++ b/grafika_projekt/src/Engine.cpp @@ -107,6 +107,22 @@ void Core::Engine::generateObjectArray() { } } +void Core::Engine::generateObjectSize() { + std::uniform_real_distribution<> distr(0.1f, 0.25f); + for (int i = 0; i < 200; i++) { + float random = distr(this->gen); + objectSize.push_back(random); + } +} + +void Core::Engine::generateObjectRotation() { + std::uniform_real_distribution<> distr(0.0f, 360.0f); + for (int i = 0; i < 200; i++) { + float random = distr(this->gen); + objectRotation.push_back(random); + } +} + void Core::Engine::initBubbles() { this->generateBubbleArray(); } diff --git a/grafika_projekt/src/Engine.h b/grafika_projekt/src/Engine.h index c0191f2..07378f7 100644 --- a/grafika_projekt/src/Engine.h +++ b/grafika_projekt/src/Engine.h @@ -19,6 +19,8 @@ namespace Core { GLuint skyboxVAO; Core::RenderContext submarineContext, fishContext, bubbleContext, terrainContext, plant1Context, plant2Context, plant3Context, coral1Context, rocktower1Context, archContext; std::vector bubbleArray[300]; + std::vector objectSize; + std::vector objectRotation; glm::vec3 objectArray[200]; void initShaderPrograms(); void shutdownShaderPrograms(); @@ -27,6 +29,8 @@ namespace Core { void initSkybox(); void initBubbles(); void generateObjectArray(); + void generateObjectSize(); + void generateObjectRotation(); Terrain terrain; void initRandomGenerator(std::default_random_engine gen, std::uniform_int_distribution<> distr); static const float skyboxVerticeParameter; diff --git a/grafika_projekt/src/Terrain.cpp b/grafika_projekt/src/Terrain.cpp index b00d346..c9950a5 100644 --- a/grafika_projekt/src/Terrain.cpp +++ b/grafika_projekt/src/Terrain.cpp @@ -30,7 +30,7 @@ obj::Model Terrain::generateTerrain() { textureCoords[vertexPointer * 2 + 1] = float(i) / float(VERTEX_COUNT - 1) * 40; vertexPointer++; heightTable[j][i] = height; - std::cout << heightTable[j][i] << std::endl; + //std::cout << heightTable[j][i] << std::endl; } } int pointer = 0; diff --git a/grafika_projekt/src/main.cpp b/grafika_projekt/src/main.cpp index e3b76d4..d55c7c7 100644 --- a/grafika_projekt/src/main.cpp +++ b/grafika_projekt/src/main.cpp @@ -240,22 +240,27 @@ void renderScene() - 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(90.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 j = 0; j < 100; j++) { + glm::mat4 objectTransformation; + if (j % 5 == 0) { + objectTransformation = glm::translate(engine.objectArray[j]) * glm::rotate(glm::radians(engine.objectRotation[j]), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(engine.objectSize[j])); + drawObjectTexture(engine.plant1Context, objectTransformation, engine.plant1Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + } else if (j % 5 == 1) { + objectTransformation = glm::translate(engine.objectArray[25 + j]) * glm::rotate(glm::radians(engine.objectRotation[j]), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(engine.objectSize[j])); + drawObjectTexture(engine.plant2Context, objectTransformation, engine.plant2Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + } + else if (j % 5 == 2) { + objectTransformation = glm::translate(engine.objectArray[50 + j]) * glm::rotate(glm::radians(engine.objectRotation[j]), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(engine.objectSize[j])); + drawObjectTexture(engine.plant3Context, objectTransformation, engine.plant3Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + } + else if (j % 5 == 3) { + objectTransformation = glm::translate(engine.objectArray[75 + j]) * glm::rotate(glm::radians(engine.objectRotation[j]), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(engine.objectSize[j])); + drawObjectTexture(engine.coral1Context, objectTransformation, engine.coral1Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + } + else if (j % 5 == 4) { + objectTransformation = glm::translate(engine.objectArray[100 + j]) * glm::rotate(glm::radians(engine.objectRotation[j]), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(engine.objectSize[j])); + drawObjectTexture(engine.archContext, objectTransformation, engine.archTexture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); + } } for (int i = 0; i < 5; i++) { @@ -301,6 +306,8 @@ void init() engine.initSkybox(); engine.initBubbles(); engine.generateObjectArray(); + engine.generateObjectSize(); + engine.generateObjectRotation(); initKeyRotation(); }