Game Development Reference
In-Depth Information
Chapter 9
Programming Input Devices
Even though user interface programming seems easy, it
s actually quite tricky, which
is ironic since most game companies assign the user interface code to their greenest
programmers. It
'
s a simple matter under almost any platform to read a keyboard,
mouse, or gamepad. Most programmers take this input, like the X,Y coordinate of a
mouse, and use it to directly modify the game state, such as where the player is look-
ing in a first-person shooter. This technique works all too well until you want to do
something like switch out that mouse for a USB gamepad or perhaps change how the
controls are interpreted by the game. Maybe your player wants to switch the
up/down or Y-axis of the camera controls from normal to inverted, like I prefer.
The framework presented in this topic puts reading the hardware input devices
squarely inside the application layer, which is the layer that handles any and all oper-
ating system or machine-dependent code. Once the application layer handles the raw
input, it is handed off to the game view layer, usually a game view written specifically
for a human player, to interpret the raw input and translate it into a command for
your game. This chapter deals with the hardware and the raw messages, and you
'
'
ll
learn how these messages are handled in a game view in the next chapter, on user
interface programming.
Because input devices are typically very hardware specific, this chapter has a decid-
edly Windows feel to it. While that is true, the concepts used in the chapter regarding
what you do with the data coming from those devices are universal. While it can be a
big headache to rewrite a hardware support layer for a new platform, it falls into the
239
 
 
 
Search WWH ::




Custom Search