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 
50  inline float getWidth() const { return mRightPlane - mLeftPlane; }
51 
58  inline float getHeight() const { return mTopPlane - mBottomPlane; }
59 
65  float getRatio() const { return getHeight() / getWidth(); }
66 
72  void adjust(float ratio) { mTopPlane = ratio * getWidth() + mBottomPlane; }
73  };
74 
78  class NAPAPI OrthoCameraComponent : public CameraComponent
79  {
80  RTTI_ENABLE(CameraComponent)
82  public:
84  };
85 
86 
88  // OrthoCameraComponentInstance
90 
97  {
98  RTTI_ENABLE(CameraComponentInstance)
99  public:
100 
101  // Default constructor
103 
108  virtual bool init(utility::ErrorState& errorState) override;
109 
115  virtual void setRenderTargetSize(const glm::ivec2& size) override;
116 
123  virtual const glm::mat4& getProjectionMatrix() const override;
124 
128  virtual const glm::mat4 getViewMatrix() const override;
129 
133  const OrthoCameraProperties& getProperties() const { return mProperties; }
134 
139  void setProperties(const OrthoCameraProperties& properties);
140 
145  void setMode(EOrthoCameraMode mode);
146 
151  void setClipRect(const math::Rect& clipRect);
152 
153 
157  void restoreClipRect();
158 
162  virtual float getNearClippingPlane() const override;
163 
167  virtual float getFarClippingPlane() const override;
168 
176  virtual const glm::mat4& getRenderProjectionMatrix() const override;
177 
184  static glm::mat4 createRenderProjectionMatrix(float left, float right, float bottom, float top, float zNear, float zFar);
185 
192  static glm::mat4 createRenderProjectionMatrix(float left, float right, float bottom, float top);
193 
194  private:
195 
199  void setDirty() { mDirty = true; }
200 
204  void updateProjectionMatrices() const;
205 
206  private:
207  mutable glm::mat4x4 mViewMatrix; // The composed view matrix
208  mutable glm::mat4x4 mProjectionMatrix; // The composed projection matrix
209  mutable glm::mat4x4 mRenderProjectionMatrix; // The composed projection matrix used by the renderer
210  mutable bool mDirty = true; // If the projection matrix needs to be recalculated
211  OrthoCameraProperties mProperties; // These properties are copied from the resource to the instance. When these are changed, only the instance is affected
212  TransformComponentInstance* mTransformComponent; // Cached transform component
213  };
214 }
215 
nap::OrthoCameraComponentInstance::getProperties
const OrthoCameraProperties & getProperties() const
Definition: orthocameracomponent.h:133
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::OrthoCameraProperties::adjust
void adjust(float ratio)
Definition: orthocameracomponent.h:72
nap::EOrthoCameraMode::CorrectAspectRatio
@ CorrectAspectRatio
User provides all planes, but height is recalculated for correct aspect ratio.
nap::CameraComponent
Definition: cameracomponent.h:23
nap::OrthoCameraProperties::getHeight
float getHeight() const
Definition: orthocameracomponent.h:58
nap::EntityInstance
Definition: entity.h:34
nap::Component
Definition: component.h:151
nap::OrthoCameraProperties::getRatio
float getRatio() const
Definition: orthocameracomponent.h:65
nap
Definition: templateapp.h:17
nap::OrthoCameraComponentInstance
Definition: orthocameracomponent.h:96
nap::EOrthoCameraMode::Custom
@ Custom
All planes are retrieved from properties.
nap::OrthoCameraProperties::getWidth
float getWidth() const
Definition: orthocameracomponent.h:50
nap::OrthoCameraComponent
Definition: orthocameracomponent.h:78
nap::EOrthoCameraMode
EOrthoCameraMode
Definition: orthocameracomponent.h:22
nap::OrthoCameraComponent::mProperties
OrthoCameraProperties mProperties
Property:'Properties' the camera settings.
Definition: orthocameracomponent.h:83