Simplify tilt, step 1
This commit is contained in:
parent
99b2349d6b
commit
a288c59841
3 changed files with 13 additions and 20 deletions
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue