1
Vote

Thumbstick handling incorrect on Y axis

description

Hi,
I'm using a wireless XBox controller. I noticed that when I pressed down on the left thumbstick, GamePad told me that up was pressed.

I investigated further. When down is pressed fully, -32768 is set for the Y axis and when up is pressed fully, it's 32767.

Then I looked at GamePad::AddThumbstickButtons:
        private static Microsoft.Xna.Framework.Input.Buttons AddThumbstickButtons(
            short thumbX, short thumbY, short deadZone, 
            Microsoft.Xna.Framework.Input.Buttons bitFieldToAddTo,
            Microsoft.Xna.Framework.Input.Buttons thumbstickLeft, 
            Microsoft.Xna.Framework.Input.Buttons thumbStickRight, 
            Microsoft.Xna.Framework.Input.Buttons thumbStickUp, 
            Microsoft.Xna.Framework.Input.Buttons thumbStickDown)
        {
            // TODO: this needs adjustment. Very naive implementation. Doesn't match XNA yet

           if (thumbY < -deadZone)
                bitFieldToAddTo = bitFieldToAddTo | thumbStickUp;
            else if (thumbY > deadZone)
                bitFieldToAddTo = bitFieldToAddTo | thumbStickDown;

           return bitFieldToAddTo;
        }
The dead zone for the left thumbstick is 7849, so when I press down (thumbY=-32768), it's comparing -32768 < -7849, which it is, so it says that Up button is pressed.

Here's the new correct code:
        private static Microsoft.Xna.Framework.Input.Buttons AddThumbstickButtons(
            short thumbX, short thumbY, short deadZone, 
            Microsoft.Xna.Framework.Input.Buttons bitFieldToAddTo,
            Microsoft.Xna.Framework.Input.Buttons thumbstickLeft, 
            Microsoft.Xna.Framework.Input.Buttons thumbStickRight, 
            Microsoft.Xna.Framework.Input.Buttons thumbStickUp, 
            Microsoft.Xna.Framework.Input.Buttons thumbStickDown)
        {
            // TODO: this needs adjustment. Very naive implementation. Doesn't match XNA yet
            if (thumbX < -deadZone)
                bitFieldToAddTo = bitFieldToAddTo | thumbstickLeft;
            if (thumbX > deadZone)
                bitFieldToAddTo = bitFieldToAddTo | thumbStickRight;
            if (thumbY > deadZone)
                bitFieldToAddTo = bitFieldToAddTo | thumbStickUp;
            else if (thumbY < -deadZone)
                bitFieldToAddTo = bitFieldToAddTo | thumbStickDown;
            return bitFieldToAddTo;
        }
Would you like a pull request?

comments