mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Add KrossX's fix for XInput analog range. The PSPs analog is really far extended outside the circle, even further than the 360.
This commit is contained in:
1 parent
059aed36ee
commit
fe41d405c0
1 file changed
+25
-28
+25
-28
@@ -90,37 +90,34 @@ int XinputDevice::UpdateState(InputState &input_state) {
|
||||
}
|
||||
}
|
||||
|
||||
// We only filter the left stick since PSP has no analog triggers or right stick
|
||||
static Stick NormalizedDeadzoneFilter(short x, short y) {
|
||||
static const short DEADZONE = XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE;
|
||||
Stick left;
|
||||
left.x = x;
|
||||
left.y = y;
|
||||
|
||||
float magnitude = sqrt(left.x*left.x + left.y*left.y);
|
||||
|
||||
Stick norm;
|
||||
norm.x = left.x / magnitude;
|
||||
norm.y = left.y / magnitude;
|
||||
|
||||
if (magnitude > DEADZONE) {
|
||||
if (magnitude > 32767) magnitude = 32767;
|
||||
// normalize the magnitude
|
||||
magnitude -= DEADZONE;
|
||||
magnitude /= (32767 - DEADZONE);
|
||||
|
||||
// normalize the axis
|
||||
left.x = norm.x * magnitude;
|
||||
left.y = norm.y * magnitude;
|
||||
} else {
|
||||
left.x = left.y = 0;
|
||||
}
|
||||
|
||||
return left;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct xinput_button_name {
|
||||
unsigned int button;
|
||||
char name[10];
|
||||
|
||||
Reference in new issue
Block a user