Hi!
To let the player customise the controls of my game, I have written a class
for my GUI system that captures user input. The way I use it is pop up a
window with an instance of the capture class and a message telling the user
to press any key or button. The capture object then watches for key or
joybutton events and captures the first one it receives. This key or button
will then be assigned to the action the user is customising.
What’s still missing is support for joystick axes. I.e., if the user moves any
joystick axis of any joystick instead of pressing a key or button, I want the
capture class to recognise that and tell me which axis was used.
Now I can’t just accept the first joyaxis event I get, because it might just
be a small variation within the joystick’s dead zone. I could watch for
events representing axis changes greater than, e.g. 1000, but I assume doing
this every frame would mean that owners of very fast PCs might have to move
their axis extremely quickly. Perhaps I’m too careful here, but I’m afraid
this solution might be a bit too much of a hack.
So my current idea is this: On any joyaxis event, convert the current axis
position to a boolean value, true meaning that the position is greater than
16000 or smaller than -16000, i.e. that the axis is “on”. Then check a
std::map to see the last state of this axis. If it is different from the new
one, assume that the user has moved this axis, otherwise keep looking.
However, before I start implementing, I’d like to ask if there are
simpler/more elegant/more effective solutions? I’m sure this is a common
problem for user-friendly games, and I might have just overlooked the most
obvious & best way to do it.
Thx in advance,
Marian.–
Hofstadter’s law: “It always takes longer than you think, even when you take
account of Hofstadter’s law”.