#ifndef CAMERA_H #define CAMERA_H #include #include class Camera { public: virtual glm::mat4 getProjectionMatrix() = 0; virtual glm::mat4 getViewMatrix() = 0; virtual void resize(int width, int height) = 0; virtual ~Camera() {} }; class BasicCamera : public Camera { protected: glm::mat4 m_view; glm::mat4 m_projection; float m_fov; float m_near; float m_far; float m_ratio; void computeProj() { m_projection = glm::perspective(m_fov, m_ratio, m_near, m_far); } public: BasicCamera(float myFov = 70.f, float myNear = 0.1f, float myFar = 100.f) : m_fov(myFov), m_near(myNear), m_far(myFar), m_ratio(1.f) { computeProj(); setView(glm::vec3(0), glm::vec3(0, 0, 1)); } virtual glm::mat4 getProjectionMatrix() { return m_projection; } virtual glm::mat4 getViewMatrix() { return m_view; } virtual void resize(int width, int height) { if(width > 0 && height > 0) { m_ratio = float(width)/float(height); computeProj(); } } void setFov(float fov = 70.f) { m_fov = fov; computeProj(); } void setNear(float myNear = 0.1f) { m_near = myNear; computeProj(); } void setFar(float myFar = 100.f) { m_far = myFar; computeProj(); } void setView(glm::vec3 cameraPos, glm::vec3 target, glm::vec3 upVector = glm::vec3(0, 1, 0)) { m_view = glm::lookAt(cameraPos, target, upVector); } }; #endif // CAMERA_H