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