feat: add lights

This commit is contained in:
2025-10-14 11:45:46 +02:00
parent c34d3f803f
commit 50a4f56e75
14 changed files with 355 additions and 10 deletions

View File

@@ -9,6 +9,7 @@
#include "buffer.h"
#include "camera.h"
#include "light.h"
#include "logger.h"
#include "material.h"
#include "mesh.h"
@@ -19,6 +20,10 @@
#include "vertex.h"
#include "world.h"
// Instance variables
std::shared_ptr<Light> point_light;
// Constants
constexpr int screen_width = 800;
constexpr int screen_height = 600;
constexpr double fps_limit = 1.0 / 60.0;
@@ -140,6 +145,7 @@ void Engine::setup()
// Create world
world_ = std::make_unique<World>();
world_->set_ambient(glm::vec3(0.2f, 0.2f, 0.2f));
Logger::info("World created");
// Create camera
@@ -180,6 +186,26 @@ void Engine::setup()
Logger::info("Gunslinger model loaded and added to world");
}
// Create directional light
auto directional_light = std::make_shared<Light>();
directional_light->set_type(Light::Type::DIRECTIONAL);
directional_light->set_color(glm::vec3(1.0f, 1.0f, 1.0f));
directional_light->set_intensity(1.0f);
directional_light->set_position(glm::normalize(
glm::vec3(1.0f, 1.0f, 1.0f))); // Use position as direction
world_->add_entity(directional_light);
Logger::info("Directional light created and added to world");
// Create point light
point_light = std::make_shared<Light>();
point_light->set_type(Light::Type::POINT);
point_light->set_color(glm::vec3(1.0f, 0.0f, 0.0f));
point_light->set_intensity(2.0f);
point_light->set_linear_attenuation(0.2f);
point_light->set_position(glm::vec3(5.0f, 0.0f, 0.0f));
world_->add_entity(point_light);
Logger::info("Point light created and added to world");
Logger::info("Scene setup complete");
}
@@ -227,6 +253,16 @@ void Engine::process_input(const double delta_time)
void Engine::update(const double delta_time)
{
// Update angle for orbiting light
angle_ += delta_time;
// Make point light orbit around the model
if (point_light) {
constexpr float radius = 7.5f;
point_light->set_position(glm::vec3(radius * cos(angle_), 2.0f,
radius * sin(angle_)));
}
// Update world
world_->update(static_cast<float>(delta_time));
}