CHAPTER 5 Input Control © 2008 Cengage Learning EMEA.

16
CHAPTER 5 CHAPTER 5 Input Control Input Control © 2008 Cengage Learning EM

Transcript of CHAPTER 5 Input Control © 2008 Cengage Learning EMEA.

CHAPTER 5CHAPTER 5

Input ControlInput Control

© 2008 Cengage Learning EMEA

LEARNING OBJECTIVESLEARNING OBJECTIVES In this chapter you will learn about:

– Input devices– Six classes of input– DirectInput– DirectInput device setup (keyboard, mouse or joystick)– Creating a DirectInput object– Creating a DirectInput device– Setting the data format of a DirectInput device– Setting the cooperative level of a DirectInput device– Acquiring a DirectInput device– Reading data from a DirectInput device– Buffered and immediate data (keyboard, mouse or joystick)– Action mapping– The specification of actions– Setting up an action map– Applying an action map to physical devices– Applying an action map to a device– Retrieving action map data– Force feedback– Setting up a force feedback device– Using effects– XInput

INPUT DEVICESINPUT DEVICES We classify physical input devices into two

primary categories: – keyboard devices – pointing devices.

The mouse is by far the most popular and commonly used pointing device.– It generates two independent values converted

by some API, device interface, or user program into positional data that can be interpreted as screen coordinates.

– This direct approach is, however, rarely used and these two independent values generated by the device are more commonly interpreted by the device driver as velocities.

INPUT DEVICESINPUT DEVICES

The main purpose behind using velocities, rather than distance values, lies with the desire to create a variable-sensitivity input device.

Variable sensitivity refers to slow movements from rest resulting in nominal changes with rapid mouse movements leading to large changes in the cursor’s onscreen position.

INPUT DEVICESINPUT DEVICES The mouse is referred to as a relative-

positioning device. Absolute positioning provides a way of

linking onscreen data with the device’s physical position.

The joystick is another very important input device, especially to the world of computer gaming and simulations. – In its simplest form we interpret the motion of

its stick in both an x and a y direction. These values are then, just as with the mouse, translated into velocities and subsequently integrated into screen coordinates.

INPUT DEVICESINPUT DEVICES

INPUT DEVICESINPUT DEVICES

SIX CLASSES OF INPUTSIX CLASSES OF INPUT

We can identify six classes of logical input devices: – choice devices– locator devices – pick devices – string devices – stroke devices – valuators.

DIRECTINPUTDIRECTINPUT

DirectInput is DirectX’s primary input processing API.

It provides hardware-independent input control for keyboards, mice, joysticks, gamepads, steering wheels, flight yokes, space balls, paddles, etc.

DirectInput’s hardware-independent nature can be attributed to the API interfacing directly with the device drivers.

DIRECTINPUTDIRECTINPUT DirectInput is thus responsible for the

processing of messages sent to and received from physical input devices.

DirectInput Device Setup DirectInput Device Setup (Keyboard, Mouse, or Joystick)(Keyboard, Mouse, or Joystick)

Creating a DirectInput Object Creating a DirectInput Device Setting the Data Format of a DirectInput

Device Setting the Cooperative Level of a DirectInput

Device Acquiring the DirectInput Device Reading Data from a DirectInput Device

[see the textbook and the DirectInput code samples on the book’s website for a complete discussion].

Device DataDevice Data

Buffered as an alternative to Immediate Keyboard Data

Buffered as an Alternative to Immediate Mouse Data

Buffered as an Alternative to Immediate Joystick Data

[see the textbook and the DirectInput code samples on the book’s website for a complete discussion].

Action MappingAction Mapping

Action mapping eliminates the need for hard coded event-object mapping by binding events to virtual control objects

Specifying the Actions Setting up the Action Map Applying an Action Map to Physical Devices Applying the Action Map to a Device Retrieving Action Map Data

Force FeedbackForce Feedback Force feedback is an all-

encompassing term used to describe input devices equipped with actuators, motors and resistance-inducing elements that are used for exerting vibration-based forces.

Force FeedbackForce Feedback

Setting up a Force Feedback Device Using Effects

[see the textbook and the DirectInput Force Feedback code sample on the book’s website for a complete discussion].

XINPUTXINPUT

XInput, introduced with the release of the Xbox 360 gaming console, allows any computer running Windows XP SP1 or later to interface with an Xbox 360 controller.

[see the textbook and the XInput code sample on the book’s website for a complete discussion].