NAP
perspcameracomponent.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 namespace nap
11 {
12  // Forward Declares
13  class PerspCameraComponentInstance;
14  class TransformComponentInstance;
15  class TransformComponent;
16 
20  struct NAPAPI PerspCameraProperties
21  {
22  float mFieldOfView = 50.0f;
23  float mNearClippingPlane = 1.0f;
24  float mFarClippingPlane = 1000.0f;
25  glm::ivec2 mGridDimensions = { 1, 1 };
26  glm::ivec2 mGridLocation = { 0, 0 };
27  };
28 
29 
33  class NAPAPI PerspCameraComponent : public CameraComponent
34  {
35  RTTI_ENABLE(CameraComponent)
37  public:
39  };
40 
41 
47  {
48  RTTI_ENABLE(CameraComponentInstance)
49  public:
50  // Default constructor
52 
58  virtual bool init(utility::ErrorState& errorState) override;
59 
65  virtual void setRenderTargetSize(const glm::ivec2& size) override;
66 
73  virtual const glm::mat4& getProjectionMatrix() const override;
74 
78  virtual const glm::mat4 getViewMatrix() const override;
79 
86  void setGridDimensions(int numRows, int numColumns);
87 
91  void setGridLocation(int row, int column);
92 
97  void setFieldOfView(float fov);
98 
102  float getFieldOfView() const;
103 
107  virtual float getNearClippingPlane() const override;
108 
112  virtual float getFarClippingPlane() const override;
113 
121  virtual const glm::mat4& getRenderProjectionMatrix() const override;
122 
126  PerspCameraProperties getProperties() const;
127 
131  void setProperties(const PerspCameraProperties& props);
132 
133  private:
134 
138  void setDirty() { mDirty = true; }
139 
143  void updateProjectionMatrices() const;
144 
145  protected:
146  mutable glm::mat4x4 mProjectionMatrix; // The composed projection matrix
147  mutable glm::mat4x4 mRenderProjectionMatrix; // The composed projection matrix used by the renderer
148  mutable bool mDirty = true; // If the projection matrix needs to be recalculated
149  PerspCameraProperties mProperties; // These properties are copied from the resource to the instance. When these are changed, only the instance is affected
150  TransformComponentInstance* mTransformComponent; // Cached transform component
151 
152  bool mPerpendicularRenderProjection = true; // Whether the render projection matrix should be projected onto a perpendicular surface
153  };
154 }
nap::PerspCameraComponent
Definition: perspcameracomponent.h:33
nap::PerspCameraProperties
Definition: perspcameracomponent.h:20
nap::CameraComponentInstance
Definition: cameracomponent.h:38
nap::utility::ErrorState
Definition: errorstate.h:19
nap::PerspCameraComponentInstance::mRenderProjectionMatrix
glm::mat4x4 mRenderProjectionMatrix
Definition: perspcameracomponent.h:147
nap::PerspCameraComponentInstance::mProjectionMatrix
glm::mat4x4 mProjectionMatrix
Definition: perspcameracomponent.h:146
nap::CameraComponent
Definition: cameracomponent.h:23
nap::PerspCameraComponentInstance::mProperties
PerspCameraProperties mProperties
Definition: perspcameracomponent.h:149
nap::PerspCameraComponent::mProperties
PerspCameraProperties mProperties
Property: 'Properties' the perspective camera settings.
Definition: perspcameracomponent.h:38
nap::EntityInstance
Definition: entity.h:34
nap::Component
Definition: component.h:151
nap::PerspCameraComponentInstance
Definition: perspcameracomponent.h:46
nap::PerspCameraComponentInstance::mTransformComponent
TransformComponentInstance * mTransformComponent
Definition: perspcameracomponent.h:150
nap
Definition: templateapp.h:17
nap::TransformComponentInstance
Definition: transformcomponent.h:73