1#include "hellfire/graphics/geometry/Quad.h"
5#include "hellfire/ecs/RenderableComponent.h"
6#include "hellfire/ecs/Entity.h"
7#include "hellfire/ecs/TransformComponent.h"
8#include "hellfire/ecs/components/MeshComponent.h"
9#include "hellfire/scene/Scene.h"
38 auto* mesh_comp = entity->add_component<MeshComponent>();
39 std::vector<Vertex> vertices;
40 std::vector<
unsigned int> indices;
41 get_quad_data(vertices, indices, config.color);
42 mesh_comp->set_mesh(std::make_shared<
Mesh>(vertices, indices));
46 auto* renderable = entity->add_component<RenderableComponent>();
47 if (config.material) {
48 renderable->set_material(config.material);
51 renderable->set_material(material);
63 std::vector<Vertex> vertices;
64 std::vector<
unsigned int> indices;
65 get_quad_data(vertices, indices);
66 return std::make_shared<
Mesh>(vertices, indices);
69 void Quad::get_quad_data(std::vector<Vertex>& vertices, std::vector<
unsigned int>& indices,
70 const glm::vec3& color) {
75 indices.assign(indices_.begin(), indices_.end());
78 glm::vec3 p0(vertices_[0], vertices_[1], vertices_[2]);
79 glm::vec3 p1(vertices_[3], vertices_[4], vertices_[5]);
80 glm::vec3 p2(vertices_[6], vertices_[7], vertices_[8]);
83 glm::vec3 edge1 = p1 - p0;
84 glm::vec3 edge2 = p2 - p0;
86 glm::vec3 normal = glm::normalize(glm::cross(edge1, edge2));
88 for (size_t i = 0; i < 4; ++i) {
90 v.position = glm::vec3(vertices_[i * 3], vertices_[i * 3 + 1], vertices_[i * 3 + 2]);
93 v.texCoords = glm::vec2(uvs_[i * 2], uvs_[i * 2 + 1]);
94 vertices.push_back(v);
TransformComponent * transform()
static const std::vector< float > uvs_
static EntityID create(Scene *scene, const std::string &name, const Config &config=Config{})
static const std::vector< unsigned int > indices_
static std::shared_ptr< Mesh > create_mesh()
static const std::vector< float > vertices_
Manages a collection of entities and their hierarchical relationships.
Entity * get_entity(EntityID id)
Retrieves an entity by its ID.
EntityID create_entity(const std::string &name="GameObject")
Creates a new entity in the scene.