44
55namespace inexor ::vulkan_renderer {
66
7+ enum class CameraType { LOOKAT, FIRSTPERSON };
8+
79// / @brief A RAII wrapper class for camera position and movement.
810// / @todo Refactor method naming!
911class Camera {
10- float m_fov;
11- float m_z_near, m_z_far;
12-
1312 // / @brief Update the view matrix.
1413 // / @note The view matrix should only be updated if necessary.
1514 void update_view_matrix ();
1615
17- public:
18- // TODO: Why is so much stuff here public? refactor!
19-
20- enum CameraType { LOOKAT, FIRSTPERSON };
2116 CameraType m_type{CameraType::LOOKAT};
2217
23- glm::vec3 m_rotation{};
2418 glm::vec3 m_position{};
19+ glm::vec3 m_rotation{};
2520
26- float m_rotation_speed{1 .0f };
2721 float m_movement_speed{1 .0f };
22+ float m_rotation_speed{1 .0f };
23+
24+ float m_fov{0 .0f };
25+ float m_z_near{0 .0f };
26+ float m_z_far{0 .0f };
2827
2928 bool m_updated{false };
3029
3130 struct {
32- glm::mat4 perspective;
33- glm::mat4 view;
31+ glm::mat4 perspective = glm::mat4() ;
32+ glm::mat4 view = glm::mat4() ;
3433 } m_matrices;
3534
3635 struct {
@@ -40,6 +39,28 @@ class Camera {
4039 bool down{false };
4140 } m_keys;
4241
42+ public:
43+ Camera () = default;
44+ // / @brief Constructs a camera based on camera properties.
45+ // / @param type The type of the camera.
46+ // / @param position The camera's position.
47+ // / @param rotation The camera's rotation.
48+ // / @param movement_speed The movement speed of the camera.
49+ // / @param rotation_speed The rotation speed of the camera.
50+ // / @param fov The camera's field of view.
51+ // / @param z_near The near clipping value.
52+ // / @param z_far The far clipping value.
53+ // / @param window_width The width of the window which is used to calculate aspect ratio.
54+ // / @param window_height The height of the window which is used to calculate aspect ratio.
55+ Camera (CameraType type, glm::vec3 position, glm::vec3 rotation, float movement_speed, float rotation_speed,
56+ float fov, float z_near, float z_far, std::uint32_t window_width, std::uint32_t window_height);
57+ Camera (const Camera &) = default;
58+ Camera (Camera &&) noexcept ;
59+ ~Camera () = default ;
60+
61+ Camera &operator =(const Camera &) = default ;
62+ Camera &operator =(Camera &&) = default ;
63+
4364 // / @brief Check if any of the following keys is pressed: W, A, S, D.
4465 bool moving ();
4566
@@ -85,6 +106,22 @@ class Camera {
85106 // / @param delta_time The amount of time which passed since last update.
86107 // / @return Returns true if view or position has been changed.
87108 bool update_pad (glm::vec2 axis_left, glm::vec2 axis_right, float delta_time);
109+
110+ [[nodiscard]] glm::mat4 get_perspective () const {
111+ return m_matrices.perspective ;
112+ }
113+
114+ [[nodiscard]] glm::mat4 get_view () const {
115+ return m_matrices.view ;
116+ }
117+
118+ [[nodiscard]] float get_rotation_speed () const {
119+ return m_rotation_speed;
120+ }
121+
122+ [[nodiscard]] float get_movement_speed () const {
123+ return m_movement_speed;
124+ }
88125};
89126
90127} // namespace inexor::vulkan_renderer
0 commit comments