generate pants on y from generated terrain

This commit is contained in:
Thyme1 2022-01-25 20:57:03 +01:00
parent c99d7d76db
commit 1be1d6d95a
5 changed files with 42 additions and 10 deletions

View File

@ -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);
}
}

View File

@ -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<glm::vec3> 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<glm::vec3> genBubbleKeyPoints();
};

View File

@ -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;

View File

@ -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;

View File

@ -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();
}