Now all configurable with json.
This commit is contained in:
parent
3041ae0172
commit
d3169d3eca
25 changed files with 720 additions and 244 deletions
|
|
@ -10,98 +10,55 @@
|
|||
#include "shader.hpp"
|
||||
#include "model.hpp"
|
||||
#include "camera.hpp"
|
||||
#include "scene.hpp"
|
||||
#include "components.hpp"
|
||||
#include <vector>
|
||||
|
||||
const unsigned int SCR_WIDTH = 800;
|
||||
const unsigned int SCR_HEIGHT = 600;
|
||||
|
||||
const float AMBIENT_LEVEL = 0.25f;
|
||||
struct Thing {
|
||||
Model& model;
|
||||
components::Position position;
|
||||
Material& material;
|
||||
};
|
||||
|
||||
struct Scene {
|
||||
Shader shader;
|
||||
Shader lightShader;
|
||||
std::vector<Model> models;
|
||||
|
||||
Lighting light{
|
||||
.directional={
|
||||
.direction={-0.2f, -1.0f, -0.3f},
|
||||
.ambient={0.2f, 0.2f, 0.2f},
|
||||
.diffuse={0.8f, 0.8f, 0.8f},
|
||||
.specular={1.0f, 1.0f, 1.0f},
|
||||
},
|
||||
.positioned={
|
||||
{
|
||||
.position={1.2f, 1.0f, 2.0f},
|
||||
.direction={-0.2f, -1.0f, -0.3f},
|
||||
.ambient={0.2f, 0.2f, 0.2f},
|
||||
.diffuse={0.8f, 0.8f, 0.8f},
|
||||
.specular={1.0f, 1.0f, 1.0f},
|
||||
.constant=1.0f,
|
||||
.linear=0.09f,
|
||||
.quadratic=0.032f,
|
||||
.cutOff=12.5f,
|
||||
.outerCutOff=17.5f,
|
||||
},
|
||||
{
|
||||
.position={-1.2f, -1.0f, -2.0f},
|
||||
.direction={0.2f, 1.0f, 0.3f},
|
||||
.ambient={0.2f, 0.2f, 0.2f},
|
||||
.diffuse={0.8f, 0.8f, 0.8f},
|
||||
.specular={1.0f, 1.0f, 1.0f},
|
||||
.constant=1.0f,
|
||||
.linear=0.09f,
|
||||
.quadratic=0.032f,
|
||||
.cutOff=12.5f,
|
||||
.outerCutOff=17.5f,
|
||||
},
|
||||
},
|
||||
.spot={
|
||||
.position={2.2f, 1.0f, 2.0f},
|
||||
.direction={0.0f, 0.0f, -1.0f},
|
||||
.ambient={0.2f, 0.2f, 0.2f},
|
||||
.diffuse={0.8f, 0.8f, 0.8f},
|
||||
.specular={1.0f, 1.0f, 1.0f},
|
||||
.constant=1.0f,
|
||||
.linear=0.09f,
|
||||
.quadratic=0.032f,
|
||||
.cutOff=12.5f,
|
||||
.outerCutOff=17.5f,
|
||||
},
|
||||
};
|
||||
|
||||
// positions all containers
|
||||
std::vector<glm::vec3> positions{
|
||||
{0.0f, 0.0f, 0.0f},
|
||||
{2.0f, 5.0f, -15.0f},
|
||||
{-1.5f, -2.2f, -2.5f},
|
||||
{-3.8f, -2.0f, -12.3f},
|
||||
{ 2.4f, -0.4f, -3.5f},
|
||||
{-1.7f, 3.0f, -7.5f},
|
||||
{ 1.3f, -2.0f, -2.5f},
|
||||
{ 1.5f, 2.0f, -2.5f},
|
||||
{ 1.5f, 0.2f, -1.5f},
|
||||
{-1.3f, 1.0f, -1.5f}
|
||||
};
|
||||
|
||||
Camera camera{
|
||||
.pos={2.2f, 1.0f, 2.0f},
|
||||
.movementSpeed=2.0f
|
||||
};
|
||||
|
||||
Material cubeMaterial{
|
||||
.ambient = {1.0f, 0.5f, 0.31f},
|
||||
.shininess = 32.0f,
|
||||
.diffuseMap = 0,
|
||||
.specularMap = 0,
|
||||
};
|
||||
Shader light_shader;
|
||||
std::map<std::string, components::Material> materials;
|
||||
Camera camera;
|
||||
components::Lighting light;
|
||||
std::map<std::string, Model> models;
|
||||
std::vector<Thing> things;
|
||||
|
||||
float deltaTime = 0.0f;
|
||||
float lastFrame = 0.0f;
|
||||
|
||||
Scene(components::Scene& config):
|
||||
shader{config.shader.vertex_path, config.shader.frag_path},
|
||||
light_shader{config.light_shader.vertex_path, config.shader.frag_path},
|
||||
materials{config.materials},
|
||||
camera{
|
||||
.position=config.camera.position,
|
||||
.front=config.camera.front,
|
||||
.up=config.camera.up,
|
||||
.direction=config.camera.direction,
|
||||
.movement_speed=config.camera.movement_speed,
|
||||
},
|
||||
light{config.light}
|
||||
{
|
||||
for(auto& [name, model] : config.models) {
|
||||
models.try_emplace(name, model.directory, model.model_path);
|
||||
}
|
||||
|
||||
for(auto& thing : config.things) {
|
||||
things.emplace_back(
|
||||
models.at(thing.model),
|
||||
thing.position,
|
||||
materials.at(thing.material));
|
||||
}
|
||||
}
|
||||
|
||||
void updateDelta();
|
||||
void configure();
|
||||
void draw_model(Model& scene_model, glm::mat4& projection, glm::mat4& view, glm::vec3& position);
|
||||
void draw_model(Model& scene_model, Material& material, glm::mat4& projection, glm::mat4& view, glm::vec3& position);
|
||||
void render(GLFWwindow* window);
|
||||
void cleanup();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue