From a4fdad5f6941b02aa93cc0b754b0074872b805d8 Mon Sep 17 00:00:00 2001 From: VDm Date: Mon, 23 Jun 2025 21:15:55 +0400 Subject: [PATCH] feat(math): add CMath::normalize --- tempest/math/CMath.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tempest/math/CMath.hpp b/tempest/math/CMath.hpp index 10ac6dd..fc236ea 100644 --- a/tempest/math/CMath.hpp +++ b/tempest/math/CMath.hpp @@ -61,6 +61,23 @@ class CMath { STORM_ASSERT(x >= 0.0f); return ::sqrt(x); } + + static void normalize(float& x, float& y) { + float m = x * x + y * y; + STORM_ASSERT(m >= 0.0f); + m = 1.0f / CMath::sqrt(m); + x *= m; + y *= m; + } + + static void normalize(float& x, float& y, float& z) { + float m = x * x + y * y + z * z; + STORM_ASSERT(m >= 0.0f); + m = 1.0f / CMath::sqrt(m); + x *= m; + y *= m; + z *= m; + } }; #endif