diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-12-10 16:50:12 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-12-16 14:25:56 +0000 |
commit | 6b32b710bcdfe73b01050f15b5d565fa5fc56ad7 (patch) | |
tree | 5cea804b3a60a129d484fc691df14887ca16c377 /src/input | |
parent | edb8095b8c9a9d86f6b6abccf5d4d821470a5154 (diff) |
Smoothly transition from deadzone by adjusting gradient of response
Change-Id: Ibb76111afb7d7ae6fb14aadf2e7225895e45152e
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/backend/qabstractphysicaldevicebackendnode.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/input/backend/qabstractphysicaldevicebackendnode.cpp b/src/input/backend/qabstractphysicaldevicebackendnode.cpp index 336ab0186..92eaffd41 100644 --- a/src/input/backend/qabstractphysicaldevicebackendnode.cpp +++ b/src/input/backend/qabstractphysicaldevicebackendnode.cpp @@ -63,6 +63,11 @@ QVector<int> variantListToVector(const QVariantList &list) return v; } +Q_DECL_CONSTEXPR int signum(float v) +{ + return (v > 0.0f) - (v < 0.0f); +} + } namespace Qt3DInput { @@ -229,9 +234,27 @@ float QAbstractPhysicalDeviceBackendNode::processedAxisValue(int axisIdentifier) } // Deadzone handling - if (!qFuzzyIsNull(axisSetting->deadZone())) { - if (std::abs(val) <= axisSetting->deadZone()) + const float d = axisSetting->deadZone(); + if (!qFuzzyIsNull(d)) { + if (std::abs(val) <= d) { val = 0.0f; + } else { + // Calculate value that goes from 0 to 1 linearly from the boundary of + // the dead zone up to 1. That is we with a dead zone value of d, we do not + // want a step change from 0 to d when the axis leaves the deadzone. Instead + // we want to increase the gradient of the line so that it goes from 0 to 1 + // over the range d to 1. So instead of having y = x, the equation of the + // line becomes + // + // y = x / (1-d) - d / (1-d) = (x - d) / (1 - d) + // + // for positive values, and + // + // y = x / (1-d) + d / (1-d) = (x + d) / (1 - d) + // + // for negative values. + val = (val - signum(val) * d) / (1.0f - d); + } } return val; |