コード例 #1
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : effectnum - 
//			params - 
//-----------------------------------------------------------------------------
void CInput::ForceFeedback_Start( int effectnum, const FFBaseParams_t& params )
{
	if ( !m_pFF || !m_pFF->m_bForceFeedbackAvailable )
		return;

	// Unpause system...
	if ( m_pFF->m_bPaused )
	{
		ForceFeedback_Resume();
	}

	// look up the effect
	FORCEFEEDBACK_t effect = (FORCEFEEDBACK_t)effectnum;

	if ( effect < 0 || effect >= NUM_FORCE_FEEDBACK_PRESETS )
	{
		Assert( !"ForceFeedback_Start with bogus effectnum" );
		return;
	}

	EffectMap_t *map = &g_EffectMap[ effectnum ];

	vecEffectPtr_t *effects = map->pVecEffectPtr;


	// Play the effects on the device
	int c = effects->Count();
	for ( int i = 0; i < c; ++i )
	{
		LPDIRECTINPUTEFFECT pEffect = (*effects)[ i ];

		if ( !map->m_bDownloaded )
		{
			pEffect->Download();
			map->m_bDownloaded = true;
		}

		DWORD flags = DIEP_DIRECTION | DIEP_GAIN | DIEP_DURATION;

		LONG            rglDirection[2] = { 0, 100 };

		// Fill in parameters
		DIEFFECT effect;
		Q_memset( &effect, 0, sizeof( effect ) );
		effect.dwSize = sizeof( effect );
		effect.dwFlags = DIEFF_POLAR | DIEFF_OBJECTOFFSETS;
		effect.rglDirection = rglDirection;
		effect.cAxes = 2;

		HRESULT hr = pEffect->GetParameters( &effect, flags );
		if ( !FAILED( hr ) )
		{
			// If params.m_flDuration == 0.0f then that means use the duration in the file
			if ( params.m_flDuration <= -0.999f )
			{
				effect.dwDuration = INFINITE;
			}
			else if( params.m_flDuration >= 0.001f )
			{
				// Convert to microsseconds
				effect.dwDuration = (DWORD)( params.m_flDuration * 1000000.0f );
			}

			effect.dwGain = params.m_flGain * 10000.0f;
			effect.rglDirection[ 0 ] = 100.0f * params.m_flDirection;
			effect.rglDirection[ 1 ] = 0;

			hr = pEffect->SetParameters( &effect, flags );
			if ( !FAILED( hr ) )
			{
				pEffect->Start( 1, params.m_bSolo ? DIES_SOLO : 0 );
			}
		}
	}
}