ctaza/camera.cpp

51 lines
894 B
C++

#include "camera.hpp"
static glm::vec3 UP(0.0f, 1.0f, 0.0f);
Camera::Camera(glm::vec3 pos)
{
position = pos;
yaw = -M_PI/2;
}
glm::vec3
Camera::get_direction() const
{
return glm::vec3(
cos(yaw) * cos(pitch),
sin(pitch),
sin(yaw) * cos(pitch));
}
glm::vec3
Camera::get_front() const
{
return glm::normalize(get_direction());
}
glm::vec3
Camera::get_flat_front()
{
float old_pitch = pitch;
pitch = 0;
glm::vec3 ret = glm::normalize(get_direction());
pitch = old_pitch;
return ret;
}
glm::vec3
Camera::get_right() const
{
return glm::normalize(glm::cross(UP, get_direction()));
}
glm::mat4
Camera::get_view() const
{
glm::vec3 dir = get_direction();
glm::vec3 front = get_front();
glm::vec3 right = get_right();
glm::vec3 up = glm::cross(dir, right);
return glm::lookAt(position, position + front, up);
}