![](http://images-20200215.ebookreading.net/11/4/4/9781568814773/9781568814773__a-hitchhikers-guide__9781568814773__bg1f7.png)
i
i
i
i
i
i
i
i
486 17. Programming Input and Force Feedback
static void CreateForceFeedbackEffects(LPDIRECTINPUTEFFECT
*
ppEffectC,
LPDIRECTINPUTEFFECT
*
ppEffectF,LPDIRECTINPUTEFFECT
*
ppEffectS,
LPDIRECTINPUTEFFECT
*
ppEffectPoke, LPDIRECTINPUTDEVICE8 pDevice){
DIEFFECT eff; // effect parameter structure
DIPROPDWORD dipdw;
HRESULT hr;
// set the effects to work in 2 dimensions (X Y)
DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y };
// set default values for the parameters of the forces - these will be
// changes as necessary
// consult DirectInput Manual for details.
LONG rglDirection[2] = { 0, 0 };
DICONSTANTFORCE cf = { 0 };
DICONDITION cd = { 0, 10000,10000,0, 0, 0 };
DICONDITION cd2[2] = { 0, 10000,10000,0, 0, 0, 0, 10000, 10000,
0, 0, 0};
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = FALSE;
// tell force to automatically center the joystick on startup
if(FAILED(hr=pDevice->SetProperty(DIPROP_AUTOCENTER, &dipdw.diph)))return;
// the "eff" structure shows typical settings for a constant force.
ZeroMemory( &eff, sizeof(eff) ); // constant force effect
eff.dwSize = sizeof(DIEFFECT);
eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
eff.dwDuration = INFINITE; // force continues indefinitely
eff.dwSamplePeriod = 0; // no time limit on force
eff.dwGain = DI_FFNOMINALMAX; // maximum force
eff.dwTriggerButton = DIEB_NOTRIGGER; // force is NOT triggered
eff.dwTriggerRepeatInterval = 0;
eff.cAxes = 2; // number of axes to get force
eff.rgdwAxes = rgdwAxes; // which axes
eff.rglDirection = rglDirection; // direction of force
eff.lpEnvelope = 0; // no - envelope constant force
eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
eff.lpvTypeSpecificParams = &cf;
eff.dwStartDelay = 0;
// create the effect using the "eff" effect structure - return
// pointer to effect
if(FAILED(hr=pDevice->CreateEffect(GUID_ConstantForce,&eff,ppEffectC,
NULL)))return;
..//
..// the other effects are set in a similar way.
// Consult the full project code for details
return;
}
Listing 17.5. Create a constant force effect that can be played out to a joystick device.