Switch to axis for accelerometer usage.

This commit is contained in:
Unknown W. Brackets 2017-03-14 20:52:30 -07:00
parent f3c518ac7f
commit 2a745f86ac
3 changed files with 19 additions and 48 deletions

View File

@ -832,45 +832,6 @@ void EmuScreen::update(InputState &input) {
// Virtual keys.
__CtrlSetRapidFire(virtKeys[VIRTKEY_RAPID_FIRE - VIRTKEY_FIRST]);
// Apply tilt to left stick
// TODO: Make into an axis
#ifdef MOBILE_DEVICE
/*
if (g_Config.bAccelerometerToAnalogHoriz) {
// Get the "base" coordinate system which is setup by the calibration system
float base_x = g_Config.fTiltBaseX;
float base_y = g_Config.fTiltBaseY;
//convert the current input into base coordinates and normalize
//TODO: check if all phones give values between [-50, 50]. I'm not sure how iOS works.
float normalized_input_x = (input.acc.y - base_x) / 50.0 ;
float normalized_input_y = (input.acc.x - base_y) / 50.0 ;
//TODO: need a better name for computed x and y.
float delta_x = tiltInputCurve(normalized_input_x * 2.0 * (g_Config.iTiltSensitivityX)) ;
//if the invert is enabled, invert the motion
if (g_Config.bInvertTiltX) {
delta_x *= -1;
}
float delta_y = tiltInputCurve(normalized_input_y * 2.0 * (g_Config.iTiltSensitivityY)) ;
if (g_Config.bInvertTiltY) {
delta_y *= -1;
}
//clamp the delta between [-1, 1]
leftstick_x += clamp1(delta_x);
__CtrlSetAnalogX(clamp1(leftstick_x), CTRL_STICK_LEFT);
leftstick_y += clamp1(delta_y);
__CtrlSetAnalogY(clamp1(leftstick_y), CTRL_STICK_LEFT);
}
*/
#endif
// Make sure fpsLimit starts at 0
if (PSP_CoreParameter().fpsLimit != 0 && PSP_CoreParameter().fpsLimit != 1) {
PSP_CoreParameter().fpsLimit = 0;
@ -1136,4 +1097,4 @@ void EmuScreen::releaseButtons() {
void EmuScreen::resized() {
RecreateViews();
}
}

View File

@ -57,12 +57,20 @@ void TiltAnalogSettingsScreen::CreateViews() {
void TiltAnalogSettingsScreen::update(InputState &input) {
UIScreen::update(input);
//I'm not sure why y is x and x is y. i's probably because of the orientation
//of the screen (the x and y are in portrait coordinates). once portrait and
//reverse-landscape is enabled, this will probably have to change.
//If needed, we can add a "swap x and y" option.
currentTiltX_ = input.acc.y;
currentTiltY_ = input.acc.x;
}
bool TiltAnalogSettingsScreen::axis(const AxisInput &axis) {
if (axis.deviceId == DEVICE_ID_ACCELEROMETER) {
// Historically, we've had X and Y swapped, likely due to portrait vs landscape.
// TODO: We may want to configure this based on screen orientation.
if (axis.axisId == JOYSTICK_AXIS_ACCELEROMETER_X) {
currentTiltY_ = axis.value;
}
if (axis.axisId == JOYSTICK_AXIS_ACCELEROMETER_Y) {
currentTiltX_ = axis.value;
}
}
return false;
}
UI::EventReturn TiltAnalogSettingsScreen::OnCalibrate(UI::EventParams &e) {

View File

@ -26,8 +26,10 @@ class TiltAnalogSettingsScreen : public UIDialogScreenWithBackground {
public:
TiltAnalogSettingsScreen() : currentTiltX_(0), currentTiltY_(0) {}
virtual void CreateViews();
virtual void update(InputState &input);
void CreateViews() override;
void update(InputState &input) override;
bool axis(const AxisInput &axis) override;
private:
UI::EventReturn OnCalibrate(UI::EventParams &e);
float currentTiltX_, currentTiltY_;