Setup for day 17.
This commit is contained in:
parent
d3169d3eca
commit
187bf4c1d1
84 changed files with 14784 additions and 0 deletions
66
17-refactor-bug-fix/src/scene.cpp
Normal file
66
17-refactor-bug-fix/src/scene.cpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#include "scene.hpp"
|
||||
#include "dbc.hpp"
|
||||
#include <math.h>
|
||||
|
||||
void Scene::updateDelta() {
|
||||
float currentFrame = glfwGetTime();
|
||||
deltaTime = currentFrame - lastFrame;
|
||||
lastFrame = currentFrame;
|
||||
}
|
||||
|
||||
void Scene::configure() {
|
||||
// REFACTOR: really this should be done somewhere else
|
||||
for(auto& [name, model] : models) {
|
||||
model.connect_shader(shader);
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::draw_model(Model& scene_model, Material& material, glm::mat4& projection, glm::mat4& view, glm::vec3& position)
|
||||
{
|
||||
shader.apply_material(material);
|
||||
|
||||
float time = glfwGetTime();
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, position);
|
||||
model = glm::rotate(model, glm::radians(time * 10.0f), glm::vec3(1.0f, 0.3f, 0.5f));
|
||||
|
||||
shader.setMat4("model", model);
|
||||
|
||||
scene_model.draw(shader);
|
||||
}
|
||||
|
||||
void Scene::render(GLFWwindow* window) {
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
shader.use();
|
||||
|
||||
// time is used for fake 3d rotation
|
||||
float time = glfwGetTime();
|
||||
|
||||
camera.update(deltaTime);
|
||||
|
||||
glm::mat4 view = camera.look_at();
|
||||
glm::mat4 projection = glm::mat4(1.0f);
|
||||
|
||||
// fov, aspect, near plane, far plane
|
||||
projection = glm::perspective(glm::radians(camera.fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||
|
||||
shader.use();
|
||||
shader.setMat4("view", view);
|
||||
shader.setMat4("projection", projection);
|
||||
shader.setVec3("viewPos", camera.position);
|
||||
|
||||
light.camera.position = camera.position;
|
||||
light.camera.direction = camera.front;
|
||||
shader.apply_lighting(light);
|
||||
|
||||
// BUG: no connection between models and positions
|
||||
for(auto& thing : things) {
|
||||
draw_model(thing.model, thing.material, projection, view, thing.position);
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::cleanup() {
|
||||
shader.cleanup();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue