HIRO_DRAW
Computer Graphics Structures library
Scene.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef HIRO_DRAW_SCENE_H
7 #define HIRO_DRAW_SCENE_H
8 #include <deque>
9 
10 #include <Utils/GeometryStructures.h>
11 
12 #include <HIRO_DRAW/VisualCamera.h>
13 #include <HIRO_DRAW/Renderer.h>
14 #include <HIRO_DRAW/ShaderApi.h>
15 
16 
17 
18 namespace hiro::draw
19 {
20 
22  struct HIRO_DRAW_API ProjectionParams
23  {
25  int32_t top;
27  int32_t left;
29  int32_t bottom;
31  int32_t right;
33  float fov_x;
35  float fov_y;
39  float far_distance;
41  glm_ext::TransMat4 view;
43  glm_ext::TransMat4 proj;
45  float width;
47  float height;
49  float aspect;
50 
60  glm::vec3 CastRay(const glm::vec2 &clip_coords) const;
61 
68  glm::vec2 ScreenToClipCoords(float x, float y) const;
69 
71  geom::IRect GetViewport() const;
72  };
73 
74 
75 
77  enum class GroundGrid
78  {
79  none = 0,
80  xy = 1,
81  yz = 2,
82  zx = 3
83  };
84 
92  class HIRO_DRAW_API Scene
93  {
94  friend class RenderSystem;
95  public:
96 
97  static const int32_t INVALID_INSTANCE_INDEX;
98 
99  bool render_world_axes = true;
100  hiro::draw::GroundGrid render_ground_grid = hiro::draw::GroundGrid::none;
101  float ground_grid_scale = 1.0f;
102 
104  Scene() = default;
106  Scene(int32_t x, int32_t y, int32_t width, int32_t height);
107  Scene(const Scene &) = delete;
108 
121  glm::vec3 MoveInProjectionSpace(const glm::vec3 &point, const glm::vec2 &proj_move_origin, const glm::vec2 &proj_move_end);
122 
124  hiro::draw::VisualCamera *GetCamera();
125 
127  uint32_t GetInstanceCount();
128 
138  int32_t AddInstance(const hiro::draw::PRenderer object, const hiro::draw::PStyle style, const uint8_t layer = 0);
139 
141  void RemoveInstance(int32_t index);
142 
144  void ClearInstances();
145 
147  void AddLight(const uint32_t &light);
148 
150  void SetLights(const std::vector<uint32_t> &lights);
151 
153  void SetProjectionPersp(float fov, float near_plane = 0.01f, float far_plane = 1000.0f);
154 
156  void SetProjectionOrtho(float sizing, float near_plane = 0.01f, float far_plane = 1000.0f);
157 
159  void SetProjectionCustom(const glm::mat4 &proj_matrix);
160 
162  void SetProjectionCameraParams(const glm::uvec2 &resolution, float fx, float fy, float cx, float cy, float near_plane = 0.01f, float far_plane = 1000.0f);
163 
165  void SetProjMatrix(const glm::mat4 &proj_mat);
166 
168  const glm_ext::TransMat4 &GetProjectionMat() const;
169 
171  glm_ext::TransMat4 GetViewProjMat() const;
172 
174  glm_ext::TransMat4 GetViewMat() const;
175 
177  void SetViewport(int32_t x, int32_t y, int32_t width, int32_t height);
178 
180  const geom::IRect &GetViewport() const;
181 
183  float GetNearDistance() const { return proj_near_plane_; }
185  float GetFarDistance() const { return proj_far_plane_; }
186 
188  float GetFovX() const;
190  float GetFovY() const;
191 
193  float GetAspectRatio() const;
194 
196  ProjectionParams GetProjectionParams() const;
197 
198  private:
199 
200  struct HIRO_DRAW_API Instance
201  {
202  public:
203  int32_t index;
204  hiro::draw::PRenderer object;
205  hiro::draw::PStyle style;
206  uint8_t layer;
207  };
208 
209  enum class ProjectionType
210  {
211  perspective = 0,
212  ortho = 1,
213  custom = 2
214  };
215 
216  int32_t next_index_ = 0;
217  std::deque<hiro::draw::Scene::Instance> instances_;
218 
219  geom::IRect viewport_;
220 
221  hiro::draw::VisualCamera camera_;
222 
223  hiro::draw::Scene::ProjectionType proj_type_ = hiro::draw::Scene::ProjectionType::perspective;
224  float proj_ortho_sizing_ = 1.0f;
225  float proj_fov_ = QUAT_PI;
226  float proj_near_plane_ = 0.01f;
227  float proj_far_plane_ = 1000.0f;
228  glm_ext::TransMat4 projection_;
229 
230  std::vector<uint32_t> lights_;
231 
232  bool data_has_changed_ = true;
233 
235  void RecalculateProjection();
236  };
237 
238  using PScene = std::shared_ptr<hiro::draw::Scene>;
239 
240 }
241 
242 #endif /* !HIRO_DRAW_SCENE_H */
float aspect
Aspect ratio of a viewport (width/height);.
Definition: Scene.h:49
glm_ext::TransMat4 proj
Projection matrix.
Definition: Scene.h:43
GroundGrid
Mode for rendering ground grid lines.
Definition: Scene.h:77
int32_t right
Viewport offset from the right window border. In pixels.
Definition: Scene.h:31
Render ground grid aligned with zx plane, and y normal.
Projection, camera and viewport parameters.
Definition: Scene.h:22
int32_t left
Viewport offset from the left window border. In pixels.
Definition: Scene.h:27
Render ground grid aligned with yz plane, and x normal.
float fov_x
Horizontal view angle. In radians.
Definition: Scene.h:33
Render ground grid aligned with xy plane, and z normal.
float near_distance
Distance to near projection plane.
Definition: Scene.h:37
int32_t top
Viewport offset from the top window border. In pixels.
Definition: Scene.h:25
Extensions for object visualization. Implements a higher level of OpenGL rendering.
Definition: API.h:20
int32_t bottom
Viewport offset from the bottom window border. In pixels.
Definition: Scene.h:29
float height
Vertical pixel resolution of viewport.
Definition: Scene.h:47
float fov_y
Vertical view angle, In radians.
Definition: Scene.h:35
float GetFarDistance() const
Returns far plane distance.
Definition: Scene.h:185
float far_distance
Distance to far projection plane.
Definition: Scene.h:39
float GetNearDistance() const
Returns near plane distance.
Definition: Scene.h:183
float width
Horizontal pixel resolution of viewport.
Definition: Scene.h:45
glm_ext::TransMat4 view
Camera view matrix.
Definition: Scene.h:41
A wrapper over view matrix, providing intuitive control.
Definition: VisualCamera.h:27
Class responsible for rendering loop implementation and its optimization.
Definition: RenderSystem.h:42
Defines rendering viewport, contains multiple object instances and a camera.
Definition: Scene.h:92