Sign in to follow this  
FlyinDeath

Delay of force feedback in DirectInput

Recommended Posts

FlyinDeath    122
I have copied and pasted the sample code in the force feedback tutorial in MSDN, but there was a 1-second delay every time I started the effect. And, in debug mode, the force feedback effect didn't even respond. Only in release mode did the force feedback work. The code looks like this:
	void CControl::InitializeForceFeedback(HWND hWnd)
	{
		HRESULT hr;

		//enumerate force feedback device
		pDirectInput8->EnumDevices(DI8DEVCLASS_GAMECTRL, Callbacks::EnumerateForceFeedback, NULL, DIEDFL_FORCEFEEDBACK | DIEDFL_ATTACHEDONLY);

		//check if a force feedback device is availible
		if(!pForceFeedback)
			return;

		//initialize the force feedback device
		hr = pForceFeedback->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
		if (FAILED(hr))
			return;

		hr = pForceFeedback->SetDataFormat(&c_dfDIJoystick);
		if (FAILED(hr))
			return;

		pForceFeedback->Acquire();

		pForceFeedback->SendForceFeedbackCommand(DISFFC_RESET);

		InitializeForceEffect();
	}


	void CControl::InitializeForceEffect(void)
	{
		//check if a force feedback device is availible
		if(!pForceFeedback)
			return;

		DWORD      dwAxes[2] = {DIJOFS_X, DIJOFS_Y};
		LONG       lDirection[2] = {0, 0};

		DIPERIODIC diPeriodic;      // type-specific parameters
		DIENVELOPE diEnvelope;      // envelope
		DIEFFECT   diEffect;        // general parameters

		diPeriodic.dwMagnitude = DI_FFNOMINALMAX; 
		diPeriodic.lOffset = 0; 
		diPeriodic.dwPhase = 0; 
		diPeriodic.dwPeriod = (DWORD)(0.025 * DI_SECONDS); 
		 

		diEnvelope.dwSize = sizeof(DIENVELOPE);
		diEnvelope.dwAttackLevel = DI_FFNOMINALMAX; 
		diEnvelope.dwAttackTime = (DWORD)(0.5 * DI_SECONDS); 
		diEnvelope.dwFadeLevel = 0; 
		diEnvelope.dwFadeTime = (DWORD)(3.0 * DI_SECONDS); 

		diEffect.dwSize = sizeof(DIEFFECT); 
		diEffect.dwFlags = DIEFF_POLAR | DIEFF_OBJECTOFFSETS; 
		diEffect.dwDuration = (DWORD)(3 * DI_SECONDS);

		diEffect.dwSamplePeriod = 0;               // = default 
		diEffect.dwGain = DI_FFNOMINALMAX;         // no scaling
		diEffect.dwTriggerButton = DIEB_NOTRIGGER;
		diEffect.dwTriggerRepeatInterval = 0;      
		diEffect.cAxes = 2; 
		diEffect.rgdwAxes = dwAxes; 
		diEffect.rglDirection = &lDirection[0]; 
		diEffect.lpEnvelope = &diEnvelope; 
		diEffect.cbTypeSpecificParams = sizeof(diPeriodic);
		diEffect.lpvTypeSpecificParams = &diPeriodic;  

		HRESULT hr = pForceFeedback->CreateEffect(
							GUID_Triangle,     // GUID from enumeration
							&diEffect,      // where the data is
							&pEffect,  // where to put interface pointer
							NULL);          // no aggregation

		pConstantForce->Download();
	}


	void CControl::PlayEffect(void)
	{
		HRESULT hr;

		if(pEffect)
			hr = pEffect->Start(1, NULL);
	}


What could be the possible problem? [Edited by - FlyinDeath on March 15, 2006 11:07:31 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this