Search Tips Advanced Search |
| Delphi Graphics and Game Programming Exposed with DirectX 7.0 by John Ayres Wordware Publishing, Inc. ISBN: 1556226373 Pub Date: 12/01/99
Search this book:
Previous | Table of Contents | Next
## CHAPTER 8 Force Feedback This chapter covers the following topics: • Creating and using standard force feedback effects • Creating and using custom force feedback effects • Modifying a force feedback effect on the fly • Shaping force feedback effects with envelopes Cutting-edge computer games offer an entertainment experience very similar to Hollywood movies. Such games feature almost photo-realistic environments, complete with appropriate lighting, 3-D sound effects, and music to enhance the emotional impact. However, consider how much more realistic and immersive a gaming experience would be if you could feel the blow of your axe against an enemy’s armor, or the resistance of gravity and air as you wheel your jet fighter through a tight turn. This is what force feedback technology is all about. Force feedback allows the game developer to add the illusion of mass and momentum to game elements previously only represented as dots of colored light. Like sound and music, it adds an intangible realistic element to a game that could not be accomplished otherwise. Force feedback support appeared in DirectX 5, and since then, game manufacturers have slowly implemented force feedback support into their products. Like sound and music, no game absolutely requires force feedback in order to make it entertaining. On the other hand, unless you’re making a game like Solitaire, it would be crazy to ignore the exciting functionality this new technology offers; it is certainly a requirement for action games to actively compete in the retail market. The force feedback API is part of DirectInput. At the time of this writing, force feedback functionality is available primarily on joysticks and a few wheels, but the technology is designed to work with devices of any shape and size. The result is a very flexible yet complex system. For our purposes, we will focus our discussion of force feedback as it applies to joysticks, but keep in mind that the concepts to follow can be applied to any type of force feedback device.
| Tip: These examples were written and tested specifically on the Microsoft SideWinder® Force Feedback Pro joystick, but they should work on any force feedback device with an x- and y-axis.
### Features Force feedback has no equivalent in the Win32 API world, and as such cannot be compared to any existing functionality. As we’ve discussed, the purpose of force feedback is to provide the user with tactile output based on conditions within the game world. This is accomplished through either an active push on one or more of the axes supported by the device, or through some form of resistance along those axes when the user manipulates the device. Considering this, DirectInput’s force feedback functionality provides the following features of interest to game developers: • Several different standard effects representing a wide range of tactile responses • Device-specific effects implemented by the device driver (when available) • Modification of effects on the fly (when available) • Creation of customized effects • Triggered effects controlled by the device In the following sections we will discuss how the Delphi game developer can take advantage of each of these features to create tactile feedback that provides a new level of realism to game environments. ### Functional Overview In order to begin using force feedback, the application must already have an initialized IDirectInputDevice2 object. An elaborate data structure is then initialized depending on the type of effect desired. IDirectInputDevice2 uses this initialized data structure to create an IDirectInputEffect object. The IDirectInputEffect object represents the developer’s direct interface to the force feedback hardware. This is not to be confused with the functionality provided by the IDirectInputDevice2 object; IDirectInputDevice2 is responsible for communicating user input from the device, whereas IDirectInputEffect is responsible for outputting tactile feedback responses to the device. Through the IDirectInputEffect interface, the application can query the force feedback hardware’s capabilities, start and stop the effect, modify the effect on the fly, and control other aspects of the force feedback hardware itself. Once an effect is created, it must be downloaded to the device. This typically happens automatically, as we’ll discuss below. The act of downloading an effect tells the driver to prepare the effect for playback. How this is accomplished is determined by the driver, but typically the effect’s parameters are placed into hardware memory so that the device will not need to communicate with the system in response to axis movement and button presses. However, a device can only handle a finite number of effects, and may return a DIERR_DEVICEFULL error. The workaround is to simply unload another, hopefully unused, effect and then try again. Once an effect is created, it must be explicitly started. Effects can play infinitely or for a specified amount of time, and can be stopped if necessary. Alternatively, when the effect is being created, it can be associated with a button on the device. The device driver will then start the effect when the button is pressed. Triggered effects such as this will stop when the effect duration has been reached or when the button is released, whichever comes first. This functionality is totally independent of the application. Some devices even support repeating an effect while the button is held down, perfect for re-creating the kickback of a machine gun or other automatic weapon. ### Basic Concepts When discussing force feedback effects, it is necessary to understand several general concepts as they apply to the effect itself. These concepts define the action of the effect, such as its strength and direction. Such concepts include kinetic forces, conditions, magnitude, coefficient, gain, duration, sample period, axes, direction, and envelope. #### Kinetic Force A kinetic force is an effect that actively pushes on one or more axes. This push can be in a single direction or in alternating directions such as occurs with periodic effects. This active push is applied regardless of the position or movement of the axis (or axes). An example of this is a push on the joystick in the direction of the user to simulate recoil from firing a rocket.
Previous | Table of Contents | Next

Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.