From: divverent Date: Sun, 2 May 2010 14:08:23 +0000 (+0000) Subject: Weapon following: Subtract player velocity from gun origin rather than making the... X-Git-Tag: xonotic-v0.1.0preview~230^2~329 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a8b88dda9e6e91a74a5cd0eabf8e6deb88de9acd;p=xonotic%2Fdarkplaces.git Weapon following: Subtract player velocity from gun origin rather than making the gun follow the player. Reduces a huge code to a few lines and works much better. How could I not realize this until now? :P From: MirceaKitsune git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10148 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/darkplaces.txt b/darkplaces.txt index dff51333..798df506 100644 --- a/darkplaces.txt +++ b/darkplaces.txt @@ -407,11 +407,11 @@ cl_leanmodel_up 1 enables gu cl_leanmodel_up_speed 0.35 gun leaning upward speed cl_leanmodel_up_limit 25 gun leaning upward limit cl_followmodel_side 1 enables gun following sideways -cl_followmodel_side_speed 15 gun following sideways speed -cl_followmodel_side_limit 1 gun following sideways limit +cl_followmodel_side_speed 0.015 gun following sideways speed +cl_followmodel_side_limit 2 gun following sideways limit cl_followmodel_up 1 enables gun following upward -cl_followmodel_up_speed 10 gun following upward speed -cl_followmodel_up_limit 0.5 gun following upward limit +cl_followmodel_up_speed 0.01 gun following upward speed +cl_followmodel_up_limit 1.5 gun following upward limit cl_bobup 0.5 view bobbing adjustment that makes the up or down swing of the bob last longer cl_capturevideo 0 enables saving of video to a .avi file using uncompressed I420 colorspace and PCM audio, note that scr_screenshot_gammaboost affects the brightness of the output) cl_capturevideo_fps 30 how many frames per second to save (29.97 for NTSC, 30 for typical PC video, 15 can be useful) diff --git a/view.c b/view.c index e6bdf966..1ed91142 100644 --- a/view.c +++ b/view.c @@ -53,11 +53,11 @@ cvar_t cl_leanmodel_up_speed = {CVAR_SAVE, "cl_leanmodel_up_speed", "0.35", "gun cvar_t cl_leanmodel_up_limit = {CVAR_SAVE, "cl_leanmodel_up_limit", "25", "gun leaning upward limit"}; cvar_t cl_followmodel_side = {CVAR_SAVE, "cl_followmodel_side", "1", "enables gun following sideways"}; -cvar_t cl_followmodel_side_speed = {CVAR_SAVE, "cl_followmodel_side_speed", "15", "gun following sideways speed"}; -cvar_t cl_followmodel_side_limit = {CVAR_SAVE, "cl_followmodel_side_limit", "1", "gun following sideways limit"}; +cvar_t cl_followmodel_side_speed = {CVAR_SAVE, "cl_followmodel_side_speed", "0.015", "gun following sideways speed"}; +cvar_t cl_followmodel_side_limit = {CVAR_SAVE, "cl_followmodel_side_limit", "2", "gun following sideways limit"}; cvar_t cl_followmodel_up = {CVAR_SAVE, "cl_followmodel_up", "1", "enables gun following upward"}; -cvar_t cl_followmodel_up_speed = {CVAR_SAVE, "cl_followmodel_up_speed", "10", "gun following upward speed"}; -cvar_t cl_followmodel_up_limit = {CVAR_SAVE, "cl_followmodel_up_limit", "0.5", "gun following upward limit"}; +cvar_t cl_followmodel_up_speed = {CVAR_SAVE, "cl_followmodel_up_speed", "0.01", "gun following upward speed"}; +cvar_t cl_followmodel_up_limit = {CVAR_SAVE, "cl_followmodel_up_limit", "1.5", "gun following upward limit"}; cvar_t cl_viewmodel_scale = {0, "cl_viewmodel_scale", "1", "changes size of gun model, lower values prevent poking into walls but cause strange artifacts on lighting and especially r_stereo/vid_stereobuffer options where the size of the gun becomes visible"}; @@ -569,22 +569,10 @@ void V_CalcRefdef (void) VectorSet(gunangles, cl.viewmodel_push_x, cl.viewmodel_push_y, viewangles[2]); // gun model following code - if(cl_followmodel_side.value && cl_followmodel_side_speed.value * ef_speed < 1) // bad things happen if this goes over 1, so prevent the effect + if(cl_followmodel_side.value) { - vec_t d0 = vieworg[0] - cl.gunorg_follow[0]; - vec_t d1 = vieworg[1] - cl.gunorg_follow[1]; - d = sqrt(d0 * d0 + d1 * d1); - if(d > 0) - { - cl.gunorg_follow[0] = cl.gunorg_follow[0] + d0 * cl_followmodel_side_speed.value * ef_speed; - cl.gunorg_follow[1] = cl.gunorg_follow[1] + d1 * cl_followmodel_side_speed.value * ef_speed; - d *= (1 - cl_followmodel_side_speed.value * ef_speed); - if(d > cl_followmodel_side_limit.value) - { - cl.gunorg_follow[0] = vieworg[0] - (d0 / d) * cl_followmodel_side_limit.value; - cl.gunorg_follow[1] = vieworg[1] - (d1 / d) * cl_followmodel_side_limit.value; - } - } + cl.gunorg_follow[0] = vieworg[0] - bound(-cl_followmodel_side_limit.value, cl.movement_velocity[0] * cl_followmodel_side_speed.value, cl_followmodel_side_limit.value); + cl.gunorg_follow[1] = vieworg[1] - bound(-cl_followmodel_side_limit.value, cl.movement_velocity[1] * cl_followmodel_side_speed.value, cl_followmodel_side_limit.value); } else { @@ -592,13 +580,14 @@ void V_CalcRefdef (void) cl.gunorg_follow[1] = vieworg[1]; } - if(cl_followmodel_up.value && cl_followmodel_up_speed.value * ef_speed < 1) // bad things happen if this goes over 1, so prevent the effect + if(cl_followmodel_up.value) { - d = vieworg[2] - cl.gunorg_follow[2]; - cl.gunorg_follow[2] = bound(vieworg[2] - cl_followmodel_up_limit.value, cl.gunorg_follow[2] + d * cl_followmodel_up_speed.value * ef_speed, vieworg[2] + cl_followmodel_up_limit.value); + cl.gunorg_follow[2] = vieworg[2] - bound(-cl_followmodel_up_limit.value, cl.movement_velocity[2] * cl_followmodel_up_speed.value, cl_followmodel_up_limit.value); } else + { cl.gunorg_follow[2] = vieworg[2]; + } VectorCopy(cl.gunorg_follow, gunorg);