Merge pull request #12823 from iota97/analog-rot-square

Auto rotate over a square
This commit is contained in:
Henrik Rydgård 2020-04-14 10:36:12 +02:00 committed by GitHub
commit 30eebe2f1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View file

@ -1186,12 +1186,13 @@ void EmuScreen::update() {
if (autoRotatingAnalogCW_) { if (autoRotatingAnalogCW_) {
const float now = time_now_d(); const float now = time_now_d();
__CtrlSetAnalogX(cos(now*-g_Config.fAnalogAutoRotSpeed), 0); // Clamp to a square
__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);
} else if (autoRotatingAnalogCCW_) { } else if (autoRotatingAnalogCCW_) {
const float now = time_now_d(); const float now = time_now_d();
__CtrlSetAnalogX(cos(now*g_Config.fAnalogAutoRotSpeed), 0); __CtrlSetAnalogX(std::min(1.0f, std::max(-1.0f, 1.42f*cosf(now*g_Config.fAnalogAutoRotSpeed))), 0);
__CtrlSetAnalogY(sin(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. // This is here to support the iOS on screen back button.

View file

@ -202,8 +202,9 @@ void AnalogRotationButton::Update() {
if (autoRotating_) { if (autoRotating_) {
float speed = clockWise_ ? -g_Config.fAnalogAutoRotSpeed : g_Config.fAnalogAutoRotSpeed; float speed = clockWise_ ? -g_Config.fAnalogAutoRotSpeed : g_Config.fAnalogAutoRotSpeed;
__CtrlSetAnalogX(cos(now*speed), 0); // Clamp to a square
__CtrlSetAnalogY(sin(now*speed), 0); __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);
} }
} }