60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#ifndef CAMERA_H
|
|
#define CAMERA_H
|
|
|
|
#include <glm/mat4x4.hpp>
|
|
#include <glm/ext.hpp>
|
|
|
|
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_width;
|
|
float m_height;
|
|
|
|
void computeProj() { m_projection = glm::perspectiveFov(m_fov, m_width, m_height, 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_width(800.f), m_height(600.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_width = width;
|
|
m_height = 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
|