From 43b752ee63c31446e44cc1e652641db5540ddd27 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Wed, 18 Mar 2015 08:54:38 +0100 Subject: [PATCH] Implemented cross chunk objects. This concludes the chunk render implementation and closes #4. --- data/levels/Compositions.xml | 22 ++++++++++++++++++++++ game/level.cc | 21 +++++++++++++++++---- game/level.hh | 2 +- game/loader.cc | 3 ++- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/data/levels/Compositions.xml b/data/levels/Compositions.xml index 5989849..a955243 100644 --- a/data/levels/Compositions.xml +++ b/data/levels/Compositions.xml @@ -5,6 +5,7 @@ 20 false + true marbleSmooth.obj 0.0 @@ -22,6 +23,7 @@ 40 false + true block.obj 0.0 @@ -39,6 +41,7 @@ 60 false + false column.obj 0.0 @@ -56,6 +59,7 @@ 80 false + false torch.obj 0.0 @@ -85,6 +89,7 @@ 81 false + false torch.obj 0.0 @@ -129,6 +134,7 @@ 100 false + false column.obj 0.0 @@ -168,6 +174,7 @@ 120 false + false switchInner.obj 0.0 @@ -251,6 +258,7 @@ 140 true + false block.obj 0.0 @@ -268,6 +276,7 @@ 141 true + false block.obj 0.0 @@ -289,6 +298,7 @@ 160 true + false block.obj 0.0 @@ -339,6 +349,7 @@ 161 true + false block.obj 0.0 @@ -389,6 +400,7 @@ 163 true + false torch.obj 0.0 @@ -462,6 +474,7 @@ 164 true + false torch.obj -1.5 @@ -535,6 +548,7 @@ 180 true + false simpleWall.obj 0.0 @@ -552,6 +566,7 @@ 181 true + false simpleWall.obj 0.0 @@ -569,6 +584,7 @@ 200 false + true block.obj 0.0 @@ -586,6 +602,7 @@ 220 true + false gate.obj 0.0 @@ -603,6 +620,7 @@ 221 true + false gate.obj 0.0 @@ -620,6 +638,7 @@ 240 false + true movableBlock.obj 0.0 @@ -637,6 +656,7 @@ 245 false + false brazier.obj 0.0 @@ -654,6 +674,7 @@ 250 false + false hint.obj 0.0 @@ -671,6 +692,7 @@ 254 false + false exit.obj 0.0 diff --git a/game/level.cc b/game/level.cc index 2b86dbd..1040f3a 100644 --- a/game/level.cc +++ b/game/level.cc @@ -88,6 +88,14 @@ void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, } } } + for (unsigned int i = 0; irender(shader, lightingPass, true, viewProjectionMatrix, shadowVPs); + } + else { + crossChunkObjects.at(i)->render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs); + } + } if (lightingPass && waterPlane) { waterPlane->render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs); } @@ -253,11 +261,16 @@ void Level::setSkydomeObject(Skydome object){ this->skydome = object; } -void Level::addObject(Object* object) { +void Level::addObject(Object* object, bool crossesChunks) { allObjects.push_back(object); - int xPosition = ((int)object->getPosition().x + (terrain.getHeightmapWidth()/2))/chunkSize; - int zPosition = ((int)object->getPosition().z + (terrain.getHeightmapHeight()/2))/chunkSize; - chunks.at(xPosition).at(zPosition).addObject(object); + if (crossesChunks) { + crossChunkObjects.push_back(object); + } + else { + int xPosition = ((int)object->getPosition().x + (terrain.getHeightmapWidth()/2))/chunkSize; + int zPosition = ((int)object->getPosition().z + (terrain.getHeightmapHeight()/2))/chunkSize; + chunks.at(xPosition).at(zPosition).addObject(object); + } } void Level::addToSpecificChunk(Object* object, int xPosition, int zPosition) { diff --git a/game/level.hh b/game/level.hh index 587a72f..f5f61c3 100644 --- a/game/level.hh +++ b/game/level.hh @@ -49,7 +49,7 @@ class Level { void moveObject(int objectIndex, float strength, float xPos, float yPos, float zPos); void setStrength(float strength); void setSkydomeObject(Skydome object); - void addObject(Object* object); + void addObject(Object* object, bool crossesChunks); void addPhysicsObject(Object* object); void setAmbientLight(glm::vec3 colour); void setFogColourDay(glm::vec4 colour); diff --git a/game/loader.cc b/game/loader.cc index dc8bab0..cc7c616 100644 --- a/game/loader.cc +++ b/game/loader.cc @@ -294,7 +294,8 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa objectRot[2] = queryFloat(xmlObject, "zRot"); objectRot *= 0.0174532925; //transform degrees to radians Object* object = new Object(model, material, objectPosition, compRot+objectRot, renderable); - level->addObject(object); + bool crossesChunks = queryBool(composition, "crossesChunks"); + level->addObject(object, crossesChunks); //add object to physics std::string physicType = queryString(objectData, "physicType");