Plasma Engine  2.0
Loading...
Searching...
No Matches
CameraComponent.h
1#pragma once
2
3#include <Core/Graphics/Camera.h>
4#include <Core/World/World.h>
5#include <RendererCore/Declarations.h>
6#include <RendererCore/Pipeline/Declarations.h>
7
8class plView;
9struct plResourceEvent;
10
11class PL_RENDERERCORE_DLL plCameraComponentManager : public plComponentManager<class plCameraComponent, plBlockStorageType::Compact>
12{
13public:
16
17 virtual void Initialize() override;
18 virtual void Deinitialize() override;
19
20 void Update(const plWorldModule::UpdateContext& context);
21
22 void ReinitializeAllRenderTargetCameras();
23
24 const plCameraComponent* GetCameraByUsageHint(plCameraUsageHint::Enum usageHint) const;
25 plCameraComponent* GetCameraByUsageHint(plCameraUsageHint::Enum usageHint);
26
27private:
28 friend class plCameraComponent;
29
30 void AddRenderTargetCamera(plCameraComponent* pComponent);
31 void RemoveRenderTargetCamera(plCameraComponent* pComponent);
32
33 void OnViewCreated(plView* pView);
34 void OnCameraConfigsChanged(void* dummy);
35
36 plDynamicArray<plComponentHandle> m_ModifiedCameras;
37 plDynamicArray<plComponentHandle> m_RenderTargetCameras;
38};
39
56class PL_RENDERERCORE_DLL plCameraComponent : public plComponent
57{
58 PL_DECLARE_COMPONENT_TYPE(plCameraComponent, plComponent, plCameraComponentManager);
59
61 // plComponent
62
63public:
64 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
65 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
66
67protected:
68 virtual void OnActivated() override;
69 virtual void OnDeactivated() override;
70
72 // plCameraComponent
73
74public:
77
79 void SetUsageHint(plEnum<plCameraUsageHint> val); // [ property ]
80 plEnum<plCameraUsageHint> GetUsageHint() const { return m_UsageHint; } // [ property ]
81
83 void SetRenderTargetFile(const char* szFile); // [ property ]
84 const char* GetRenderTargetFile() const; // [ property ]
85
87 void SetRenderTargetRectOffset(plVec2 value); // [ property ]
88 plVec2 GetRenderTargetRectOffset() const { return m_vRenderTargetRectOffset; } // [ property ]
89
91 void SetRenderTargetRectSize(plVec2 value); // [ property ]
92 plVec2 GetRenderTargetRectSize() const { return m_vRenderTargetRectSize; } // [ property ]
93
95 void SetCameraMode(plEnum<plCameraMode> val); // [ property ]
96 plEnum<plCameraMode> GetCameraMode() const { return m_Mode; } // [ property ]
97
99 void SetNearPlane(float fVal); // [ property ]
100 float GetNearPlane() const { return m_fNearPlane; } // [ property ]
101
103 void SetFarPlane(float fVal); // [ property ]
104 float GetFarPlane() const { return m_fFarPlane; } // [ property ]
105
107 void SetFieldOfView(float fVal); // [ property ]
108 float GetFieldOfView() const { return m_fPerspectiveFieldOfView; } // [ property ]
109
111 void SetOrthoDimension(float fVal); // [ property ]
112 float GetOrthoDimension() const { return m_fOrthoDimension; } // [ property ]
113
115 plRenderPipelineResourceHandle GetRenderPipeline() const;
116
118 plViewHandle GetRenderTargetView() const;
119
121 void SetRenderPipelineEnum(const char* szFile); // [ property ]
122 const char* GetRenderPipelineEnum() const; // [ property ]
123
124 void SetAperture(float fAperture); // [ property ]
125 float GetAperture() const { return m_fAperture; } // [ property ]
126
127 void SetShutterTime(plTime shutterTime); // [ property ]
128 plTime GetShutterTime() const { return m_ShutterTime; } // [ property ]
129
130 void SetISO(float fISO); // [ property ]
131 float GetISO() const { return m_fISO; } // [ property ]
132
133 float GetFocusDistance() const { return m_fFocusDistance; } // [ property ]
134 void SetFocusDistance(float fFocusDistance); // [ property ]
135
136 void SetExposureCompensation(float fEC); // [ property ]
137 float GetExposureCompensation() const { return m_fExposureCompensation; } // [ property ]
138
139 float GetEV100() const; // [ property ]
140 float GetExposure() const; // [ property ]
141
143 plTagSet m_IncludeTags; // [ property ]
144
146 plTagSet m_ExcludeTags; // [ property ]
147
148 void ApplySettingsToView(plView* pView) const;
149
150private:
151 void UpdateRenderTargetCamera();
152 void ShowStats(plView* pView);
153
154 void ResourceChangeEventHandler(const plResourceEvent& e);
155
156 plEnum<plCameraUsageHint> m_UsageHint;
158 plRenderToTexture2DResourceHandle m_hRenderTarget;
159 float m_fNearPlane = 0.25f;
160 float m_fFarPlane = 1000.0f;
161 float m_fPerspectiveFieldOfView = 60.0f;
162 float m_fOrthoDimension = 10.0f;
163 plRenderPipelineResourceHandle m_hCachedRenderPipeline;
164
165 float m_fAperture = 1.0f;
166 plTime m_ShutterTime = plTime::MakeFromSeconds(1.0f);
167 float m_fISO = 100.0f;
168 float m_fFocusDistance = 100.0f;
169 float m_fExposureCompensation = 0.0f;
170
171 void MarkAsModified();
172 void MarkAsModified(plCameraComponentManager* pCameraManager);
173
174 bool m_bIsModified = false;
175 bool m_bShowStats = false;
176 bool m_bRenderTargetInitialized = false;
177
178 // -1 for none, 0 to 9 for ALT+Number
179 plInt8 m_iEditorShortcut = -1; // [ property ]
180
181 void ActivateRenderToTexture();
182 void DeactivateRenderToTexture();
183
184 plViewHandle m_hRenderTargetView;
185 plVec2 m_vRenderTargetRectOffset = plVec2(0.0f);
186 plVec2 m_vRenderTargetRectSize = plVec2(1.0f);
187 plCamera m_RenderTargetCamera;
188 plHashedString m_sRenderPipeline;
189};
Adds a camera to the scene.
Definition CameraComponent.h:57
plTagSet m_ExcludeTags
If non-empty, objects with these tags will be excluded from this camera's output.
Definition CameraComponent.h:146
plTagSet m_IncludeTags
If non-empty, only objects with these tags will be included in this camera's output.
Definition CameraComponent.h:143
Definition CameraComponent.h:12
A camera class that stores the orientation and some basic camera settings.
Definition Camera.h:41
Base class of all component types.
Definition Component.h:25
Definition ComponentManager.h:88
Definition DynamicArray.h:81
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
A dynamic collection of tags featuring fast lookups.
Definition TagSet.h:23
Definition Declarations.h:64
Encapsulates a view on the given world through the given camera and rendered with the specified Rende...
Definition View.h:21
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
virtual void Initialize()
This method is called after the constructor. A derived type can override this method to do initializa...
Definition WorldModule.h:98
virtual void Deinitialize()
This method is called before the destructor. A derived type can override this method to do deinitiali...
Definition WorldModule.h:101
Reads a world description from a stream. Allows to instantiate that world multiple times in different...
Definition WorldReader.h:47
Stores an entire plWorld in a stream.
Definition WorldWriter.h:13
Enum
Definition Declarations.h:85
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
These events may be sent by a specific plResource or by the plResourceManager.
Definition Declarations.h:22
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
PL_ALWAYS_INLINE static constexpr plTime MakeFromSeconds(double fSeconds)
Creates an instance of plTime that was initialized from seconds.
Definition Time.h:30
Definition WorldModule.h:33