Aether3D Game Engine
CameraComponent.hpp
1 #ifndef CAMERA_COMPONENT_H
2 #define CAMERA_COMPONENT_H
3 
4 #include <string>
5 #include "Vec3.hpp"
6 #include "Matrix.hpp"
7 #include "RenderTexture.hpp"
8 
9 namespace ae3d
10 {
13  {
14  public:
16  class GameObject* GetGameObject() const { return gameObject; }
17 
19  enum class ProjectionType { Orthographic, Perspective };
20 
22  enum class ClearFlag { DepthAndColor, Depth, DontClear };
23 
25  const Matrix44& GetProjection() const { return projectionMatrix; }
26 
28  const Matrix44& GetView() const { return viewMatrix; }
29 
34  Vec3 GetScreenPoint( const Vec3& worldPoint, float viewWidth, float viewHeight ) const;
35 
37  ProjectionType GetProjectionType() const { return projectionType; }
38 
40  void SetProjectionType( ProjectionType aProjectionType ) { projectionType = aProjectionType; }
41 
52  void SetProjection( float left, float right, float bottom, float top, float near, float far );
53 
62  void SetProjection( float fovDegrees, float aspect, float near, float far );
63 
65  void SetProjection( const Matrix44& proj );
66 
68  Vec3 GetClearColor() const { return clearColor; }
69 
71  RenderTexture* GetTargetTexture() { return targetTexture; }
72 
74  RenderTexture& GetDepthNormalsTexture() { return depthNormalsTexture; }
75 
77  void SetClearColor( const Vec3& color );
78 
80  void SetTargetTexture( RenderTexture* renderTexture );
81 
83  void SetClearFlag( ClearFlag aClearFlag ) { clearFlag = aClearFlag; }
84 
86  void SetLayerMask( unsigned aLayerMask ) { layerMask = aLayerMask; }
87 
89  unsigned GetRenderOrder() const { return renderOrder; }
90 
92  void SetRenderOrder( unsigned order ) { renderOrder = order; }
93 
95  unsigned GetLayerMask() const { return layerMask; }
96 
98  ClearFlag GetClearFlag() const { return clearFlag; }
99 
101  float GetNear() const { return nearp; }
102 
104  float GetFar() const { return farp; }
105 
107  float GetAspect() const { return aspect; }
108 
110  float GetFovDegrees() const { return fovDegrees; }
111 
113  std::string GetSerialized() const;
114 
116  float GetLeft() const { return orthoParams.left; }
117 
119  float GetRight() const { return orthoParams.right; }
120 
122  float GetBottom() const { return orthoParams.down; }
123 
125  float GetTop() const { return orthoParams.top; }
126 
129  void SetView( const Matrix44& view ) { viewMatrix = view; }
130 
131  private:
132  friend class GameObject;
133  friend class Scene;
134 
136  static int Type() { return 0; }
137 
139  static unsigned New();
140 
142  static CameraComponent* Get( unsigned index );
143 
144  Matrix44 projectionMatrix;
145  Matrix44 viewMatrix;
146  Vec3 clearColor;
147  RenderTexture* targetTexture = nullptr;
148  RenderTexture depthNormalsTexture;
149 
150  struct OrthoParams
151  {
152  float left = 0;
153  float right = 100;
154  float top = 0;
155  float down = 100;
156  } orthoParams;
157 
158  float nearp = 0;
159  float farp = 1;
160  float fovDegrees = 45;
161  float aspect = 1;
162  unsigned layerMask = 1;
163  unsigned renderOrder = 0;
164  ProjectionType projectionType = ProjectionType::Orthographic;
165  ClearFlag clearFlag = ClearFlag::DepthAndColor;
166  GameObject* gameObject = nullptr;
167  };
168 }
169 #endif
ClearFlag
Clear flag.
Definition: CameraComponent.hpp:22
Vec3 GetScreenPoint(const Vec3 &worldPoint, float viewWidth, float viewHeight) const
RenderTexture & GetDepthNormalsTexture()
Definition: CameraComponent.hpp:74
Definition: AudioClip.hpp:4
float GetTop() const
Definition: CameraComponent.hpp:125
float GetNear() const
Definition: CameraComponent.hpp:101
const Matrix44 & GetView() const
Definition: CameraComponent.hpp:28
void SetClearColor(const Vec3 &color)
float GetLeft() const
Definition: CameraComponent.hpp:116
3-component vector.
Definition: Vec3.hpp:12
void SetClearFlag(ClearFlag aClearFlag)
Definition: CameraComponent.hpp:83
void SetRenderOrder(unsigned order)
Definition: CameraComponent.hpp:92
Render texture.
Definition: RenderTexture.hpp:12
float GetBottom() const
Definition: CameraComponent.hpp:122
RenderTexture * GetTargetTexture()
Definition: CameraComponent.hpp:71
float GetRight() const
Definition: CameraComponent.hpp:119
ProjectionType
Projection type.
Definition: CameraComponent.hpp:19
const Matrix44 & GetProjection() const
Definition: CameraComponent.hpp:25
unsigned GetRenderOrder() const
Definition: CameraComponent.hpp:89
ClearFlag GetClearFlag() const
Definition: CameraComponent.hpp:98
std::string GetSerialized() const
void SetView(const Matrix44 &view)
Definition: CameraComponent.hpp:129
GameObject is composed of components that define its behavior.
Definition: GameObject.hpp:9
float GetFar() const
Definition: CameraComponent.hpp:104
class GameObject * GetGameObject() const
Definition: CameraComponent.hpp:16
void SetProjectionType(ProjectionType aProjectionType)
Definition: CameraComponent.hpp:40
void SetProjection(float left, float right, float bottom, float top, float near, float far)
Camera views the scene. GameObject containing a camera component must also contain a TransformCompone...
Definition: CameraComponent.hpp:12
void SetLayerMask(unsigned aLayerMask)
Definition: CameraComponent.hpp:86
void SetTargetTexture(RenderTexture *renderTexture)
unsigned GetLayerMask() const
Definition: CameraComponent.hpp:95
ProjectionType GetProjectionType() const
Definition: CameraComponent.hpp:37
Contains game objects in a transform hierarchy.
Definition: Scene.hpp:17
float GetAspect() const
Definition: CameraComponent.hpp:107
float GetFovDegrees() const
Definition: CameraComponent.hpp:110
Vec3 GetClearColor() const
Definition: CameraComponent.hpp:68