Skip to content

Commit

Permalink
One more little fix with an updated GamepadMotionHelpers for more res…
Browse files Browse the repository at this point in the history
…ponsive tiny adjustments on quaternions.
  • Loading branch information
JibbSmart committed Mar 9, 2023
1 parent b8ed74c commit 6084270
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions JoyShockLibrary/GamepadMotion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 6084270

Please sign in to comment.