From 8794e8979cc926433753fdb47c5a87d13572cab8 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 8 Dec 2024 18:39:08 +0100 Subject: [PATCH] Add NormalizeAngleRad --- openVulkanoCpp/Math/Math.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/openVulkanoCpp/Math/Math.hpp b/openVulkanoCpp/Math/Math.hpp index cfd8cc7..4205600 100644 --- a/openVulkanoCpp/Math/Math.hpp +++ b/openVulkanoCpp/Math/Math.hpp @@ -36,6 +36,22 @@ namespace OpenVulkano::Math { return val * val; } + + // Ensures that a given angle is between 0 and 2 pi + template>> + constexpr T NormalizeAngleRad(T angle) + { + constexpr T PIX2 = 2 * std::numbers::pi; + while (angle < 0) + { + angle += PIX2; + } + while (angle >= PIX2) + { + angle -= PIX2; + } + return angle; + } } template using Matrix2_SIMD = glm::tmat2x2;