Cogs.Core
OGC3DTilesBounds.cpp
1#include "OGC3DTilesBounds.h"
2
3#include "OGC3DTilesSystem.h"
4#include "../OGC3DTilesUtils.h"
5
6using namespace Cogs::Core;
7
8OGC3DTilesBounds::OGC3DTilesBounds(OGC3DTilesSystem* s)
9{
10 this->system = s;
11}
12
13void
14OGC3DTilesBounds::getBounds(Context* context, Cogs::Geometry::BoundingBox& bounds)
15{
16 for (auto& comp : this->system->pool) {
17 getBounds(context, comp, bounds, false);
18 }
19}
20
21bool
22OGC3DTilesBounds::getBounds(Context* context, const ComponentModel::Entity* entity, Cogs::Geometry::BoundingBox& bounds, bool ignoreVisibility) const
23{
25 return !compPtr ? false : getBounds(context, *compPtr, bounds, ignoreVisibility);
26}
27
28bool
29OGC3DTilesBounds::getBounds(Context* /*context*/, const OGC3DTilesComponent& comp, Cogs::Geometry::BoundingBox& bounds, bool /*ignoreVisibility*/) const
30{
31 OGC3DTilesDataHolder& h = this->system->getData(&comp);
32 OGC3DTilesData* componentState = h.data.get();
33
34 if (!componentState->tilesets.empty()) {
35 // FIXME: We should consider caching the converted bbox to avoid re-converting it each time this method is called.
36 // Tileset #0 is always the main tileset.
37 Cogs::Geometry::DBoundingBox bbox =
38 OGC3DTilesUtils::boundingVolumeConverter(componentState->tilesets[0]->root.boundingVolume, componentState->tilesets[0]->root.transform);
39 bounds.min = glm::min(glm::dvec3(bounds.min), bbox.min);
40 bounds.max = glm::max(glm::dvec3(bounds.max), bbox.max);
41 return true;
42 }
43
44 return false;
45}
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
void getBounds(Context *context, Cogs::Geometry::BoundingBox &bounds) override
Expand bounds including bounds of all entities in this system in world coordinates.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....