aboutsummaryrefslogtreecommitdiff
path: root/src/Core/Camera.cpp
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-20 02:27:02 +0200
committerhachem <im@hachem.wtf>2026-08-20 02:40:07 +0200
commit5b361d81dbd2af0d0e99b9eb1adebea76ff05db0 (patch)
tree34db1df17e8c7248aeeb92156d635d31c2484e3f /src/Core/Camera.cpp
parente3abaaf59777258ba06705135a0cafcb5918ad12 (diff)
[chore]: MASSIVE refactor + more vulkan bs
Diffstat (limited to 'src/Core/Camera.cpp')
-rw-r--r--src/Core/Camera.cpp214
1 files changed, 107 insertions, 107 deletions
diff --git a/src/Core/Camera.cpp b/src/Core/Camera.cpp
index 028924e..35b7a2f 100644
--- a/src/Core/Camera.cpp
+++ b/src/Core/Camera.cpp
@@ -1,68 +1,68 @@
-#include "Camera.h"
+#include "camera.h"
#include <glm/gtc/quaternion.hpp>
#include <GLFW/glfw3.h>
namespace Donut
{
- Camera::Camera(float fov, float aspectRatio, float nearPlane, float farPlane)
- : m_FOV(fov), m_AspectRatio(aspectRatio), m_NearPlane(nearPlane), m_FarPlane(farPlane)
+ Camera::Camera(float fov, float aspect_ratio, float near_plane, float far_plane)
+ : m_fov(fov), m_aspect_ratio(aspect_ratio), m_near_plane(near_plane), m_far_plane(far_plane)
{
- RecalculateProjectionMatrix();
- RecalculateViewMatrix();
+ recalculate_projection_matrix();
+ recalculate_view_matrix();
}
- void Camera::SetProjection(float fov, float aspectRatio, float nearPlane, float farPlane)
+ auto Camera::set_projection(float fov, float aspect_ratio, float near_plane, float far_plane) -> void
{
- m_FOV = fov;
- m_AspectRatio = aspectRatio;
- m_NearPlane = nearPlane;
- m_FarPlane = farPlane;
- RecalculateProjectionMatrix();
+ m_fov = fov;
+ m_aspect_ratio = aspect_ratio;
+ m_near_plane = near_plane;
+ m_far_plane = far_plane;
+ recalculate_projection_matrix();
}
- void Camera::RecalculateProjectionMatrix()
+ auto Camera::recalculate_projection_matrix() -> void
{
- m_ProjectionMatrix = glm::perspective(glm::radians(m_FOV), m_AspectRatio, m_NearPlane, m_FarPlane);
- m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix;
+ m_projection_matrix = glm::perspective(glm::radians(m_fov), m_aspect_ratio, m_near_plane, m_far_plane);
+ m_view_projection_matrix = m_projection_matrix * m_view_matrix;
}
- void Camera::RecalculateViewMatrix()
+ auto Camera::recalculate_view_matrix() -> void
{
- if (m_CameraMode == CameraMode::FPS)
+ if (m_camera_mode == CameraMode::FPS)
{
- float pitch = glm::radians(m_Rotation.x);
- float yaw = glm::radians(m_Rotation.y);
- float roll = glm::radians(m_Rotation.z);
+ float pitch = glm::radians(m_rotation.x);
+ float yaw = glm::radians(m_rotation.y);
+ float roll = glm::radians(m_rotation.z);
glm::vec3 direction;
direction.x = cos(yaw) * cos(pitch);
direction.y = sin(pitch);
direction.z = sin(yaw) * cos(pitch);
- glm::vec3 worldUp(0.0f, 1.0f, 0.0f);
+ glm::vec3 world_up(0.0f, 1.0f, 0.0f);
glm::vec3 front = glm::normalize(direction);
- glm::vec3 right = glm::normalize(glm::cross(front, worldUp));
+ glm::vec3 right = glm::normalize(glm::cross(front, world_up));
glm::vec3 up = glm::normalize(glm::cross(right, front));
- m_ViewMatrix = glm::lookAt(m_Position, m_Position + front, up);
- m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix;
+ m_view_matrix = glm::lookAt(m_position, m_position + front, up);
+ m_view_projection_matrix = m_projection_matrix * m_view_matrix;
}
- else if (m_CameraMode == CameraMode::Orbital)
+ else if (m_camera_mode == CameraMode::Orbital)
{
- glm::vec3 position = GetOrbitalPosition();
- glm::vec3 target = m_OrbitalTarget;
+ glm::vec3 position = get_orbital_position();
+ glm::vec3 target = m_orbital_target;
glm::vec3 up(0.0f, 1.0f, 0.0f);
-
- m_ViewMatrix = glm::lookAt(position, target, up);
- m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix;
+
+ m_view_matrix = glm::lookAt(position, target, up);
+ m_view_projection_matrix = m_projection_matrix * m_view_matrix;
}
}
- glm::vec3 Camera::GetForwardDirection() const
+ auto Camera::get_forward_direction() const -> glm::vec3
{
- float pitch = glm::radians(m_Rotation.x);
- float yaw = glm::radians(m_Rotation.y);
+ float pitch = glm::radians(m_rotation.x);
+ float yaw = glm::radians(m_rotation.y);
glm::vec3 direction;
direction.x = cos(yaw) * cos(pitch);
@@ -72,154 +72,154 @@ namespace Donut
return glm::normalize(direction);
}
- glm::vec3 Camera::GetRightDirection() const
+ auto Camera::get_right_direction() const -> glm::vec3
{
- glm::vec3 worldUp(0.0f, 1.0f, 0.0f);
- return glm::normalize(glm::cross(GetForwardDirection(), worldUp));
+ glm::vec3 world_up(0.0f, 1.0f, 0.0f);
+ return glm::normalize(glm::cross(get_forward_direction(), world_up));
}
- glm::vec3 Camera::GetUpDirection() const
+ auto Camera::get_up_direction() const -> glm::vec3
{
- return glm::normalize(glm::cross(GetRightDirection(), GetForwardDirection()));
+ return glm::normalize(glm::cross(get_right_direction(), get_forward_direction()));
}
- void Camera::OnMouseMove(float xOffset, float yOffset, bool constrainPitch)
+ auto Camera::on_mouse_move(float x_offset, float y_offset, bool constrain_pitch) -> void
{
- if (m_CameraMode == CameraMode::FPS)
+ if (m_camera_mode == CameraMode::FPS)
{
- xOffset *= m_MouseSensitivity;
- yOffset *= m_MouseSensitivity;
+ x_offset *= m_mouse_sensitivity;
+ y_offset *= m_mouse_sensitivity;
- m_Rotation.y += xOffset;
- m_Rotation.x += yOffset;
+ m_rotation.y += x_offset;
+ m_rotation.x += y_offset;
- if (constrainPitch)
+ if (constrain_pitch)
{
- if (m_Rotation.x > 89.0f)
- m_Rotation.x = 89.0f;
- if (m_Rotation.x < -89.0f)
- m_Rotation.x = -89.0f;
+ if (m_rotation.x > 89.0f)
+ m_rotation.x = 89.0f;
+ if (m_rotation.x < -89.0f)
+ m_rotation.x = -89.0f;
}
- RecalculateViewMatrix();
+ recalculate_view_matrix();
}
}
- void Camera::MoveForward(float deltaTime)
+ auto Camera::move_forward(float delta_time) -> void
{
- if (m_CameraMode == CameraMode::FPS)
+ if (m_camera_mode == CameraMode::FPS)
{
- m_Position += GetForwardDirection() * m_MovementSpeed * deltaTime;
- RecalculateViewMatrix();
+ m_position += get_forward_direction() * m_movement_speed * delta_time;
+ recalculate_view_matrix();
}
}
- void Camera::MoveBackward(float deltaTime)
+ auto Camera::move_backward(float delta_time) -> void
{
- if (m_CameraMode == CameraMode::FPS)
+ if (m_camera_mode == CameraMode::FPS)
{
- m_Position -= GetForwardDirection() * m_MovementSpeed * deltaTime;
- RecalculateViewMatrix();
+ m_position -= get_forward_direction() * m_movement_speed * delta_time;
+ recalculate_view_matrix();
}
}
- void Camera::MoveRight(float deltaTime)
+ auto Camera::move_right(float delta_time) -> void
{
- if (m_CameraMode == CameraMode::FPS)
+ if (m_camera_mode == CameraMode::FPS)
{
- m_Position += GetRightDirection() * m_MovementSpeed * deltaTime;
- RecalculateViewMatrix();
+ m_position += get_right_direction() * m_movement_speed * delta_time;
+ recalculate_view_matrix();
}
}
- void Camera::MoveLeft(float deltaTime)
+ auto Camera::move_left(float delta_time) -> void
{
- if (m_CameraMode == CameraMode::FPS)
+ if (m_camera_mode == CameraMode::FPS)
{
- m_Position -= GetRightDirection() * m_MovementSpeed * deltaTime;
- RecalculateViewMatrix();
+ m_position -= get_right_direction() * m_movement_speed * delta_time;
+ recalculate_view_matrix();
}
}
- void Camera::MoveUp(float deltaTime)
+ auto Camera::move_up(float delta_time) -> void
{
- if (m_CameraMode == CameraMode::FPS)
+ if (m_camera_mode == CameraMode::FPS)
{
- glm::vec3 worldUp(0.0f, 1.0f, 0.0f);
- m_Position += worldUp * m_MovementSpeed * deltaTime;
- RecalculateViewMatrix();
+ glm::vec3 world_up(0.0f, 1.0f, 0.0f);
+ m_position += world_up * m_movement_speed * delta_time;
+ recalculate_view_matrix();
}
}
- void Camera::MoveDown(float deltaTime)
+ auto Camera::move_down(float delta_time) -> void
{
- if (m_CameraMode == CameraMode::FPS)
+ if (m_camera_mode == CameraMode::FPS)
{
- glm::vec3 worldUp(0.0f, 1.0f, 0.0f);
- m_Position -= worldUp * m_MovementSpeed * deltaTime;
- RecalculateViewMatrix();
+ glm::vec3 world_up(0.0f, 1.0f, 0.0f);
+ m_position -= world_up * m_movement_speed * delta_time;
+ recalculate_view_matrix();
}
}
- glm::vec3 Camera::GetOrbitalPosition() const
+ auto Camera::get_orbital_position() const -> glm::vec3
{
- float clampedElevation = glm::clamp(m_Elevation, 0.01f, float(std::numbers::pi) - 0.01f);
+ float clamped_elevation = glm::clamp(m_elevation, 0.01f, float(std::numbers::pi) - 0.01f);
return glm::vec3
(
- m_OrbitalRadius * sin(clampedElevation) * cos(m_Azimuth),
- m_OrbitalRadius * cos(clampedElevation),
- m_OrbitalRadius * sin(clampedElevation) * sin(m_Azimuth)
+ m_orbital_radius * sin(clamped_elevation) * cos(m_azimuth),
+ m_orbital_radius * cos(clamped_elevation),
+ m_orbital_radius * sin(clamped_elevation) * sin(m_azimuth)
);
}
- void Camera::UpdateOrbital()
+ auto Camera::update_orbital() -> void
{
- m_OrbitalTarget = glm::vec3(0.0f, 0.0f, 0.0f);
- if (m_Dragging || m_Panning)
- m_Moving = true;
+ m_orbital_target = glm::vec3(0.0f, 0.0f, 0.0f);
+ if (m_dragging || m_panning)
+ m_moving = true;
else
- m_Moving = false;
- RecalculateViewMatrix();
+ m_moving = false;
+ recalculate_view_matrix();
}
- void Camera::ProcessOrbitalMouseMove(double x, double y)
+ auto Camera::process_orbital_mouse_move(double x, double y) -> void
{
- if (m_Dragging && !m_Panning)
+ if (m_dragging && !m_panning)
{
- float dx = float(x - m_LastX_Orbital);
- float dy = float(y - m_LastY_Orbital);
-
- m_Azimuth += dx * m_OrbitalSpeed;
- m_Elevation -= dy * m_OrbitalSpeed;
- m_Elevation = glm::clamp(m_Elevation, 0.01f, float(std::numbers::pi) - 0.01f);
+ float dx = float(x - m_last_x_orbital);
+ float dy = float(y - m_last_y_orbital);
+
+ m_azimuth += dx * m_orbital_speed;
+ m_elevation -= dy * m_orbital_speed;
+ m_elevation = glm::clamp(m_elevation, 0.01f, float(std::numbers::pi) - 0.01f);
}
-
- m_LastX_Orbital = x;
- m_LastY_Orbital = y;
- UpdateOrbital();
+
+ m_last_x_orbital = x;
+ m_last_y_orbital = y;
+ update_orbital();
}
- void Camera::ProcessOrbitalMouseButton(int button, int action, int mods)
+ auto Camera::process_orbital_mouse_button(int button, int action, int mods) -> void
{
if (button == GLFW_MOUSE_BUTTON_LEFT)
{
if (action == GLFW_PRESS)
{
- m_Dragging = true;
- m_Panning = false;
+ m_dragging = true;
+ m_panning = false;
}
else if (action == GLFW_RELEASE)
{
- m_Dragging = false;
- m_Panning = false;
+ m_dragging = false;
+ m_panning = false;
}
}
}
- void Camera::ProcessOrbitalScroll(double xoffset, double yoffset)
+ auto Camera::process_orbital_scroll(double x_offset, double y_offset) -> void
{
- m_OrbitalRadius -= yoffset * m_ZoomSpeed;
- m_OrbitalRadius = glm::clamp(m_OrbitalRadius, m_OrbitalMinRadius, m_OrbitalMaxRadius);
- UpdateOrbital();
+ m_orbital_radius -= y_offset * m_zoom_speed;
+ m_orbital_radius = glm::clamp(m_orbital_radius, m_orbital_min_radius, m_orbital_max_radius);
+ update_orbital();
}
}