Add zoom level to orthographic camera
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <algorithm> // std::max, std::min
|
||||
#include <memory> // std::make_shared
|
||||
|
||||
#include <glm/ext/matrix_clip_space.hpp> // glm::perspective, glm::ortho
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user