1#include "OrthoCamera.h"
2#include "common/maths/Vec.h"
3#include <glm/gtc/matrix_transform.hpp>
6OrthoCamera::OrthoCamera(
Vivid::Maths::Vec3 position,
float rotation,
float zoomLevel,
float near,
float far)
8 , m_ZoomLevel(zoomLevel)
12 m_Position = position;
14 m_Right = m_ViewportWidth / 2;
16 m_Top = m_ViewportHeight / 2;
18 updateProjectionMatrix();
22void OrthoCamera::updateProjectionMatrix()
26 m_ProjectionMatrix = glm::ortho(m_Left, m_Right, m_Bottom, m_Top, m_Near, m_Far);
29void OrthoCamera::updateViewMatrix()
33 glm::mat4 transform = glm::translate(glm::mat4(1.0f), m_Position.ToGLM())
34 * glm::rotate(glm::mat4(1.0f), m_Rotation, glm::vec3(0, 0, 1));
35 m_ViewMatrix = glm::inverse(transform);
38void OrthoCamera::SetRotation(
float rotation)
40 m_Rotation = rotation;
43void OrthoCamera::SetPerspective(
float left,
float right,
float bottom,
float top)
45 m_ProjectionMatrix = glm::ortho(left, right, bottom, top, -1.0f, 1.0f);
48void OrthoCamera::SetViewportSize(
int width,
int height)
54 m_ViewportWidth = width;
55 m_ViewportHeight = height;
56 updateProjectionMatrix();
60void OrthoCamera::MoveForward()
63 m_ZoomLevel = std::fmax(m_ZoomLevel, 0.01f);
67void OrthoCamera::MoveBackward()
70 m_ZoomLevel = std::fmax(m_ZoomLevel, 0.01f);
74void OrthoCamera::MoveLeft()
76 m_Position.x += m_Speed;
80void OrthoCamera::MoveRight()
82 m_Position.x -= m_Speed;
86void OrthoCamera::ProcessMouseScroll(
float scrollOffset)
88 m_ZoomLevel -= scrollOffset;
89 m_ZoomLevel = std::fmax(m_ZoomLevel, 0.25f);
90 updateProjectionMatrix();
93void OrthoCamera::ProcessMouseMovement(
float xOffset,
float yOffset,
bool constrainPitch)
95 m_Position.x -= xOffset * m_Speed * m_ScrollSpeed;
96 m_Position.y += yOffset * m_Speed * m_ScrollSpeed;
102 glm::vec4 screenPos = glm::vec4(x, y, 0.0f, 1.0f);
103 glm::vec4 worldPos = glm::inverse(m_ViewMatrix) * screenPos;