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

View File

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

View File

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