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 PerpCameraProperties
21  {
22  float mFieldOfView = 50.0f;
23  float mNearClippingPlane = 1.0f;
24  float mFarClippingPlane = 1000.0f;
25  glm::ivec2 mGridDimensions = glm::ivec2(1, 1);
26  glm::ivec2 mGridLocation = glm::ivec2(0, 0);
27  };
28 
29 
33  class NAPAPI PerspCameraComponent : public Component
34  {
35  RTTI_ENABLE(Component)
37 
38 
41  virtual void getDependentComponents(std::vector<rtti::TypeInfo>& components) const override;
42 
43  public:
45  };
46 
47 
53  {
54  RTTI_ENABLE(CameraComponentInstance)
55  public:
56  // Default constructor
58 
64  virtual bool init(utility::ErrorState& errorState) override;
65 
71  virtual void setRenderTargetSize(const glm::ivec2& size) override;
72 
79  virtual const glm::mat4& getProjectionMatrix() const override;
80 
84  virtual const glm::mat4 getViewMatrix() const override;
85 
92  void setGridDimensions(int numRows, int numColumns);
93 
97  void setGridLocation(int row, int column);
98 
103  void setFieldOfView(float fov);
104 
108  float getFieldOfView() const;
109 
113  float getNearClippingPlane() const;
114 
118  float getFarClippingPlane() const;
119 
127  virtual const glm::mat4& getRenderProjectionMatrix() const override;
128 
129  private:
130 
134  void setDirty() { mDirty = true; }
135 
139  void updateProjectionMatrices() const;
140 
141  protected:
142  mutable glm::mat4x4 mProjectionMatrix; // The composed projection matrix
143  mutable glm::mat4x4 mRenderProjectionMatrix; // The composed projection matrix used by the renderer
144  mutable bool mDirty = true; // If the projection matrix needs to be recalculated
145  PerpCameraProperties mProperties; // These properties are copied from the resource to the instance. When these are changed, only the instance is affected
146  TransformComponentInstance* mTransformComponent; // Cached transform component
147 
148  bool mPerpendicularRenderProjection = true; // Whether the render projection matrix should be projected onto a perpendicular surface
149  };
150 }
nap::PerspCameraComponent
Definition: perspcameracomponent.h:33
nap::CameraComponentInstance
Definition: cameracomponent.h:19
nap::PerspCameraComponentInstance::mProperties
PerpCameraProperties mProperties
Definition: perspcameracomponent.h:145
nap::utility::ErrorState
Definition: errorstate.h:19
nap::PerspCameraComponentInstance::mRenderProjectionMatrix
glm::mat4x4 mRenderProjectionMatrix
Definition: perspcameracomponent.h:143
nap::PerspCameraComponent::mProperties
PerpCameraProperties mProperties
Property: 'Properties' the perspective camera settings.
Definition: perspcameracomponent.h:44
nap::PerspCameraComponentInstance::mProjectionMatrix
glm::mat4x4 mProjectionMatrix
Definition: perspcameracomponent.h:142
nap::EntityInstance
Definition: entity.h:34
nap::PerpCameraProperties
Definition: perspcameracomponent.h:20
nap::Component
Definition: component.h:151
nap::PerspCameraComponentInstance
Definition: perspcameracomponent.h:52
nap::PerspCameraComponentInstance::mTransformComponent
TransformComponentInstance * mTransformComponent
Definition: perspcameracomponent.h:146
nap
Definition: templateapp.h:17
nap::TransformComponentInstance
Definition: transformcomponent.h:53