Hi
Here is code for a simple speedometer display, much like the one ETPro has:
cg_draw.c right after the CG_DrawFPS function (which is around 469)
/*
==================
CG_DrawSpeedometer
==================
CHRUKER: Used ETPro to find the ratios
*/
#define SPEED_US_TO_KPH 15.58f
#define SPEED_US_TO_MPH 23.44f
static float CG_DrawSpeedometer( float y ) {
char *s;
int w;
static vec_t highestSpeed;
vec_t speed;
vec4_t timerBackground = { 0.16f, 0.2f, 0.17f, 0.8f };
vec4_t timerBorder = { 0.5f, 0.5f, 0.5f, 0.5f };
vec4_t tclr = { 0.625f, 0.625f, 0.6f, 1.0f };
speed = VectorLength(cg.predictedPlayerState.velocity);
if (speed > highestSpeed) {highestSpeed = speed;}
switch (cg_drawSpeedometer.integer) {
case 1: // Units per second
s = va("%.1f UPS", speed);
break;
case 10: // Units per second
s = va("%.1f UPS (%.1f UPS)", speed, highestSpeed);
break;
case 2: // Kilometers per hour
s = va("%.1f KPH", (speed / SPEED_US_TO_KPH));
break;
case 20: // Kilometers per hour
s = va("%.1f KPH (%.1f KPH)", (speed / SPEED_US_TO_KPH), (highestSpeed / SPEED_US_TO_KPH));
break;
case 3: // Miles per hour
s = va("%.1f MPH", (speed / SPEED_US_TO_MPH));
break;
case 30: // Miles per hour
s = va("%.1f MPH (%.1f MPH)", (speed / SPEED_US_TO_MPH), (highestSpeed / SPEED_US_TO_MPH));
break;
default:
s = "Set cg_drawSpeedometer to: 1 - Units per second, 2 - KPH, 3 - MPH. Use 10, 20 or 30 for max speed";
break;
}
w = CG_Text_Width_Ext( s, 0.19f, 0, &cgs.media.limboFont1 );
CG_FillRect( UPPERRIGHT_X - w - 2, y, w + 5, 12 + 2, timerBackground );
CG_DrawRect_FixedBorder( UPPERRIGHT_X - w - 2, y, w + 5, 12 + 2, 1, timerBorder );
CG_Text_Paint_Ext( UPPERRIGHT_X - w, y + 11, 0.19f, 0.19f, tclr, s, 0, 0, 0, &cgs.media.limboFont1 );
return y + 12 + 4;
}
cg_draw.c find the function CG_DrawUpperRight and change the bottom of it to match this:
if ( cg_drawFPS.integer ) {
y = CG_DrawFPS( y );
}
// CHRUKER: Speedometer
if ( cg_drawSpeedometer.integer ) {
y = CG_DrawSpeedometer( y );
}
if ( cg_drawSnapshot.integer ) {
y = CG_DrawSnapshot( y );
}
cg_main.c add this to the cvars
// CHRUKER: Features
vmCvar_t cg_drawSpeedometer; // Show a speedometer
and in the table
// CHRUKER: Features
{ &cg_drawSpeedometer, "cg_drawSpeedometer", "0", CVAR_ARCHIVE }, // Show a speedometer
cg_local.h add this to the cvars
// CHRUKER: Features
extern vmCvar_t cg_drawSpeedometer; // Show a speedometer
