summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-11-03 11:11:46 +0100
committerStanislaw Halik <sthalik@misaki.pl>2016-11-03 11:12:03 +0100
commite26830bf71ca5968fc9d9d473966ea4b75120b56 (patch)
tree27ade992facd45b2746b167dc031adfd96537035
parent2dc57da89cdc56a61ec8da1c7fa7770448f3d3f6 (diff)
logic/tracker, dinput, tracker/joystick: fix rounding errors
Issue: #487 Reported-by: @H-Bear-22 Closes #487 Also use a power of two for joy_axis_size. Floats are base 2. axis_max in tracker/joystick had a fencepost error.
-rw-r--r--dinput/win32-joystick.hpp2
-rw-r--r--logic/tracker.cpp6
-rw-r--r--tracker-joystick/ftnoir_tracker_joystick.cpp8
-rw-r--r--tracker-joystick/ftnoir_tracker_joystick.h2
4 files changed, 12 insertions, 6 deletions
diff --git a/dinput/win32-joystick.hpp b/dinput/win32-joystick.hpp
index 4b48d4a1..6454c51c 100644
--- a/dinput/win32-joystick.hpp
+++ b/dinput/win32-joystick.hpp
@@ -55,7 +55,7 @@ struct OPENTRACK_DINPUT_EXPORT win32_joy_ctx
using joys_t = std::unordered_map<QString, std::shared_ptr<joy>>;
- static constexpr int joy_axis_size = 65535;
+ static constexpr int joy_axis_size = 65536;
struct joy_info
{
diff --git a/logic/tracker.cpp b/logic/tracker.cpp
index dc148eba..fd6ecfe7 100644
--- a/logic/tracker.cpp
+++ b/logic/tracker.cpp
@@ -141,9 +141,13 @@ void Tracker::logic()
{
using std::fmod;
using std::copysign;
+ using std::fabs;
const double x = value(i);
- value(i) = fmod(x + copysign(180, x), 360) - copysign(180, x);
+ if (fabs(x) - 1e-2 > 180)
+ value(i) = fmod(x - copysign(180, -x), 360) + copysign(180, x);
+ else
+ value(i) = clamp(x, -180, 180);
}
logger.write_pose(raw); // raw
diff --git a/tracker-joystick/ftnoir_tracker_joystick.cpp b/tracker-joystick/ftnoir_tracker_joystick.cpp
index 263a5cb0..fff060d6 100644
--- a/tracker-joystick/ftnoir_tracker_joystick.cpp
+++ b/tracker-joystick/ftnoir_tracker_joystick.cpp
@@ -5,6 +5,7 @@
* copyright notice and this permission notice appear in all copies.
*/
#include "ftnoir_tracker_joystick.h"
+#include "compat/util.hpp"
#include "api/plugin-api.hpp"
#include <QMutexLocker>
@@ -48,11 +49,11 @@ void FTNoIR_Tracker::data(double *data)
180,
180
};
-
+
const QString guid = s.guid;
int axes[8];
const bool ret = joy_ctx.poll_axis(guid, axes);
-
+
if (ret)
{
for (int i = 0; i < 6; i++)
@@ -61,7 +62,8 @@ void FTNoIR_Tracker::data(double *data)
if (k < 0 || k >= 8)
data[i] = 0;
else
- data[i] = axes[k] * limits[i] / AXIS_MAX;
+ data[i] = clamp(axes[k] * limits[i] / AXIS_MAX,
+ -limits[i], limits[i]);
}
}
}
diff --git a/tracker-joystick/ftnoir_tracker_joystick.h b/tracker-joystick/ftnoir_tracker_joystick.h
index 0af1444e..a7e8fddd 100644
--- a/tracker-joystick/ftnoir_tracker_joystick.h
+++ b/tracker-joystick/ftnoir_tracker_joystick.h
@@ -45,7 +45,7 @@ public:
void data(double *data);
settings s;
QString guid;
- static constexpr int AXIS_MAX = win32_joy_ctx::joy_axis_size - 1;
+ static constexpr int AXIS_MAX = win32_joy_ctx::joy_axis_size;
win32_joy_ctx joy_ctx;
};