jubilant-funicular
Camera2D.h
1 #ifndef NTA_CAMERA2D_H_INCLUDED
2 #define NTA_CAMERA2D_H_INCLUDED
3 
4 #include "MyEngine.h"
5 
6 namespace nta {
13  class Camera2D {
14  private:
16  glm::vec2 m_center;
18  glm::vec2 m_dimensions;
21  public:
24  Camera2D();
25  Camera2D(crvec2 center);
26  Camera2D(crvec2 center, crvec2 dimensions);
27  Camera2D(crvec2 center, crvec2 dimensions, float orientation);
29  ~Camera2D();
30  glm::mat3 getTranslationMatrix() const;
31  glm::mat3 getRotationMatrix() const;
32  glm::mat3 getInverseRotationMatrix() const;
33  glm::mat3 getDilationMatrix() const;
37  glm::mat3 getCameraMatrix() const;
38  glm::mat3 getInverseCameraMatrix() const;
40  glm::vec4 getBoundsCenter() const;
41  glm::vec4 getBoundsTopLeft() const;
43  glm::vec2 getCenter() const;
44  glm::vec2 getTopLeft() const;
45  glm::vec2 getDimensions() const;
46  glm::vec2 getRotatedDimensions() const;
47  float getOrientation() const;
49  std::tuple<glm::vec2, glm::vec2> getAxes() const;
51  glm::vec2 mouseToGame(crvec2 mouse, crvec2 windowDimensions) const;
56  glm::vec2 screenToGame(crvec2 screen) const;
58  bool inBounds(crvec2 pt) const;
59  bool inBounds(float x, float y) const;
61  bool isVisible(const std::vector<glm::vec2>& polygon) const;
63  void setCenter(crvec2 center);
64  void setCenter(float x, float y);
65  void setDimensions(crvec2 dimensions);
66  void setDimensions(float w, float h);
67  void setOrientation(float t);
70  void translateCenter(crvec2 translation, bool move_along_axes = false);
71  void translateCenter(float dx, float dy, bool move_along_axes = false);
73  void scaleDimensions(crvec2 dilation);
74  void scaleDimensions(float dw, float dh);
76  void rotate(float dt);
77  };
78 }
79 
80 #endif // NTA_CAMERA2D_H_INCLUDED
nta::Camera2D::m_center
glm::vec2 m_center
center of the camera's view in world coordinates
Definition: Camera2D.h:16
nta::Camera2D::scaleDimensions
void scaleDimensions(crvec2 dilation)
scales the camera's field of view
Definition: Camera2D.cpp:189
nta::Camera2D::inBounds
bool inBounds(crvec2 pt) const
Returns true if this pt is contained within the camera.
Definition: Camera2D.cpp:106
nta::Camera2D::isVisible
bool isVisible(const std::vector< glm::vec2 > &polygon) const
Returns ture if this polygon would show up in the camera.
Definition: Camera2D.cpp:115
nta::Camera2D::screenToGame
glm::vec2 screenToGame(crvec2 screen) const
Definition: Camera2D.cpp:102
nta::Camera2D::Camera2D
Camera2D()
Definition: Camera2D.cpp:9
nta::Camera2D::getBoundsCenter
glm::vec4 getBoundsCenter() const
returns camera bounds in the given format
Definition: Camera2D.cpp:68
nta::Camera2D::rotate
void rotate(float dt)
rotates the camera
Definition: Camera2D.cpp:196
nta::Camera2D::~Camera2D
~Camera2D()
destructor
Definition: Camera2D.cpp:30
nta::Camera2D::getAxes
std::tuple< glm::vec2, glm::vec2 > getAxes() const
returns (normalized) axes aligned with the camera
Definition: Camera2D.cpp:91
nta::Camera2D::m_dimensions
glm::vec2 m_dimensions
half dimensions of camera's view in world coordinates
Definition: Camera2D.h:18
nta
Definition: Animation2D.h:6
nta::Camera2D::m_orientation
float m_orientation
rotation about axis orthogonal to the world
Definition: Camera2D.h:20
nta::Camera2D::translateCenter
void translateCenter(crvec2 translation, bool move_along_axes=false)
Definition: Camera2D.cpp:178
nta::Camera2D::getCameraMatrix
glm::mat3 getCameraMatrix() const
Definition: Camera2D.cpp:62
nta::Camera2D::mouseToGame
glm::vec2 mouseToGame(crvec2 mouse, crvec2 windowDimensions) const
converts mouse coordinates to world coordinates
Definition: Camera2D.cpp:96
nta::Camera2D
Definition: Camera2D.h:13
nta::Camera2D::setCenter
void setCenter(crvec2 center)
sets the values of the camera's fields
Definition: Camera2D.cpp:161
nta::Camera2D::getCenter
glm::vec2 getCenter() const
returns the center, top left coordinate, and (half) dimensions of the camera's view
Definition: Camera2D.cpp:74