Share via


Step 6: Changing an Effect

Next, you modify the effect to simulate the slowing down of the engine as the saw bites into wood. DirectInput enables you to modify the parameters of an effect while it is playing.

To change the effect, set up a new DIEFFECT structure or have access to the one you used to create the effect. If you are setting up a new structure with local scope, initialize only the dwSize member and any members that contain or point to data that is to be changed.

In this case, you want to change a type-specific parameter - the period of the effect - so you need to have access to the DIPERIODIC structure you used when creating the effect. Alternatively, you can create a local copy with all members initialized. Make sure that the address of the DIPERIODIC structure is in the lpvTypeSpecificParams member of the DIEFFECT structure.

First, set the new period of the effect.

diPeriodic.dwPeriod = (DWORD)(0.08 * DI_SECONDS); 

Next, call the IDirectInputEffect::SetParameters method to make the changes.

hr = g_lpdiEffect->SetParameters(&diEffect, DIEP_TYPESPECIFICPARAMS);

Note the DIEP_TYPESPECIFICPARAMS flag that restricts the changes to a single member of the DIEFFECT structure.

You can control the way changes are handled by using other flags. For example, by using the DIEP_NODOWNLOAD flag you could change the parameters immediately after starting the effect but delay the implementation until a specific call to the IDirectInputEffect::Download method. For more information concerning use of the various control flags, see IDirectInputEffect::SetParameters.

For additional DirectInput tutorials, see DirectInput Tutorials.