#include "svl/util/camera.h" #include "glm/gtc/matrix_transform.hpp" namespace svl { namespace util { Camera::Camera(const glm::vec2 &viewport, CameraProjectionMode mode) { mViewport = viewport; mFieldOfView = 45.0f; mNearPlane = 0.01f; mFarPlane = 100.0f; mProjectionMode = mode; } Camera::~Camera() { } void Camera::updateProjectMatrix() { if (mProjectionMode == CameraProjectionMode::Perspective) { mProjectMatrix = glm::perspective(glm::radians(mFieldOfView), mViewport.x * 1.0f / mViewport.y, mNearPlane, mFarPlane); } else { mProjectMatrix = glm::ortho(-mViewport.x / 2.0f, mViewport.x / 2.0f, -mViewport.y / 2.0f, mViewport.y / 2.0f, mNearPlane, mFarPlane); } } glm::mat4 Camera::orientation() const { glm::mat4 orientation; orientation = glm::rotate(orientation, glm::radians(mVerticalAngle), glm::vec3(1, 0, 0)); orientation = glm::rotate(orientation, glm::radians(mHorizontalAngle), glm::vec3(0, 1, 0)); return orientation; } void Camera::lookAt(const glm::vec3 &at) { assert(mPosition != at); //position = } void Camera::move(const glm::vec3 &offset) { mPosition += offset; } void Camera::moveTo(const glm::vec3 &pos) { if (mPosition != pos) { mPosition = pos; } } const glm::mat4 &Camera::projectionMatrix() { return mProjectMatrix; } const glm::mat4 &Camera::viewMatrix() { return mViewMatrix; } } // namespace util } // namespace svl