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
Ramp Forces A ramp force creates a steadily increasing or decreasing push on an axis over the duration specified by the dwDuration member of the TDIEffect structure. Ramp forces use a TDIRampForce structure for their type-specific parameters, which is defined as:
    TDIRampForce = packed record

      lStart : longint;                    // the starting force magnitude

      lEnd : longint;                      // the ending force magnitude

    end;
As with constant forces, the lStart and lEnd members indicate the strength of the force in the range 10,000 to 10,000, with positive values pushing the axis in the indicated direction and negative values pushing in the opposite direction.
| Note: The dwDuration member of the TDIEffect structure cannot be set to INFINITE for ramp forces.
Periodic Forces A periodic effect causes a force to be applied to an axis in an oscillating manner. This is also known as a wave effect, as the magnitude and direction of a force changes over time. Similar to conditions, periodic forces are divided into subtypes: sine, triangle, sawtooth up, sawtooth down, and square. These produce alternating forces on an axis in a manner suggested by their name, as indicated by the following illustration. Figure 8-4: Periodic forces All periodic effects use a TDIPeriodic structure for their type-specific parameters. The TDIPeriodic structure is defined as:
    TDIPeriodic = packed record

      dwMagnitude : DWORD;                  //the absolute force magnitude

      1Offset : longint;                    //neutral wave position

      dwPhase : DWORD;                      //force start position

      dwPeriod : DWORD;                     // wave frequency

    end;
The dwMagnitude member indicates the absolute magnitude of the force to be exerted on the axis, in a range of 0 to 10,000. While the force is playing, this magnitude will steadily cycle between this value through the negative of this value and back again, creating a push on the axis in alternating directions. The manner in which this cycling takes effect is determined by the force type, as indicated in Figure 8-4. For example, a sine force would cycle the magnitude, and thus direction, of the force in a steady, smooth manner, where a square force would push the axis in alternating directions at the greatest magnitude in a very jarring, immediate manner. The lOffset member indicates the center of the waveform in relation to the amount of force exerted, and will raise or lower the absolute magnitude of the force appropriately. For example, a value of zero indicates that the waveform will oscillate around zero magnitude. A value of 1,000, however, indicates that the waveform will oscillate around 1,000 magnitude, modifying the positive and negative magnitudes of the waveform accordingly. This is visually illustrated in the figure below. Figure 8-5: Modifying the waveform offset
| Note: The sum of dwMagnitude and the absolute value of lOffset cannot exceed 10,000 or DI_FFNOMINALMAX.
The dwPhase member indicates the point at which the waveform should start, and is measured in hundredths of degrees. For example, setting this member to 9,000 for a sine periodic effect shifts the starting point by 90 degrees, and creates a cosine effect. This member is not always supported by all drivers. Finally, the dwPeriod member indicates the frequency of the waveform, measured in microseconds. For most drivers, this value cannot be set above one second, and it will have a minimum practical value based on how fast the motors in the device can reverse their direction. Device-Specific Effects Many force feedback manufacturers provide several effects built in to the device driver. Many of these may be standard effect types, such as ramp forces, constant forces, or conditions, but some may be custom forces. Additionally, some of these forces may have adjustable type-specific parameters. If they have adjustable parameters and are not a custom force, you can use the type-specific parameters structure appropriate for the force type to modify the force during playback. Otherwise, you’ll need to get the type-specific parameters structure from the driver documentation if you wish to change an adjustable device-specific custom force on the fly. Of course, device-specific forces are going to change from device to device, but non-adjustable device-specific forces are perhaps the easiest to use as the application needs to know nothing about them. In order to use a device-specific effect, we must first retrieve a list of available effects; this is accomplished by using the EnumEffects method of the IDirectInputDevice2 interface. The EnumEffects method is defined as:
    function EnumEffects(

    lpCallback: TDIEnumEffectsCallbackA;      // a pointer to the callback function

    pvRef: pointer;                           // application-specific data

    dwEffType: DWORD                          // flag affecting enumeration

    ) : HResult;                              // returns a DirectX error code
The pvRef parameter is simply a pointer to application-specific data, which will be passed to the callback function. The dwEffType parameter contains a DIEFT_* flag which determines what type of effects are to be enumerated. In our case, we’ll use the DIEFT_HARDWARE flag to indicate that we want only hardware-specific effects. The lpCallback parameter is a pointer to the callback function. The callback function itself must be defined as:
    function TDIEnumEffectsCallbackA(

    var pdei: TDIEffectInfoA;             // a TDIEffectInfoA structure

    pvRef: pointer                        // a pointer to application-specific data

    ) : BOOL; stdcall;                    // returns TRUE or FALSE
The pdei parameter contains an initialized TDIEffectInfoA structure that has all of the pertinent information about the enumerated effect. In particular, the GUID member of this structure contains the GUID for the enumerated effect, which will need to be recorded for subsequent use when the effect is created. The pvRef parameter simply contains a pointer to the application-defined data specified when the EnumEffects method was called. This callback function should return TRUE to continue enumeration or FALSE to cancel it. Listing 8-2 demonstrates how to use the EnumEffects method to enumerate all device- specific effects that do not have any adjustable type-specific parameters.
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.