Cogs.Core
VectorFieldSystem.h
1#pragma once
2
3#include "Scene/GetBounds.h"
4#include "Scene/RayPick.h"
5#include "VectorFieldComponent.h"
6#include "VectorFieldRenderer.h"
7#include "Systems/ComponentSystem.h"
8#include "Resources/VertexFormats.h"
9#include "Resources/MeshStreamsLayout.h"
10
11namespace Cogs::Core::VectorField
12{
14 {
15 glm::vec3 pos;
16 uint32_t color;
17 glm::quat rot;
18 glm::vec4 scale;
19 };
21 {
22 public:
23 VectorFieldBounds(VectorFieldSystem *system, ComponentHandle handle) : system(system), handle(handle) {}
24 void getBounds(Context * context, Cogs::Geometry::BoundingBox & bounds) final;
25 bool getBounds(Context* context, const ComponentModel::Entity* entity, Cogs::Geometry::BoundingBox& bounds, bool ignoreVisibility) const final;
26
27 private:
28 bool getBounds(Context* context, Cogs::Geometry::BoundingBox& bounds, bool ignoreVisibility) const;
29
30 private:
31 VectorFieldSystem *system;
32 ComponentHandle handle;
33 };
35 {
36 public:
37
38 VectorFieldPick(VectorFieldSystem *system, ComponentHandle handle) : system(system), handle(handle) {}
39 bool pickCamera(Context* context,
40 const CameraComponent& camera,
41 const glm::vec2& normPosition,
42 float /*rayLength*/,
43 float /*radius*/,
44 PickingFlags pickingFlags,
45 PicksReturned returnFlag,
46 const RayPicking::RayPickFilter& filter,
47 std::vector<RayPicking::RayPickHit>& hits) override;
48 private:
49 VectorFieldSystem *system;
50 ComponentHandle handle;
51 };
53 {
54 VectorFieldSystem *system;
55 ComponentHandle handle;
56
57 Cogs::VertexElement pos_element;
58 Cogs::VertexElement color_element;
59 Cogs::VertexElement rot_element;
60 Cogs::VertexElement scale_element;
61 Cogs::VertexFormatHandle pos_format;
62
63 size_t buffer_count;
64 BufferHandle buffer_handle; // TODO double buffer???
65 MeshStreamsLayout layout_cap;
66 MeshStreamsLayout layout_base;
67
68 std::unique_ptr<VectorFieldBounds> getBounds;
69 std::unique_ptr<VectorFieldPick> rayPick;
70
71 Geometry::BoundingBox bbox;
72
73 float time;
74
75 glm::mat4 worldMatrix;
76 glm::vec3 cam_pos;
77
78 std::vector<float> time_offset;
79 std::vector<float> time_offset_speed;
80 std::vector<glm::vec3> dither_offset;
81 float ditherSize = 1.0f;
82 };
83 struct VectorFieldSystem: public ComponentSystemWithDataPool<VectorFieldComponent, VectorFieldData>
84 {
85 public:
86 VectorFieldSystem(Memory::Allocator * allocator, SizeType capacity) : ComponentSystemWithDataPool(allocator, capacity) {}
87
88 void initialize(Context * context) override;
89 void update(Context * context) override;
91 void destroyComponent(ComponentHandle component) override;
92
93 VectorFieldRenderer *vector_field_renderer;
94 MaterialInstanceHandle material_instance_cap;
95 MaterialInstanceHandle material_instance_base;
96 ModelHandle model_cap;
97 ModelHandle model_base;
98 };
99}// namespace ...
Container for components, providing composition of dynamic entities.
Definition: Entity.h:18
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
Component system with parallel data per component stored in a pool similar to how the components them...
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Interface for modules implementing custom picking.
Definition: RayPick.h:140
void getBounds(Context *context, Cogs::Geometry::BoundingBox &bounds) final
Expand bounds including bounds of all entities in this system in world coordinates.
bool pickCamera(Context *context, const CameraComponent &camera, const glm::vec2 &normPosition, float, float, PickingFlags pickingFlags, PicksReturned returnFlag, const RayPicking::RayPickFilter &filter, std::vector< RayPicking::RayPickHit > &hits) override
Do a ray pick from a normalized screen space position in the camera direction and return all hits.
Base allocator implementation.
Definition: Allocator.h:30
PicksReturned
  * Options for returning picking hits.
Definition: PickingFlags.h:40
PickingFlags
Options for COGS picking.
Definition: PickingFlags.h:12
ComponentIndex SizeType
Type used to track the size of pools.
Definition: Component.h:19
Handle to a Component instance.
Definition: Component.h:67
ComponentModel::ComponentHandle createComponent() override
void destroyComponent(ComponentHandle component) override
void initialize(Context *context) override
Initialize the system.
Vertex element structure used to describe a single data element in a vertex for the input assembler.
Definition: VertexFormat.h:38