Added generation of chunks.

This commit is contained in:
Faerbit 2015-03-17 09:39:42 +01:00
parent 7b742e913f
commit 498be94102
2 changed files with 31 additions and 9 deletions

View File

@ -53,11 +53,13 @@ void Level::load() {
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs) {
for(unsigned int i = 0; i<chunks.size(); i++) {
if (lightingPass) {
chunks.at(i).render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs);
}
else {
chunks.at(i).render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs);
for(unsigned int j = 0; j<chunks.at(i).size(); j++) {
if (lightingPass) {
chunks.at(i).at(j).render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs);
}
else {
chunks.at(i).at(j).render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs);
}
}
}
if (lightingPass && waterPlane) {
@ -227,7 +229,7 @@ void Level::setSkydomeObject(Skydome object){
void Level::addObject(Object* object) {
allObjects.push_back(object);
chunks.at(0).addObject(object);
chunks.at(0).at(0).addObject(object);
}
void Level::addPhysicsObject(Object* object) {
@ -333,6 +335,26 @@ void Level::printPosition() {
}
void Level::generateChunks(int chunkSize) {
chunks = std::vector<Chunk>(1);
chunks.at(0) = Chunk();
int numberChunksX = 0;
if (terrain.getHeightmapHeight() % chunkSize == 0) {
numberChunksX = terrain.getHeightmapHeight()/chunkSize;
}
else {
numberChunksX = (terrain.getHeightmapHeight()/chunkSize) + 1;
}
int numberChunksZ = 0;
if (terrain.getHeightmapHeight() % chunkSize == 0) {
numberChunksZ = terrain.getHeightmapHeight()/chunkSize;
}
else {
numberChunksZ = (terrain.getHeightmapHeight()/chunkSize) + 1;
}
chunks = std::vector<std::vector<Chunk>> (numberChunksX);
for(int i = 0; i<numberChunksX; i++) {
std::vector<Chunk> zChunks = std::vector<Chunk>(numberChunksZ);
for(int j = 0; j<numberChunksZ; j++) {
zChunks.at(j) = Chunk();
}
chunks.at(i) = zChunks;
}
}

View File

@ -80,7 +80,7 @@ class Level {
std::vector<Object*> crossChunkObjects;
std::vector<Object*> allObjects;
std::vector<Object*> physicsObjects;
std::vector<Chunk> chunks;
std::vector<std::vector<Chunk>> chunks;
std::vector<Light> lights;
std::vector<Trigger> triggers;
Object* waterPlane;