Implemented cross chunk objects. This concludes the chunk render implementation and closes #4.

This commit is contained in:
Faerbit 2015-03-18 08:54:38 +01:00
parent f9212c9938
commit 43b752ee63
4 changed files with 42 additions and 6 deletions

View File

@ -5,6 +5,7 @@
<composition> <composition>
<typeID>20</typeID> <typeID>20</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
<crossesChunks>true</crossesChunks>
<object> <object>
<modelPath>marbleSmooth.obj</modelPath> <modelPath>marbleSmooth.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -22,6 +23,7 @@
<composition> <composition>
<typeID>40</typeID> <typeID>40</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
<crossesChunks>true</crossesChunks>
<object> <object>
<modelPath>block.obj</modelPath> <modelPath>block.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -39,6 +41,7 @@
<composition> <composition>
<typeID>60</typeID> <typeID>60</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>column.obj</modelPath> <modelPath>column.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -56,6 +59,7 @@
<composition> <composition>
<typeID>80</typeID> <typeID>80</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>torch.obj</modelPath> <modelPath>torch.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -85,6 +89,7 @@
<composition> <composition>
<typeID>81</typeID> <typeID>81</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>torch.obj</modelPath> <modelPath>torch.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -129,6 +134,7 @@
<composition> <composition>
<typeID>100</typeID> <typeID>100</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>column.obj</modelPath> <modelPath>column.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -168,6 +174,7 @@
<composition> <composition>
<typeID>120</typeID> <typeID>120</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>switchInner.obj</modelPath> <modelPath>switchInner.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -251,6 +258,7 @@
<composition> <composition>
<typeID>140</typeID> <typeID>140</typeID>
<ignoreHeightmap>true</ignoreHeightmap> <ignoreHeightmap>true</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>block.obj</modelPath> <modelPath>block.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -268,6 +276,7 @@
<composition> <composition>
<typeID>141</typeID> <typeID>141</typeID>
<ignoreHeightmap>true</ignoreHeightmap> <ignoreHeightmap>true</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>block.obj</modelPath> <modelPath>block.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -289,6 +298,7 @@
<composition> <composition>
<typeID>160</typeID> <typeID>160</typeID>
<ignoreHeightmap>true</ignoreHeightmap> <ignoreHeightmap>true</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>block.obj</modelPath> <modelPath>block.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -339,6 +349,7 @@
<composition> <composition>
<typeID>161</typeID> <typeID>161</typeID>
<ignoreHeightmap>true</ignoreHeightmap> <ignoreHeightmap>true</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>block.obj</modelPath> <modelPath>block.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -389,6 +400,7 @@
<composition> <composition>
<typeID>163</typeID> <typeID>163</typeID>
<ignoreHeightmap>true</ignoreHeightmap> <ignoreHeightmap>true</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>torch.obj</modelPath> <modelPath>torch.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -462,6 +474,7 @@
<composition> <composition>
<typeID>164</typeID> <typeID>164</typeID>
<ignoreHeightmap>true</ignoreHeightmap> <ignoreHeightmap>true</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>torch.obj</modelPath> <modelPath>torch.obj</modelPath>
<xOffset>-1.5</xOffset> <xOffset>-1.5</xOffset>
@ -535,6 +548,7 @@
<composition> <composition>
<typeID>180</typeID> <typeID>180</typeID>
<ignoreHeightmap>true</ignoreHeightmap> <ignoreHeightmap>true</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>simpleWall.obj</modelPath> <modelPath>simpleWall.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -552,6 +566,7 @@
<composition> <composition>
<typeID>181</typeID> <typeID>181</typeID>
<ignoreHeightmap>true</ignoreHeightmap> <ignoreHeightmap>true</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>simpleWall.obj</modelPath> <modelPath>simpleWall.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -569,6 +584,7 @@
<composition> <composition>
<typeID>200</typeID> <typeID>200</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
<crossesChunks>true</crossesChunks>
<object> <object>
<modelPath>block.obj</modelPath> <modelPath>block.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -586,6 +602,7 @@
<composition> <composition>
<typeID>220</typeID> <typeID>220</typeID>
<ignoreHeightmap>true</ignoreHeightmap> <ignoreHeightmap>true</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>gate.obj</modelPath> <modelPath>gate.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -603,6 +620,7 @@
<composition> <composition>
<typeID>221</typeID> <typeID>221</typeID>
<ignoreHeightmap>true</ignoreHeightmap> <ignoreHeightmap>true</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>gate.obj</modelPath> <modelPath>gate.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -620,6 +638,7 @@
<composition> <composition>
<typeID>240</typeID> <typeID>240</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
<crossesChunks>true</crossesChunks>
<object> <object>
<modelPath>movableBlock.obj</modelPath> <modelPath>movableBlock.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -637,6 +656,7 @@
<composition> <composition>
<typeID>245</typeID> <typeID>245</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>brazier.obj</modelPath> <modelPath>brazier.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -654,6 +674,7 @@
<composition> <composition>
<typeID>250</typeID> <typeID>250</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>hint.obj</modelPath> <modelPath>hint.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
@ -671,6 +692,7 @@
<composition> <composition>
<typeID>254</typeID> <typeID>254</typeID>
<ignoreHeightmap>false</ignoreHeightmap> <ignoreHeightmap>false</ignoreHeightmap>
<crossesChunks>false</crossesChunks>
<object> <object>
<modelPath>exit.obj</modelPath> <modelPath>exit.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>

