Exemple #1
0
void Controller::InterpolateValue(FadeState *pState, float t)
{
	float newAlpha, r, g, b, a;
    LTVector newColor, destColor;
    uint32 i;

	if(m_ParamType == Param_Alpha)
	{
		// Alpha.
        newAlpha = LTLERP(pState->m_StartVal.GetAlpha(), m_DestValue.GetAlpha(), t);
        g_pLTServer->GetObjectColor(pState->m_hTarget, &r, &g, &b, &a);
        g_pLTServer->SetObjectColor(pState->m_hTarget, r, g, b, newAlpha);
	}
	else
	{
		// Color.
		destColor = m_DestValue.GetColor();
		for(i=0; i < 3; i++)
		{
			if(destColor[i] == -1.0f)
				newColor[i] = pState->m_StartVal.m_Color[i];
			else
                newColor[i] = LTLERP(pState->m_StartVal.m_Color[i], m_DestValue.m_Color[i], t);
		}

        g_pLTServer->GetObjectColor(pState->m_hTarget, &r, &g, &b, &a);
        g_pLTServer->SetObjectColor(pState->m_hTarget,
			newColor.x / 255.0f,
			newColor.y / 255.0f,
			newColor.z / 255.0f,
			a);
	}
}
Exemple #2
0
void d3d_InitViewBox2(ViewBoxDef *pDef, 
	float nearZ, float farZ,
	const ViewParams&  PrevParams,
	float screenMinX, float screenMinY, 
	float screenMaxX, float screenMaxY)
{
	// Get the extents of the previous view frustum's view window.
	float xMinPrev = PrevParams.m_ViewBox.m_COP.x - PrevParams.m_ViewBox.m_WindowSize[0];
	float yMinPrev = -PrevParams.m_ViewBox.m_COP.y - PrevParams.m_ViewBox.m_WindowSize[1];
	float xMaxPrev = PrevParams.m_ViewBox.m_COP.x + PrevParams.m_ViewBox.m_WindowSize[0];
	float yMaxPrev = -PrevParams.m_ViewBox.m_COP.y + PrevParams.m_ViewBox.m_WindowSize[1];
	
	// Get the percents.
	float xMin = (screenMinX - (float)PrevParams.m_Rect.left) / (float)(PrevParams.m_Rect.right - PrevParams.m_Rect.left);
	float yMin = (screenMinY - (float)PrevParams.m_Rect.top) / (float)(PrevParams.m_Rect.bottom - PrevParams.m_Rect.top);
	float xMax = (screenMaxX - (float)PrevParams.m_Rect.left) / (float)(PrevParams.m_Rect.right - PrevParams.m_Rect.left);
	float yMax = (screenMaxY - (float)PrevParams.m_Rect.top) / (float)(PrevParams.m_Rect.bottom - PrevParams.m_Rect.top);

	// Note: Y is negated here because we're going from screen to world space.

	// Translate them into our COP space.
	xMin = LTLERP(xMinPrev, xMaxPrev, xMin);
	yMin = -LTLERP(yMinPrev, yMaxPrev, yMin);
	xMax = LTLERP(xMinPrev, xMaxPrev, xMax);
	yMax = -LTLERP(yMinPrev, yMaxPrev, yMax);
	
	pDef->m_NearZ			= nearZ;
	pDef->m_FarZ			= farZ;
	pDef->m_COP.z			= 1.0f;			 
	pDef->m_COP.x			= (xMin + xMax) * 0.5f;
	pDef->m_COP.y			= (yMin + yMax) * 0.5f;
	pDef->m_WindowSize[0]	= (xMax - xMin) * 0.5f;
	pDef->m_WindowSize[1]	= -(yMax - yMin) * 0.5f;
}
Exemple #3
0
void Prop::UpdateFade()
{
	if( !m_bFading )
	{
		return;
	}

	bool bDone = false;
	float fCurTime = g_pLTServer->GetTime();

	// Update the fade if the delay has past...

	if( m_fFadeStartTime <= fCurTime )
	{
		float t = (fCurTime - m_fFadeStartTime) / m_fFadeDuration;
		float fAlpha = Clamp( LTLERP( m_fStartAlpha, m_fEndAlpha, t ), 0.0f, 1.0f );

		float r, g, b, a;
		g_pLTServer->GetObjectColor( m_hObject, &r, &g, &b, &a );
		g_pLTServer->SetObjectColor( m_hObject, r, g, b, fAlpha );

		float fDiff = (float)fabs( m_fEndAlpha - fAlpha );

		if( fDiff <= MATH_EPSILON )
			bDone = true;
	}

	if( bDone )
	{
		if( m_bFadeRemoveWhenDone )
		{
			g_pLTServer->RemoveObject( m_hObject ); 
		}

		m_bFading = false;
	}
	else
	{
		// The fade is not done yet so keep updating...

		SetNextUpdate(UPDATE_NEXT_FRAME);
	}
}
Exemple #4
0
void HeadBobMgr::Update( float fFrameTime )
{
	// Skip this if the game is paused, or we have no record data to use...
	if( !m_hRecord || ( GetScale() <= 0.0f ) )
	{
		return;
	}

	// See if we're using debug console commands instead of the record data
	bool bDebug = ( g_vtHeadBobDebugMode.GetFloat() != 0.0f );

	// Update the cycle position
	if( m_fSpeed <= 0.0f )
	{
		m_fCyclePosition = 0.0f;
	}
	else
	{
		float fSpeedScale = ( bDebug ? g_vtHeadBobSpeedScale.GetFloat() : m_fSpeedScale );
		if (g_pMoveMgr)
		{
			fSpeedScale *= g_pMoveMgr->GetDamageMovementMultiplier();
		}
		float fPrevPosition = m_fCyclePosition;

		m_fCyclePosition += ( m_fSpeed * fSpeedScale * fFrameTime * m_fCycleDirection );

		// Do our custom callback if we have one
		if( m_pCustomCycleNotifyFn )
		{
			bool bCrossBoundary = false;
			bool bMaxExtent, bApproachFromCenter;

			// Crossing upper boundary from center...
			if( ( fPrevPosition <= m_fCustomCycleNotifyRange ) && ( m_fCyclePosition > m_fCustomCycleNotifyRange ) )
			{
				bCrossBoundary = true;
				bMaxExtent = true;
				bApproachFromCenter = true;
			}
			// Crossing upper boundary from edge...
			else if( ( fPrevPosition >= m_fCustomCycleNotifyRange ) && ( m_fCyclePosition < m_fCustomCycleNotifyRange ) )
			{
				bCrossBoundary = true;
				bMaxExtent = true;
				bApproachFromCenter = false;
			}
			// Crossing lower boundary from center...
			else if( ( fPrevPosition >= -m_fCustomCycleNotifyRange ) && ( m_fCyclePosition < -m_fCustomCycleNotifyRange ) )
			{
				bCrossBoundary = true;
				bMaxExtent = false;
				bApproachFromCenter = true;
			}
			// Crossing lower boundary from edge...
			if( ( fPrevPosition <= -m_fCustomCycleNotifyRange ) && ( m_fCyclePosition > -m_fCustomCycleNotifyRange ) )
			{
				bCrossBoundary = true;
				bMaxExtent = false;
				bApproachFromCenter = false;
			}

			// Execute the callback
			if( bCrossBoundary )
			{
				( *m_pCustomCycleNotifyFn )( bMaxExtent, m_pCustomCycleNotifyUserData, bApproachFromCenter );
			}
		}

		// Handle changing directions of the cycle
		if( ( m_fCycleDirection == 1.0f ) && ( m_fCyclePosition > 1.0f ) )
		{
			m_fCyclePosition = ( 1.0f - ( m_fCyclePosition - 1.0f ) );
			m_fCycleDirection = -1.0f;

			if( m_pCycleNotifyFn )
			{
				( *m_pCycleNotifyFn )( true, m_pCycleNotifyUserData, true );
			}
		}
		else if( ( m_fCycleDirection == -1.0f ) && ( m_fCyclePosition < -1.0f ) )
		{
			m_fCyclePosition = ( -1.0f - ( m_fCyclePosition + 1.0f ) );
			m_fCycleDirection = 1.0f;

			if( m_pCycleNotifyFn )
			{
				( *m_pCycleNotifyFn )( false, m_pCycleNotifyUserData, true );
			}
		}
	}

	// Update the transition time
	if( m_fTransitionTime > 0.0f )
	{
		m_fTransitionTime -= fFrameTime;

		if( m_fTransitionTime < 0.0f )
		{
			m_fTransitionTime = 0.0f;
		}
	}

	// Adjust the headbob by the appropriate scaling factor...
	ClientDB &rClientDatabase = ClientDB::Instance( );
	HRECORD hIdle = rClientDatabase.GetRecord( rClientDatabase.GetHeadBobCategory( ), "Idle" );
	float fHeadBobMod = GetConsoleFloat( ((m_hRecord == hIdle) ? "IdleBreathing" : "HeadBob"), 1.0f );
	
	// Go through each element and update it
	float fDelta, fWave, fInterp;

	for( uint32 i = 0; i < HBE_COUNT; ++i )
	{
		float fWaveMin = ( bDebug ? g_vtHeadBobWaveMin[ i ].GetFloat() : m_aHBDRecord[ i ].m_vWave.x );
		float fWaveMax = ( bDebug ? g_vtHeadBobWaveMax[ i ].GetFloat() : m_aHBDRecord[ i ].m_vWave.y );
		float fAmplitude = ( bDebug ? g_vtHeadBobAmp[ i ].GetFloat() : m_aHBDRecord[ i ].m_vAmplitude.x );
		float fAmplitudeOffset = ( bDebug ? g_vtHeadBobAmpOffset[ i ].GetFloat() : m_aHBDRecord[ i ].m_vAmplitude.y );
		uint32 nFlags = ( bDebug ? ( uint32 )g_vtHeadBobFlags[ i ].GetFloat() : m_aHBDRecord[ i ].m_nFlags );

		// Calculate the current amplitude of this parameter
		if( ( m_fSpeed > 0.0f ) && ( fAmplitude != 0.0f ) )
		{
			fDelta = ( ( fWaveMax - fWaveMin ) * 0.5f );
			fWave = ( ( fWaveMin + fDelta ) + ( fDelta * m_fCyclePosition ) );

			if( nFlags & HeadBobElementData::HBEDF_SINE )
			{
				fWave = LTSin( fWave );
			}

			m_aAmpsActive[ i ] = ( fAmplitudeOffset + ( fWave * fAmplitude ) ) * fHeadBobMod;
		}
		else
		{
			m_aAmpsActive[ i ] = 0.0f;
		}

		// Handle transitioning...
		if( m_fTransitionTime > 0.0f )
		{
			fInterp = ( 1.0f - ( m_fTransitionTime / m_fTotalTransitionTime ) );
			m_aAmpsActive[ i ] = LTLERP( m_aAmpsTransFrom[ i ], m_aAmpsActive[ i ], fInterp );
		}
	}
}