feat: entt library

This commit is contained in:
2025-10-08 18:17:47 +02:00
parent 4e86d92987
commit 99f5cd3715
15 changed files with 129 additions and 143 deletions

View File

@ -7,8 +7,12 @@
#include "window/window.h"
#include "IO/file_manager.h"
Renderer::Renderer(ecs::Entity& light, ecs::Entity& camera)
: m_light(light), m_camera(camera)
#include "components/transform.h"
#include "components/camera.h"
#include "components/light.h"
#include "components/mesh.h"
Renderer::Renderer()
{
m_proj = glm::perspective(
static_cast<float>(M_PI_2),
@ -25,6 +29,8 @@ Renderer::Renderer(ecs::Entity& light, ecs::Entity& camera)
m_model = glm::mat4(1.f);
m_shader.use();
m_shader.setMat4("u_projection", m_proj);
}
void Renderer::OnWindowResized(int w, int h) {
@ -34,53 +40,53 @@ void Renderer::OnWindowResized(int w, int h) {
0.01f,
100.0f
);
m_shader.setMat4("u_projection", m_proj);
}
void Renderer::RenderLight() {
void Renderer::Render(entt::registry& registry) {
auto view = registry.view<transform, mesh>();
auto cam = registry.view<transform, camera>().back();
auto camTransform = registry.get<transform>(cam);
auto lightEntt = registry.view<transform, light>().back();
auto lightTransform = registry.get<transform>(lightEntt);
m_view = glm::lookAt(
m_camera.transform.pos,
m_camera.transform.pos + m_camera.transform.rot,
camTransform.position,
camTransform.position + camTransform.rotation,
glm::vec3(0.f, 1.f, 0.f)
);
m_shader.setMat4("u_view", m_view);
m_shader.setMat4("u_projection", m_proj);
m_shader.setVec3("lightColor", glm::vec3(1.0f, 1.0f, 1.0f));
m_shader.setVec3("lightPos", m_light.transform.pos);
m_shader.setVec3("viewPos", m_camera.transform.pos);
m_shader.setVec3("lightPos", lightTransform.position);
m_shader.setVec3("viewPos", camTransform.position);
m_model = glm::mat4(1.f);
m_model = glm::translate(m_model, m_light.transform.pos);
// std::cout << "cam pos: " << "vec(" << camTransform.position.x << ", " << camTransform.position.y << ", " << camTransform.position.z << ")" << std::endl;
// std::cout << "cam rot: " << "vec(" << camTransform.rotation.x << ", " << camTransform.rotation.y << ", " << camTransform.rotation.z << ")" << std::endl;
m_shader.setMat4("u_model", m_model);
// std::cout << "light pos: " << "vec(" << lightTransform.position.x << ", " << lightTransform.position.y << ", " << lightTransform.position.z << ")" << std::endl;
// std::cout << "light rot: " << "vec(" << lightTransform.rotation.x << ", " << lightTransform.rotation.y << ", " << lightTransform.rotation.z << ")" << std::endl;
m_light.mesh.object->Render(m_shader);
}
for (auto [entity, transf, mesh] : view.each()) {
if (mesh.object == nullptr) {
std::cerr << "WARN: Entity doesn't have a mesh to render" << std::endl;
return;
}
void Renderer::RenderEntity(const ecs::Entity& entity) {
if (entity.mesh.object == nullptr) {
std::cerr << "WARN: Entity doesn't have a mesh to render" << std::endl;
return;
m_model = glm::mat4(1.0f);
// Apply translation
m_model = glm::translate(m_model, transf.position);
// Apply rotations (order matters!)
m_model = glm::rotate(m_model, transf.rotation.x, glm::vec3(1, 0, 0)); // pitch
m_model = glm::rotate(m_model, transf.rotation.y, glm::vec3(0, 1, 0)); // yaw
m_model = glm::rotate(m_model, transf.rotation.z, glm::vec3(0, 0, 1)); // roll
m_shader.setMat4("u_model", m_model);
mesh.object->Render(m_shader);
}
m_view = glm::lookAt(
m_camera.transform.pos,
m_camera.transform.pos + m_camera.transform.rot,
glm::vec3(0.f, 1.f, 0.f)
);
m_model = glm::mat4(1.0f);
// Apply translation
m_model = glm::translate(m_model, entity.transform.pos);
// Apply rotations (order matters!)
m_model = glm::rotate(m_model, entity.transform.rot.x, glm::vec3(1, 0, 0)); // pitch
m_model = glm::rotate(m_model, entity.transform.rot.y, glm::vec3(0, 1, 0)); // yaw
m_model = glm::rotate(m_model, entity.transform.rot.z, glm::vec3(0, 0, 1)); // roll
m_shader.setMat4("u_model", m_model);
entity.mesh.object->Render(m_shader);
}