add random values for rotation/size objects

This commit is contained in:
Matraf 2022-01-26 12:23:51 +01:00
parent 03d3efd52e
commit a0ac366237
6 changed files with 46 additions and 19 deletions

View File

@ -29,7 +29,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<ShowAllFiles>false</ShowAllFiles> <ShowAllFiles>true</ShowAllFiles>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -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() { void Core::Engine::initBubbles() {
this->generateBubbleArray(); this->generateBubbleArray();
} }

View File

@ -19,6 +19,8 @@ namespace Core {
GLuint skyboxVAO; GLuint skyboxVAO;
Core::RenderContext submarineContext, fishContext, bubbleContext, terrainContext, plant1Context, plant2Context, plant3Context, coral1Context, rocktower1Context, archContext; Core::RenderContext submarineContext, fishContext, bubbleContext, terrainContext, plant1Context, plant2Context, plant3Context, coral1Context, rocktower1Context, archContext;
std::vector<glm::vec3> bubbleArray[300]; std::vector<glm::vec3> bubbleArray[300];
std::vector<float> objectSize;
std::vector<float> objectRotation;
glm::vec3 objectArray[200]; glm::vec3 objectArray[200];
void initShaderPrograms(); void initShaderPrograms();
void shutdownShaderPrograms(); void shutdownShaderPrograms();
@ -27,6 +29,8 @@ namespace Core {
void initSkybox(); void initSkybox();
void initBubbles(); void initBubbles();
void generateObjectArray(); void generateObjectArray();
void generateObjectSize();
void generateObjectRotation();
Terrain terrain; Terrain terrain;
void initRandomGenerator(std::default_random_engine gen, std::uniform_int_distribution<> distr); void initRandomGenerator(std::default_random_engine gen, std::uniform_int_distribution<> distr);
static const float skyboxVerticeParameter; static const float skyboxVerticeParameter;

View File

@ -30,7 +30,7 @@ obj::Model Terrain::generateTerrain() {
textureCoords[vertexPointer * 2 + 1] = float(i) / float(VERTEX_COUNT - 1) * 40; textureCoords[vertexPointer * 2 + 1] = float(i) / float(VERTEX_COUNT - 1) * 40;
vertexPointer++; vertexPointer++;
heightTable[j][i] = height; heightTable[j][i] = height;
std::cout << heightTable[j][i] << std::endl; //std::cout << heightTable[j][i] << std::endl;
} }
} }
int pointer = 0; int pointer = 0;

View File

@ -240,22 +240,27 @@ void renderScene()
for (int j = 0; j < 25; j++) { for (int j = 0; j < 100; 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)); glm::mat4 objectTransformation;
if (j % 5 == 0) {
drawObjectTexture(engine.plant1Context, objectTransformation, engine.plant1Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); 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);
objectTransformation = glm::translate(engine.objectArray[25+j]) * glm::rotate(glm::radians(0.f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.3f)); } else if (j % 5 == 1) {
drawObjectTexture(engine.plant2Context, objectTransformation, engine.plant2Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); 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);
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); 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]));
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.plant3Context, objectTransformation, engine.plant3Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix);
drawObjectTexture(engine.coral1Context, objectTransformation, engine.coral1Texture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); }
else if (j % 5 == 3) {
objectTransformation = glm::translate(engine.objectArray[100+j]) * glm::rotate(glm::radians(90.f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.3f)); 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.archContext, objectTransformation, engine.archTexture, engine.textureShader, lightDir, cameraMatrix, perspectiveMatrix); 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++) { for (int i = 0; i < 5; i++) {
@ -301,6 +306,8 @@ void init()
engine.initSkybox(); engine.initSkybox();
engine.initBubbles(); engine.initBubbles();
engine.generateObjectArray(); engine.generateObjectArray();
engine.generateObjectSize();
engine.generateObjectRotation();
initKeyRotation(); initKeyRotation();
} }