From 60842708b31394a5145127f2a7cc0eec1656ae9b Mon Sep 17 00:00:00 2001 From: Jibb Smart Date: Thu, 9 Mar 2023 21:32:34 +0800 Subject: [PATCH] One more little fix with an updated GamepadMotionHelpers for more responsive tiny adjustments on quaternions. --- JoyShockLibrary/GamepadMotion.hpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/JoyShockLibrary/GamepadMotion.hpp b/JoyShockLibrary/GamepadMotion.hpp index ff18662..2c1de6b 100644 --- a/JoyShockLibrary/GamepadMotion.hpp +++ b/JoyShockLibrary/GamepadMotion.hpp @@ -318,22 +318,14 @@ namespace GamepadMotionHelpers inline void Quat::Normalize() { - //printf("Normalizing: %.4f, %.4f, %.4f, %.4f\n", w, x, y, z); - const float length = sqrtf(x * x + y * y + z * z); - float targetLength = 1.0f - w * w; - if (targetLength <= 0.0f || length <= 0.0f) - { - Set(1.0f, 0.0f, 0.0f, 0.0f); - return; - } - targetLength = sqrtf(targetLength); - const float fixFactor = targetLength / length; + const float length = sqrtf(w * w + x * x + y * y + z * z); + const float fixFactor = 1.0f / length; + w *= fixFactor; x *= fixFactor; y *= fixFactor; z *= fixFactor; - //printf("Normalized: %.4f, %.4f, %.4f, %.4f\n", w, x, y, z); return; }