Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
// Purpose: Moves the client pitch angle towards cl.idealpitch sent by the server.
// If the user is adjusting pitch manually, either with lookup/lookdown,
//   mlook and mouse, or klook and keyboard, pitch drifting is constantly stopped.
//-----------------------------------------------------------------------------
void CViewRender::DriftPitch (void)
{
	float		delta, move;

	C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
	if ( !player )
		return;

#if defined( REPLAY_ENABLED )
	if ( engine->IsHLTV() || g_pEngineClientReplay->IsPlayingReplayDemo() || ( player->GetGroundEntity() == NULL ) || engine->IsPlayingDemo() )
#else
	if ( engine->IsHLTV() || ( player->GetGroundEntity() == NULL ) || engine->IsPlayingDemo() )
#endif
	{
		m_PitchDrift.driftmove = 0;
		m_PitchDrift.pitchvel = 0;
		return;
	}

	// Don't count small mouse motion
	if ( m_PitchDrift.nodrift )
	{
		if ( fabs( input->GetLastForwardMove() ) < cl_forwardspeed.GetFloat() )
		{
			m_PitchDrift.driftmove = 0;
		}
		else
		{
			m_PitchDrift.driftmove += gpGlobals->frametime;
		}
	
		if ( m_PitchDrift.driftmove > v_centermove.GetFloat() )
		{
			StartPitchDrift ();
		}
		return;
	}
	
	// How far off are we
	delta = prediction->GetIdealPitch() - player->GetAbsAngles()[ PITCH ];
	if ( !delta )
	{
		m_PitchDrift.pitchvel = 0;
		return;
	}

	// Determine movement amount
	move = gpGlobals->frametime * m_PitchDrift.pitchvel;
	// Accelerate
	m_PitchDrift.pitchvel += gpGlobals->frametime * v_centerspeed.GetFloat();
	
	// Move predicted pitch appropriately
	if (delta > 0)
	{
		if ( move > delta )
		{
			m_PitchDrift.pitchvel = 0;
			move = delta;
		}
		player->SetLocalAngles( player->GetLocalAngles() + QAngle( move, 0, 0 ) );
	}
	else if ( delta < 0 )
	{
		if ( move > -delta )
		{
			m_PitchDrift.pitchvel = 0;
			move = -delta;
		}
		player->SetLocalAngles( player->GetLocalAngles() - QAngle( move, 0, 0 ) );
	}
}
void CGERadar::WorldToRadar( CGERadarContact *contact )
{
	// If we are out of range don't bother
	if ( !IsContactInRange( contact ) )
		return;

	C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
	if ( !pLocalPlayer )
		return;

	Vector vContact = GetContactPosition(contact);

	float x_diff = vContact.x - pLocalPlayer->GetAbsOrigin().x;
	float y_diff = vContact.y - pLocalPlayer->GetAbsOrigin().y;

	// Supply epsilon values to avoid divide-by-zero
	if(x_diff == 0.0f )
		x_diff = 0.001f;

	if(y_diff == 0.0f )
		y_diff = 0.001f;

	float fRadarRadius = m_flRadarDiameter * 0.500f;
	float fRange = GetRadarRange();
	float fScale = fRange >= 1.000f ? fRadarRadius / fRange : 0.000f;
	float dist = min( GetContactRange( vContact ), fRange );

	float flOffset = atan(y_diff/x_diff);
	float flPlayerY;

	// If we're in first person spectate mode we should use the rotation of whoever we're spectating.
	if (pLocalPlayer->IsObserver() && pLocalPlayer->GetObserverTarget() && pLocalPlayer->GetObserverMode() == OBS_MODE_IN_EYE)
		flPlayerY = (pLocalPlayer->GetLocalAngles().y * M_PI) * 0.0055555f;
	else
		flPlayerY = (pLocalPlayer->LocalEyeAngles().y * M_PI) * 0.0055555f;

	// Always add because atan will return neg angle w/ neg coeff
	if ( x_diff < 0 )
		flOffset += M_PI;
	else
		flOffset += M_TWOPI;

	flOffset = flPlayerY - flOffset;

	// Transform relative to radar source
	float xnew_diff = dist * sin(flOffset);
	float ynew_diff = -dist * cos(flOffset);

	// Scale the dot's position to match radar scale
	xnew_diff *= fScale;
	ynew_diff *= fScale;

	// Make sure we never leave our radar circle!
	contact->m_vScaledPos.x = fRadarRadius + xnew_diff + m_iSideBuff;
	contact->m_vScaledPos.y = fRadarRadius + ynew_diff + m_iSideBuff;
	contact->m_vScaledPos.z = vContact.z - pLocalPlayer->GetAbsOrigin().z;

	// Figure out our alpha modulation
	if ( !contact->m_bAlwaysVisible && dist > fRange * 0.8f )
		contact->m_flAlphaMod = RemapValClamped( dist, fRange * 0.8f, fRange, 1.0, 0 );
	else
		contact->m_flAlphaMod = 1.0f;
}