#include "Camera.hpp" #include "AppConfig.hpp" #include Camera::Camera() : eye(0.0f, 0.0f, 0.0f) , target(0.0, 0.0f, -2.0f) , pixelsPerMeter{ 50.0f } // Basic default , fov{ M_PI / 4 } // 45deg is the convention , perspective{ false } // { } void Camera::SetEyePos(glm::vec3 pos) { auto lookVector = this->target - /*Old pos*/ this->eye; this->eye = pos; this->target = pos + lookVector; } void Camera::SetTargetPos(glm::vec3 pos) { this->target = pos; } void Camera::SetTargetDirection(glm::vec3 lookVector) { this->target = this->eye + lookVector; } void Camera::SetHasPerspective(bool perspective) { this->perspective = perspective; } glm::mat4 Camera::CalcViewMatrix() const { return glm::lookAt(eye, target, glm::vec3(0, 1, 0)); } glm::mat4 Camera::CalcProjectionMatrix() const { if (perspective) { return glm::perspective(fov, AppConfig::mainWindowAspectRatio, 0.1f, 1000.0f); } else { float widthMeters = AppConfig::mainWindowWidth / pixelsPerMeter; float heightMeters = AppConfig::mainWindowHeight / pixelsPerMeter; return glm::ortho(-widthMeters / 2, +widthMeters / 2, -heightMeters / 2, +heightMeters / 2); } }