Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


DirectInput: CreateEffect Force Feedback

This topic is 5759 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m not able to get the CreateEffect method of the directinputdevice8 interface to work. It doesn''t seem to load the effect to the device. I''m using a Microsoft Sidewinder Pro FF. I''m using this code and I get the pointer effect == NULL. I read that the device could be full of effects but it should reset when you create a new anyway. Anyone know? private: iObjectRegistry* object_reg; LPDIRECTINPUT8 di; HRESULT hr; LPDIRECTINPUTDEVICE8 joystick; GUID guidEffect; int nbr; LPDIRECTINPUTEFFECT effect; bool csForceFeedback::loadEffect(){ hr = joystick->Poll(); if (FAILED(hr)) { hr = joystick->Acquire(); while(hr == DIERR_INPUTLOST) hr = joystick->Acquire(); } DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; LONG rglDirection[2] = { 0, 0 }; DICONSTANTFORCE cf = { 0 }; DIEFFECT eff; ZeroMemory( &eff, sizeof(eff) ); eff.dwSize = sizeof(DIEFFECT); eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; eff.dwDuration = INFINITE; eff.dwSamplePeriod = 0; eff.dwGain = DI_FFNOMINALMAX; eff.dwTriggerButton = DIEB_NOTRIGGER; eff.dwTriggerRepeatInterval = 0; eff.cAxes = 2; eff.rgdwAxes = rgdwAxes; eff.rglDirection = rglDirection; eff.lpEnvelope = 0; eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE); eff.lpvTypeSpecificParams = &cf; eff.dwStartDelay = 0; // Create the prepared effect if( FAILED( hr = joystick->CreateEffect( GUID_ConstantForce, &eff, &effect, NULL ) ) ) { csPrintf("Couldn''t create effect\n"); } if( NULL == effect ) { csPrintf("NULL"); return false; } return true; } BOOL CALLBACK csForceFeedback::EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, VOID* pContext) { csForceFeedback *self = (csForceFeedback *)pContext; HRESULT hr; // Obtain an interface to the enumerated joystick. hr = self->di->CreateDevice(pdidInstance->guidInstance, &self->joystick, NULL); if(FAILED(hr)) return DIENUM_CONTINUE; // Set cooperative level. hr = self->joystick->SetCooperativeLevel(NULL, DISCL_EXCLUSIVE | DISCL_FOREGROUND); if (FAILED(hr)) return hr; // set game data format hr = self->joystick->SetDataFormat(&c_dfDIJoystick); if (FAILED(hr)) return hr; //Turn off autocenter DIPROPDWORD DIPropAutoCenter; DIPropAutoCenter.diph.dwSize = sizeof(DIPropAutoCenter); DIPropAutoCenter.diph.dwHeaderSize = sizeof(DIPROPHEADER); DIPropAutoCenter.diph.dwObj = 0; DIPropAutoCenter.diph.dwHow = DIPH_DEVICE; DIPropAutoCenter.dwData = DIPROPAUTOCENTER_OFF; hr = self->joystick->SetProperty(DIPROP_AUTOCENTER, &DIPropAutoCenter.diph); if (FAILED(hr)) { // Handle the failure as appropriate csPrintf("Could not turn off autocenter!"); } return DIENUM_STOP; } And this among other things is called in a init() method if( FAILED( hr = di->EnumDevices( DI8DEVCLASS_GAMECTRL,EnumJoysticksCallback, (void*) this, DIEDFL_FORCEFEEDBACK | DIEDFL_ATTACHEDONLY) ) ) { csPrintf("Force feedback device not found!\n"); return false; }

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!