summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon
diff options
context:
space:
mode:
authorLéo Lam <leo@innovatetechnologi.es>2016-07-09 14:29:41 +0200
committerLéo Lam <leo@innovatetechnologi.es>2016-09-24 15:57:46 +0200
commit5cf07fdfbf07bbf768f3ed02bc29b45713b08106 (patch)
tree8ea007f293e742485712e8fddfe507239cb939e1 /Source/Core/InputCommon
parent58d0e223547dd111d3e8975ad6ff7f1988fbddfe (diff)
Add relative input for the Wiimote IR
This adds an option to enable relative input for the Wiimote IR as described in issue 9014. Enabling it will result in the pointer not going back to the centre and the inputs will control the direction, not the absolute position. Also adds a Dead Zone setting which is really needed when relative input is enabled to prevent the cursor from slowly drifting on most controllers. (Note: the Deadzone setting has no effect when relative input is disabled)
Diffstat (limited to 'Source/Core/InputCommon')
-rw-r--r--Source/Core/InputCommon/ControllerEmu.cpp2
-rw-r--r--Source/Core/InputCommon/ControllerEmu.h29
2 files changed, 29 insertions, 2 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu.cpp b/Source/Core/InputCommon/ControllerEmu.cpp
index 2fd85b3fac..5b0b93f021 100644
--- a/Source/Core/InputCommon/ControllerEmu.cpp
+++ b/Source/Core/InputCommon/ControllerEmu.cpp
@@ -299,6 +299,8 @@ ControllerEmu::Cursor::Cursor(const std::string& _name)
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Center"), 0.5));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Width"), 0.5));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Height"), 0.5));
+ numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 20));
+ boolean_settings.emplace_back(std::make_unique<BooleanSetting>(_trans("Relative Input"), false));
}
void ControllerEmu::LoadDefaults(const ControllerInterface& ciface)
diff --git a/Source/Core/InputCommon/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu.h
index 215b2557b4..d90850b137 100644
--- a/Source/Core/InputCommon/ControllerEmu.h
+++ b/Source/Core/InputCommon/ControllerEmu.h
@@ -12,6 +12,7 @@
#include <vector>
#include "Common/IniFile.h"
+#include "Common/MathUtil.h"
#include "Core/ConfigManager.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/GCPadStatus.h"
@@ -424,12 +425,36 @@ public:
yy += (numeric_settings[0]->GetValue() - 0.5);
}
- *x = xx;
- *y = yy;
+ // relative input
+ if (boolean_settings[0]->GetValue())
+ {
+ const ControlState deadzone = numeric_settings[3]->GetValue();
+ // deadzone to avoid the cursor slowly drifting
+ if (std::abs(xx) > deadzone)
+ m_x = MathUtil::Clamp(m_x + xx * SPEED_MULTIPLIER, -1.0, 1.0);
+ if (std::abs(yy) > deadzone)
+ m_y = MathUtil::Clamp(m_y + yy * SPEED_MULTIPLIER, -1.0, 1.0);
+ }
+ else
+ {
+ m_x = xx;
+ m_y = yy;
+ }
+
+ *x = m_x;
+ *y = m_y;
}
}
ControlState m_z;
+
+ private:
+ // This is used to reduce the cursor speed for relative input
+ // to something that makes sense with the default range.
+ static constexpr double SPEED_MULTIPLIER = 0.04;
+
+ ControlState m_x = 0.0;
+ ControlState m_y = 0.0;
};
class Extension : public ControlGroup