Skip to content

Commit

Permalink
Simplify tilt, step 1
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Feb 16, 2023
1 parent 99b2349 commit a288c59
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
18 changes: 11 additions & 7 deletions Core/TiltEventProcessor.cpp
Expand Up @@ -19,6 +19,13 @@ static u32 tiltButtonsDown = 0;
float rawTiltAnalogX;
float rawTiltAnalogY;

// Represents a generic Tilt event
struct Tilt {
Tilt() : x_(0), y_(0) {}
Tilt(const float x, const float y) : x_(x), y_(y) {}
float x_, y_;
};

// These functions generate tilt events given the current Tilt amount,
// and the deadzone radius.
void GenerateAnalogStickEvent(const Tilt &tilt);
Expand Down Expand Up @@ -51,7 +58,7 @@ inline Tilt DampenTilt(const Tilt &tilt, float deadzone, float xSensitivity, flo
);
}

Tilt GenTilt(bool landscape, float calibrationAngle, float x, float y, float z, bool invertX, bool invertY, float xSensitivity, float ySensitivity) {
void ProcessTilt(bool landscape, float calibrationAngle, float x, float y, float z, bool invertX, bool invertY, float xSensitivity, float ySensitivity) {
if (landscape) {
std::swap(x, y);
} else {
Expand All @@ -78,18 +85,15 @@ Tilt GenTilt(bool landscape, float calibrationAngle, float x, float y, float z,
}

// finally, dampen the tilt according to our curve.
return DampenTilt(transformedTilt, deadzone, xSensitivity, ySensitivity);
}

void TranslateTiltToInput(const Tilt &tilt) {
rawTiltAnalogX = tilt.x_;
rawTiltAnalogY = tilt.y_;
Tilt tilt = DampenTilt(transformedTilt, deadzone, xSensitivity, ySensitivity);

switch (g_Config.iTiltInputType) {
case TILT_NULL:
break;

case TILT_ANALOG:
rawTiltAnalogX = tilt.x_;
rawTiltAnalogY = tilt.y_;
GenerateAnalogStickEvent(tilt);
break;

Expand Down
11 changes: 1 addition & 10 deletions Core/TiltEventProcessor.h
Expand Up @@ -2,18 +2,9 @@

namespace TiltEventProcessor {

// Represents a generic Tilt event
struct Tilt {
Tilt() : x_(0), y_(0) {}
Tilt(const float x, const float y) : x_(x), y_(y) {}
float x_, y_;
};

// generates a tilt in the correct coordinate system based on
// calibration. x, y, z is the current accelerometer reading (with no conversion).
Tilt GenTilt(bool landscape, const float calibrationAngle, float x, float y, float z, bool invertX, bool invertY, float xSensitivity, float ySensitivity);

void TranslateTiltToInput(const Tilt &tilt);
void ProcessTilt(bool landscape, const float calibrationAngle, float x, float y, float z, bool invertX, bool invertY, float xSensitivity, float ySensitivity);
void ResetTiltEvents();

// Lets you preview the amount of tilt in TiltAnalogSettingsScreen.
Expand Down
4 changes: 1 addition & 3 deletions UI/NativeApp.cpp
Expand Up @@ -1404,11 +1404,9 @@ void NativeAxis(const AxisInput &axis) {
// see [http://developer.android.com/guide/topics/sensors/sensors_overview.html] for details
bool landscape = dp_yres < dp_xres;
// now transform out current tilt to the calibrated coordinate system
Tilt trueTilt = GenTilt(landscape, tiltBaseAngleY, tiltX, tiltY, tiltZ,
ProcessTilt(landscape, tiltBaseAngleY, tiltX, tiltY, tiltZ,
g_Config.bInvertTiltX, g_Config.bInvertTiltY,
xSensitivity, ySensitivity);

TranslateTiltToInput(trueTilt);
}

void NativeMessageReceived(const char *message, const char *value) {
Expand Down

0 comments on commit a288c59

Please sign in to comment.