From 989ee470df117ace4eedcabaac8c4e317cd7a165 Mon Sep 17 00:00:00 2001 From: Emmanuel AYME Date: Sun, 22 Feb 2026 11:22:48 +0100 Subject: [PATCH] Add Horizontal to vertical FOV convert and vice versa --- libs/Maths/Maths.cpp | 10 +++++++++- libs/Maths/Maths.hpp | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libs/Maths/Maths.cpp b/libs/Maths/Maths.cpp index 84870a4..cacf6a1 100644 --- a/libs/Maths/Maths.cpp +++ b/libs/Maths/Maths.cpp @@ -7,11 +7,19 @@ #include "Maths.hpp" #include +float Maths::FOVHToV(float fovH, float aspect) { + return 2.0f * std::atan(std::tan(fovH * 0.5f * (M_PI / 180.0f)) / aspect) * (180.0f / M_PI); +} + +float Maths::FOVVToH(float fovV, float aspect) { + return 2.0f * std::atan(std::tan(fovV * 0.5f * (M_PI / 180.0f)) * aspect) * (180.0f / M_PI); +} + double Maths::DegreesToRadians(double degrees) { return degrees * M_PI / 180.0; } -// Convertit des radians en degrés +// Converts radians in degree double Maths::RadiansToDegrees(double radians) { return radians * 180.0 / M_PI; } diff --git a/libs/Maths/Maths.hpp b/libs/Maths/Maths.hpp index f7d9892..63415e9 100644 --- a/libs/Maths/Maths.hpp +++ b/libs/Maths/Maths.hpp @@ -7,6 +7,10 @@ class Maths public: // Compute new horizontal FOV based on native and target aspect ratio static double CompensateHorizontalFOV(const double baseHorizontalFOVDeg, const double baseAspectRatio, const double targetAspectRatio); + // Compute FOV horizontal to vertical based on aspect ratio + static float FOVHToV(float fovH, float aspect); + // Compute FOV vertical to horizontal based on aspect ratio + static float FOVVToH(float fovV, float aspect); private: static double DegreesToRadians(double degrees);