diff --git a/Core/Config.cpp b/Core/Config.cpp index 023d006c74..6b21897453 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -969,6 +969,7 @@ static ConfigSetting controlSettings[] = { #ifdef MOBILE_DEVICE ConfigSetting("TiltBaseX", &g_Config.fTiltBaseX, 0.0f, true, true), ConfigSetting("TiltBaseY", &g_Config.fTiltBaseY, 0.0f, true, true), + ConfigSetting("TiltOrientation", &g_Config.iTiltOrientation, 0, true, true), ConfigSetting("InvertTiltX", &g_Config.bInvertTiltX, false, true, true), ConfigSetting("InvertTiltY", &g_Config.bInvertTiltY, true, true, true), ConfigSetting("TiltSensitivityX", &g_Config.iTiltSensitivityX, 100, true, true), diff --git a/Core/Config.h b/Core/Config.h index 06562aa18b..ce00dafe3c 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -292,6 +292,7 @@ public: //the base x and y tilt. this inclination is treated as (0,0) and the tilt input //considers this orientation to be equal to no movement of the analog stick. float fTiltBaseX, fTiltBaseY; + int iTiltOrientation; //whether the x axes and y axes should invert directions (left becomes right, top becomes bottom.) bool bInvertTiltX, bInvertTiltY; //the sensitivity of the tilt in the x direction diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 024b3d3f43..3c63e45c35 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1360,13 +1360,27 @@ bool NativeAxis(const AxisInput &axis) { // This is static, since we need to remember where we last were (in terms of orientation) static Tilt currentTilt; + // tilt on x or y? + static bool verticalTilt; + if (g_Config.iTiltOrientation == 0) + verticalTilt = false; + else if (g_Config.iTiltOrientation == 1) + verticalTilt = true; + // x and y are flipped if we are in landscape orientation. The events are // sent with respect to the portrait coordinate system, while we // take all events in landscape. // see [http://developer.android.com/guide/topics/sensors/sensors_overview.html] for details bool portrait = dp_yres > dp_xres; switch (axis.axisId) { + //TODO: make this generic. case JOYSTICK_AXIS_ACCELEROMETER_X: + if (verticalTilt) { + if (fabs(axis.value) < 0.8f && g_Config.iTiltOrientation == 2) // Auto tilt switch + verticalTilt = false; + else + return false; // Tilt on Z instead + } if (portrait) { currentTilt.x_ = axis.value; } else { @@ -1383,9 +1397,18 @@ bool NativeAxis(const AxisInput &axis) { break; case JOYSTICK_AXIS_ACCELEROMETER_Z: - //don't handle this now as only landscape is enabled. - //TODO: make this generic. - return false; + if (!verticalTilt) { + if (fabs(axis.value) < 0.8f && g_Config.iTiltOrientation == 2) // Auto tilt switch + verticalTilt = true; + else + return false; // Tilt on X instead + } + if (portrait) { + currentTilt.x_ = -axis.value; + } else { + currentTilt.y_ = -axis.value; + } + break; case JOYSTICK_AXIS_OUYA_UNKNOWN1: case JOYSTICK_AXIS_OUYA_UNKNOWN2: diff --git a/UI/TiltAnalogSettingsScreen.cpp b/UI/TiltAnalogSettingsScreen.cpp index 99e2a7a4f6..d1170df37b 100644 --- a/UI/TiltAnalogSettingsScreen.cpp +++ b/UI/TiltAnalogSettingsScreen.cpp @@ -35,6 +35,8 @@ void TiltAnalogSettingsScreen::CreateViews() { settings->Add(new ItemHeader(co->T("Invert Axes"))); settings->Add(new CheckBox(&g_Config.bInvertTiltX, co->T("Invert Tilt along X axis"))); settings->Add(new CheckBox(&g_Config.bInvertTiltY, co->T("Invert Tilt along Y axis"))); + static const char* tiltMode[] = { "Screen aligned to ground", "Screen at right angle to ground", "Auto-switch" }; + settings->Add(new PopupMultiChoice(&g_Config.iTiltOrientation, co->T("Base tilt position"), tiltMode, 0, ARRAY_SIZE(tiltMode), co->GetName(), screenManager())); settings->Add(new ItemHeader(co->T("Sensitivity"))); //TODO: allow values greater than 100? I'm not sure if that's needed. diff --git a/UI/TiltEventProcessor.cpp b/UI/TiltEventProcessor.cpp index 8beb768508..2b7c51f8bb 100644 --- a/UI/TiltEventProcessor.cpp +++ b/UI/TiltEventProcessor.cpp @@ -104,12 +104,12 @@ void TiltEventProcessor::GenerateDPadEvent(const Tilt &tilt) { static const int dir[4] = {CTRL_RIGHT, CTRL_DOWN, CTRL_LEFT, CTRL_UP}; if (tilt.x_ == 0) { - __CtrlButtonUp(CTRL_RIGHT | CTRL_LEFT); + __CtrlButtonUp(tiltButtonsDown & (CTRL_RIGHT | CTRL_LEFT)); tiltButtonsDown &= ~(CTRL_LEFT | CTRL_RIGHT); } if (tilt.y_ == 0) { - __CtrlButtonUp(CTRL_UP | CTRL_DOWN); + __CtrlButtonUp(tiltButtonsDown & (CTRL_UP | CTRL_DOWN)); tiltButtonsDown &= ~(CTRL_UP | CTRL_DOWN); } @@ -129,7 +129,7 @@ void TiltEventProcessor::GenerateDPadEvent(const Tilt &tilt) { case 6: ctrlMask |= CTRL_UP; break; case 7: ctrlMask |= CTRL_UP | CTRL_RIGHT; break; } - + ctrlMask &= ~__CtrlPeekButtons(); __CtrlButtonDown(ctrlMask); tiltButtonsDown |= ctrlMask; } @@ -138,12 +138,12 @@ void TiltEventProcessor::GenerateActionButtonEvent(const Tilt &tilt) { static const int buttons[4] = {CTRL_CIRCLE, CTRL_CROSS, CTRL_SQUARE, CTRL_TRIANGLE}; if (tilt.x_ == 0) { - __CtrlButtonUp(CTRL_SQUARE | CTRL_CIRCLE); + __CtrlButtonUp(tiltButtonsDown & (CTRL_SQUARE | CTRL_CIRCLE)); tiltButtonsDown &= ~(CTRL_SQUARE | CTRL_CIRCLE); } if (tilt.y_ == 0) { - __CtrlButtonUp(CTRL_TRIANGLE | CTRL_CROSS); + __CtrlButtonUp(tiltButtonsDown & (CTRL_TRIANGLE | CTRL_CROSS)); tiltButtonsDown &= ~(CTRL_TRIANGLE | CTRL_CROSS); } @@ -152,15 +152,18 @@ void TiltEventProcessor::GenerateActionButtonEvent(const Tilt &tilt) { } int direction = (int)(floorf((atan2f(tilt.y_, tilt.x_) / (2.0f * (float)M_PI) * 4.0f) + 0.5f)) & 3; - __CtrlButtonDown(buttons[direction]); - tiltButtonsDown |= buttons[direction]; + int downButtons = buttons[direction] & ~__CtrlPeekButtons(); + __CtrlButtonDown(downButtons); + tiltButtonsDown |= downButtons; } void TiltEventProcessor::GenerateTriggerButtonEvent(const Tilt &tilt) { u32 upButtons = 0; u32 downButtons = 0; - // KISS, let's only look at X. Expect deadzone to already be applied. - if (tilt.x_ == 0.0f) { + // Y axis for both + if (tilt.y_ < 0.0f) { + downButtons = CTRL_LTRIGGER | CTRL_RTRIGGER; + } else if (tilt.x_ == 0.0f) { upButtons = CTRL_LTRIGGER | CTRL_RTRIGGER; } else if (tilt.x_ < 0.0f) { downButtons = CTRL_LTRIGGER; @@ -170,7 +173,8 @@ void TiltEventProcessor::GenerateTriggerButtonEvent(const Tilt &tilt) { upButtons = CTRL_LTRIGGER; } - __CtrlButtonUp(upButtons); + downButtons &= ~__CtrlPeekButtons(); + __CtrlButtonUp(tiltButtonsDown & upButtons); __CtrlButtonDown(downButtons); tiltButtonsDown = (tiltButtonsDown & ~upButtons) | downButtons; }