2017-02-08 22:15:43 -05: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"
|
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
|
|
|
{
|
2018-04-10 17:22:30 +02: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-08 22:15:43 -05:00
|
|
|
|
2018-04-10 17:22:30 +02:00
|
|
|
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Modifier")));
|
2017-02-08 22:15:43 -05:00
|
|
|
|
|
|
|
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Angle"), 0.9, 0, 180));
|
|
|
|
}
|
|
|
|
|
2018-12-30 10:52:45 -06:00
|
|
|
Tilt::ReshapeData Tilt::GetReshapableState(bool adjusted)
|
2017-02-08 22:15:43 -05:00
|
|
|
{
|
2018-12-30 09:10:32 -06: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-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
|
|
|
|
2018-12-29 16:06:03 -06:00
|
|
|
const ControlState modifier = controls[4]->control_ref->State();
|
2017-02-08 22:15:43 -05:00
|
|
|
|
2019-01-29 14:39:14 -06:00
|
|
|
return Reshape(x, y, modifier);
|
2018-12-29 16:06:03 -06:00
|
|
|
}
|
2017-02-08 22:15:43 -05:00
|
|
|
|
2018-12-30 09:10:32 -06:00
|
|
|
Tilt::StateData Tilt::GetState()
|
|
|
|
{
|
|
|
|
return GetReshapableState(true);
|
|
|
|
}
|
|
|
|
|
2018-12-29 16:06:03 -06:00
|
|
|
ControlState Tilt::GetGateRadiusAtAngle(double ang) const
|
|
|
|
{
|
|
|
|
const ControlState max_tilt_angle = numeric_settings[SETTING_MAX_ANGLE]->GetValue() / 1.8;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-02-08 22:15:43 -05:00
|
|
|
} // namespace ControllerEmu
|