Develop into master #9
@@ -10,19 +10,27 @@
|
|||||||
#include "../renderEngine/renderer.h"
|
#include "../renderEngine/renderer.h"
|
||||||
#include "../shaders/entity_shader.h"
|
#include "../shaders/entity_shader.h"
|
||||||
#include "../toolbox/toolbox.h"
|
#include "../toolbox/toolbox.h"
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
|
#define MAX_MODEL_DEQUE_SIZE 6 // max amount of models to load at the same time
|
||||||
|
#define UPCOMING_MODEL_AMOUNT 4 // how much models should be loaded in front of us
|
||||||
|
|
||||||
|
|
||||||
namespace scene
|
namespace scene
|
||||||
{
|
{
|
||||||
std::vector<entities::Entity> entities;
|
std::deque<entities::Entity> entites;
|
||||||
std::vector<entities::Light> lights;
|
std::deque<entities::Light> lights;
|
||||||
|
entities::Light sun;
|
||||||
|
|
||||||
models::RawModel raw_model;
|
models::RawModel raw_model;
|
||||||
models::ModelTexture texture;
|
models::ModelTexture texture;
|
||||||
shaders::EntityShader *shader;
|
shaders::EntityShader* shader;
|
||||||
shaders::GuiShader *gui_shader;
|
shaders::GuiShader* gui_shader;
|
||||||
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
|
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
|
||||||
std::vector<gui::GuiTexture*> guis;
|
std::vector<gui::GuiTexture*> guis;
|
||||||
|
|
||||||
|
models::TexturedModel model;
|
||||||
|
|
||||||
|
|
||||||
In_Game_Scene::In_Game_Scene()
|
In_Game_Scene::In_Game_Scene()
|
||||||
{
|
{
|
||||||
@@ -34,22 +42,41 @@ namespace scene
|
|||||||
gui_shader->Init();
|
gui_shader->Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void load_chunk(int model_pos)
|
||||||
|
{
|
||||||
|
std::cout << "loading model chunk" << std::endl;
|
||||||
|
if (entites.size() >= MAX_MODEL_DEQUE_SIZE)
|
||||||
|
{
|
||||||
|
entites.pop_back();
|
||||||
|
}
|
||||||
|
int z_offset = model_pos * (model.raw_model.model_size.x * 20); // how much "in the distance" we should load the model
|
||||||
|
entites.push_front(entities::Entity(model, glm::vec3(0, -50, -50 - z_offset), glm::vec3(0, 90, 0), 20));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
scene::Scenes scene::In_Game_Scene::start(GLFWwindow* window)
|
scene::Scenes scene::In_Game_Scene::start(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
raw_model = render_engine::LoadObjModel("res/House.obj");
|
raw_model = render_engine::LoadObjModel("res/House.obj");
|
||||||
texture = { render_engine::loader::LoadTexture("res/Texture.png") };
|
texture = { render_engine::loader::LoadTexture("res/Texture.png") };
|
||||||
texture.shine_damper = 10;
|
texture.shine_damper = 10;
|
||||||
texture.reflectivity = 0;
|
texture.reflectivity = 0;
|
||||||
models::TexturedModel model = { raw_model, texture };
|
model = { raw_model, texture };
|
||||||
|
|
||||||
|
/*int z = 0;
|
||||||
|
|
||||||
int z = 0;
|
|
||||||
for (int i = 0; i < 5; ++i)
|
for (int i = 0; i < 5; ++i)
|
||||||
{
|
{
|
||||||
entities.push_back(entities::Entity(model, glm::vec3(0, -50, -50 - z), glm::vec3(0, 90, 0), 20));
|
entities.push_back(entities::Entity(model, glm::vec3(0, -50, -50 - z), glm::vec3(0, 90, 0), 20));
|
||||||
z += (raw_model.model_size.x * 20);
|
z += (raw_model.model_size.x * 20);
|
||||||
|
}*/
|
||||||
|
for (int i = 0; i <= UPCOMING_MODEL_AMOUNT; i++)
|
||||||
|
{
|
||||||
|
load_chunk(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
lights.push_back(entities::Light(glm::vec3(0, 1000, -7000), glm::vec3(5, 5, 5)));
|
sun = entities::Light(glm::vec3(0, 1000, -7000), glm::vec3(5, 5, 5));
|
||||||
lights.push_back(entities::Light(glm::vec3(0, 0, -30), glm::vec3(2, 0, 2), glm::vec3(0.0001f, 0.0001f, 0.0001f)));
|
lights.push_back(entities::Light(glm::vec3(0, 0, -30), glm::vec3(2, 0, 2), glm::vec3(0.0001f, 0.0001f, 0.0001f)));
|
||||||
lights.push_back(entities::Light(glm::vec3(0, 0, -200), glm::vec3(0, 2, 0), glm::vec3(0.0001f, 0.0001f, 0.0001f)));
|
lights.push_back(entities::Light(glm::vec3(0, 0, -200), glm::vec3(0, 2, 0), glm::vec3(0.0001f, 0.0001f, 0.0001f)));
|
||||||
|
|
||||||
@@ -90,9 +117,14 @@ namespace scene
|
|||||||
shader->LoadViewMatrix(camera);
|
shader->LoadViewMatrix(camera);
|
||||||
|
|
||||||
// Renders each entity in the entities list
|
// Renders each entity in the entities list
|
||||||
for (entities::Entity& entity : entities)
|
/*for (entities::Entity& entity : entities)
|
||||||
{
|
{
|
||||||
render_engine::renderer::Render(entity, *shader);
|
render_engine::renderer::Render(entity, *shader);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
for (entities::Entity& model_entity : entites)
|
||||||
|
{
|
||||||
|
render_engine::renderer::Render(model_entity, *shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render GUI items
|
// Render GUI items
|
||||||
@@ -105,6 +137,17 @@ namespace scene
|
|||||||
void scene::In_Game_Scene::update(GLFWwindow* window)
|
void scene::In_Game_Scene::update(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
camera.Move(window);
|
camera.Move(window);
|
||||||
|
|
||||||
|
// calculate where the next house model should be loaded
|
||||||
|
static int last_model_pos = 0;
|
||||||
|
int model_pos = -round(camera.GetPosition().z / (model.raw_model.model_size.x * 20)); // how much models we have passed, minus because we are moving in the negative z axis
|
||||||
|
|
||||||
|
// if we have passed a model, load a new one and delete the one behind us
|
||||||
|
if (last_model_pos != model_pos)
|
||||||
|
{
|
||||||
|
load_chunk(model_pos + UPCOMING_MODEL_AMOUNT);
|
||||||
|
}
|
||||||
|
last_model_pos = model_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void scene::In_Game_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods)
|
void scene::In_Game_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "entity_shader.h"
|
#include "entity_shader.h"
|
||||||
#include "../toolbox/toolbox.h"
|
#include "../toolbox/toolbox.h"
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
namespace shaders
|
namespace shaders
|
||||||
{
|
{
|
||||||
@@ -160,6 +161,25 @@ namespace shaders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityShader::LoadLights(std::deque<entities::Light>& lights) const
|
||||||
|
{
|
||||||
|
for (int i = 0; i < MAX_LIGHTS; ++i)
|
||||||
|
{
|
||||||
|
if (i < lights.size())
|
||||||
|
{
|
||||||
|
LoadVector(location_light_position[i], lights[i].GetPosition());
|
||||||
|
LoadVector(location_light_color[i], lights[i].GetColor());
|
||||||
|
LoadVector(location_light_attenuation[i], lights[i].GetAttenuation());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadVector(location_light_position[i], glm::vec3(0, 0, 0));
|
||||||
|
LoadVector(location_light_color[i], glm::vec3(0, 0, 0));
|
||||||
|
LoadVector(location_light_attenuation[i], glm::vec3(1, 0, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EntityShader::LoadShineVariables(float shine_damper, float reflectivity) const
|
void EntityShader::LoadShineVariables(float shine_damper, float reflectivity) const
|
||||||
{
|
{
|
||||||
LoadFloat(location_shine_damper, shine_damper);
|
LoadFloat(location_shine_damper, shine_damper);
|
||||||
|
|||||||
@@ -58,6 +58,13 @@ namespace shaders
|
|||||||
*/
|
*/
|
||||||
void LoadLights(std::vector<entities::Light>& lights) const;
|
void LoadLights(std::vector<entities::Light>& lights) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief loads some lights contained in a deque.
|
||||||
|
*
|
||||||
|
* @param lights the deque containing the lights to load
|
||||||
|
*/
|
||||||
|
void LoadLights(std::deque<entities::Light>& lights) const;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief: A method to load the the shine variables from a model into the shader
|
* @brief: A method to load the the shine variables from a model into the shader
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user