Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ForceFeedBack

Status
Not open for further replies.

tihobg

Programmer
Apr 2, 2007
1
BG
Hi
I'm working with SDK DirectX (August 2006) and Microsoft Visual Studio 6 C++. I'm trying to start force feedback of my joystick but I can't. I read joystick data. If somebody can help I'll be very happy. This is my code here:

BOOL WINAPI InitDirectInputJ()
{
HRESULT hr;
LPDIRECTINPUT g_pDI;
HANDLE hEvent;
DIDEVCAPS g_diDevCaps;
if( FAILED( hr = DirectInputCreate( hInst,
DIRECTINPUT_VERSION, &g_lpDI, NULL )))

return FALSE;

if( FAILED( hr = g_lpDI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumFFDevicesCallback, NULL, DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK)))
return FALSE;

if (FAILED(hr = g_lpJoystick->SetDataFormat(&c_dfDIJoystick)))
{
return FALSE;
}

if (FAILED(hr = g_lpJoystick->SetCooperativeLevel(hWndMain,
DISCL_EXCLUSIVE | DISCL_FOREGROUND)))
return FALSE;

DIPROPRANGE prop;
prop.diph.dwSize = sizeof(prop);
prop.diph.dwHeaderSize = sizeof(prop.diph);
prop.diph.dwObj = 0;
prop.diph.dwHow = DIPH_DEVICE;
prop.lMax = 100;
prop.lMin = -100;

if (FAILED(hr = g_lpJoystick->SetProperty(DIPROP_RANGE, &prop.diph)))
return FALSE;
DIDEVCAPS g_DevCaps;
g_DevCaps.dwSize = sizeof(DIDEVCAPS);

if (FAILED(hr = g_lpJoystick->GetCapabilities(&g_diDevCaps)))
return FALSE;

DIPROPDWORD AutoCenter;
AutoCenter.diph.dwSize = sizeof(AutoCenter);
AutoCenter.diph.dwHeaderSize = sizeof(DIPROPHEADER);
AutoCenter.diph.dwObj = 0;
AutoCenter.diph.dwHow = DIPH_DEVICE;
AutoCenter.dwData = DIPROPAUTOCENTER_OFF;
if (FAILED(hr = g_lpJoystick->SetProperty(DIPROP_AUTOCENTER, &AutoCenter.diph)))
return FALSE;

g_lpJoystick->Acquire();
DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y };
LONG rglDirection[2] = { 0, 0};

DICONSTANTFORCE cf = {1000};
g_dwNumForceFeedbackAxis = 2;
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 = g_dwNumForceFeedbackAxis;
eff.rgdwAxes = rgdwAxes;
eff.rglDirection = &rglDirection[0];
eff.lpEnvelope = 0;
eff.cbTypeSpecificParams = sizeof(DIRAMPFORCE);
eff.lpvTypeSpecificParams = &cf;

if (FAILED (hr = g_lpEffect->SetParameters(&eff, DIEP_DIRECTION | DIEP_TYPESPECIFICPARAMS | DIEP_START )))

return FALSE;

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top