Camera.hpp 5.66 KB
Newer Older
1
2
#pragma once

3
4
#define GLM_DEPTH_ZERO_TO_ONE
#define GLM_FORCE_LEFT_HANDED
5
6
7
8
9
10
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/matrix_access.hpp>

namespace vkcv {

11
    /**
12
     * @brief Used to create a camera which governs the view and projection matrices.
13
     */
14
    class Camera final {
15
    protected:
16
17
18
19
20
21
22
23
		glm::mat4 m_view;
		glm::mat4 m_projection;

		float m_near;
		float m_far;
		float m_fov;
		float m_ratio;

24
		glm::vec3 m_up;
25
        glm::vec3 m_position;
26
27
        glm::vec3 m_center;

28
29
        float m_pitch;
        float m_yaw;
30
31

    public:
32
33
34
35

        /**
         * @brief The default constructor of the camera
         */
36
37
        Camera();

38
39
40
        /**
         * @brief The destructor of the camera (default behavior)
         */
41
        ~Camera();
42
43
        
        /**
44
         * @brief Sets the perspective object according to @p fov, @p ratio, @p near and @p far. This leads to changes in the projection matrix of the camera
45
46
47
48
49
         * @param fov The desired field of view in radians
         * @param ratio The aspect ratio
         * @param near Distance to near clipping plane
         * @param far Distance to far clipping plane
         */
50
51
        void setPerspective(float fov, float ratio, float near, float far);

52
53
54
55
        /**
         * @brief Gets the view matrix of the camera
         * @return The view matrix of the camera
         */
56
        glm::mat4& getView();
57

58
59
60
61
62
63
        /**
         * @brief Sets the view matrix of the camera according to @p position, @p center and @p up
         * @param[out] position The position of the camera
         * @param[out] center The target position the camera is looking at
         * @param[out] up The vector that defines which direction is 'up' depending on the camera's orientation
         */
64
65
        void lookAt(glm::vec3 position, glm::vec3 center, glm::vec3 up);

66
67
68
69
        /**
         * @brief Gets the current projection of the camera
         * @return The current projection matrix
         */
70
        glm::mat4& getProjection();
71

72
        /**
73
74
         * @brief Sets the projection matrix of the camera to @p projection
         * @param[in] projection The projection matrix
75
         */
76
        void setProjection(const glm::mat4 projection);
77

78
79
80
81
82
83
        /**
         * @brief Gets the model-view-projection matrix of the camera
         * @return The model-view-projection matrix
         */
        glm::mat4 getMVP() const;

84
85
86
87
88
        /**
         * @brief Gets the near and far bounds of the view frustum of the camera.
         * @param[out] near The near bound of the view frustum
         * @param[out] far The far bound of the view frustum
         */
89
        void getNearFar(float &near, float &far) const;
90

91
        /**
92
93
         * @brief Gets the current field of view of the camera in radians
         * @return[in] The current field of view in radians
94
         */
95
        float getFov() const;
96

97
        /**
98
99
         * @brief Sets the field of view of the camera to @p fov in radians
         * @param[in] fov The new field of view in radians
100
         */
101
        void setFov(float fov);
102

103
        /**
104
105
         * @brief Gets the current aspect ratio of the camera
         * @return The current aspect ratio of the camera
106
         */
107
        float getRatio() const;
108
109
110
111
112

        /**
         * @brief Updates the aspect ratio of the camera with @p ratio and, thus, changes the projection matrix
         * @param[in] ratio The new aspect ratio of the camera
         */
113
        void setRatio(float ratio);
114

115
116
117
118
119
        /**
         * @brief Sets @p near and @p far as new values for the view frustum of the camera. This leads to changes in the projection matrix according to these two values.
         * @param[in] near The new near bound of the view frustum
         * @param[in] far The new far bound of the view frustum
         */
120
        void setNearFar(float near, float far);
121

122
123
124
125
        /**
         * @brief Gets the current front vector of the camera in world space
         * @return The current front vector of the camera
         */
126
        glm::vec3 getFront() const;
127

128
129
130
131
        /**
         * @brief Gets the current position of the camera in world space
         * @return The current position of the camera in world space
         */
132
        glm::vec3 getPosition() const;
133

134
135
136
137
        /**
         * @brief Sets the position of the camera to @p position
         * @param[in] position The new position of the camera
         */
138
139
        void setPosition( glm::vec3 position );

140
        /**
141
142
         * @brief Gets the center point.
         * @return The center point.
143
         */
144
        glm::vec3 getCenter() const;
145

146
        /**
147
148
         * @brief Sets @p center as the new center point.
         * @param center The new center point.
149
         */
150
        void setCenter(glm::vec3 center);
151

152
        /**
153
154
         * @brief Gets the pitch value of the camera in degrees.
         * @return The pitch value in degrees.
155
         */
156
        float getPitch() const;
157

158
        /**
159
160
         * @brief Sets the pitch value of the camera to @p pitch in degrees.
         * @param[in] pitch The new pitch value in degrees.
161
         */
162
        void setPitch(float pitch);
163

164
        /**
165
166
         * @brief Gets the yaw value of the camera in degrees.
         * @return The yaw value in degrees.
167
         */
168
        float getYaw() const;
169

170
        /**
171
172
         * @brief Sets the yaw value of the camera to @p yaw.
         * @param[in] yaw The new yaw value in degrees.
173
         */
174
        void setYaw(float yaw);
175

176
        /**
177
178
         * @brief Gets the up vector.
         * @return The up vector.
179
         */
180
        glm::vec3 getUp() const;
181
182

        /**
183
184
         * @brief Sets @p up as the new up vector.
         * @param up The new up vector.
185
         */
186
        void setUp(const glm::vec3 &up);
187
188
189
    };

}