2017-02-09 03:15:43 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#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
|
|
|
{
|
2018-04-10 15:22:30 +00:00
|
|
|
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("Left")));
|
|
|
|
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Right")));
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2018-04-10 15:22:30 +00:00
|
|
|
controls.emplace_back(std::make_unique<Input>(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
|
|
|
}
|
|
|
|
|
2018-12-30 16:52:45 +00:00
|
|
|
Tilt::ReshapeData Tilt::GetReshapableState(bool adjusted)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2018-12-30 15:10:32 +00:00
|
|
|
const ControlState y = controls[0]->control_ref->State() - controls[1]->control_ref->State();
|
|
|
|
const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
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
|
|
|
|
2018-12-29 22:06:03 +00:00
|
|
|
const ControlState modifier = controls[4]->control_ref->State();
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2019-01-29 20:39:14 +00:00
|
|
|
return Reshape(x, y, modifier);
|
2018-12-29 22:06:03 +00:00
|
|
|
}
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2018-12-30 15:10:32 +00:00
|
|
|
Tilt::StateData Tilt::GetState()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
} // namespace ControllerEmu
|