Platform SDK: DirectX |
This topic pertains only to application development in Visual Basic. See DirectInput C/C++ Tutorials.
Let's suppose that in your application you wish to simulate the pull of a stationary object (say a magnet) on a movable object (say an iron ball) controlled by the joystick. At the beginning of the simulation, the iron ball is due south of the magnet and experiencing one-half the maximum possible pull.
You will simulate the pull of the magnet by a constant force. First you set up the DIEFFECT type that describes the force:
Dim EffectInfo as DIEFFECT With EffectInfo .constantForce.lMagnitude = 5000 .lDuration = -1 ' Infinite .x = 18000 .lGain = 10000 ' Play at full magnitude .lTriggerButton = -1 ' No trigger button End With
All the other members of DIEFFECT are either not relevant to a constant force or are valid as 0.
Now create the effect:
Dim di_effect As DirectInputEffect Set di_effect = didev.CreateEffect("GUID_ConstantForce", EffectInfo)
If the device is in an acquired state at this time, the effect is automatically downloaded. If not, the effect will be downloaded when it is started.
di_effect.Start(1, 0)
Only one iteration of the effect is needed, since it has infinite duration, and no flags are required in this case.
Next: Step 4: Modify an Effect