diff --git a/inferno/src/inferno/render/camera.cpp b/inferno/src/inferno/render/camera.cpp index a81fd52..3f6e0f0 100644 --- a/inferno/src/inferno/render/camera.cpp +++ b/inferno/src/inferno/render/camera.cpp @@ -1,4 +1,5 @@ -#include // std::make_shared +#include // std::max, std::min +#include // std::make_shared #include // glm::perspective, glm::ortho #include // glm::radians, glm::lookAt @@ -39,8 +40,10 @@ namespace Inferno { void OrthographicCamera::initialize() { + m_zoomLevel = 1.0f; + // Set the roatation axis - m_rotate = glm::vec3(0.0f, 0.0f, 1.0f); + m_rotateAxis = glm::vec3(0.0f, 0.0f, 1.0f); dbg(Log::Info) << "OrthographicCamera initialized"; } @@ -91,18 +94,31 @@ namespace Inferno { transform()->setTranslate(translate); + // Update camera zoom + + float zoomSpeed = ZOOM_SENSITIVITY * deltaTime; + + if (Input::isKeyPressed(KeyCode("GLFW_KEY_EQUAL"))) { + m_zoomLevel -= zoomSpeed; + } + if (Input::isKeyPressed(KeyCode("GLFW_KEY_MINUS"))) { + m_zoomLevel += zoomSpeed; + } + m_zoomLevel = std::max(m_zoomLevel, 0.25f); + m_zoomLevel = std::min(m_zoomLevel, 10.0f); + // Update camera matrix // Local space -> World space: model matrix // Is done in Object::update() // World space -> View space: view matrix - transform()->setTransform(glm::translate(glm::mat4(1.0f), translate) * glm::rotate(glm::mat4(1.0f), glm::radians(rotate.z), m_rotate)); + transform()->setTransform(glm::translate(glm::mat4(1.0f), translate) * glm::rotate(glm::mat4(1.0f), glm::radians(rotate.z), m_rotateAxis)); transform()->setTransform(glm::inverse(transform()->transform())); // View space -> Clip space: projection matrix float aspectRatio = Application::get().getWindow().getAspect(); - setProjection(glm::ortho(-aspectRatio, aspectRatio, -1.0f, 1.0f, -1.0f, 1.0f)); + setProjection(glm::ortho(-aspectRatio * m_zoomLevel, aspectRatio * m_zoomLevel, -m_zoomLevel, m_zoomLevel, -1.0f, 1.0f)); // Clip space -> Screen space: viewport transform // Is done in the fragment shader using the settings of glViewport @@ -137,8 +153,8 @@ namespace Inferno { void PerspectiveCamera::update(float deltaTime) { // Get mouse movement offset compared to last frame - float xOffset = Input::getXOffset() * SENSITIVITY; - float yOffset = Input::getYOffset() * SENSITIVITY; + float xOffset = Input::getXOffset() * MOUSE_SENSITIVITY; + float yOffset = Input::getYOffset() * MOUSE_SENSITIVITY; m_yaw += xOffset; m_pitch += yOffset; diff --git a/inferno/src/inferno/render/camera.h b/inferno/src/inferno/render/camera.h index c14cd32..aff7b55 100644 --- a/inferno/src/inferno/render/camera.h +++ b/inferno/src/inferno/render/camera.h @@ -1,10 +1,10 @@ #ifndef CAMERA_H #define CAMERA_H -#include "inferno/log.h" // @@@@@@@@@@ #define TRANSLATE_SPEED 2.5f #define ROTATE_SPEED 90.0f -#define SENSITIVITY 0.25f +#define ZOOM_SENSITIVITY 2.5f +#define MOUSE_SENSITIVITY 0.25f #define NEAR_PLANE 0.1f #define FAR_PLANE 100.0f @@ -21,7 +21,7 @@ namespace Inferno { public: Camera(); Camera(glm::vec3 translate, glm::vec3 rotate); - virtual ~Camera() { dbg(Log::Danger) << "KILLED CAMERA"; } + virtual ~Camera() {} virtual void initialize() = 0; virtual void update(float deltaTime) = 0; @@ -44,7 +44,7 @@ namespace Inferno { public: OrthographicCamera(); OrthographicCamera(glm::vec3 translate, glm::vec3 rotate); - virtual ~OrthographicCamera() { dbg(Log::Danger) << "KILLED ORTHOGRAPHICCAMERA"; } + virtual ~OrthographicCamera() {} virtual void initialize() override; virtual void update(float deltaTime) override; @@ -52,7 +52,8 @@ namespace Inferno { // virtual void destroy() override; private: - glm::vec3 m_rotate; + float m_zoomLevel; + glm::vec3 m_rotateAxis; }; // ---------------------------------------- @@ -61,7 +62,7 @@ namespace Inferno { public: PerspectiveCamera(); PerspectiveCamera(glm::vec3 translate, glm::vec3 rotate); - virtual ~PerspectiveCamera() { dbg(Log::Danger) << "KILLED PERSPECTIVECAMERA"; } + virtual ~PerspectiveCamera() {} virtual void initialize() override; virtual void update(float deltaTime) override; @@ -83,5 +84,4 @@ namespace Inferno { // @Todo: // - Add sensitivity, fov to settings:camera -// - Add zoom to ortho camera // - Change ortho view matrix to use glm::lookAt()