void CameraAdjustVar::UpdateVar(float fTimeDelta)
{
	if (fVar == 0.0f) return;

	// Figure out the direction we are going...

	if (m_fCurTime <= 0.0f)
	{
		if (fTime1 > 0.0f)
		{
			m_nDir = 1;
			m_fLastRealValue = 0.0f;
		}
		else if (fTime2 > 0.0f)
		{
			m_nDir = -1;
			m_fLastRealValue = fVar;
		}
		else
		{
			return;
		}
	}


	// Determine percent of time gone by...

	float fPercent = 0.0f;
	WaveType eType = eWave1;

	if (m_nDir == 1)
	{
		eType = eWave1;
		fPercent = m_fCurTime / fTime1;
		m_fRealValue = fVar * GetWaveFn(eType)(fPercent);
	}
	else
	{
		eType = eWave2;
		fPercent = m_fCurTime / fTime2;
		m_fRealValue = fVar - (fVar * GetWaveFn(eType)(fPercent));
	}


	// Set our variable value as an increment from the last value...

	if (bIncrement)
	{
		m_fValue = m_fRealValue - m_fLastRealValue;
		m_fLastRealValue = m_fRealValue;
	}
	else // Normal calculation...
	{
		m_fValue = m_fRealValue;
	}

    // g_pLTClient->CPrint("m_fValue = %.2f (in Deg = %.2f)", m_fValue, RAD2DEG(m_fValue));

	// Calculate new value...

	m_fCurTime += fTimeDelta;

	if (m_nDir == 1 && m_fCurTime > fTime1)
	{
		m_fCurTime = 0.0f;
		fTime1 = 0.0f;
	}
	else if (m_nDir == -1 && m_fCurTime > fTime2)
	{
		// We're done, so clear everything...

		Init();
	}
}
Exemple #2
0
void Controller::Update()
{
    uint32 i;
	FadeState *pState;
	float curTime, t;

	if(m_bFirstUpdate)
	{
		FirstUpdate();
        m_bFirstUpdate = LTFALSE;
	}

	if(m_State == CState_Fade)
	{
		// Find out if we're even interpolating.
        curTime = g_pLTServer->GetTime();
		if(curTime > (m_fStartTime + m_fDuration))
		{

			for(i=0; i < MAX_CONTROLLER_TARGETS; i++)
			{
				pState = &m_Fades[i];

				if(!pState->m_hTarget)
					continue;

				InterpolateValue(pState, 1.0f);
			}

			return;
		}

		t = (curTime - m_fStartTime) / m_fDuration;
		t = GetWaveFn(m_WaveType)(t); // Apply wave function.

		for(i=0; i < MAX_CONTROLLER_TARGETS; i++)
		{
			pState = &m_Fades[i];

			if(!pState->m_hTarget)
				continue;

			InterpolateValue(pState, t);
		}

		Activate();
	}
	else if(m_State == CState_Flicker)
	{
        if(g_pLTServer->GetTime() > m_fNextFlickerTime)
		{
			// Send the message.
			for(i=0; i < MAX_CONTROLLER_TARGETS; i++)
			{
				pState = &m_Fades[i];

				if(!pState->m_hTarget)
					continue;

                SendTriggerMsgToObject(this, pState->m_hTarget, LTFALSE, m_FlickerMsg);
			}

			// Go again?
			if(m_FlickerCounter != FLICKER_FOREVER)
				--m_FlickerCounter;

			if(m_FlickerCounter == 0)
				HandleOffCommand(CParsedMsg());

            m_fNextFlickerTime = g_pLTServer->GetTime() + GetRandom(m_fIntervalMin, m_fIntervalMax);
		}

		Activate();
	}
	else
	{
		Deactivate();
	}
}