This commit is contained in:
2026-03-21 23:10:48 +01:00
parent 8cbb794dba
commit 3153735d0c
18 changed files with 249 additions and 195 deletions
+2 -22
View File
@@ -10,15 +10,13 @@
Camera::Camera(const glm::vec3& position, const glm::vec3& up)
: m_position{position}, m_up{up} {
// Initialize yaw to -90 degrees so the camera faces -Z by default
m_yaw = -glm::half_pi<float>();
m_pitch = 0.0f;
}
void Camera::Update(float deltaTime) {
auto& input = InputManager::GetInstance();
const auto& input = InputManager::GetInstance();
// --- tuning ---
float moveSpeed = m_movementSpeed;
if (input.IsKeyDown(SDL_SCANCODE_LSHIFT) || input.IsKeyDown(SDL_SCANCODE_RSHIFT)) {
moveSpeed *= 2.0f;
@@ -29,10 +27,7 @@ void Camera::Update(float deltaTime) {
moveSpeed *= 3.0f;
}
// =========================
// Look Input (Keyboard & Controller)
// =========================
const float keyLookSpeed = glm::radians(120.0f);
constexpr float keyLookSpeed = glm::radians(120.0f);
if (input.IsKeyDown(SDL_SCANCODE_UP)) m_pitch += keyLookSpeed * deltaTime;
if (input.IsKeyDown(SDL_SCANCODE_DOWN)) m_pitch -= keyLookSpeed * deltaTime;
if (input.IsKeyDown(SDL_SCANCODE_LEFT)) m_yaw -= keyLookSpeed * deltaTime;
@@ -46,13 +41,8 @@ void Camera::Update(float deltaTime) {
m_pitch -= ry * padLookSpeed * deltaTime; // Inverted to match stick convention
}
// Clamp pitch to prevent flipping over the top
m_pitch = glm::clamp(m_pitch, -glm::half_pi<float>() + 0.01f, glm::half_pi<float>() - 0.01f);
// =========================
// Update Basis Vectors
// =========================
// Standard Spherical to Cartesian coordinates (Y-Up, Right-Handed)
glm::vec3 front;
front.x = cos(m_yaw) * cos(m_pitch);
front.y = sin(m_pitch);
@@ -62,9 +52,6 @@ void Camera::Update(float deltaTime) {
m_right = glm::normalize(glm::cross(m_forward, glm::vec3(0, 1, 0))); // World Up
m_up = glm::normalize(glm::cross(m_right, m_forward));
// =========================
// Movement Input
// =========================
glm::vec3 move(0.0f);
if (input.IsKeyDown(SDL_SCANCODE_W)) move += m_forward;
if (input.IsKeyDown(SDL_SCANCODE_S)) move -= m_forward;
@@ -105,18 +92,11 @@ void Camera::CalculateViewMatrix() {
}
void Camera::CalculateProjectionMatrix() {
// RH_ZO: Right-Handed, Zero-to-One depth (Vulkan/D3D standard)
m_projectionMatrix = glm::perspectiveRH_ZO(glm::radians(fovAngle), m_aspectRatio, m_zNear, m_zFar);
// CRITICAL VULKAN FIX: Flip Y-axis
// This keeps the world upright and fixes winding order issues
m_projectionMatrix[1][1] *= -1;
}
// ---------------------------------------------------------
// Helpers to keep orientation consistent
// ---------------------------------------------------------
void Camera::SetRotation(float yawRadians, float pitchRadians) {
m_yaw = yawRadians;
m_pitch = glm::clamp(pitchRadians, -glm::half_pi<float>() + 0.001f, glm::half_pi<float>() - 0.001f);