2017-02-09 03:15:43 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Tilt.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "Common/Common.h"
|
2019-10-06 14:44:46 +00:00
|
|
|
#include "Common/MathUtil.h"
|
2018-12-30 15:10:32 +00:00
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Input.h"
|
2017-02-26 20:00:24 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
2019-01-29 20:39:14 +00:00
|
|
|
Tilt::Tilt(const std::string& name_) : ReshapableInput(name_, name_, GroupType::Tilt)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2019-10-27 16:04:08 +00:00
|
|
|
AddInput(Translate, _trans("Forward"));
|
|
|
|
AddInput(Translate, _trans("Backward"));
|
|
|
|
AddInput(Translate, _trans("Left"));
|
|
|
|
AddInput(Translate, _trans("Right"));
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2019-10-27 16:04:08 +00:00
|
|
|
AddInput(Translate, _trans("Modifier"));
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
AddSetting(&m_max_angle_setting,
|
|
|
|
{_trans("Angle"),
|
|
|
|
// i18n: The symbol/abbreviation for degrees (unit of angular measure).
|
|
|
|
_trans("°"),
|
2019-10-28 10:16:55 +00:00
|
|
|
// i18n: Refers to tilting an emulated Wii Remote.
|
2019-03-27 00:31:03 +00:00
|
|
|
_trans("Maximum tilt angle.")},
|
2019-10-06 14:46:51 +00:00
|
|
|
85, 0, 180);
|
2019-10-06 14:44:46 +00:00
|
|
|
|
|
|
|
AddSetting(&m_max_rotational_velocity,
|
|
|
|
{_trans("Velocity"),
|
|
|
|
// i18n: The symbol/abbreviation for hertz (cycles per second).
|
|
|
|
_trans("Hz"),
|
2019-10-28 10:16:55 +00:00
|
|
|
// i18n: Refers to tilting an emulated Wii Remote.
|
|
|
|
_trans("Peak angular velocity (measured in turns per second).")},
|
2019-10-06 14:44:46 +00:00
|
|
|
7, 1, 50);
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 20:47:55 +00:00
|
|
|
Tilt::ReshapeData Tilt::GetReshapableState(bool adjusted) const
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2020-02-09 02:36:26 +00:00
|
|
|
const ControlState y = controls[0]->GetState() - controls[1]->GetState();
|
|
|
|
const ControlState x = controls[3]->GetState() - controls[2]->GetState();
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2018-12-29 22:06:03 +00:00
|
|
|
// Return raw values. (used in UI)
|
|
|
|
if (!adjusted)
|
|
|
|
return {x, y};
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2022-01-04 20:09:50 +00:00
|
|
|
return Reshape(x, y, GetModifierInput()->GetState());
|
2018-12-29 22:06:03 +00:00
|
|
|
}
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2021-05-04 20:47:55 +00:00
|
|
|
Tilt::StateData Tilt::GetState() const
|
2018-12-30 15:10:32 +00:00
|
|
|
{
|
|
|
|
return GetReshapableState(true);
|
|
|
|
}
|
|
|
|
|
2018-12-29 22:06:03 +00:00
|
|
|
ControlState Tilt::GetGateRadiusAtAngle(double ang) const
|
|
|
|
{
|
2019-03-27 00:31:03 +00:00
|
|
|
const ControlState max_tilt_angle = m_max_angle_setting.GetValue() / 180;
|
2018-12-29 22:06:03 +00:00
|
|
|
return SquareStickGate(max_tilt_angle).GetRadiusAtAngle(ang);
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
2018-12-29 22:06:03 +00:00
|
|
|
|
2019-02-05 00:50:07 +00:00
|
|
|
ControlState Tilt::GetDefaultInputRadiusAtAngle(double ang) const
|
|
|
|
{
|
|
|
|
return SquareStickGate(1.0).GetRadiusAtAngle(ang);
|
|
|
|
}
|
|
|
|
|
2019-10-06 14:44:46 +00:00
|
|
|
ControlState Tilt::GetMaxRotationalVelocity() const
|
|
|
|
{
|
|
|
|
return m_max_rotational_velocity.GetValue() * MathUtil::TAU;
|
|
|
|
}
|
|
|
|
|
2022-01-04 20:09:50 +00:00
|
|
|
Control* Tilt::GetModifierInput() const
|
|
|
|
{
|
|
|
|
return controls[4].get();
|
|
|
|
}
|
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
} // namespace ControllerEmu
|