diff options
| author | Mat M <mathew1800@gmail.com> | 2018-12-28 06:18:56 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-28 06:18:56 -0500 |
| commit | de03019c77691f4d596d5d9b0d67bcceefa8ce9d (patch) | |
| tree | 0ad62c370609b92c2a664ae172c6b8a0ad5eab14 /Source/Core/InputCommon/ControllerEmu/StickGate.cpp | |
| parent | f006af441e87f0331ea39d38082a0a52a9b86277 (diff) | |
| parent | c614f5f534cdb7a083387505aff90e8be94fed73 (diff) | |
Merge pull request #7628 from jordan-woyak/stick-shapes
ControllerEmu: Add ability to reshape analog sticks. Make the mapping indicator pretty.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/StickGate.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerEmu/StickGate.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/StickGate.cpp b/Source/Core/InputCommon/ControllerEmu/StickGate.cpp new file mode 100644 index 0000000000..c0c2a668a3 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/StickGate.cpp @@ -0,0 +1,47 @@ +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/StickGate.h" + +#include <cmath> + +#include "Common/MathUtil.h" + +namespace ControllerEmu +{ +OctagonStickGate::OctagonStickGate(ControlState radius) : m_radius(radius) +{ +} + +ControlState OctagonStickGate::GetRadiusAtAngle(double ang) const +{ + constexpr int sides = 8; + constexpr double sum_int_angles = (sides - 2) * MathUtil::PI; + constexpr double half_int_angle = sum_int_angles / sides / 2; + + ang = std::fmod(ang, MathUtil::TAU / sides); + // Solve ASA triangle using The Law of Sines: + return m_radius / std::sin(MathUtil::PI - ang - half_int_angle) * std::sin(half_int_angle); +} + +RoundStickGate::RoundStickGate(ControlState radius) : m_radius(radius) +{ +} + +ControlState RoundStickGate::GetRadiusAtAngle(double) const +{ + return m_radius; +} + +SquareStickGate::SquareStickGate(ControlState half_width) : m_half_width(half_width) +{ +} + +ControlState SquareStickGate::GetRadiusAtAngle(double ang) const +{ + constexpr double section_ang = MathUtil::TAU / 4; + return m_half_width / std::cos(std::fmod(ang + section_ang / 2, section_ang) - section_ang / 2); +} + +} // namespace ControllerEmu |
