Cogs.Core
Bounds.cpp
1#include "Foundation/Logging/Logger.h"
2
3#include "Systems/Core/TransformSystem.h"
4
5#include "Image360System.h"
6
7namespace {
8 using namespace Cogs::Core;
9 using namespace Cogs::Core::Image360;
10
12
13 bool getBounds(Context* context, const Image360Component& im360Comp, const Image360Data& data, Cogs::Geometry::BoundingBox& bounds, bool ignoreVisibility)
14 {
15 if (!ignoreVisibility && !im360Comp.isVisible()) return false;
16
17 if (const TransformComponent* trComp = im360Comp.getComponent<TransformComponent>(); trComp) {
18 const glm::vec3 pos = context->transformSystem->getLocalToWorld(trComp)[3];
19 bounds.min = glm::min(bounds.min, pos - data.config.extent);
20 bounds.max = glm::max(bounds.max, pos + data.config.extent);
21 return true;
22 }
23
24 return false;
25 }
26
27}
28
29
30Cogs::Core::Image360::Bounds::Bounds(Image360System* im360System) : im360System(im360System) {}
31
32
33void Cogs::Core::Image360::Bounds::getBounds(Context* context, Cogs::Geometry::BoundingBox& bounds)
34{
35 for (const Image360Component& im360Comp : im360System->pool) {
36 const Image360Data& data = im360System->getData(&im360Comp);
37 ::getBounds(context, im360Comp, data, bounds, false);
38 }
39}
40
41
42bool Cogs::Core::Image360::Bounds::getBounds(Context* context, const Cogs::ComponentModel::Entity* entity, Cogs::Geometry::BoundingBox& bounds, bool ignoreVisibility) const
43{
44 if (const Image360Component* im360Comp = entity->getComponent<Image360Component>(); im360Comp) {
45 const Image360Data& data = im360System->getData(im360Comp);
46 return ::getBounds(context, *im360Comp, data, bounds, ignoreVisibility);
47 }
48 return false;
49}
ComponentType * getComponent() const
Definition: Component.h:159
Container for components, providing composition of dynamic entities.
Definition: Entity.h:18
T * getComponent() const
Get a pointer to the first component implementing the given type in the entity.
Definition: Entity.h:35
ComponentPool< ComponentType > pool
Pool of components managed by the system.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
constexpr bool isVisible() const
Check if the entity is visible or not.
Defines a 4x4 transformation matrix for the entity and a global offset for root entities.
Log implementation class.
Definition: LogManager.h:139
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Definition: LogManager.h:180
void getBounds(Context *context, Cogs::Geometry::BoundingBox &bounds) override
Expand bounds including bounds of all entities in this system in world coordinates.
Definition: Bounds.cpp:33