Cogs.Core
TrajectoryLayoutSystem.cpp
1#include "TrajectoryLayoutSystem.h"
2#include "Context.h"
3
4#include "Components/Core/TransformComponent.h"
5#include "Components/Core/CameraComponent.h"
6#include "Components/Data/TrajectoryComponent.h"
7
8#include "Systems/Core/TransformSystem.h"
9#include "Systems/Core/CameraSystem.h"
10
11#include "Foundation/Geometry/Glm.hpp"
12#include "Foundation/Geometry/SampleListGenerator.hpp"
13#include "Foundation/Geometry/PathGenerator.hpp"
14
16{
17 for (auto & layout : pool) {
18 auto layoutTransform = layout.getComponent<TransformComponent>();
19
20 if (layout.layoutTrajectory && layout.entities.size()) {
21 auto trajectory = layout.layoutTrajectory->getComponent<TrajectoryComponent>();
22
23 const size_t count = layout.entities.size();
24
25 std::vector<glm::vec3> positions(count);
26 std::vector<glm::vec3> directions(count);
27
28 Cogs::Geometry::PathGenerator::generateLinearPath(
29 layout.depths.data(),
30 layout.depths.size(),
31 trajectory->indexes.data(),
32 trajectory->positions.data(),
33 static_cast<int>(trajectory->positions.size()),
34 positions.data(),
35 directions.data());
36
37 for (size_t e = 0; e < count; ++e) {
38 auto entity = layout.entities[e].lock();
39
40 if (!entity) continue;
41
42 auto transform = entity->getComponent<TransformComponent>();
43
44 transform->coordinates = layoutTransform->coordinates;
45 transform->position = positions[e] + layout.offset;
46
47 context->transformSystem->updateTransformData(*transform);
48 }
49 }
50 }
51}
ComponentType * getComponent() const
Definition: Component.h:159
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
ComponentPool< TrajectoryLayoutComponent > 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
Defines a 4x4 transformation matrix for the entity and a global offset for root entities.
glm::dvec3 coordinates
Global coordinates.
void updateTransformData(const TransformComponent &component)
Force an update of the transform data associated with the given component.
Data component defining a 3D trajectory, for example a Well trajectory.