//-----------------------------------------------------------------------------
// Purpose: Alien Swarm camera yaw.
//-----------------------------------------------------------------------------
float CASWInput::ASW_GetCameraYaw( const float *pfDeathCamInterp /*= NULL*/ )
{
	float fDeathCamInterp;
	if ( pfDeathCamInterp )
	{
		fDeathCamInterp = *pfDeathCamInterp;
	}
	else
	{
		fDeathCamInterp = ( ASWGameRules() ? ASWGameRules()->GetMarineDeathCamInterp() : 0.0f );
	}

	if ( fDeathCamInterp > 0.0f )
	{
		float fRotate = gpGlobals->curtime * asw_cam_marine_yaw_death_rate.GetFloat() + ASWGameRules()->m_fDeathCamYawAngleOffset;
		float fFullRotations = static_cast< int >( fRotate / 360.0f );
		fRotate -= fFullRotations * 360.0f;

		fRotate = AngleNormalize( fRotate );

		return ( 1.0f - fDeathCamInterp ) * asw_cam_marine_yaw.GetFloat() + fDeathCamInterp * ( asw_cam_marine_yaw.GetFloat() + fRotate );
	}

	// Check to see if we are in a camera volume.
	C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if (pPlayer && pPlayer->GetMarine())
	{
		C_ASW_Camera_Volume *pCameraVolume = C_ASW_Camera_Volume::IsPointInCameraVolume( pPlayer->GetMarine()->GetAbsOrigin() );
		if ( pCameraVolume )
		{
			m_fCurrentBlendCamYaw = ASW_ClampYaw( asw_cam_marine_yaw_rate.GetFloat(), m_fCurrentBlendCamYaw, pCameraVolume->m_fCameraYaw, MIN( 0.2f, gpGlobals->frametime ) );
		}
		else
		{
			m_fCurrentBlendCamYaw = ASW_ClampYaw( asw_cam_marine_yaw_rate.GetFloat(), m_fCurrentBlendCamYaw, asw_cam_marine_yaw.GetFloat(), MIN( 0.2f, gpGlobals->frametime ) );
		}
		if ( m_flLastYawSend + 0.2f < gpGlobals->curtime || m_flLastYawSend > gpGlobals->curtime )
		{
			m_flLastYawSend = gpGlobals->curtime;
			char buf[32];
			Q_snprintf( buf, sizeof( buf ), "cl_aswcamerayaw %f\n", m_fCurrentBlendCamYaw );
			engine->ServerCmd( buf, false );
		}
	}

	return m_fCurrentBlendCamYaw;
}
void CASW_Simple_Alien::UpdateYaw(float delta)
{
	// don't allow turning in the air
	if (!m_bOnGround)
		return;
	float current = UTIL_AngleMod( GetLocalAngles().y );
	float ideal = UTIL_AngleMod( GetIdealYaw() );
	
	float dt = MIN( 0.2, delta );	
	float newYaw = ASW_ClampYaw( GetYawSpeed(), current, ideal, dt );
		
	if (newYaw != current)
	{
		QAngle angles = GetLocalAngles();
		angles.y = newYaw;
		SetLocalAngles( angles );
	}
}
//-----------------------------------------------------------------------------
// Purpose: Alien Swarm camera pitch.
//-----------------------------------------------------------------------------
float CASWInput::ASW_GetCameraPitch( const float *pfDeathCamInterp /*= NULL*/ )
{
	// Get the given pitch.
	float flPitch = asw_cam_marine_pitch.GetFloat();

	// Check to see if we are in a camera volume.
	C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if (pPlayer && pPlayer->GetMarine())
	{
		C_ASW_Camera_Volume *pCameraVolume = C_ASW_Camera_Volume::IsPointInCameraVolume( pPlayer->GetMarine()->GetAbsOrigin() );
		if ( pCameraVolume )
		{
			flPitch = pCameraVolume->m_fCameraPitch;
		}
	}

	float fDeathCamInterp;
	if ( pfDeathCamInterp )
	{
		fDeathCamInterp = *pfDeathCamInterp;
	}
	else
	{
		fDeathCamInterp = ( ASWGameRules() ? ASWGameRules()->GetMarineDeathCamInterp() : 0.0f );
	}

	if ( fDeathCamInterp > 0.0f )
	{
		flPitch = ( 1.0f - fDeathCamInterp ) * flPitch + fDeathCamInterp * asw_cam_marine_pitch_death.GetFloat();
	}

	if ( m_fCurrentCameraPitch != flPitch )
	{
		float flDelta = MIN( 0.2f, gpGlobals->frametime );
		m_fCurrentCameraPitch = ASW_ClampYaw( asw_cam_marine_pitch_rate.GetFloat(), m_fCurrentCameraPitch, flPitch, flDelta );
	}

	return m_fCurrentCameraPitch;
}