NAP
orthocameracomponent.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local Includes
8 #include "cameracomponent.h"
9 
10 // External Includes
11 #include <utility/dllexport.h>
12 
13 namespace nap
14 {
15  class OrthoCameraComponentInstance;
16  class TransformComponentInstance;
17  class TransformComponent;
18 
23  {
24  PixelSpace = 0,
26  Custom
27  };
28 
29 
33  struct NAPAPI OrthoCameraProperties
34  {
36  float mNearClippingPlane = 1.0f;
37  float mFarClippingPlane = 1000.0f;
38  float mLeftPlane = 0.0f;
39  float mRightPlane = 100.0f;
40  float mTopPlane = 100.0f;
41  float mBottomPlane = 0.0f;
42  math::Rect mClipRect = { {0.0f, 0.0f}, {1.0f, 1.0f} };
43  };
44 
48  class NAPAPI OrthoCameraComponent : public CameraComponent
49  {
50  RTTI_ENABLE(CameraComponent)
52  public:
54  };
55 
56 
58  // OrthoCameraComponentInstance
60 
67  {
68  RTTI_ENABLE(CameraComponentInstance)
69  public:
70 
71  // Default constructor
73 
78  virtual bool init(utility::ErrorState& errorState) override;
79 
85  virtual void setRenderTargetSize(const glm::ivec2& size) override;
86 
93  virtual const glm::mat4& getProjectionMatrix() const override;
94 
98  virtual const glm::mat4 getViewMatrix() const override;
99 
103  const OrthoCameraProperties& getProperties() const { return mProperties; }
104 
109  void setProperties(const OrthoCameraProperties& properties);
110 
115  void setMode(EOrthoCameraMode mode);
116 
121  void setClipRect(const math::Rect& clipRect);
122 
123 
127  void restoreClipRect();
128 
132  virtual float getNearClippingPlane() const override;
133 
137  virtual float getFarClippingPlane() const override;
138 
146  virtual const glm::mat4& getRenderProjectionMatrix() const override;
147 
154  static glm::mat4 createRenderProjectionMatrix(float left, float right, float bottom, float top, float zNear, float zFar);
155 
162  static glm::mat4 createRenderProjectionMatrix(float left, float right, float bottom, float top);
163 
164  private:
165 
169  void setDirty() { mDirty = true; }
170 
174  void updateProjectionMatrices() const;
175 
176  private:
177  mutable glm::mat4x4 mViewMatrix; // The composed view matrix
178  mutable glm::mat4x4 mProjectionMatrix; // The composed projection matrix
179  mutable glm::mat4x4 mRenderProjectionMatrix; // The composed projection matrix used by the renderer
180  mutable bool mDirty = true; // If the projection matrix needs to be recalculated
181  OrthoCameraProperties mProperties; // These properties are copied from the resource to the instance. When these are changed, only the instance is affected
182  TransformComponentInstance* mTransformComponent; // Cached transform component
183  };
184 }
nap::OrthoCameraComponentInstance::getProperties
const OrthoCameraProperties & getProperties() const
Definition: orthocameracomponent.h:103
nap::EOrthoCameraMode::PixelSpace
@ PixelSpace
Planes are scaled automatically to pixel coordinates. Near/Far is retrieved from properties.
nap::OrthoCameraProperties
Definition: orthocameracomponent.h:33
nap::CameraComponentInstance
Definition: cameracomponent.h:38
nap::uint8
uint8_t uint8
Definition: numeric.h:16
nap::math::Rect
Definition: rect.h:19
nap::utility::ErrorState
Definition: errorstate.h:19
nap::EOrthoCameraMode::CorrectAspectRatio
@ CorrectAspectRatio
User provides all planes, but height is recalculated for correct aspect ratio.
nap::CameraComponent
Definition: cameracomponent.h:23
nap::EntityInstance
Definition: entity.h:34
nap::Component
Definition: component.h:151
nap
Definition: templateapp.h:17
nap::OrthoCameraComponentInstance
Definition: orthocameracomponent.h:66
nap::EOrthoCameraMode::Custom
@ Custom
All planes are retrieved from properties.
nap::OrthoCameraComponent
Definition: orthocameracomponent.h:48
nap::EOrthoCameraMode
EOrthoCameraMode
Definition: orthocameracomponent.h:22
nap::OrthoCameraComponent::mProperties
OrthoCameraProperties mProperties
Property:'Properties' the camera settings.
Definition: orthocameracomponent.h:53