From cf967a7e700fb458dea1189b9151f67a8bd28ffd Mon Sep 17 00:00:00 2001 From: div0 Date: Thu, 23 Jul 2009 17:21:39 +0000 Subject: [PATCH] crosshair hittest: blur cvar; fix blur with RL git-svn-id: svn://svn.icculus.org/nexuiz/trunk@7256 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/defaultNexuiz.cfg | 3 ++- data/qcsrc/client/View.qc | 57 ++++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/data/defaultNexuiz.cfg b/data/defaultNexuiz.cfg index 1e01b804f..7afcf2fa8 100644 --- a/data/defaultNexuiz.cfg +++ b/data/defaultNexuiz.cfg @@ -95,7 +95,8 @@ _cl_playerskin 0 crosshair 5 seta crosshair_per_weapon 0 "when 1, each gun will display a different crosshair" seta crosshair_color_override 0 "when 1, crosshair_color_* overrides the per-weapon color" -seta crosshair_hittest 1 "when not 0, the crosshair is blurred if the shot wouldn't hit the crosshair because of obstructions; also, the crosshair is scaled by the given number when aiming at an enemy" +seta crosshair_hittest 1 "do a crosshair hit evaluation; also, the crosshair is scaled by the given number when aiming at an enemy, and blurred when aiming at a team mate" +seta crosshair_hittest_blur 1 "blur the crosshair if the shot is obstructed" seta crosshair_hittest_showimpact 0 "move the crosshair to the actual impact location if obstructed" seta crosshair_laser "" "crosshair to display when wielding the laser" seta crosshair_laser_color_red 1 "crosshair color red component to display when wielding the laser" diff --git a/data/qcsrc/client/View.qc b/data/qcsrc/client/View.qc index f9fd5ff90..00a5a85a4 100644 --- a/data/qcsrc/client/View.qc +++ b/data/qcsrc/client/View.qc @@ -222,12 +222,11 @@ void TrueAim_Init() trueaim.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE; } -float EnemyHitCheck(vector start, vector mi, vector ma, vector end) +float EnemyHitCheck() { float t; - tracebox(start, mi, ma, end, MOVE_NORMAL, trueaim); - if(cvar("crosshair_hittest_showimpact")) - wcross_origin = project_3d_to_2d(trace_endpos); + wcross_origin = project_3d_to_2d(trace_endpos); + wcross_origin_z = 0; if(trace_networkentity < 1) return SHOTTYPE_HITWORLD; if(trace_networkentity > maxclients) @@ -259,7 +258,10 @@ float TrueAimCheck() return SHOTTYPE_HITWORLD; case WEP_CAMPINGRIFLE: if(zoomscript_caught) - return EnemyHitCheck(view_origin, '0 0 0', '0 0 0', view_origin + view_forward * MAX_SHOT_DISTANCE); + { + tracebox(view_origin, '0 0 0', '0 0 0', view_origin + view_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, trueaim); + return EnemyHitCheck(); + } break; case WEP_ROCKET_LAUNCHER: // projectile has a size! mi = '-3 -3 -3'; @@ -288,16 +290,18 @@ float TrueAimCheck() tracebox(w_shotorg, mi, ma, w_shotorg + view_forward * (vecs_x + nudge), MOVE_NORMAL, trueaim); // FIXME this MOVE_NORMAL part will misbehave a little in csqc w_shotorg = trace_endpos - view_forward * nudge; - shottype = EnemyHitCheck(w_shotorg, mi, ma, trueaimpoint); + tracebox(w_shotorg, mi, ma, trueaimpoint, MOVE_NORMAL, trueaim); + shottype = EnemyHitCheck(); if(shottype != SHOTTYPE_HITWORLD) return shottype; - - // now test whether we will actually hit the trueaimpoint... - tracebox(w_shotorg, mi, ma, trueaimpoint, MOVE_NOMONSTERS, trueaim); - - if(vlen(trace_endpos - trueaimpoint) > vlen(ma - mi) + 1) + +#if 0 + // FIXME WHY DOES THIS NOT WORK FOR THE ROCKET LAUNCHER? + // or rather, I know why, but see no fix + if(vlen(trace_endpos - trueaimpoint) > vlen(ma) + vlen(mi) + 1) // yes, this is an ugly hack... but it seems good enough to find out whether the test hits the same place as the initial trace return SHOTTYPE_HITOBSTRUCTION; +#endif return SHOTTYPE_HITWORLD; } @@ -318,6 +322,7 @@ void CSQC_UpdateView(float w, float h) entity e; float fov; float f, i, j; + vector v; dprint_load(); WaypointSprite_Load(); @@ -566,11 +571,25 @@ void CSQC_UpdateView(float w, float h) float bullets, ring_scale; // wcross_origin = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight; wcross_origin = project_3d_to_2d(view_origin + MAX_SHOT_DISTANCE * view_forward); + wcross_origin_z = 0; if(cvar("crosshair_hittest")) + { + vector wcross_oldorigin; + wcross_oldorigin = wcross_origin; shottype = TrueAimCheck(); + if(shottype == SHOTTYPE_HITWORLD) + { + v = wcross_origin - wcross_oldorigin; + v_x /= vid_conwidth; + v_y /= vid_conheight; + if(vlen(v) > 0.01) + shottype = SHOTTYPE_HITOBSTRUCTION; + } + if(!cvar("crosshair_hittest_showimpact")) + wcross_origin = wcross_oldorigin; + } else shottype = SHOTTYPE_HITWORLD; - wcross_origin_z = 0; string wcross_style; wcross_style = cvar_string("crosshair"); @@ -626,13 +645,7 @@ void CSQC_UpdateView(float w, float h) else bullets = 0; - if(shottype == SHOTTYPE_HITENEMY || shottype == SHOTTYPE_HITWORLD) - { - if (bullets) - drawpic(wcross_origin - '0.5 0 0' * (wcross_size_x * ring_scale) - '0 0.5 0' * (wcross_size_y * ring_scale), strcat("gfx/hud/rifle_ring_", ftos(bullets)), wcross_size * ring_scale, wcross_color, wcross_alpha, DRAWFLAG_NORMAL); - drawpic(wcross_origin - '0.5 0 0' * (wcross_size_x) - '0 0.5 0' * ( wcross_size_y), wcross_name, wcross_size, wcross_color, wcross_alpha, DRAWFLAG_NORMAL); - } - else + if(shottype == SHOTTYPE_HITTEAM || (shottype == SHOTTYPE_HITOBSTRUCTION && cvar("crosshair_hittest_blur"))) { wcross_alpha *= 0.04 * 0.75; for(i = -2; i <= 2; ++i) @@ -643,6 +656,12 @@ void CSQC_UpdateView(float w, float h) drawpic(wcross_origin - '0.5 0 0' * (wcross_size_x + i) - '0 0.5 0' * (wcross_size_y + j), wcross_name, wcross_size, wcross_color, wcross_alpha, DRAWFLAG_NORMAL); } } + else + { + if (bullets) + drawpic(wcross_origin - '0.5 0 0' * (wcross_size_x * ring_scale) - '0 0.5 0' * (wcross_size_y * ring_scale), strcat("gfx/hud/rifle_ring_", ftos(bullets)), wcross_size * ring_scale, wcross_color, wcross_alpha, DRAWFLAG_NORMAL); + drawpic(wcross_origin - '0.5 0 0' * (wcross_size_x) - '0 0.5 0' * ( wcross_size_y), wcross_name, wcross_size, wcross_color, wcross_alpha, DRAWFLAG_NORMAL); + } } } } -- 2.39.2