sculpto
camera.h
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file camera.h
3 * \brief Renderer virtual camer class definiton module.
4 *
5 * \author Sabitov Kirill
6 * \date 02 July 2022
7 *********************************************************************/
8
9#pragma once
10
11#include "base.h"
12
13namespace scl
14{
16 class frame_buffer;
17
20 {
23 };
24
27 {
28 bool HDR { false };
29 float Exposure { 0 };
31 bool Bloom { false };
33 int BloomAmount { 0 };
36 camera_effects(bool HDR = false, float Exposure = 0, bool Bloom = false, int BloomAmount = 0) :
38 };
39
41 class camera
42 {
43 private:
45 matr4 Projection {};
46 matr4 View {};
47 matr4 ViewProjection {};
48
50 camera_projection_type ProjectionType;
51 float FieldOfView { 0.1f };
52 float ProjectionDistance { 0.1f };
53 float FarClip { 1000.0f };
54 int ViewportWidth {};
55 int ViewportHeight {};
56 float ViewportProjectionWidth {};
57 float ViewportProjectionHeight {};
58
60 vec3 UpDirection {};
61 vec3 LookDirection {};
62 vec3 RightDirection {};
63 vec3 Position {};
64 vec3 Focus {};
65
67 shared<frame_buffer> MainFrameBuffer {};
68 shared<frame_buffer> GBuffer {};
69 shared<frame_buffer> HDRFrameBuffer {};
70 shared<frame_buffer> BlurFrameBuffers[2] {};
72 public:
75
76 public:
78 const matr4 &GetProjection() const { return Projection; }
80 const matr4 &GetView() const { return View; }
82 const matr4 &GetViewProjection() const { return ViewProjection; }
83
85 camera_projection_type GetProjectionType() const { return ProjectionType; }
87 float GetFieldOfView() const { return FieldOfView; }
89 float GetProjectionDistance() const { return ProjectionDistance; };
91 float GetFarClip() const { return FarClip; };
93 int GetViewportWidth() const { return ViewportWidth; };
95 int GetViewportHeight() const { return ViewportHeight; };
97 float GetViewportProjectionWidth() const { return ViewportProjectionWidth; }
99 float GetViewportProjectionHeight() const { return ViewportProjectionHeight; }
100
102 const vec3 &GetUpDirection() const { return UpDirection; }
104 const vec3 &GetDirection() const { return LookDirection; }
106 const vec3 &GetRightDirection() const { return RightDirection; }
108 const vec3 &GetPosition() const { return Position; }
110 const vec3 &GetFocus() const { return Focus; }
111
113 const shared<frame_buffer> &GetMainFrameBuffer() const { return MainFrameBuffer; }
115 const shared<frame_buffer> &GetGBuffer() const { return GBuffer; }
117 const shared<frame_buffer> &GetHDRFrameBuffer() const { return HDRFrameBuffer; }
119 const shared<frame_buffer> &GetBlurFrameBuffers(int Index = 0) const { return BlurFrameBuffers[Index]; }
120
122 void SetProjectionType(camera_projection_type ProjectionType);
124 void SetFieldOfView(float FieldOfView);
126 void SetProjectionDistance(float ProjectionDistance);
128 void SetFarClip(float FarClip);
130 void SetViewportWidth(int ViewportWidth);
132 void SetViewportHeight(int ViewportHeight);
133
135 void SetUpDirection(const vec3 &UpDirection);
137 void SetDirection(const vec3 &Direction);
139 void SetPosition(const vec3 &Position);
141 void SetFocus(const vec3 &Focus);
142
143 /*!*
144 * Set view matrix by camera translation parametrs.
145 *
146 * \param Position - camera position.
147 * \param Focus - camera focusing point.
148 * \param UpDirection - camera up direction.
149 */
150 void SetView(const vec3 &Position, const vec3 &Focus, const vec3 &UpDirection);
151
152 /*!*
153 * Set flag, showing wheather camera main buffer is swap chain target or not.
154 *
155 * \param IsSwapChainTarget - flag, showing wheather camera main buffer is swap chain target or not
156 * \return None.
157 */
158 void SetRenderToSwapChain(bool IsSwapChainTarget);
159
160 private:
161 /*!*
162 * Invalidate camera view projection matrix function.
163 *
164 * \param None.
165 * \retrun None.
166 */
167 void InvalidateViewProjection();
168
169 /*!*
170 * Invalidate camera projection matrix function.
171 *
172 * \param None.
173 * \return None.
174 */
175 void InvalidateProjection();
176
177 /*!*
178 * Invalidate camera view matrix function.
179 *
180 * \param None.
181 * \return None.
182 */
183 void InvalidateView();
184
185 /*!*
186 * Invalidate camera frame buffers function.
187 * Creates uncreated ones, and resizes if needed.
188 *
189 * \param None.
190 * \return None.
191 */
192 void InvalidateBuffers();
193
194 /*!***********************************************************************************
195 * Frame buffers resize functions.
196 * Call actual resize only if specifed viewport size is diffrent with buffer current.
197 ************************************************************************************/
198
199 void ResizeMainFrameBuffer();
200 void ResizeGBuffer();
201 void ResizeHDRFrameBuffer();
202 void ResizeBlurFrameBuffers();
203
204 public:
205 /*!*
206 * Render camera controller default constructor.
207 *
208 * \param ProjectionType - render camera projection type.
209 */
211
214
215 /*!*
216 * Set camera project pixel size function..
217 *
218 * \param ViewportWidth, ViewportHeight - new projection plane size in pixels.
219 * \return - self reference.
220 */
221 camera &Resize(int ViewportWidth, int ViewportHeight);
222
223 /*!*
224 * Camera rotate function..
225 *
226 * \param Axis - rotation axis.
227 * \param Angle - rotation angle (in degree).
228 * \return self reference.
229 */
230 camera &Rotate(const vec3 &Axis, degrees Angle);
231
232 /*!*
233 * Camera movement function.
234 *
235 * \param MoveVector - movement directions.
236 * \return self reference.
237 */
238 camera &Move(const vec3 &MoveVector);
239 };
240}
Topology object basis class for mesh creating implementation module.
camera & Move(const vec3 &MoveVector)
Definition: camera.cpp:210
float GetFarClip() const
Definition: camera.h:91
const vec3 & GetUpDirection() const
Definition: camera.h:102
int GetViewportWidth() const
Definition: camera.h:93
const shared< frame_buffer > & GetBlurFrameBuffers(int Index=0) const
Definition: camera.h:119
const vec3 & GetFocus() const
Definition: camera.h:110
void SetProjectionDistance(float ProjectionDistance)
Definition: camera.cpp:23
void SetView(const vec3 &Position, const vec3 &Focus, const vec3 &UpDirection)
Definition: camera.cpp:69
camera_projection_type GetProjectionType() const
Definition: camera.h:85
float GetProjectionDistance() const
Definition: camera.h:89
float GetViewportProjectionHeight() const
Definition: camera.h:99
const shared< frame_buffer > & GetHDRFrameBuffer() const
Definition: camera.h:117
void SetProjectionType(camera_projection_type ProjectionType)
Definition: camera.cpp:13
camera & Resize(int ViewportWidth, int ViewportHeight)
Definition: camera.cpp:183
const matr4 & GetViewProjection() const
Definition: camera.h:82
void SetFieldOfView(float FieldOfView)
Definition: camera.cpp:18
void SetDirection(const vec3 &Direction)
Definition: camera.cpp:49
float GetFieldOfView() const
Definition: camera.h:87
camera(camera_projection_type ProjectionType, camera_effects Effects={})
Definition: camera.cpp:171
void SetFarClip(float FarClip)
Definition: camera.cpp:28
void SetViewportHeight(int ViewportHeight)
Definition: camera.cpp:38
float GetViewportProjectionWidth() const
Definition: camera.h:97
camera_effects Effects
Definition: camera.h:74
camera & Rotate(const vec3 &Axis, degrees Angle)
Definition: camera.cpp:193
const matr4 & GetProjection() const
Definition: camera.h:78
const matr4 & GetView() const
Definition: camera.h:80
const shared< frame_buffer > & GetMainFrameBuffer() const
Definition: camera.h:113
const vec3 & GetPosition() const
Definition: camera.h:108
int GetViewportHeight() const
Definition: camera.h:95
const vec3 & GetRightDirection() const
Definition: camera.h:106
const shared< frame_buffer > & GetGBuffer() const
Definition: camera.h:115
void SetPosition(const vec3 &Position)
Definition: camera.cpp:55
void SetUpDirection(const vec3 &UpDirection)
Definition: camera.cpp:43
void SetRenderToSwapChain(bool IsSwapChainTarget)
Definition: camera.cpp:79
const vec3 & GetDirection() const
Definition: camera.h:104
void SetViewportWidth(int ViewportWidth)
Definition: camera.cpp:33
void SetFocus(const vec3 &Focus)
Definition: camera.cpp:62
Definition: base.h:33
std::shared_ptr< T > shared
Definition: smart_ptr.h:15
camera_projection_type
Definition: camera.h:20
camera_effects(bool HDR=false, float Exposure=0, bool Bloom=false, int BloomAmount=0)
Definition: camera.h:36