Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
camera.h
Go to the documentation of this file.
1 #ifndef CAMERA_H
2 #define CAMERA_H
3 #include <glm/glm.hpp>
4 #include <memory>
5 #include "component.h"
6 #include "transform.h"
8 #include "graphics/renderable.h"
9 #include "events/observer.h"
10 #include "events/event_type.h"
11 //= SCRIPTABLE
12 //= SCRIPTABLE BASES Component
13 
14 #undef near
15 #undef far
16 
17 namespace Graphics {
21  class Camera : public Component {
22  private:
23  glm::mat4 projection_matrix;
24  //THESE NEED TO BE MOVED TO SOMEWHERE ELSE, PERHAPS AN INHERITED CLASS
25  Transform last_transform;
26  glm::mat4 last_projection_matrix;
27 
28  std::shared_ptr<ShaderManager> shader_manager;
29  float viewport_width;
30  float viewport_height;
31  float near;
32  float far;
33 
34  glm::vec2 velocity;
35  glm::vec2 target_position;
36 
37  int screen_padding_in_tiles;
38  bool free_camera;
39  float free_camera_speed;
40 
41  Transform negateTransformForScreen(std::shared_ptr<Transform> trans);
42  public:
43  Camera() = delete;
49  Camera(const std::shared_ptr<ShaderManager> shader_manager);
59  Camera(const std::shared_ptr<ShaderManager> shader_manager, const float viewport_width, const float viewport_height, const float near = 0.1, const float far = 1.0);
60  virtual void onStart() override;
61  virtual bool onUpdate(const double delta) override;
62  virtual void onDestroy() override;
63 
64  //= BEGIN SCRIPTABLE
65 
71  void setScreenPaddingInTiles(const int padding) noexcept;
77  int getScreenPaddingInTiles() const noexcept;
83  void setWidth(const float width) noexcept;
89  float getWidth() const noexcept;
95  void setHeight(const float height) noexcept;
101  float getHeight() const noexcept;
107  void setNear(const float near) noexcept;
113  float getNear() const noexcept;
119  void setFar(const float far) noexcept;
125  float getFar() const noexcept;
131  void setFreeCameraSpeed(const float speed) noexcept;
137  float getFreeCameraSpeed() const noexcept;
138 
144  glm::mat4 getProjectionMatrix() const noexcept;
145 
153  bool isComponentWithin(const Component& component) const;
154  virtual std::string className() const noexcept override;
155  //= END SCRIPTABLE
156 
157  virtual unsigned long long getValueForSorting() const noexcept override;
158 
159  virtual void onNotifyNow(std::shared_ptr<Events::Event> event) override;
160  virtual void handleQueuedEvent(std::shared_ptr<Events::Event> event) override;
161 
162  virtual void log(el::base::type::ostream_t& os) const override;
163  };
164 }
165 #endif
Base Class for all components.
Definition: component.h:20
virtual void onStart() override
Called when the engine starts and when a new scene is loaded.
Definition: camera.cpp:27
glm::mat4 getProjectionMatrix() const noexcept
Gets the projection matrix.
Definition: camera.cpp:222
virtual std::string className() const noexceptoverride
Returns a string representing the class name.
Definition: camera.cpp:257
float getNear() const noexcept
Gets the near z plane.
Definition: camera.cpp:202
void setWidth(const float width) noexcept
Sets the width.
Definition: camera.cpp:182
Class for transform.
Definition: transform.h:13
int getScreenPaddingInTiles() const noexcept
Gets the screen padding in tiles.
Definition: camera.cpp:178
float getWidth() const noexcept
Gets the width.
Definition: camera.cpp:186
void setNear(const float near) noexcept
Sets the near z plane.
Definition: camera.cpp:198
virtual unsigned long long getValueForSorting() const noexceptoverride
Gets the value for sorting.
Definition: camera.cpp:226
virtual void handleQueuedEvent(std::shared_ptr< Events::Event > event) override
HandleQueuedEvent allows derived classes to define behaviour for when queuedEvents are received...
Definition: camera.cpp:83
virtual bool onUpdate(const double delta) override
Called every engine loop.
Definition: camera.cpp:43
void setFreeCameraSpeed(const float speed) noexcept
Sets the free camera speed when in free camera mode.
Definition: camera.cpp:214
virtual void log(el::base::type::ostream_t &os) const override
Definition: camera.cpp:252
void setHeight(const float height) noexcept
Sets the height.
Definition: camera.cpp:190
Class for camera.
Definition: camera.h:21
virtual void onDestroy() override
Called when the engine is shutting down.
Definition: camera.cpp:80
void setScreenPaddingInTiles(const int padding) noexcept
Sets the screen padding in tiles.
Definition: camera.cpp:174
float getHeight() const noexcept
Gets the height.
Definition: camera.cpp:194
bool isComponentWithin(const Component &component) const
Determines if component within.
Definition: camera.cpp:230
virtual void onNotifyNow(std::shared_ptr< Events::Event > event) override
When receiving an event that is immediate, onNotifyNow is used. It acts as an interrupt to make sure ...
Definition: camera.cpp:170
float getFreeCameraSpeed() const noexcept
Gets the free camera speed when in free camera mode.
Definition: camera.cpp:218
void setFar(const float far) noexcept
Sets the far z plane.
Definition: camera.cpp:206
float getFar() const noexcept
Gets the far z plane.
Definition: camera.cpp:210