Commit b03ef97a authored by Sadman Kazi's avatar Sadman Kazi 🎸

added translate and rotation to the camera

parent 7e8b2607
#ifndef CAMERA_H_INCLUDED
#define CAMERA_H_INCLUDED
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/rotate_vector.hpp>
class Camera
{
public:
Camera(const glm::vec3& pos, float fov, float aspect, float zNear, float zFar) : m_position(pos) {
m_perspective = glm::perspective(fov, aspect, zNear, zFar);
//assuming that the vertical axis is y
m_forward = glm::vec3(0, 0, 1);
m_up = glm::vec3(0, 1, 0);
}
inline glm::mat4 getViewProjection() const {
return m_perspective * glm::lookAt(m_position, m_position + m_forward, m_up);
}
inline void rotate(float angle, glm::vec3& axis) {
m_forward = glm::rotate(m_forward, angle, axis);
m_up = glm::rotate(m_up, angle, axis);
}
inline void translate(glm::vec3& displacement) {
m_position += displacement;
}
~Camera() {};
private:
glm::mat4 m_perspective;
glm::vec3 m_position;
glm::vec3 m_forward;
glm::vec3 m_up;
};
#endif CAMERA_H_INCLUDED
\ No newline at end of file
......@@ -61,6 +61,7 @@ void Game::render() {
m_mesh->draw();
if (Input::getKeyDown(SDLK_UP)) {
std::cout << "You have pressed up!" << std::endl;
m_camera->translate(glm::vec3(0.0f, 0.0f, 0.1f));
}
else if (Input::getKeyUp(SDLK_UP)) {
std::cout << "You have released up!" << std::endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment