Platform SDK: DirectX

Step 4: Modify an Effect

[C++]

This topic pertains only to application development in Visual Basic. See DirectInput C/C++ Tutorials.

[Visual Basic]

As the user moves the iron ball around, the application will adjust the direction and magnitude of the effect. First of all, though, you may want to check whether the device allows you to change the direction of the effect without stopping and restarting it. DirectInput will stop and restart the effect automatically if necessary, but you might want to modify the behavior of your application to avoid breaks in continuity.

In order to examine the capabilities for any effect, you need to enumerate supported effects and then look for the particular one you are interested in.

Dim diEnumEffects As DirectInputEnumEffects
Dim params As Long
Dim i As Long
 
' Enumerate constant forces
 
Set diEnumEffects = didev.GetEffectsEnum(DIEFT_CONSTANTFORCE)
 
For i = 1 To diEnumEffects.GetCount
 
  ' Look for the standard constant force. There could be others.
 
  If diEnumEffects.GetEffectGuid(i) = "GUID_ConstantForce" Then
    params = diEnumEffects.GetDynamicParams(i)
    Exit For
  End If
 
Next i

If Not (params And DIEP_DIRECTION) Then
  ' Cannot change direction dynamically. Take remedial action such 
  ' as limiting points at which modifications will be made.
End If

Similarly, to learn whether you can change the magnitude of the effect dynamically, perform the following check:

if Not (params And DIEP_TYPESPECIFICPARAMS)
   ' Can't change type-specific parameters dynamically.
End If 

Now you wish to modify the effect each time the device has been polled for input and the iron ball has moved. Let's presume that you have calculated the new magnitude in CurrentMag and the new direction (in degrees) in CurrentBearing. In order to make the necessary changes, you need to initialize only those members of DIEFFECT that are relevant.

EffectInfo.constantForce.lMagnitude = CurrentMag
EffectInfo.x = CurrentBearing * 100

You now pass the DIEFFECT type to DirectInputEffect.SetParameters along with flags indicating which members contain valid data:

di_effect.SetParameters(EffectInfo, _
        DIEP_DIRECTION Or DIEP_TYPESPECIFICPARAMS)

The DIEP_TYPESPECIFICPARAMS flag indicates that any member containing information particular to that type of effect is valid. In the case of a constant force, this means the constantForce member.