#include "camera.h" #include Camera::Camera(int width, int height, glm::vec3 pos, glm::vec3 look, glm::vec3 up, float fov, float nearPlane, float farPlane): m_width(width), m_height(height), m_pos(pos), m_look(look), m_up(up), m_fov(fov), m_aspect(width/float(height)), m_near(nearPlane), m_far(farPlane) { calculateProjection(); calculateView(); } Camera::~Camera(){ } glm::mat4 Camera::getProjection(){ return m_proj; } glm::mat4 Camera::getView(){ return m_view; } void Camera::resize(int width, int height){ m_width = width; m_height = height; m_aspect = float(width)/float(height); calculateProjection(); } void Camera::translate(glm::vec3 move){ m_pos += move; calculateView(); } void Camera::setPos(glm::vec3 newPos){ m_pos = newPos; calculateView(); } glm::vec3 Camera::getPos(){ return m_pos; } void Camera::rotate(float angle, glm::vec3 axis){ glm::mat4 lookRotation = glm::rotate(glm::mat4(1), angle, axis); glm::vec3 tempLook = glm::vec3(lookRotation * glm::vec4(m_look, 0)); if(glm::cross(tempLook, m_up) != glm::vec3(0)){ m_look = tempLook; calculateView(); } } void Camera::setLook(glm::vec3 newLook){ // std::cout << "up: " << m_up.x << "," << m_up.y << "," << m_up.z << std::endl; // std::cout << "look: " << newLook.x << "," << newLook.y << "," << newLook.z << std::endl; if(glm::cross(newLook, m_up) == glm::vec3(0)){ std::cout<<"Error: Look vector cannot be parallel to up vector!"<