ezEngine  Milestone 9
CameraComponent.h
1 #pragma once
2 
3 #include <RendererCore/Declarations.h>
4 #include <RendererCore/Pipeline/Declarations.h>
5 #include <Core/World/World.h>
6 #include <Core/Graphics/Camera.h>
7 
8 class ezView;
9 struct ezResourceEvent;
10 
11 class EZ_RENDERERCORE_DLL ezCameraComponentManager : public ezComponentManager<class ezCameraComponent, ezBlockStorageType::Compact>
12 {
13 public:
16 
17  virtual void Initialize() override;
18  virtual void Deinitialize() override;
19 
20  void Update(const ezWorldModule::UpdateContext& context);
21 
22  void ReinitializeAllRenderTargetCameras();
23 
24  const ezCameraComponent* GetCameraByUsageHint(ezCameraUsageHint::Enum usageHint) const;
25  ezCameraComponent* GetCameraByUsageHint(ezCameraUsageHint::Enum usageHint);
26 
27 private:
28  friend class ezCameraComponent;
29 
30  void AddRenderTargetCamera(ezCameraComponent* pComponent);
31  void RemoveRenderTargetCamera(ezCameraComponent* pComponent);
32 
33  void OnViewCreated(ezView* pView);
34  void OnCameraConfigsChanged(void* dummy);
35 
36  ezDynamicArray<ezComponentHandle> m_modifiedCameras;
37  ezDynamicArray<ezComponentHandle> m_RenderTargetCameras;
38 };
39 
40 
41 class EZ_RENDERERCORE_DLL ezCameraComponent : public ezComponent
42 {
43  EZ_DECLARE_COMPONENT_TYPE(ezCameraComponent, ezComponent, ezCameraComponentManager);
44 
45 public:
48 
50  // ezComponent interface
51  //
52 
53 public:
54  virtual void SerializeComponent(ezWorldWriter& stream) const override;
55  virtual void DeserializeComponent(ezWorldReader& stream) override;
56 
57 protected:
58  virtual void OnActivated() override;
59  virtual void OnDeactivated() override;
60 
62  // ezCameraComponent interface
63  //
64 
65 public:
66  void UpdateRenderTargetCamera();
67 
68  ezEnum<ezCameraUsageHint> GetUsageHint() const { return m_UsageHint; }
69  void SetUsageHint(ezEnum<ezCameraUsageHint> val);
70 
71  void SetRenderTargetFile(const char* szFile);
72  const char* GetRenderTargetFile() const;
73 
74  void SetRenderTargetRectOffset(ezVec2 value);
75  ezVec2 GetRenderTargetRectOffset() const { return m_RenderTargetRectOffset; }
76 
77  void SetRenderTargetRectSize(ezVec2 value);
78  ezVec2 GetRenderTargetRectSize() const { return m_RenderTargetRectSize; }
79 
80  ezEnum<ezCameraMode> GetCameraMode() const { return m_Mode; }
81  void SetCameraMode(ezEnum<ezCameraMode> val);
82 
83  float GetNearPlane() const { return m_fNearPlane; }
84  void SetNearPlane(float val);
85 
86  float GetFarPlane() const { return m_fFarPlane; }
87  void SetFarPlane(float val);
88 
89  float GetFieldOfView() const { return m_fPerspectiveFieldOfView; }
90  void SetFieldOfView(float val);
91 
92  float GetOrthoDimension() const { return m_fOrthoDimension; }
93  void SetOrthoDimension(float val);
94 
95  ezRenderPipelineResourceHandle GetRenderPipeline() const;
96 
97  const char* GetRenderPipelineEnum() const;
98  void SetRenderPipelineEnum(const char* szFile);
99 
100  float GetAperture() const { return m_fAperture; }
101  void SetAperture(float fAperture);
102 
103  ezTime GetShutterTime() const { return m_ShutterTime; }
104  void SetShutterTime(ezTime ShutterTime);
105 
106  float GetISO() const { return m_fISO; }
107  void SetISO(float fISO);
108 
109  float GetExposureCompensation() const { return m_fExposureCompensation; }
110  void SetExposureCompensation(float fEC);
111 
112  float GetEV100() const;
113  float GetExposure() const;
114 
115  void ApplySettingsToView(ezView* pView) const;
116 
117  ezTagSet m_IncludeTags;
118  ezTagSet m_ExcludeTags;
119 
120 private:
121  void ResourceChangeEventHandler(const ezResourceEvent& e);
122 
123  ezEnum<ezCameraUsageHint> m_UsageHint;
124  ezEnum<ezCameraMode> m_Mode;
125  ezRenderToTexture2DResourceHandle m_hRenderTarget;
126  float m_fNearPlane;
127  float m_fFarPlane;
128  float m_fPerspectiveFieldOfView;
129  float m_fOrthoDimension;
130  ezRenderPipelineResourceHandle m_hCachedRenderPipeline;
131 
132  float m_fAperture;
133  ezTime m_ShutterTime;
134  float m_fISO;
135  float m_fExposureCompensation;
136 
137  void MarkAsModified();
138  void MarkAsModified(ezCameraComponentManager* pCameraManager);
139 
140  bool m_bIsModified;
141  bool m_bShowStats;
142  bool m_bRenderTargetInitialized = false;
143  ezInt8 m_iEditorShortcut = -1; // -1 for none, 0 to 9 for ALT+Number
144 
145  void ActivateRenderToTexture();
146  void DeactivateRenderToTexture();
147 
148  ezViewHandle m_hRenderTargetView;
149  ezVec2 m_RenderTargetRectOffset = ezVec2(0.0f);
150  ezVec2 m_RenderTargetRectSize = ezVec2(1.0f);
151  ezCamera m_RenderTargetCamera;
152  ezHashedString m_sRenderPipeline;
153 };
154 
Definition: CameraComponent.h:11
A camera class that stores the orientation and some basic camera settings.
Definition: Camera.h:37
Encapsulates a view on the given world through the given camera and rendered with the specified Rende...
Definition: View.h:18
Reads a world description from a stream. Allows to instantiate that world multiple times in different...
Definition: WorldReader.h:12
virtual void Initialize()
This method is called after the constructor. A derived type can override this method to do initializa...
Definition: WorldModule.h:103
Base class of all component types.
Definition: Component.h:19
Definition: CameraComponent.h:41
virtual void DeserializeComponent(ezWorldReader &stream)
Override this to load the current state of the component from the given stream.
Definition: Component.cpp:71
virtual void SerializeComponent(ezWorldWriter &stream) const
Override this to save the current state of the component to the given stream.
Definition: Component.cpp:69
The time class encapsulates a double value storing the time in seconds.
Definition: Time.h:10
Definition: WorldModule.h:29
virtual void Deinitialize()
This method is called before the destructor. A derived type can override this method to do deinitiali...
Definition: WorldModule.h:106
virtual void OnDeactivated()
This method is called when the component gets deactivated.
Definition: Component.cpp:198
virtual void OnActivated()
This method is called when the component gets activated.
Definition: Component.cpp:196
A dynamic collection of tags featuring fast lookups.
Definition: TagSet.h:22
These events may be sent by a specific ezResource or by the ezResourceManager.
Definition: Declarations.h:19
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition: World.h:18
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition: HashedString.h:24
Definition: Declarations.h:53
Definition: ComponentManager.h:81
Stores an entire ezWorld in a stream.
Definition: WorldWriter.h:15