Presentation is loading. Please wait.

Presentation is loading. Please wait.

GAM666 – Introduction To Game Programming ● DirectInput is the part of DirectX for managing input devices, such as keyboard, mouse and joystick ● Supports.

Similar presentations


Presentation on theme: "GAM666 – Introduction To Game Programming ● DirectInput is the part of DirectX for managing input devices, such as keyboard, mouse and joystick ● Supports."— Presentation transcript:

1 GAM666 – Introduction To Game Programming ● DirectInput is the part of DirectX for managing input devices, such as keyboard, mouse and joystick ● Supports both digital (buttons, D-pads) and analog (sliders, joystick axes, mouse axes) objects on a device ● Can handle relative (e.g. mouse axes) and absolute (e.g. Joystick axes) analog objects ● Data coming from the device can be buffered or immediate (in which case you poll the device) ● Also controls force feedback joysticks (input device used for output) DirectInput

2 GAM666 – Introduction To Game Programming ● Use DirectInput8Create() once to create a LPDIRECTINPUT8 COM object to control all subsequent DirectInput activity ● Use its EnumDevices() function to enumerate available devices of the desired type, supplying your own function to handle each matching device (e.g. to find each one's GUID) ● Use its CreateDevice() function to create a LPDIRECTINPUTDEVICE8 object to handle a specific device DirectInput

3 GAM666 – Introduction To Game Programming ● Once you have a device, use its SetDataFormat() function to identify the structure that will be receiving data ● Use its EnumObjects() function to find out about available buttons, axes, etc., supplying your own function to handle each object ● Use its SetCooperativeLevel() function to identify how the device is to be shared with other running programs ● Use its SetProperty() function to control how it works DirectInput

4 GAM666 – Introduction To Game Programming ● Any absolute axis you have must be configured before use, setting the at least the following properties: ● DIPROP_RANGE – the minimum and maximum values returned by the axis ● DIPROP_DEADZONE – the percentage play (i.e. area where there is no change in input) at the middle of the axis (in hundreths of a percent) ● DIPROP_SATURATION – the percentage play at the end of the axis DirectInput

5 GAM666 – Introduction To Game Programming ● When specifying a device object such as an axis or a button, you can identify it by offset (i.e. position in the structure receiving the data) or by ID (available when enumerating device objects) ● Before being able to read from the device it must be Acquire()ed ● At any time the device might be taken from the program, in which case it must be Acquire()ed again DirectInput

6 GAM666 – Introduction To Game Programming ● To poll an input device (immediate data)use the GetDeviceState() member function to fill up a structure containing a snapshot of the current state of the device ● Some devices require calling Poll() before GetDeviceState() [it doesn't hurt to call it even if not necessary] ● To get buffered data use the GetDeviceData() function to fill an array of object state changes DirectInput


Download ppt "GAM666 – Introduction To Game Programming ● DirectInput is the part of DirectX for managing input devices, such as keyboard, mouse and joystick ● Supports."

Similar presentations


Ads by Google