Esempio n. 1
0
void CCamera::Update(float ftDelta)
{
	SRotator  Rot = this->Location().Rotation;

	if(m_bImpact)
	{
		if(m_ftElapsedTime < m_ftImpactTime/2.0f)
		{
			m_vctTargetEye = m_vctTargetEye*m_ftElapsedTime + m_vctCurrentEye*(m_ftImpactTime/2.0f-m_ftElapsedTime);
			m_vctTargetEye *= m_ftImpactTime/2.0f;
		}
		else
		{
			m_vctTargetEye = m_vctTargetEye*(m_ftElapsedTime-m_ftImpactTime/2.0f) + m_vctCurrentEye*(m_ftImpactTime-m_ftElapsedTime);
			m_vctTargetEye *= m_ftImpactTime/2.0f;
		}
	}
	
	float ftVelocityEye = 10.0f;
	
	SVector vctDelta = m_vctTargetEye - m_vctCurrentEye;

	if(vctDelta.Size2D() < ftDelta * ftVelocityEye)
	{
		m_vctCurrentEye = m_vctTargetEye;
	}
	else
	{
		vctDelta.Normalize();
		m_vctCurrentEye = m_vctCurrentEye + vctDelta * ftDelta * ftVelocityEye;
	}

	m_vctCurrentEye = m_vctTargetEye;

	if(m_bJerk)
	{		
		// if(((int)(m_fFlashTime * 5.0f)) % 2 == 0)
		SVector vctDelta = m_vctCurrentEye - m_vctCurrentAt;
		m_vctCurrentAt.Y += float(rand()%10-5)/10.0f * m_ftJerk * vctDelta.Size() / 20.0f;
	}

	CreateLookAt(m_vctCurrentEye, m_vctCurrentAt, SVector(0.0f, 1.0f, 0.0f));
}
Esempio n. 2
0
void CCamera::Tick(float ftDelta)
{
	if(m_bImpact)
	{
		m_ftElapsedTime += ftDelta;
		if(m_ftElapsedTime > m_ftImpactTime)
		{
			m_bImpact = false;
		}
		else
		{
			if(m_pImpactCharacter)
			{
				m_vctTargetAt = m_pImpactCharacter->GetLocation()->Location;
				m_vctTargetAt.Y = m_ftFocusHeight;
				if(m_ftElapsedTime < m_ftImpactTime/2.0f)
				{
					m_vctTargetAt = m_vctTargetAt*m_ftElapsedTime + m_vctCurrentAt*(m_ftImpactTime/2.0f-m_ftElapsedTime);
					m_vctTargetAt *= m_ftImpactTime/2.0f;
				}
				else
				{
					m_vctTargetAt = m_vctTargetAt*(m_ftElapsedTime-m_ftImpactTime/2.0f) + m_vctCurrentAt*(m_ftImpactTime-m_ftElapsedTime);
					m_vctTargetAt *= m_ftImpactTime/2.0f;
				}
			}
		}
	}
	else
	{
		if(m_pCharacter&&m_pBall&&m_pRim)
		{
			SVector vctRim(0.0f, 0.0f, 0.0f);

			vctRim.X = m_pRim->X;
			if(vctRim.X > 0)
			{
				vctRim.X += m_ftRimOffset;
			}
			else
			{
				vctRim.X -= m_ftRimOffset;
			}

			SVector vctBall = m_pBall->GetLocation()->Location;
			SVector vctChar = m_pCharacter->GetLocation()->Location;

			if(m_pBall->Ani())
			{
				vctBall = m_pBall->GetCharacter()->GetLocation()->Location;
			}

			m_vctTargetAt = (m_ftRatioChar*vctChar+m_ftRatioBall*vctBall+m_ftRatioRim*vctRim)/
				(m_ftRatioChar+m_ftRatioBall+m_ftRatioRim);
			m_vctTargetAt.Y = m_ftFocusHeight;
		}
	}

	float ftVelocityAt = 5.0f;

	SVector vctDelta = m_vctTargetAt - m_vctCurrentAt; 
	
	if(vctDelta.Size2D() < ftDelta*ftVelocityAt)
	{
		m_vctCurrentAt = m_vctTargetAt;
	}
	else
	{
		vctDelta.Normalize();
		m_vctCurrentAt = m_vctCurrentAt + vctDelta * ftDelta * ftVelocityAt;
	}
	
	//	m_vctCurrentAt = m_vctTargetAt;
	m_bJerk = false;
	if(m_ftJerk > 0.0f)
	{
		for(int i=0; i<30; i++)
		{
			if( m_ftJerk-ftDelta < 0.03*i && m_ftJerk > 0.03*i )
			{
				m_bJerk = true;
			}
		}
		m_ftJerk -= ftDelta;
	}
}