Merge pull request #4010 from leoetlino/relative-input

Add relative input for the Wiimote IR
This commit is contained in:
shuffle2
2016-10-03 03:26:04 -07:00
committed by GitHub
4 changed files with 122 additions and 19 deletions

View File

@ -295,10 +295,13 @@ ControllerEmu::Cursor::Cursor(const std::string& _name)
controls.emplace_back(std::make_unique<Input>("Forward"));
controls.emplace_back(std::make_unique<Input>("Backward"));
controls.emplace_back(std::make_unique<Input>(_trans("Hide")));
controls.emplace_back(std::make_unique<Input>("Recenter"));
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)

View File

@ -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,43 @@ 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);
// recenter
if (controls[7]->control_ref->State() > 0.5)
{
m_x = 0.0;
m_y = 0.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