aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Nichols <andy.nichols@theqtcompany.com>2015-11-03 00:38:22 +0100
committerAndy Nichols <andy.nichols@theqtcompany.com>2015-11-05 09:11:03 +0000
commit1f608eb05791b762edebbb6df8a091c4c1cfb30c (patch)
treeaf2f06579681da1789e6fdd3388264e0821d86fd
parent591e1229eccddaef43b8b2d67b9cd48077317a9b (diff)
Fix normalize function to correctly trigger axis
The trigger button API's expect normalized values from 0.0 to 1.0. With previous code the normalized value would be from -1.0 to 1.0 even if the min value reported by the device was 0. So now we handle this correctly by having a range of 2 when an axis reports a negative min value, and 1 when it is >= 0. Change-Id: I626045728138e44aa4170d1d3eef589be1d3ba1b Reviewed-by: BogDan Vatra <bogdan@kdab.com>
-rw-r--r--src/gamepad/qgamepadbackend_p.h9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/gamepad/qgamepadbackend_p.h b/src/gamepad/qgamepadbackend_p.h
index e170511..4103481 100644
--- a/src/gamepad/qgamepadbackend_p.h
+++ b/src/gamepad/qgamepadbackend_p.h
@@ -58,10 +58,13 @@ public:
virtual double normalized(T value) const
{
- if (minValue >= 0)
- return 2.0 * double(value - double(maxValue - minValue) / 2.0) / double(maxValue - minValue);
- else
+ if (gamepadAxis == QGamepadManager::AxisInvalid && minValue >= 0) {
+ //case 0.0 - 1.0
+ return double(value - minValue) / double(maxValue - minValue);
+ } else {
+ //case -1.0 - 1.0
return 2.0 * double(value - minValue) / double(maxValue - minValue) - 1.0;
+ }
}
T minValue;
T maxValue;