Skip to content

Commit

Permalink
Updated GamepadMotion.hpp to fix a precision issue with very, very sm…
Browse files Browse the repository at this point in the history
…all changes to the quaternion. Since this significantly impacts the utility of the quaternion in MOTION_STATE, this gets its very own bug fix release
  • Loading branch information
JibbSmart committed Mar 9, 2023
1 parent 53c40fe commit b8ed74c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions JoyShockLibrary/GamepadMotion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,11 @@ namespace GamepadMotionHelpers

inline static Quat AngleAxis(float inAngle, float inX, float inY, float inZ)
{
Quat result = Quat(cosf(inAngle * 0.5f), inX, inY, inZ);
result.Normalize();
const float sinHalfAngle = sinf(inAngle * 0.5f);
Vec inAxis = Vec(inX, inY, inZ);
inAxis.Normalize();
inAxis *= sinHalfAngle;
Quat result = Quat(cosf(inAngle * 0.5f), inAxis.x, inAxis.y, inAxis.z);
return result;
}

Expand Down Expand Up @@ -571,7 +574,7 @@ namespace GamepadMotionHelpers
Quat rotation = AngleAxis(angle, axis.x, axis.y, axis.z);
Quaternion *= rotation; // do it this way because it's a local rotation, not global

//printf("Quat: %.4f %.4f %.4f %.4f _",
//printf("Quat: %.4f %.4f %.4f %.4f\n",
// Quaternion.w, Quaternion.x, Quaternion.y, Quaternion.z);
float accelMagnitude = accel.Length();
if (accelMagnitude > 0.0f)
Expand Down

0 comments on commit b8ed74c

Please sign in to comment.