Skip to content

Commit

Permalink
Merge pull request #12823 from iota97/analog-rot-square
Browse files Browse the repository at this point in the history
Auto rotate over a square
  • Loading branch information
hrydgard authored Apr 14, 2020
2 parents 05a5154 + c70bf66 commit 30eebe2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,12 +1186,13 @@ void EmuScreen::update() {

if (autoRotatingAnalogCW_) {
const float now = time_now_d();
__CtrlSetAnalogX(cos(now*-g_Config.fAnalogAutoRotSpeed), 0);
__CtrlSetAnalogY(sin(now*-g_Config.fAnalogAutoRotSpeed), 0);
// Clamp to a square
__CtrlSetAnalogX(std::min(1.0f, std::max(-1.0f, 1.42f*cosf(now*-g_Config.fAnalogAutoRotSpeed))), 0);
__CtrlSetAnalogY(std::min(1.0f, std::max(-1.0f, 1.42f*sinf(now*-g_Config.fAnalogAutoRotSpeed))), 0);
} else if (autoRotatingAnalogCCW_) {
const float now = time_now_d();
__CtrlSetAnalogX(cos(now*g_Config.fAnalogAutoRotSpeed), 0);
__CtrlSetAnalogY(sin(now*g_Config.fAnalogAutoRotSpeed), 0);
__CtrlSetAnalogX(std::min(1.0f, std::max(-1.0f, 1.42f*cosf(now*g_Config.fAnalogAutoRotSpeed))), 0);
__CtrlSetAnalogY(std::min(1.0f, std::max(-1.0f, 1.42f*sinf(now*g_Config.fAnalogAutoRotSpeed))), 0);
}

// This is here to support the iOS on screen back button.
Expand Down
5 changes: 3 additions & 2 deletions UI/GamepadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ void AnalogRotationButton::Update() {

if (autoRotating_) {
float speed = clockWise_ ? -g_Config.fAnalogAutoRotSpeed : g_Config.fAnalogAutoRotSpeed;
__CtrlSetAnalogX(cos(now*speed), 0);
__CtrlSetAnalogY(sin(now*speed), 0);
// Clamp to a square
__CtrlSetAnalogX(std::min(1.0f, std::max(-1.0f, 1.42f*cosf(now*speed))), 0);
__CtrlSetAnalogY(std::min(1.0f, std::max(-1.0f, 1.42f*sinf(now*speed))), 0);
}
}

Expand Down

0 comments on commit 30eebe2

Please sign in to comment.