Moving on to cubemaps.
This commit is contained in:
parent
9c75238461
commit
87c513b9f0
113 changed files with 15511 additions and 0 deletions
75
24-cubemaps/src/scene.cpp
Normal file
75
24-cubemaps/src/scene.cpp
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#include "scene.hpp"
|
||||
#include "dbc.hpp"
|
||||
#include <math.h>
|
||||
|
||||
void Scene::update() {
|
||||
float currentFrame = glfwGetTime();
|
||||
deltaTime = currentFrame - lastFrame;
|
||||
lastFrame = currentFrame;
|
||||
|
||||
// for now just detect the camera moved and do spotlight update
|
||||
if(camera.dirty) {
|
||||
light.camera.position = camera.position;
|
||||
light.camera.direction = camera.front;
|
||||
// just update the camera's light
|
||||
shader.apply_spot_light(light.camera, 0);
|
||||
camera.dirty = false;
|
||||
}
|
||||
|
||||
camera.update(deltaTime);
|
||||
}
|
||||
|
||||
void Scene::draw_thing(Shader& with_shader, Thing& thing)
|
||||
{
|
||||
with_shader.apply_material(thing.material);
|
||||
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, thing.position);
|
||||
model = glm::rotate(model, glm::radians(thing.rotation.angle), thing.rotation.axes);
|
||||
model = glm::scale(model, glm::vec3(thing.scale));
|
||||
|
||||
with_shader.setMat4("model", model);
|
||||
|
||||
thing.model.draw(with_shader);
|
||||
}
|
||||
|
||||
void Scene::render(GLFWwindow* window) {
|
||||
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);
|
||||
|
||||
framebuffer.begin();
|
||||
|
||||
// render the scene
|
||||
shader.use();
|
||||
shader.setMat4("view", view);
|
||||
shader.setMat4("projection", projection);
|
||||
|
||||
for(auto& thing : things) {
|
||||
draw_thing(shader, thing);
|
||||
}
|
||||
|
||||
framebuffer.commit();
|
||||
|
||||
framebuffer.draw(screen);
|
||||
}
|
||||
|
||||
void Scene::cleanup() {
|
||||
shader.cleanup();
|
||||
}
|
||||
|
||||
void Scene::spawn(const std::string& name, components::Position& position, components::Rotation& rotation) {
|
||||
if(models.contains(name)) {
|
||||
things.emplace_back(
|
||||
name,
|
||||
models.at(name),
|
||||
materials.at("default"),
|
||||
position,
|
||||
rotation,
|
||||
1.0f);
|
||||
} else {
|
||||
dbc::log($F("No model named: {}", name));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue