From 35e51e7ce6f4fce2feb55f22c38c0d90cebb493b Mon Sep 17 00:00:00 2001 From: fruitiex Date: Sat, 12 Sep 2009 09:52:05 +0000 Subject: [PATCH] CSQC accelerometer! Please test (cl_showacceleration 1) git-svn-id: svn://svn.icculus.org/nexuiz/trunk@7744 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/defaultNexuiz.cfg | 8 ++++++++ data/qcsrc/client/View.qc | 2 ++ data/qcsrc/client/sbar.qc | 40 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/data/defaultNexuiz.cfg b/data/defaultNexuiz.cfg index 5ae45650c..21021fdd0 100644 --- a/data/defaultNexuiz.cfg +++ b/data/defaultNexuiz.cfg @@ -1588,6 +1588,14 @@ seta cl_showspeed_z 0 "include the speed on the Z-axis" seta cl_showspeed_size 14 "size of the numbers" seta cl_showspeed_position 0.7 "Y-axis positioning of the numbers" +seta cl_showacceleration 0 "show the XY acceleration of the player" +seta cl_showacceleration_z 0 "include the speed on the Z-axis" +seta cl_showacceleration_size 40 "height of the bar" +seta cl_showacceleration_scale 1 "X-axis scale of the bar" +seta cl_showacceleration_alpha 0.5 "alpha of the bar" +seta cl_showacceleration_color "1 0 0" "color of the bar" +seta cl_showacceleration_position 0.6 "Y-axis positioning of the bar" + set g_jetpack 0 "Jetpack mutator (uses the hook's button, can't coexist with the offhand hook, but only with the onhand one)" set g_jetpack_antigravity 0.8 "factor of gravity compensation of the jetpack" set g_jetpack_acceleration_side 1200 "acceleration of the jetpack in xy direction" diff --git a/data/qcsrc/client/View.qc b/data/qcsrc/client/View.qc index a87661ae8..11cea2137 100644 --- a/data/qcsrc/client/View.qc +++ b/data/qcsrc/client/View.qc @@ -554,6 +554,8 @@ void CSQC_UpdateView(float w, float h) if (cvar("cl_showspeed")) Sbar_ShowSpeed(); + if (cvar("cl_showacceleration")) + Sbar_ShowAcceleration(); Sbar_DrawCenterPrint(); // draw centerprint messages even if viewsize >= 120 } diff --git a/data/qcsrc/client/sbar.qc b/data/qcsrc/client/sbar.qc index 3b4d141cd..41e33f883 100644 --- a/data/qcsrc/client/sbar.qc +++ b/data/qcsrc/client/sbar.qc @@ -1913,6 +1913,46 @@ void Sbar_ShowSpeed(void) drawstringcenter('1 0 0' + pos * '0 1 0', speed, numsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); } +float acc_avgspeeds = 10; // amount of frames' speeds to average, increasing this value makes the meter smoother but less responsive +float prev_speed[acc_avgspeeds]; + +void Sbar_ShowAcceleration(void) +{ + float acceleration, avgspeed, size, scale, alpha, i; + vector pos, top, color; + top_x = vid_conwidth/2; + top_y = 0; + + size = cvar("cl_showacceleration_size"); + scale = cvar("cl_showacceleration_scale"); + alpha = cvar("cl_showacceleration_alpha"); + color = stov(cvar_string("cl_showacceleration_color")); + + for(i=0;i<=acc_avgspeeds;i+=1) + avgspeed += prev_speed[i]; + avgspeed /= acc_avgspeeds; + + if (cvar("cl_showacceleration_z") == 1) + acceleration = vlen(pmove_vel) - avgspeed; + else + acceleration = vlen(pmove_vel - pmove_vel_z * '0 0 1') - avgspeed; + + for (i=acc_avgspeeds;i>=1;i-=1) + prev_speed[i] = prev_speed[i-1]; + + if (cvar("cl_showacceleration_z") == 1) + prev_speed[0] = vlen(pmove_vel); + else + prev_speed[0] = vlen(pmove_vel - pmove_vel_z * '0 0 1'); + + pos = top - size/2 * '0 1 0' + (cvar("cl_showacceleration_position") * vid_conheight) * '0 1 0'; + + if (acceleration >= 0) + drawfill(pos, acceleration * scale * '10 0 0' + size * '0 1 0', color, alpha, DRAWFLAG_NORMAL); + else + drawfill(pos + acceleration * scale * '10 0 0', -acceleration * scale * '10 0 0' + size * '0 1 0', color, alpha, DRAWFLAG_NORMAL); +} + void Sbar_DrawAccuracyStats_Description_Hitscan(vector position) { drawstring(position + '0 3 0' * sbar_fontsize_y, "Shots fired:", sbar_fontsize, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); -- 2.39.2