Archived

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

Locutus2

Force feedback in gamepads

Recommended Posts

I have a problem creating a constant force effect to my gamepad. This is the code I use :

DIEFFECT effect;
DICONSTANTFORCE constant;
constant.lMagnitude = 10000;

ZeroMemory(&effect, sizeof(DIEFFECT));

DWORD      dwAxes = DIJOFS_Z;
LONG       lDirection = 0;

effect.dwSize = sizeof(DIEFFECT);
effect.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
effect.dwDuration = 2*DI_SECONDS;

effect.dwSamplePeriod = 0;
effect.dwGain = 10000;
effect.dwTriggerButton = DIEB_NOTRIGGER;
effect.dwTriggerRepeatInterval = 0;      
effect.cAxes = 1; 
effect.rgdwAxes = &dwAxes; 
effect.rglDirection = &lDirection; 
effect.lpEnvelope = NULL; 
effect.cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
effect.lpvTypeSpecificParams = &constant;
effect.dwStartDelay = 0;

// create effect
HRESULT hr = _joystick->CreateEffect(GUID_ConstantForce,
	                             &effect,
			             &_effect, // var. to store effect
				     NULL);
 
After the CreateEffect call the hr is equal to DIERR_INVALI DPARAM. Since gamepads just have vibration motors, how do you know which axis and direction to set ?

Share this post


Link to post
Share on other sites
Not sure exactly, but it might be easier to just use the Force Editor and load those files. DirectInput will automatically adapt forces to work with the device.

Share this post


Link to post
Share on other sites