Load skybox from Json file
This commit is contained in:
@@ -2,7 +2,10 @@
|
|||||||
"models": [
|
"models": [
|
||||||
{
|
{
|
||||||
"unique_name": "backpack",
|
"unique_name": "backpack",
|
||||||
"path": "res/models/backpack.ffo"
|
"path": "res/models/backpack.ffo",
|
||||||
|
|
||||||
|
"position": ["0.0", "0.0", "0.0"],
|
||||||
|
"rotation": ["0.0", "0.0", "0.0"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"unique_name": "ground",
|
"unique_name": "ground",
|
||||||
|
|||||||
@@ -105,9 +105,6 @@ void Controller::run()
|
|||||||
|
|
||||||
World world(shaderPrograms);
|
World world(shaderPrograms);
|
||||||
|
|
||||||
Model *skyboxModel = world.getModelByName("cube");
|
|
||||||
Skybox skybox(skyboxModel, getShaderProgramByName("skyboxProgram"), "res/textures/skybox/");
|
|
||||||
|
|
||||||
Entity *lightSource = world.getEntityByName("light");
|
Entity *lightSource = world.getEntityByName("light");
|
||||||
lightSource->setScale(0.1f);
|
lightSource->setScale(0.1f);
|
||||||
lightSource->setRotation(glm::vec3(0.f));
|
lightSource->setRotation(glm::vec3(0.f));
|
||||||
@@ -163,7 +160,7 @@ void Controller::run()
|
|||||||
|
|
||||||
glViewport(0, 0, gameWindow->getWindowWidth(), gameWindow->getWindowHeight());
|
glViewport(0, 0, gameWindow->getWindowWidth(), gameWindow->getWindowHeight());
|
||||||
|
|
||||||
skybox.draw(camera->getView(), camera->getProj());
|
world.getSkybox()->draw(camera->getView(), camera->getProj());
|
||||||
world.draw(camera->getViewProj(), camera->getPosition());
|
world.draw(camera->getViewProj(), camera->getPosition());
|
||||||
|
|
||||||
pp_framebuffer->unbind();
|
pp_framebuffer->unbind();
|
||||||
|
|||||||
@@ -106,3 +106,15 @@ std::vector<ShaderProgram *> JsonParser::getShaderPrograms()
|
|||||||
return temp_shaderPrograms;
|
return temp_shaderPrograms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Skybox *JsonParser::getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram)
|
||||||
|
{
|
||||||
|
Skybox* temp_skybox;
|
||||||
|
|
||||||
|
const Json::Value shaderProgramsJson = root["skybox"];
|
||||||
|
|
||||||
|
std::string skybox_texturePath = shaderProgramsJson["texturePath"].asString();
|
||||||
|
temp_skybox = new Skybox(cubeModel, skyboxProgram, skybox_texturePath.c_str());
|
||||||
|
std::cout << "Loaded Skybox \"" << skybox_texturePath << "\"" << std::endl;
|
||||||
|
|
||||||
|
return temp_skybox;
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public:
|
|||||||
|
|
||||||
std::vector<Model*> getModels();
|
std::vector<Model*> getModels();
|
||||||
std::vector<Entity*> getEntities(std::vector<Model*> &models, std::vector<ShaderProgram*> shaderPrograms);
|
std::vector<Entity*> getEntities(std::vector<Model*> &models, std::vector<ShaderProgram*> shaderPrograms);
|
||||||
|
Skybox *getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram);
|
||||||
|
|
||||||
std::vector<ShaderProgram*> getShaderPrograms();
|
std::vector<ShaderProgram*> getShaderPrograms();
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ World::World(std::vector<ShaderProgram*> shaderPrograms) :
|
|||||||
JsonParser worldParser("res/models.json");
|
JsonParser worldParser("res/models.json");
|
||||||
models = worldParser.getModels();
|
models = worldParser.getModels();
|
||||||
entities = worldParser.getEntities(models, shaderPrograms);
|
entities = worldParser.getEntities(models, shaderPrograms);
|
||||||
|
skybox = worldParser.getSkybox(getModelByName("cube"), Controller::getShaderProgramByName(shaderPrograms, "skyboxProgram"));
|
||||||
}
|
}
|
||||||
|
|
||||||
World::~World()
|
World::~World()
|
||||||
@@ -45,6 +46,8 @@ World::~World()
|
|||||||
for (auto it = entities.begin(); it != entities.end(); it++) {
|
for (auto it = entities.begin(); it != entities.end(); it++) {
|
||||||
delete (*it);
|
delete (*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete skybox;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::addEntity(Entity *entity)
|
void World::addEntity(Entity *entity)
|
||||||
@@ -71,12 +74,6 @@ void World::clearEntities()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::loadWorld ( unsigned int id )
|
|
||||||
{
|
|
||||||
// Load World from File...
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void World::updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color)
|
void World::updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color)
|
||||||
{
|
{
|
||||||
pointLights[lightId].setActive(active);
|
pointLights[lightId].setActive(active);
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ public:
|
|||||||
void removeEntityByName(std::string name);
|
void removeEntityByName(std::string name);
|
||||||
void clearEntities();
|
void clearEntities();
|
||||||
|
|
||||||
void loadWorld(unsigned int id);
|
|
||||||
|
|
||||||
void updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color);
|
void updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color);
|
||||||
void updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color);
|
void updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color);
|
||||||
|
|
||||||
@@ -32,6 +30,10 @@ public:
|
|||||||
{
|
{
|
||||||
return pointLights.data();
|
return pointLights.data();
|
||||||
}
|
}
|
||||||
|
Skybox *getSkybox()
|
||||||
|
{
|
||||||
|
return skybox;
|
||||||
|
}
|
||||||
|
|
||||||
Entity* getEntityByName(std::string name);
|
Entity* getEntityByName(std::string name);
|
||||||
Entity* getEntityById(uint32_t id);
|
Entity* getEntityById(uint32_t id);
|
||||||
@@ -45,6 +47,7 @@ private:
|
|||||||
|
|
||||||
std::vector<Model*> models;
|
std::vector<Model*> models;
|
||||||
std::vector<Entity*> entities;
|
std::vector<Entity*> entities;
|
||||||
|
Skybox *skybox;
|
||||||
|
|
||||||
// Lights
|
// Lights
|
||||||
DirectionalLight directionalLight;
|
DirectionalLight directionalLight;
|
||||||
|
|||||||
Reference in New Issue
Block a user