Ocular Engine
Camera.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_CORE_SCENE_CAMERA__H__
19 #define __H__OCULAR_CORE_SCENE_CAMERA__H__
20 
21 #include "Priority.hpp"
22 #include "Scene/SceneObject.hpp"
23 
24 #include "Graphics/Texture/RenderTexture.hpp"
25 #include "Graphics/Texture/DepthTexture.hpp"
26 #include "Graphics/Viewport.hpp"
27 
28 #include "Events/AEventListener.hpp"
29 
30 #include "Math/Geometry/Frustum.hpp"
31 #include "Math/Bounds/Ray.hpp"
32 
33 //------------------------------------------------------------------------------------------
34 
39 namespace Ocular
40 {
45  namespace Core
46  {
47  enum class ProjectionType
48  {
49  Unknown = 0,
50  Perspective,
51  Orthographic
52  };
53 
55  {
56  float fieldOfView;
57  float aspectRatio;
58  float nearClip;
59  float farClip;
60 
62  };
63 
65  {
66  float xMin;
67  float xMax;
68  float yMin;
69  float yMax;
70  float nearClip;
71  float farClip;
72 
74  };
75 
80  {
81  public:
82 
87  Camera(std::string const& name, SceneObject* parent = nullptr);
88 
89  Camera();
90 
91  virtual ~Camera();
92 
96  void setRenderTexture(Graphics::RenderTexture* renderTexture);
97 
102 
106  void setDepthTexture(Graphics::DepthTexture* depthTexture);
107 
112 
116  ProjectionType getProjectionType() const;
117 
122 
127 
138  void setProjectionOrthographic(float xMin, float xMax, float yMin, float yMax, float nearClip, float farClip);
139 
140  void setProjectionOrthographic(OrthographicProjection const& projection);
141 
150  void setProjectionPerspective(float fov, float aspectRatio, float nearClip, float farClip);
151 
152  void setProjectionPerspective(PerspectiveProjection const& projection);
153 
162  void setProjectionMatrix(Math::Matrix4x4 const& matrix);
163 
168 
172  Math::Matrix4x4 const& getProjectionMatrix() const;
173 
178  Math::Frustum const& getFrustum(bool updateFrustum = true);
179 
184  void setPriority(Priority priority);
185 
189  Priority getPriority() const;
190 
202  void setViewport(float x, float y, float width, float height, float minDepth = 0.0f, float maxDepth = 1.0f, bool updateMatrix = true);
203 
208 
218  void setFixedViewport(bool fixed);
219 
223  bool getIsFixedViewport() const;
224 
234  void setFixedProjection(bool fixed);
235 
239  bool getIsFixedProjection() const;
240 
244  void setClearColor(Core::Color const& color);
245 
249  Color const& getClearColor() const;
250 
257  Math::Vector3f screenToWorld(Math::Vector2i const& screenPos);
258 
265 
272  Math::Ray getPickRay(Math::Vector2i const& screenPos);
273 
283  virtual bool onEvent(std::shared_ptr<AEvent> event) override;
284 
285  protected:
286 
287  void onCreation();
288  void exposeVariables();
289 
290  void updateViewport(float width, float height);
291 
292  //------------------------------------------------------------
293 
294  ProjectionType m_ProjType;
295 
296  PerspectiveProjection m_PerspectiveProj;
297  OrthographicProjection m_OrthographicProj;
298 
299  Math::Matrix4x4 m_ViewMatrix;
300  Math::Matrix4x4 m_ProjMatrix;
301 
302  Math::Frustum m_Frustum;
303 
304  Graphics::RenderTexture* m_RenderTexture;
305  Graphics::DepthTexture* m_DepthTexture;
306  Graphics::Viewport* m_Viewport;
307 
308  Core::Color m_ClearColor;
309 
310  Priority m_Priority;
311 
312  bool m_IsFixedViewport;
313  bool m_IsFixedProjection;
314  bool m_IsFrustumDirty;
315 
316  private:
317  };
318  }
322 }
327 //------------------------------------------------------------------------------------------
328 
329 #endif
void setProjectionMatrix(Math::Matrix4x4 const &matrix)
Definition: Camera.cpp:187
Definition: Ray.hpp:47
Definition: Camera.hpp:54
Definition: Camera.hpp:64
A special texture that stores high precision depth information for each pixel.
Definition: DepthTexture.hpp:41
A special texture that can be rendered directly to.
Definition: RenderTexture.hpp:41
Definition: AEventListener.hpp:43
Definition: Frustum.hpp:57
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
bool getIsFixedProjection() const
Definition: Camera.cpp:298
Definition: Color.hpp:40
bool getIsFixedViewport() const
Definition: Camera.cpp:288
PerspectiveProjection getPerspectiveProjection() const
Definition: Camera.cpp:138
void setFixedViewport(bool fixed)
Definition: Camera.cpp:283
Definition: Vector2.hpp:44
Definition: SceneObject.hpp:93
void setProjectionPerspective(float fov, float aspectRatio, float nearClip, float farClip)
Definition: Camera.cpp:169
void setViewport(float x, float y, float width, float height, float minDepth=0.0f, float maxDepth=1.0f, bool updateMatrix=true)
Definition: Camera.cpp:228
void setFixedProjection(bool fixed)
Definition: Camera.cpp:293
Graphics::Viewport * getViewport() const
Definition: Camera.cpp:257
Math::Vector2i worldToScreen(Math::Vector3f const &worldPos)
Definition: Camera.cpp:333
Definition: Camera.hpp:79
Math::Matrix4x4 const & getViewMatrix()
Definition: Camera.cpp:193
Graphics::RenderTexture * getRenderTexture()
Definition: Camera.cpp:118
void setRenderTexture(Graphics::RenderTexture *renderTexture)
Definition: Camera.cpp:113
Math::Vector3f screenToWorld(Math::Vector2i const &screenPos)
Definition: Camera.cpp:313
void setPriority(Priority priority)
Definition: Camera.cpp:218
virtual bool onEvent(std::shared_ptr< AEvent > event) override
Definition: Camera.cpp:262
A 4x4 column-major float matrix.
Definition: Matrix4x4.hpp:64
OrthographicProjection getOrthographicProjection() const
Definition: Camera.cpp:143
Definition: Viewport.hpp:40
Priority getPriority() const
Definition: Camera.cpp:223
void setProjectionOrthographic(float xMin, float xMax, float yMin, float yMax, float nearClip, float farClip)
Definition: Camera.cpp:148
Math::Ray getPickRay(Math::Vector2i const &screenPos)
Definition: Camera.cpp:346
Math::Matrix4x4 const & getProjectionMatrix() const
Definition: Camera.cpp:201
void setDepthTexture(Graphics::DepthTexture *depthTexture)
Definition: Camera.cpp:123
ProjectionType getProjectionType() const
Definition: Camera.cpp:133
Graphics::DepthTexture * getDepthTexture()
Definition: Camera.cpp:128
Math::Frustum const & getFrustum(bool updateFrustum=true)
Definition: Camera.cpp:206