View File

@ -88,6 +88,14 @@ void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
} }
} }
} }
for (unsigned int i = 0; i<crossChunkObjects.size(); i++) {
if (lightingPass) {
crossChunkObjects.at(i)->render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs);
}
else {
crossChunkObjects.at(i)->render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs);
}
}
if (lightingPass && waterPlane) { if (lightingPass && waterPlane) {
waterPlane->render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs); waterPlane->render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs);
} }
@ -253,12 +261,17 @@ void Level::setSkydomeObject(Skydome object){
this->skydome = object; this->skydome = object;
} }
void Level::addObject(Object* object) { void Level::addObject(Object* object, bool crossesChunks) {
allObjects.push_back(object); allObjects.push_back(object);
if (crossesChunks) {
crossChunkObjects.push_back(object);
}
else {
int xPosition = ((int)object->getPosition().x + (terrain.getHeightmapWidth()/2))/chunkSize; int xPosition = ((int)object->getPosition().x + (terrain.getHeightmapWidth()/2))/chunkSize;
int zPosition = ((int)object->getPosition().z + (terrain.getHeightmapHeight()/2))/chunkSize; int zPosition = ((int)object->getPosition().z + (terrain.getHeightmapHeight()/2))/chunkSize;
chunks.at(xPosition).at(zPosition).addObject(object); chunks.at(xPosition).at(zPosition).addObject(object);
} }
}
void Level::addToSpecificChunk(Object* object, int xPosition, int zPosition) { void Level::addToSpecificChunk(Object* object, int xPosition, int zPosition) {
chunks.at(xPosition).at(zPosition).addObject(object); chunks.at(xPosition).at(zPosition).addObject(object);

View File

@ -49,7 +49,7 @@ class Level {
void moveObject(int objectIndex, float strength, float xPos, float yPos, float zPos); void moveObject(int objectIndex, float strength, float xPos, float yPos, float zPos);
void setStrength(float strength); void setStrength(float strength);
void setSkydomeObject(Skydome object); void setSkydomeObject(Skydome object);
void addObject(Object* object); void addObject(Object* object, bool crossesChunks);
void addPhysicsObject(Object* object); void addPhysicsObject(Object* object);
void setAmbientLight(glm::vec3 colour); void setAmbientLight(glm::vec3 colour);
void setFogColourDay(glm::vec4 colour); void setFogColourDay(glm::vec4 colour);

View File

@ -294,7 +294,8 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
objectRot[2] = queryFloat(xmlObject, "zRot"); objectRot[2] = queryFloat(xmlObject, "zRot");
objectRot *= 0.0174532925; //transform degrees to radians objectRot *= 0.0174532925; //transform degrees to radians
Object* object = new Object(model, material, objectPosition, compRot+objectRot, renderable); 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 //add object to physics
std::string physicType = queryString(objectData, "physicType"); std::string physicType = queryString(objectData, "physicType");