23#include "guillaume/systems/ellipse_render.hpp"
24#include "guillaume/mesh_renderable.hpp"
33 std::vector<utility::math::Vector2F>
34 EllipseRender::buildLocalEllipseVertices(
const float halfWidth,
35 const float halfHeight,
38 const float pi = std::acos(-1.0f);
44 std::vector<utility::math::Vector2F> localVertices;
45 localVertices.reserve(
static_cast<std::size_t
>(segments + 1));
48 for (
int i = 0; i <= segments; ++i) {
50 (
static_cast<float>(i) /
static_cast<float>(segments)) * 2.0f
52 const float x = halfWidth * std::cos(t);
53 const float y = halfHeight * std::sin(t);
54 localVertices.push_back(utility::math::Vector2F({ x, y }));
60 std::vector<utility::graphic::PositionF>
61 EllipseRender::buildEllipseVertices(
62 const utility::graphic::PositionF ¢er,
63 const utility::graphic::OrientationF &orientation,
64 const utility::math::Vector2F &scale,
65 const utility::graphic::SizeF &size,
int segments)
67 const float halfWidth = (
size.getWidth() / 2.0f) * std::abs(scale[0]);
68 const float halfHeight = (
size.getHeight() / 2.0f) * std::abs(scale[1]);
69 const auto localVertices =
70 buildLocalEllipseVertices(halfWidth, halfHeight, segments);
71 return shape::transformToWorldVertices(localVertices, center,
101 <<
"Updating EllipseRender system for entity " << entityIdentifier;
110 const auto &transformComponent =
112 const auto &boundComponent =
114 const auto &colorComponent =
116 const auto &ellipseComponent =
119 const auto pose = transformComponent.getPose();
120 const auto color = colorComponent.getColor();
121 const auto segments = ellipseComponent.getSegments();
124 <<
"Rendering ellipse with pose: " << pose
125 <<
", size: " << boundComponent.getWidth() <<
"x"
126 << boundComponent.getHeight() <<
", segments: " << segments
127 <<
", color: " << color;
129 const utility::graphic::PositionF center(
130 pose.getPosition().x + boundComponent.getWidth() / 2.0f,
131 pose.getPosition().y - boundComponent.getHeight() / 2.0f,
132 pose.getPosition().z);
134 const auto ellipseVertices = buildEllipseVertices(
135 center, pose.getOrientation(),
136 utility::math::Vector2F({ 1.0f, 1.0f }), boundComponent, segments);
138 utility::graphic::Mesh mesh(std::vector<utility::graphic::VertexF> {},
139 std::vector<uint32_t> {});
144 if (mesh.getVertices().empty()) {
148 auto renderable = std::make_shared<MeshRenderable>(
149 std::vector<utility::graphic::Mesh> { mesh },
"mesh_material");
152 if (handle ==
nullptr) {
153 size_t objectId = _engine.createObject(renderable);
157 if (!_engine.updateObject(renderable, handle->objectId)) {
158 handle->objectId = _engine.createObject(renderable);
160 handle->renderable = renderable;
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
SystemFiller(Phase phase)
ComponentType & getComponent(const ecs::Entity::Identifier &entityIdentifier)
Get a component of an entity from the bound registry, to read or modify it.
bool requireComponent(const ecs::Entity::Identifier &entityIdentifier)
Tell whether an entity has a component, and log a warning naming the entity and the component when it...
~EllipseRender(void)
Forget the engine objects without removing them from the engine.
virtual void update(const ecs::Entity::Identifier &entityIdentifier) override
Rebuild the mesh of one ellipse and upload it, creating the engine object on the first frame.
void prepare(void) override
Mark every engine object as not drawn yet. Called once per frame before the entities are visited.
void cleanup(void) override
Remove the engine objects of the entities that were not drawn this frame. Called once per frame after...
EllipseRender(utility::Engine &engine)
Create the system in the Render phase.
void insert(const ecs::Entity::Identifier &identifier, RenderHandle handle)
Store the handle of an entity, replacing the one it had.
void markAllUnused(void)
Clear the used flag of every handle. Call it from the system's prepare(), before any entity is drawn.
void clear(void)
Forget every handle without calling utility::Engine::removeObject. Use it only when the engine object...
void removeUnused(utility::Engine &engine)
Remove from the engine, then from the map, every handle whose used flag is still false....
RenderHandle * find(const ecs::Entity::Identifier &identifier)
Look up the handle of an entity.
std::size_t size(void) const
Count the entities that have an engine object in this map.
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Rules. Every class here runs each frame on the entities that have the components it declares.
Mesh builders shared by the shape render systems.
void buildTriangleFanVertices(utility::graphic::Mesh &mesh, const utility::graphic::PositionF ¢er, const std::vector< utility::graphic::PositionF > &outline, const utility::graphic::Color32Bit &color)
Fill a closed outline with a fan of triangles around its center.
What a render system remembers about the engine object it created for one entity.