Cogs.Core
OctBounds.cpp
1#include "Components/Core/SceneComponent.h"
2#include "Components/Core/TransformComponent.h"
3#include "Systems/Core/TransformSystem.h"
4#include "Context.h"
5
6#include "Systems/OctSystem.h"
7#include "OctBounds.h"
8
9void Cogs::Core::Volumetric::OctBounds::getBounds(Context * context, Cogs::Geometry::BoundingBox & bounds)
10{
11 for (const auto & octComp : octSystem->pool) {
12 const auto & octtreeData = octSystem->getData(&octComp);
13
14 if (octtreeData.nodes.empty()) return;
15
16 const auto * sceneComp = octComp.getComponent<SceneComponent>();
17 if (sceneComp->visible == false) return;
18
19 const auto * transComp = octComp.getComponent<TransformComponent>();
20 auto & worldMatrix = context->transformSystem->getLocalToWorld(transComp);
21
22 const auto & apex = octtreeData.nodes.back();
23
24 const auto s = 1 << apex.ix4.w;
25 for (unsigned i = 0; i < 8; i++) {
26 auto r = glm::vec3(octtreeData.alignMinToZeroShift.x + s*int(apex.ix4.x + (i & 1)),
27 octtreeData.alignMinToZeroShift.y + s*int(apex.ix4.y + ((i >> 1) & 1)),
28 octtreeData.alignMinToZeroShift.z + s*int(apex.ix4.z + ((i >> 2) & 1)));
29
30 auto q = octComp.blockExtent * r + octComp.blockShift;
31 auto p = worldMatrix * glm::vec4(q, 1.f);
32 auto l = (1.f / p.w)*glm::vec3(p.x, p.y, p.z);
33
34 bounds += l;
35 }
36 }
37}
ComponentType * getComponent() const
Definition: Component.h:159
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
Contains information on how the entity behaves in the scene.
Defines a 4x4 transformation matrix for the entity and a global offset for root entities.
void getBounds(Context *context, Cogs::Geometry::BoundingBox &bounds) override
Expand bounds including bounds of all entities in this system in world coordinates.
Definition: OctBounds.cpp:9