WiimoteEmu/DolphinQt: Rename "IR" to "Point" and eliminate redundant Forward/Backward mappings.

This commit is contained in:
Jordan Woyak 2019-04-20 12:53:13 -05:00
parent 5ca9933307
commit 374585f128
12 changed files with 47 additions and 94 deletions

View File

@ -204,7 +204,6 @@ void EmulateCursor(MotionState* state, ControllerEmu::Cursor* ir_group, float ti
// Nintendo recommends a distance of 1-3 meters. // Nintendo recommends a distance of 1-3 meters.
constexpr float NEUTRAL_DISTANCE = 2.f; constexpr float NEUTRAL_DISTANCE = 2.f;
constexpr float MOVE_DISTANCE = 1.f;
// When the sensor bar position is on bottom, apply the "offset" setting negatively. // When the sensor bar position is on bottom, apply the "offset" setting negatively.
// This is kinda odd but it does seem to maintain consistent cursor behavior. // This is kinda odd but it does seem to maintain consistent cursor behavior.
@ -215,26 +214,22 @@ void EmulateCursor(MotionState* state, ControllerEmu::Cursor* ir_group, float ti
const float yaw_scale = ir_group->GetTotalYaw() / 2; const float yaw_scale = ir_group->GetTotalYaw() / 2;
const float pitch_scale = ir_group->GetTotalPitch() / 2; const float pitch_scale = ir_group->GetTotalPitch() / 2;
// TODO: Move state out of ControllerEmu::Cursor // Just jump to the target position.
// TODO: Use ApproachPositionWithJerk state->position = {0, NEUTRAL_DISTANCE, -height};
// TODO: Move forward/backward after rotation. state->velocity = {};
const auto new_position = state->acceleration = {};
Common::Vec3(0, NEUTRAL_DISTANCE - MOVE_DISTANCE * float(cursor.z), -height);
const auto target_angle = Common::Vec3(pitch_scale * -cursor.y, 0, yaw_scale * -cursor.x); const auto target_angle = Common::Vec3(pitch_scale * -cursor.y, 0, yaw_scale * -cursor.x);
// If cursor was hidden, jump to the target position/angle immediately. // If cursor was hidden, jump to the target angle immediately.
if (state->position.y < 0) if (state->position.y < 0)
{ {
state->position = new_position;
state->angle = target_angle; state->angle = target_angle;
state->angular_velocity = {};
return; return;
} }
state->acceleration = new_position - state->position;
state->position = new_position;
// Higher values will be more responsive but increase rate of M+ "desync". // Higher values will be more responsive but increase rate of M+ "desync".
// I'd rather not expose this value in the UI if not needed. // I'd rather not expose this value in the UI if not needed.
// At this value, sync is very good and responsiveness still appears instant. // At this value, sync is very good and responsiveness still appears instant.

View File

@ -138,7 +138,7 @@ void Wiimote::Reset()
Wiimote::Wiimote(const unsigned int index) : m_index(index) Wiimote::Wiimote(const unsigned int index) : m_index(index)
{ {
// buttons // Buttons
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
for (const char* named_button : named_buttons) for (const char* named_button : named_buttons)
{ {
@ -147,20 +147,14 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
new ControllerEmu::Input(ControllerEmu::DoNotTranslate, named_button, ui_name)); new ControllerEmu::Input(ControllerEmu::DoNotTranslate, named_button, ui_name));
} }
// ir // Pointing (IR)
// i18n: IR stands for infrared and refers to the pointer functionality of Wii Remotes // i18n: "Point" refers to the action of pointing a Wii Remote.
groups.emplace_back(m_ir = new ControllerEmu::Cursor(_trans("IR"))); groups.emplace_back(m_ir = new ControllerEmu::Cursor("IR", _trans("Point")));
// swing
groups.emplace_back(m_swing = new ControllerEmu::Force(_trans("Swing"))); groups.emplace_back(m_swing = new ControllerEmu::Force(_trans("Swing")));
// tilt
groups.emplace_back(m_tilt = new ControllerEmu::Tilt(_trans("Tilt"))); groups.emplace_back(m_tilt = new ControllerEmu::Tilt(_trans("Tilt")));
// shake
groups.emplace_back(m_shake = new ControllerEmu::Shake(_trans("Shake"))); groups.emplace_back(m_shake = new ControllerEmu::Shake(_trans("Shake")));
// extension // Extension
groups.emplace_back(m_attachments = new ControllerEmu::Attachments(_trans("Extension"))); groups.emplace_back(m_attachments = new ControllerEmu::Attachments(_trans("Extension")));
m_attachments->AddAttachment(std::make_unique<WiimoteEmu::None>()); m_attachments->AddAttachment(std::make_unique<WiimoteEmu::None>());
m_attachments->AddAttachment(std::make_unique<WiimoteEmu::Nunchuk>()); m_attachments->AddAttachment(std::make_unique<WiimoteEmu::Nunchuk>());
@ -174,12 +168,12 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
m_attachments->AddSetting(&m_motion_plus_setting, {_trans("Attach MotionPlus")}, true); m_attachments->AddSetting(&m_motion_plus_setting, {_trans("Attach MotionPlus")}, true);
// rumble // Rumble
groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble"))); groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble")));
m_rumble->controls.emplace_back( m_rumble->controls.emplace_back(
m_motor = new ControllerEmu::Output(ControllerEmu::Translate, _trans("Motor"))); m_motor = new ControllerEmu::Output(ControllerEmu::Translate, _trans("Motor")));
// dpad // D-Pad
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad"))); groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
for (const char* named_direction : named_directions) for (const char* named_direction : named_directions)
{ {
@ -187,7 +181,7 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
new ControllerEmu::Input(ControllerEmu::Translate, named_direction)); new ControllerEmu::Input(ControllerEmu::Translate, named_direction));
} }
// options // Options
groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options"))); groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options")));
m_options->AddSetting(&m_speaker_pan_setting, m_options->AddSetting(&m_speaker_pan_setting,
@ -211,7 +205,7 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
{"Sideways Wiimote", nullptr, nullptr, _trans("Sideways Wii Remote")}, {"Sideways Wiimote", nullptr, nullptr, _trans("Sideways Wii Remote")},
false); false);
// hotkeys // Hotkeys
groups.emplace_back(m_hotkeys = new ControllerEmu::ModifySettingsButton(_trans("Hotkeys"))); groups.emplace_back(m_hotkeys = new ControllerEmu::ModifySettingsButton(_trans("Hotkeys")));
// hotkeys to temporarily modify the Wii Remote orientation (sideways, upright) // hotkeys to temporarily modify the Wii Remote orientation (sideways, upright)
// this setting modifier is toggled // this setting modifier is toggled
@ -239,7 +233,7 @@ ControllerEmu::ControlGroup* Wiimote::GetWiimoteGroup(WiimoteGroup group)
return m_dpad; return m_dpad;
case WiimoteGroup::Shake: case WiimoteGroup::Shake:
return m_shake; return m_shake;
case WiimoteGroup::IR: case WiimoteGroup::Point:
return m_ir; return m_ir;
case WiimoteGroup::Tilt: case WiimoteGroup::Tilt:
return m_tilt; return m_tilt;
@ -636,7 +630,7 @@ void Wiimote::LoadDefaults(const ControllerInterface& ciface)
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
m_shake->SetControlExpression(i, "Click 2"); m_shake->SetControlExpression(i, "Click 2");
// IR // Pointing (IR)
m_ir->SetControlExpression(0, "Cursor Y-"); m_ir->SetControlExpression(0, "Cursor Y-");
m_ir->SetControlExpression(1, "Cursor Y+"); m_ir->SetControlExpression(1, "Cursor Y+");
m_ir->SetControlExpression(2, "Cursor X-"); m_ir->SetControlExpression(2, "Cursor X-");
@ -714,8 +708,6 @@ void Wiimote::StepDynamics()
Common::Vec3 Wiimote::GetAcceleration() Common::Vec3 Wiimote::GetAcceleration()
{ {
// TODO: Cursor forward/backward movement should produce acceleration.
Common::Vec3 accel = Common::Vec3 accel =
GetOrientation() * GetOrientation() *
GetTransformation().Transform( GetTransformation().Transform(
@ -750,7 +742,7 @@ Common::Matrix44 Wiimote::GetTransformation() const
// Includes positional and rotational effects of: // Includes positional and rotational effects of:
// Cursor, Swing, Tilt, Shake // Cursor, Swing, Tilt, Shake
// TODO: think about and clean up matrix order, make nunchuk match. // TODO: Think about and clean up matrix order + make nunchuk match.
return Common::Matrix44::Translate(-m_shake_state.position) * return Common::Matrix44::Translate(-m_shake_state.position) *
Common::Matrix44::FromMatrix33(GetRotationalMatrix( Common::Matrix44::FromMatrix33(GetRotationalMatrix(
-m_tilt_state.angle - m_swing_state.angle - m_cursor_state.angle)) * -m_tilt_state.angle - m_swing_state.angle - m_cursor_state.angle)) *

View File

@ -40,7 +40,7 @@ enum class WiimoteGroup
Buttons, Buttons,
DPad, DPad,
Shake, Shake,
IR, Point,
Tilt, Tilt,
Swing, Swing,
Rumble, Rumble,

View File

@ -212,29 +212,6 @@ void MappingIndicator::DrawCursor(ControllerEmu::Cursor& cursor)
return; return;
} }
// Deadzone for Z (forward/backward):
const double deadzone = cursor.GetDeadzonePercentage();
if (deadzone > 0.0)
{
p.setPen(GetDeadZonePen());
p.setBrush(GetDeadZoneBrush());
p.drawRect(QRectF(-scale, -deadzone * scale, scale * 2, deadzone * scale * 2));
}
// Raw Z:
p.setPen(Qt::NoPen);
p.setBrush(GetRawInputColor());
p.drawRect(
QRectF(-scale, raw_coord.z * scale - INPUT_DOT_RADIUS / 2, scale * 2, INPUT_DOT_RADIUS));
// Adjusted Z (if not hidden):
if (adj_coord.IsVisible())
{
p.setBrush(GetAdjustedInputColor());
p.drawRect(
QRectF(-scale, adj_coord.z * scale - INPUT_DOT_RADIUS / 2, scale * 2, INPUT_DOT_RADIUS));
}
// TV screen or whatever you want to call this: // TV screen or whatever you want to call this:
constexpr double TV_SCALE = 0.75; constexpr double TV_SCALE = 0.75;

View File

@ -51,6 +51,11 @@ int MappingWidget::GetPort() const
return m_parent->GetPort(); return m_parent->GetPort();
} }
QGroupBox* MappingWidget::CreateGroupBox(ControllerEmu::ControlGroup* group)
{
return CreateGroupBox(tr(group->ui_name.c_str()), group);
}
QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::ControlGroup* group) QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::ControlGroup* group)
{ {
QGroupBox* group_box = new QGroupBox(name); QGroupBox* group_box = new QGroupBox(name);

View File

@ -55,6 +55,8 @@ signals:
protected: protected:
int GetPort() const; int GetPort() const;
QGroupBox* CreateGroupBox(ControllerEmu::ControlGroup* group);
QGroupBox* CreateGroupBox(const QString& name, ControllerEmu::ControlGroup* group); QGroupBox* CreateGroupBox(const QString& name, ControllerEmu::ControlGroup* group);
private: private:

View File

@ -348,8 +348,7 @@ void MappingWindow::SetMappingType(MappingWindow::Type type)
widget = new WiimoteEmuGeneral(this, extension); widget = new WiimoteEmuGeneral(this, extension);
setWindowTitle(tr("Wii Remote %1").arg(GetPort() + 1)); setWindowTitle(tr("Wii Remote %1").arg(GetPort() + 1));
AddWidget(tr("General and Options"), widget); AddWidget(tr("General and Options"), widget);
// i18n: IR stands for infrared and refers to the pointer functionality of Wii Remotes AddWidget(tr("Motion Controls"), new WiimoteEmuMotionControl(this));
AddWidget(tr("Motion Controls and IR"), new WiimoteEmuMotionControl(this));
AddWidget(tr("Extension"), extension); AddWidget(tr("Extension"), extension);
break; break;
} }

