Ejemplo n.º 1
0
void CHudSpeedMeter::OnThink()
{
    Vector velocity(0, 0, 0);
    C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
    if (player)
        velocity = player->GetLocalVelocity();
    SetDisplayValue((int)velocity.Length());
}
Ejemplo n.º 2
0
void CHudSpeedMeter::OnThink()
{
	Vector velocity(0, 0, 0);
	C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
	if (player) {
		velocity = player->GetLocalVelocity();

		// Remove the vertical component if necessary
		if (!speedmeter_hvel.GetBool())
		{
			velocity.z = 0;
		}

		//Conversions based on https://developer.valvesoftware.com/wiki/Dimensions#Map_Grid_Units:_quick_reference
		float vel = (float)velocity.Length();
		switch (speedmeter_units.GetInt())
		{
		case 1:
			//We do nothing but break out of the switch, as default vel is already in UPS
			SetLabelText(L"UPS");
			break;
		case 2:
			//1 unit = 19.05mm -> 0.01905m -> 0.00001905Km(/s) -> 0.06858Km(/h)
			vel = vel * 0.06858;
			SetLabelText(L"KM/H");
			break;
		case 3:
			//1 unit = 0.75", 1 mile = 63360. 0.75 / 63360 ~~> 0.00001184"(/s) ~~> 0.04262MPH 
			vel = vel * 0.04262;
			SetLabelText(L"MPH");
			break;
		default:
			//We do nothing but break out of the switch, as default vel is already in UPS
			SetLabelText(L"UPS");
			break;
		}
		//With this round we ensure that the speed is as precise as possible, insetad of taking the floor value of the float
		SetDisplayValue(round(vel));
	}
}