mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-29 17:23:40 +01:00
Add back the deadzone to XInput, definitely required with my pad. Restore the magnitude square root.
This commit is contained in:
1 parent
fe41d405c0
commit
1b813ec984
1 file changed
+30
-26
+30
-26
@@ -1,4 +1,4 @@
|
||||
#include <limits.h>
|
||||
#include <limits.h>
|
||||
#include "Core/Config.h"
|
||||
#include "input/input_state.h"
|
||||
#include "XinputDevice.h"
|
||||
@@ -90,31 +90,35 @@ int XinputDevice::UpdateState(InputState &input_state) {
|
||||
}
|
||||
}
|
||||
|
||||
inline float Clampf(float val, float min, float max) {
|
||||
if (val < min) return min;
|
||||
if (val > max) return max;
|
||||
return val;
|
||||
}
|
||||
|
||||
// We only filter the left stick since PSP has no analog triggers or right stick
|
||||
// Doesn't currently do any real deadzoning. Maybe we don't need it.
|
||||
static Stick NormalizedDeadzoneFilter(short x, short y) {
|
||||
Stick s;
|
||||
float magnitude = 32767.0f;
|
||||
|
||||
s.x = (float)x / magnitude;
|
||||
s.y = (float)y / magnitude;
|
||||
|
||||
magnitude = s.x * s.x + s.y * s.y;
|
||||
|
||||
if (magnitude > 1.0f) {
|
||||
s.x *= 1.41421f;
|
||||
s.y *= 1.41421f;
|
||||
}
|
||||
|
||||
s.x = Clampf(s.x, -1.0f, 1.0f);
|
||||
s.y = Clampf(s.y, -1.0f, 1.0f);
|
||||
return s;
|
||||
inline float Clampf(float val, float min, float max) {
|
||||
if (val < min) return min;
|
||||
if (val > max) return max;
|
||||
return val;
|
||||
}
|
||||
|
||||
// We only filter the left stick since PSP has no analog triggers or right stick
|
||||
static Stick NormalizedDeadzoneFilter(short x, short y) {
|
||||
static const float DEADZONE = (float)XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE / 32767.0f;
|
||||
Stick s;
|
||||
|
||||
s.x = (float)x / 32767.0f;
|
||||
s.y = (float)y / 32767.0f;
|
||||
|
||||
float magnitude = sqrtf(s.x * s.x + s.y * s.y);
|
||||
|
||||
if (magnitude > DEADZONE) {
|
||||
if (magnitude > 1.0f) {
|
||||
s.x *= 1.41421f;
|
||||
s.y *= 1.41421f;
|
||||
}
|
||||
|
||||
s.x = Clampf(s.x, -1.0f, 1.0f);
|
||||
s.y = Clampf(s.y, -1.0f, 1.0f);
|
||||
} else {
|
||||
s.x = 0.0f;
|
||||
s.y = 0.0f;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user