irungentoo / Xiaomi_gamepad

It's a nice gamepad.
318 stars 71 forks source link

Not using full XInput thumbstick axis range #28

Closed Ryochan7 closed 8 years ago

Ryochan7 commented 8 years ago

Looking at the code in Program.cs, it looks like the assumed range for LeftStickX, LeftStickY, RightStickX, and RightStickY is [-32767, 32767]. However, upon testing and looking at some XInput documenation, the actual range for those axes is [-32768, 32767].

I have been tinkering with XInput emulation using ScpVBus and I could never get a full speed left camera turn in Duke Nukem Forever nor Bioshock 2 even though there was no problem getting a full speed right camera turn. Adjusting the range actually allowed the camera to work as expected. I was using your source code as reference for my small test program so I thought I should let you know about the potential problem.

https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinput_gamepad(v=vs.85).aspx

irungentoo commented 8 years ago

Fixed in: https://github.com/irungentoo/Xiaomi_gamepad/commit/8de6da06126956c40e26e3dcaf3725f536a0485f

Ryochan7 commented 8 years ago

Thanks for looking into this. However, I would like to make a suggestion to the change. Instead of adjusting the value at -32767, you could determine the normalized value for an axis first and then find the final output value. That way, -32767 is still available as an output value. Here is an example of how it could work.

double normalLeftStickX = Math.Max(-128.0, currentState[5] - 128) / 128; // [-1.0, 1.0]
short LeftStickX = (short)(normalLeftStickX * ((currentState[5] >= 0) ? 32767 : -32768)); // [-32768, 32767]