1#include "BillboardSystem.h"
3#include "Systems/Core/TransformSystem.h"
4#include "Systems/Core/SpriteRenderSystem.h"
6#include "Resources/TextureManager.h"
7#include "Resources/MaterialManager.h"
13 auto sprites =
context->spriteRenderSystem;
15 for (
const auto & billboard :
pool) {
16 if (!billboard.image)
continue;
17 if (billboard.imageSize.x == 0 || billboard.imageSize.y == 0)
continue;
21 if (!spriteRenderer->isVisible())
continue;
24 const auto & localToWorld =
context->transformSystem->getLocalToWorld(transform);
25 const glm::vec3 worldSpacePosition = glm::vec3(localToWorld * glm::vec4(0, 0, 0, 1.0f));
27 const glm::vec2 right(billboard.imageSize.x * 0.5f, 0);
28 const glm::vec2 up(0, billboard.imageSize.y * 0.5f);
30 glm::vec2 offset(0, 0);
32 if (billboard.horizontalAlignment == HorizontalAlignment::Left) offset += right;
33 else if (billboard.horizontalAlignment == HorizontalAlignment::Right) offset -= right;
38 auto batch = sprites->begin(DefaultSpriteMaterial,
"ViewTransformPixelSize", billboard.image, billboard.color, billboard.alwaysOnTop);
39 sprites->addSprite(spriteRenderer, worldSpacePosition, offset, billboard.imageSize, glm::vec4(0, 1, 1, 0));
41 if (billboard.flipX || billboard.flipY) {
42 batch->material->setVec2Property(batch->material->material->getVec2Key(
"imageFlip"), glm::vec2(billboard.flipX ? 1 : 0, billboard.flipY ? 1 : 0));
45 batch->worldPosition = worldSpacePosition;
46 batch->bbox = { worldSpacePosition, worldSpacePosition };
47 batch->flags |= RenderItemFlags::CalculateDepth;
48 batch->blendMode = billboard.blendMode;
49 batch->material->options.blendMode = billboard.blendMode;
ComponentType * getComponent() const
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
ComponentPool< BillboardComponent > pool
Pool of components managed by the system.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
@ Bottom
Align the text towards the bottom, making the position minus the font height the baseline of the text...
@ Top
Align the text towards the top, making the position the baseline of the text.