Now also using the correct chunks for the objects and rendering only the chunks which are necessary.
This commit is contained in:
parent
d0fed9a321
commit
ac48ab8cc0
@ -22,7 +22,7 @@ void Application::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Application::initLevel() {
|
void Application::initLevel() {
|
||||||
this->level = Level(levelXmlPath);
|
this->level = Level(levelXmlPath, farPlane);
|
||||||
level.getPhysics()->init(geometryPath);
|
level.getPhysics()->init(geometryPath);
|
||||||
// Don't change this!
|
// Don't change this!
|
||||||
ignoredMouseUpdates = 0;
|
ignoredMouseUpdates = 0;
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
#include "loader.hh"
|
#include "loader.hh"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
Level::Level(std::string xmlFilePath){
|
Level::Level(std::string xmlFilePath, float farPlane){
|
||||||
// default value
|
// default value
|
||||||
skydomeSize = 50.0f;
|
skydomeSize = 50.0f;
|
||||||
physics = Physics();
|
physics = Physics();
|
||||||
this->xmlFilePath = xmlFilePath;
|
this->xmlFilePath = xmlFilePath;
|
||||||
|
this->farPlane = farPlane;
|
||||||
}
|
}
|
||||||
|
|
||||||
Level::Level() {
|
Level::Level() {
|
||||||
@ -52,8 +53,33 @@ void Level::load() {
|
|||||||
|
|
||||||
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
||||||
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs) {
|
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs) {
|
||||||
for(unsigned int i = 0; i<chunks.size(); i++) {
|
int renderDistance = 0;
|
||||||
for(unsigned int j = 0; j<chunks.at(i).size(); j++) {
|
if ((int)farPlane % chunkSize == 0) {
|
||||||
|
renderDistance = farPlane/chunkSize;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
renderDistance = (farPlane/chunkSize) + 1;
|
||||||
|
}
|
||||||
|
int xPosition = ((int)cameraCenter->getPosition().x + (terrain.getHeightmapWidth()/2))/chunkSize;
|
||||||
|
int zPosition = ((int)cameraCenter->getPosition().z + (terrain.getHeightmapHeight()/2))/chunkSize;
|
||||||
|
int xStart = xPosition - renderDistance;
|
||||||
|
unsigned int xEnd = xPosition + renderDistance;
|
||||||
|
int zStart = zPosition - renderDistance;
|
||||||
|
unsigned int zEnd = zPosition + renderDistance;
|
||||||
|
if (xStart < 0) {
|
||||||
|
xStart = 0;
|
||||||
|
}
|
||||||
|
if (zStart < 0) {
|
||||||
|
zStart = 0;
|
||||||
|
}
|
||||||
|
if (xEnd >= chunks.size()) {
|
||||||
|
xEnd = chunks.size()-1;
|
||||||
|
}
|
||||||
|
if (zEnd >= chunks.at(0).size()) {
|
||||||
|
zEnd = chunks.at(0).size()-1;
|
||||||
|
}
|
||||||
|
for(unsigned int i = xStart; i<=xEnd; i++) {
|
||||||
|
for(unsigned int j = zStart; j<=zEnd; j++) {
|
||||||
if (lightingPass) {
|
if (lightingPass) {
|
||||||
chunks.at(i).at(j).render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs);
|
chunks.at(i).at(j).render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs);
|
||||||
}
|
}
|
||||||
@ -229,8 +255,13 @@ void Level::setSkydomeObject(Skydome object){
|
|||||||
|
|
||||||
void Level::addObject(Object* object) {
|
void Level::addObject(Object* object) {
|
||||||
allObjects.push_back(object);
|
allObjects.push_back(object);
|
||||||
//int xPosition = object->getPosition().x - terrain.getHeightmapHeight
|
int xPosition = ((int)object->getPosition().x + (terrain.getHeightmapWidth()/2))/chunkSize;
|
||||||
chunks.at(0).at(0).addObject(object);
|
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) {
|
||||||
|
chunks.at(xPosition).at(zPosition).addObject(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level::addPhysicsObject(Object* object) {
|
void Level::addPhysicsObject(Object* object) {
|
||||||
|
@ -23,7 +23,7 @@ extern "C" {
|
|||||||
|
|
||||||
class Level {
|
class Level {
|
||||||
public:
|
public:
|
||||||
Level(std::string xmlFilePath);
|
Level(std::string xmlFilePath, float farPlane);
|
||||||
Level();
|
Level();
|
||||||
~Level();
|
~Level();
|
||||||
void load();
|
void load();
|
||||||
@ -76,6 +76,7 @@ class Level {
|
|||||||
void printPosition();
|
void printPosition();
|
||||||
void generateChunks(int chunkSize);
|
void generateChunks(int chunkSize);
|
||||||
std::vector<std::vector<Chunk>>* getChunks();
|
std::vector<std::vector<Chunk>>* getChunks();
|
||||||
|
void addToSpecificChunk(Object* object, int xPosition, int zPosition);
|
||||||
private:
|
private:
|
||||||
lua_State* luaState=nullptr;
|
lua_State* luaState=nullptr;
|
||||||
std::vector<Object*> crossChunkObjects;
|
std::vector<Object*> crossChunkObjects;
|
||||||
@ -100,7 +101,8 @@ class Level {
|
|||||||
float strength;
|
float strength;
|
||||||
std::string xmlFilePath;
|
std::string xmlFilePath;
|
||||||
glm::vec3 nextLightPosition;
|
glm::vec3 nextLightPosition;
|
||||||
float chunkSize;
|
int chunkSize;
|
||||||
|
float farPlane;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -103,7 +103,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
|||||||
Object* terrainObject = new Object(terrainModel, terrainMaterial,
|
Object* terrainObject = new Object(terrainModel, terrainMaterial,
|
||||||
glm::vec3(-0.5*((float)level->getTerrain()->getHeightmapHeight()-1), 0.0f, -0.5f*((float)level->getTerrain()->getHeightmapWidth()-1)),
|
glm::vec3(-0.5*((float)level->getTerrain()->getHeightmapHeight()-1), 0.0f, -0.5f*((float)level->getTerrain()->getHeightmapWidth()-1)),
|
||||||
glm::vec3(0.0f, 0.0f, 0.0f), true);
|
glm::vec3(0.0f, 0.0f, 0.0f), true);
|
||||||
level->addObject(terrainObject);
|
level->addToSpecificChunk(terrainObject, i, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
level->getPhysics()->addTerrain(level->getTerrain()->getHeightmapWidth(), level->getTerrain()->getHeightmapHeight(), level->getTerrain()->getHeightmap());
|
level->getPhysics()->addTerrain(level->getTerrain()->getHeightmapWidth(), level->getTerrain()->getHeightmapHeight(), level->getTerrain()->getHeightmap());
|
||||||
|
@ -38,11 +38,11 @@ SharedVertexArrayObject Terrain::makeTriangleMesh(int startX, int startZ, int en
|
|||||||
if (startZ < 0) {
|
if (startZ < 0) {
|
||||||
startZ = 0;
|
startZ = 0;
|
||||||
}
|
}
|
||||||
if (endX > heightmapHeight) {
|
if (endX > heightmapWidth) {
|
||||||
endX = heightmapHeight;
|
endX = heightmapWidth;
|
||||||
}
|
}
|
||||||
if (endZ > heightmapWidth) {
|
if (endZ > heightmapHeight) {
|
||||||
endZ = heightmapWidth;
|
endZ = heightmapHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedArrayBuffer ab = SharedArrayBuffer(new ArrayBuffer());
|
SharedArrayBuffer ab = SharedArrayBuffer(new ArrayBuffer());
|
||||||
|
Loading…
Reference in New Issue
Block a user