A way to correctly determine the number of gamepad analog sticks

Viewed 53

I'm working on an extensive input mapping for my game project using SDL2. Each input device is packed in a simple structure and updated with data flowing from the devices in the form of SDL events. Thanks to this, I always have access to current data and I do not have to implement logic directly in the event loop.

To easily and conveniently perform the game logic (e.g. to move the hero), the mapper provides information such as the angle, distance and direction of movement. So I created the universal functionality of the analog stick as a simple structure that takes the new coordinates of the axes and calculates the angle and distance immediately. Works great.


But here's the problem. SDL does not provide information on the number of analog sticks, only the number of axes. The question is: is there any solution to correctly determine the number of analog sticks, regardless of the type of controller?


I need to know their number in order to be able to create the right number of objects representing the sticks. Currently I solved it like that if the number of axes is greater than 4 then I create 2 stick objects assigned to the first 4 axes of the gamepad (the other axes are treated like triggers). However, this solution seems weak to me, because the number of sticks will not be correct in the case of a gamepad with one or at least three sticks (yes, such controllers exist).

0 Answers
Related