Cogs.Core
OceanSystem.h
1#pragma once
2
3#include "Systems/ComponentSystem.h"
4
5#include "OceanComponent.h"
6#include "ExtensionRegistry.h"
7
8#include "RenderContext.h"
9
10#include "Resources/Resources.h"
11#include "Resources/MeshStreamsLayout.h"
12
13namespace Cogs
14{
15 namespace Core
16 {
17 class TerrainSystem;
18 class ViewContext;
19
21 {
22 public:
23 OceanPicker(OceanComponent * oceanComponent, OceanData * oceanData);
24
25 bool pickCamera(Context* context,
26 const CameraComponent& camera,
27 const glm::vec2& normPosition,
28 float /*rayLength*/,
29 float /*radius*/,
30 PickingFlags pickingFlags,
31 PicksReturned returnFlag,
32 const RayPicking::RayPickFilter& filter,
33 std::vector<RayPicking::RayPickHit>& hits) override;
34
35 protected:
36 OceanComponent * oceanComponent;
37 OceanData * oceanData;
38 };
39
40 class OceanBounds : public IGetBounds
41 {
42 public:
43 OceanBounds(OceanComponent * oceanComponent, OceanData * oceanData) : oceanComponent(oceanComponent), oceanData(oceanData) {}
44
45 void getBounds(Context * context, Cogs::Geometry::BoundingBox & bounds, float& nearPlaneLimit) final;
46
47 void getBounds(Context* context, Cogs::Geometry::BoundingBox& bounds) final;
48
49 protected:
50 OceanComponent * oceanComponent;
51 OceanData * oceanData;
52 };
53
54 struct OceanData
55 {
56 OceanComponent * oceanComponent;
57
58 bool initialized = false;
59 bool first = true;
60
61 MaterialHandle oceanMaterial;
62
63 MeshStreamsLayout streamsLayout;
65
66 TextureHandle reflectionTexture;
67 TextureHandle skyDomeTexture;
68
69 EntityPtr reflectionCamera;
70
71 TerrainData * terrainData;
72
73 std::unique_ptr<OceanPicker> rayPick;
74 std::unique_ptr<OceanBounds> bounds;
75
76 Geometry::BoundingBox bbox;
77 };
78
79 class OceanSystem final : public ComponentSystemWithDataPool<OceanComponent, OceanData>
80 {
81 public:
82 OceanSystem(Memory::Allocator * allocator, SizeType capacity) : ComponentSystemWithDataPool(allocator, capacity) {}
83
84 void initialize(Context * context) override;
85 void update(Context * context) override;
86
87 void destroyComponent(ComponentHandle component) override;
88
89 TerrainSystem * terrainSystem;
90 Cogs::VertexFormatHandle oceanFormat;
91
92
93 };
94 }
95}
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, float &nearPlaneLimit) final
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.
Definition: OceanSystem.cpp:33
void initialize(Context *context) override
Initialize the system.
void destroyComponent(ComponentHandle component) override
Base allocator implementation.
Definition: Allocator.h:30
std::shared_ptr< ComponentModel::Entity > EntityPtr
Smart pointer for Entity access.
Definition: EntityPtr.h:12
PicksReturned
  * Options for returning picking hits.
Definition: PickingFlags.h:40
PickingFlags
Options for COGS picking.
Definition: PickingFlags.h:12
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
ComponentIndex SizeType
Type used to track the size of pools.
Definition: Component.h:19
Handle to a Component instance.
Definition: Component.h:67