feat: basic ecs start + renderer class

This commit is contained in:
2025-10-07 21:36:23 +02:00
parent 6cef3efbbc
commit 4e86d92987
9 changed files with 218 additions and 77 deletions

14
include/ecs/camera.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef ECS_ENTITY_CAMERA_H_
#define ECS_ENTITY_CAMERA_H
#include "ecs/entity.h"
namespace ecs {
class Camera : Entity {
public:
Camera() = default;
~Camera() = default;
};
}
#endif // ECS_ENTITY_CAMERA_H_

9
include/ecs/component.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef ECS_COMPONENT_H_
#define ECS_COMPONENT_H_
namespace ecs {
class Component {
};
}
#endif // ECS_COMPONENT_H_

View File

@ -0,0 +1,16 @@
#ifndef ECS_COMP_MESH_H_
#define ECS_COMP_MESH_H_
#include "renderer/wavefront.h"
#include "ecs/component.h"
namespace ecs {
class Mesh : Component {
public:
Object* object;
Mesh(Object* model) : object(model) {}
};
}
#endif // ECS_COMP_MESH_H_

View File

@ -0,0 +1,18 @@
#ifndef ECS_COMP_TRANSFORM_H_
#define ECS_COMP_TRANSFORM_H_
#include <glm/glm.hpp>
#include "ecs/component.h"
namespace ecs {
class Transform : Component {
public:
Transform() = default;
public:
glm::vec3 pos;
glm::vec3 rot;
glm::vec3 scale;
};
}
#endif // ECS_COMP_TRANSFORM_H_

18
include/ecs/entity.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef ECS_ENTITY_H_
#define ECS_ENTITY_H_
#include "ecs/components/transform.h"
#include "ecs/components/mesh.h"
namespace ecs {
class Entity {
public:
Transform transform;
Mesh mesh;
Entity(Mesh m) : mesh(m) {}
~Entity() = default;
};
}
#endif // ECS_ENTITY_H_

View File

@ -0,0 +1,28 @@
#ifndef RENDERER_H_
#define RENDERER_H_
#include <glm/glm.hpp>
#include "renderer/shader.h"
#include "ecs/entity.h"
// TODO: make static or singleton
class Renderer {
public:
Renderer(ecs::Entity& light, ecs::Entity& camera);
void RenderLight();
void RenderEntity(const ecs::Entity& entity);
void OnWindowResized(int w, int h);
private:
Shader m_shader;
glm::mat4 m_model;
glm::mat4 m_proj;
glm::mat4 m_view;
ecs::Entity& m_light;
ecs::Entity& m_camera;
};
#endif // RENDERER_H_