View File

@ -23,14 +23,14 @@ void WiimoteEmuMotionControl::CreateMainLayout()
{ {
m_main_layout = new QHBoxLayout(); m_main_layout = new QHBoxLayout();
m_main_layout->addWidget(CreateGroupBox(
tr("Shake"), Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Shake)));
m_main_layout->addWidget( m_main_layout->addWidget(
CreateGroupBox(tr("IR"), Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::IR))); CreateGroupBox(Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Shake)));
m_main_layout->addWidget(CreateGroupBox( m_main_layout->addWidget(
tr("Tilt"), Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Tilt))); CreateGroupBox(Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Point)));
m_main_layout->addWidget(CreateGroupBox( m_main_layout->addWidget(
tr("Swing"), Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Swing))); CreateGroupBox(Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Tilt)));
m_main_layout->addWidget(
CreateGroupBox(Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Swing)));
setLayout(m_main_layout); setLayout(m_main_layout);
} }

View File

@ -15,14 +15,13 @@
namespace ControllerEmu namespace ControllerEmu
{ {
ControlGroup::ControlGroup(const std::string& name_, const GroupType type_) ControlGroup::ControlGroup(std::string name_, const GroupType type_)
: name(name_), ui_name(name_), type(type_) : name(name_), ui_name(std::move(name_)), type(type_)
{ {
} }
ControlGroup::ControlGroup(const std::string& name_, const std::string& ui_name_, ControlGroup::ControlGroup(std::string name_, std::string ui_name_, const GroupType type_)
const GroupType type_) : name(std::move(name_)), ui_name(std::move(ui_name_)), type(type_)
: name(name_), ui_name(ui_name_), type(type_)
{ {
} }

View File

@ -44,9 +44,8 @@ enum class GroupType
class ControlGroup class ControlGroup
{ {
public: public:
explicit ControlGroup(const std::string& name, GroupType type = GroupType::Other); explicit ControlGroup(std::string name, GroupType type = GroupType::Other);
ControlGroup(const std::string& name, const std::string& ui_name, ControlGroup(std::string name, std::string ui_name, GroupType type = GroupType::Other);
GroupType type = GroupType::Other);
virtual ~ControlGroup(); virtual ~ControlGroup();
virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "", virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "",

View File

@ -21,14 +21,13 @@
namespace ControllerEmu namespace ControllerEmu
{ {
Cursor::Cursor(const std::string& name_) Cursor::Cursor(std::string name, std::string ui_name)
: ReshapableInput(name_, name_, GroupType::Cursor), m_last_update(Clock::now()) : ReshapableInput(std::move(name), std::move(ui_name), GroupType::Cursor),
m_last_update(Clock::now())
{ {
for (auto& named_direction : named_directions) for (auto& named_direction : named_directions)
controls.emplace_back(std::make_unique<Input>(Translate, named_direction)); controls.emplace_back(std::make_unique<Input>(Translate, named_direction));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Forward")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Backward")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Hide"))); controls.emplace_back(std::make_unique<Input>(Translate, _trans("Hide")));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Recenter"))); controls.emplace_back(std::make_unique<Input>(Translate, _trans("Recenter")));
@ -83,13 +82,11 @@ ControlState Cursor::GetGateRadiusAtAngle(double ang) const
Cursor::StateData Cursor::GetState(const bool adjusted) Cursor::StateData Cursor::GetState(const bool adjusted)
{ {
ControlState z = controls[4]->control_ref->State() - controls[5]->control_ref->State();
if (!adjusted) if (!adjusted)
{ {
const auto raw_input = GetReshapableState(false); const auto raw_input = GetReshapableState(false);
return {raw_input.x, raw_input.y, z}; return {raw_input.x, raw_input.y};
} }
const auto input = GetReshapableState(true); const auto input = GetReshapableState(true);
@ -102,20 +99,12 @@ Cursor::StateData Cursor::GetState(const bool adjusted)
m_last_update = now; m_last_update = now;
const double max_step = STEP_PER_SEC / 1000.0 * ms_since_update; const double max_step = STEP_PER_SEC / 1000.0 * ms_since_update;
const double max_z_step = STEP_Z_PER_SEC / 1000.0 * ms_since_update;
// Apply deadzone to z:
z = ApplyDeadzone(z, GetDeadzonePercentage());
// Smooth out z movement:
// FYI: Not using relative input for Z.
m_state.z += std::clamp(z - m_state.z, -max_z_step, max_z_step);
// Relative input: // Relative input:
if (m_relative_setting.GetValue()) if (m_relative_setting.GetValue())
{ {
// Recenter: // Recenter:
if (controls[7]->control_ref->State() > BUTTON_THRESHOLD) if (controls[5]->control_ref->State() > BUTTON_THRESHOLD)
{ {
m_state.x = 0.0; m_state.x = 0.0;
m_state.y = 0.0; m_state.y = 0.0;
@ -152,7 +141,7 @@ Cursor::StateData Cursor::GetState(const bool adjusted)
m_prev_result = result; m_prev_result = result;
// If auto-hide time is up or hide button is held: // If auto-hide time is up or hide button is held:
if (!m_auto_hide_timer || controls[6]->control_ref->State() > BUTTON_THRESHOLD) if (!m_auto_hide_timer || controls[4]->control_ref->State() > BUTTON_THRESHOLD)
{ {
result.x = std::numeric_limits<ControlState>::quiet_NaN(); result.x = std::numeric_limits<ControlState>::quiet_NaN();
result.y = 0; result.y = 0;

View File

@ -19,12 +19,11 @@ public:
{ {
ControlState x{}; ControlState x{};
ControlState y{}; ControlState y{};
ControlState z{};
bool IsVisible() const; bool IsVisible() const;
}; };
explicit Cursor(const std::string& name); Cursor(std::string name, std::string ui_name);
ReshapeData GetReshapableState(bool adjusted) final override; ReshapeData GetReshapableState(bool adjusted) final override;
ControlState GetGateRadiusAtAngle(double ang) const override; ControlState GetGateRadiusAtAngle(double ang) const override;
@ -45,9 +44,6 @@ private:
// to something that makes sense with the default range. // to something that makes sense with the default range.
static constexpr double STEP_PER_SEC = 0.01 * 200; static constexpr double STEP_PER_SEC = 0.01 * 200;
// Smooth out forward/backward movements:
static constexpr double STEP_Z_PER_SEC = 0.05 * 200;
static constexpr int AUTO_HIDE_MS = 2500; static constexpr int AUTO_HIDE_MS = 2500;
static constexpr double AUTO_HIDE_DEADZONE = 0.001; static constexpr double AUTO_HIDE_DEADZONE = 0.001;