Skip to content
Snippets Groups Projects
Commit 2db9b15d authored by Sindre Eiklid's avatar Sindre Eiklid
Browse files

Randomize tree placement

parent c0d89d4c
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ class Entity {
GLuint aerialShaderProgram = 0, groundShaderProgram = 0;
GLuint aerialVAO = 0, groundVAO = 0;
int aerialMeshAmount = 0, groundMeshAmount = 0;
glm::vec3 aerialInstancePos[42], groundInstancePos[18];
glm::vec3 aerialInstancePos[1000], groundInstancePos[1000];
int aerialInstanceIndex = 0, groundInstanceIndex = 0;
std::vector<int> aerialLastDirection, groundLastDirection;
std::vector<std::vector<int>> aerialGridPosition, groundGridPosition;
......
......@@ -3,6 +3,7 @@
/* library */
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <vector>
/**
* @brief Vegetation class.
......@@ -13,7 +14,9 @@ class Vegetation {
/* private data */
GLuint shaderProgram = 0;
GLuint VAO = 0;
int meshAmount = 0, instanceIndex = 0;
int meshAmount = 0;
glm::vec3 instancePos[1000];
int instanceIndex = 0;
public:
/* public functionality */
~Vegetation();
......
......@@ -15,7 +15,7 @@ static const std::string modelVertexShader = R"(
uniform mat4 u_modelMatrix = mat4(1);
uniform mat4 u_viewMatrix = mat4(1);
uniform mat4 u_projectionMatrix = mat4(1);
uniform vec3 offsets[600];
uniform vec3 offsets[1000];
/**
* Main vertex shader program.
*/
......
......@@ -5,7 +5,6 @@
#include "camera.h"
#include "mapData.h"
#include "functionality.h"
#include <glm/glm.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
......@@ -39,7 +38,6 @@ Vegetation::Vegetation() {
modelMatrix = glm::scale(glm::mat4(1.f), glm::vec3(0.01f));
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "u_modelMatrix"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
//generate coordinates for each instance
glm::vec3 gridInstancePos[600];
for(int i = 0; i < g_mapData->gridHeight; i += 5) {
for(int j = 0; j < g_mapData->gridWidth; j += 5) {
//branch if depth is between 42 and 79 (in green area)
......@@ -49,18 +47,20 @@ Vegetation::Vegetation() {
translation.x = g_mapData->gridElement[std::make_pair(i, j)][0][X] * (100.f * 2.f);
translation.z = -g_mapData->gridElement[std::make_pair(i, j)][0][Y] * (100.f * 2.f);
translation.y = g_mapData->gridElement[std::make_pair(i, j)][0][Z] * (100.f * 2.f);
gridInstancePos[instanceIndex] = translation;
instancePos[instanceIndex] = translation;
instanceIndex++;
if(j + 10 < g_mapData->gridWidth) j += randomIndex(2, 5);
//remember initial position to compute coalition when moving entities
g_mapData->obstaclesInGridElement[i][j] = false;
}
}
}
std::cout << instanceIndex << std::endl;
//send initial position to uniform
for(unsigned int i = 0; i < instanceIndex; i++) {
std::string buffer = "offsets[" + std::to_string(i) + "]";
const char *uniformLoc = buffer.c_str();
glUniform3fv(glGetUniformLocation(shaderProgram, uniformLoc), 1, glm::value_ptr(gridInstancePos[i]));
glUniform3fv(glGetUniformLocation(shaderProgram, uniformLoc), 1, glm::value_ptr(instancePos[i]));
}
glUseProgram(0);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment