From c9f80ee2a84134b5a457d5e8a65e9eeb1fc2042d Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 4 Aug 2010 08:28:57 +0200 Subject: [PATCH] fix nearclip PROPERLY, even at evil fov values --- qcsrc/warpzonelib/client.qc | 59 +++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/qcsrc/warpzonelib/client.qc b/qcsrc/warpzonelib/client.qc index c71f984a9..2f4601219 100644 --- a/qcsrc/warpzonelib/client.qc +++ b/qcsrc/warpzonelib/client.qc @@ -102,6 +102,39 @@ void WarpZone_Outside() //cvar_set("cl_forwardspeed", ftos(warpzone_fixingview_forwardspeed)); } +vector WarpZone_FixNearClip(vector o, vector c0, vector c1, vector c2, vector c3) +{ + float nearclipdistance; + vector mi, ma; + entity e; + float pd; + + mi_x = min5(o_x, c0_x, c1_x, c2_x, c3_x); + ma_x = max5(o_x, c0_x, c1_x, c2_x, c3_x); + mi_y = min5(o_y, c0_y, c1_y, c2_y, c3_y); + ma_y = max5(o_y, c0_y, c1_y, c2_y, c3_y); + mi_z = min5(o_z, c0_z, c1_z, c2_z, c3_z); + ma_z = max5(o_z, c0_z, c1_z, c2_z, c3_z); + + e = WarpZone_Find(mi, ma); + if(e) + { + if(WarpZone_PlaneDist(e, o) < 0) + return '0 0 0'; + // can't really be, though, but if it is, this is not my warpzone, but a random different one in the same mins/maxs + pd = min( + WarpZone_PlaneDist(e, c0), + WarpZone_PlaneDist(e, c1), + WarpZone_PlaneDist(e, c2), + WarpZone_PlaneDist(e, c3) + ); + if(pd < 0) + return e.warpzone_forward * -pd; + } + + return '0 0 0'; +} + float warpzone_saved; vector warpzone_saved_origin; vector warpzone_saved_angles; @@ -112,12 +145,21 @@ var float autocvar_cl_rollkillspeed = 10; void WarpZone_FixView() { float pd, f; + vector o; entity e; + vector corner0, corner1, corner2, corner3, nearclip; + warpzone_saved = 0; warpzone_saved_origin = warpzone_fixview_origin; warpzone_saved_angles = warpzone_fixview_angles; warpzone_saved_cl_viewangles = warpzone_fixview_cl_viewangles; + nearclip = '0 0 1' * (cvar("r_nearclip") * cvar("cl_warpzonenudge")); + corner0 = cs_unproject('0 0 0' + nearclip); + corner1 = cs_unproject('1 0 0' * cvar("vid_conwidth") + nearclip); + corner2 = cs_unproject('0 1 0' * cvar("vid_conheight") + nearclip); + corner3 = cs_unproject('1 0 0' * cvar("vid_conwidth") + '0 1 0' * cvar("vid_conheight") + nearclip); + #ifndef KEEP_ROLL if(warpzone_fixview_angles_z != 0 || warpzone_fixview_cl_viewangles_z != 0) { @@ -139,6 +181,10 @@ void WarpZone_FixView() { warpzone_saved = 1; warpzone_fixview_origin = WarpZone_TransformOrigin(e, warpzone_fixview_origin); + corner0 = WarpZone_TransformOrigin(e, corner0); + corner1 = WarpZone_TransformOrigin(e, corner1); + corner2 = WarpZone_TransformOrigin(e, corner2); + corner3 = WarpZone_TransformOrigin(e, corner3); warpzone_fixview_angles = WarpZone_TransformVAngles(e, warpzone_fixview_angles); warpzone_fixview_cl_viewangles = WarpZone_TransformVAngles(e, warpzone_fixview_cl_viewangles); WarpZone_Inside(); @@ -147,16 +193,11 @@ void WarpZone_FixView() WarpZone_Outside(); // if we are near any warpzone planes - MOVE AWAY (work around nearclip) - float nearclip = 4; - e = WarpZone_Find(warpzone_fixview_origin - '1 1 1' * nearclip, warpzone_fixview_origin + '1 1 1' * nearclip); - if(e) + o = WarpZone_FixNearClip(warpzone_fixview_origin, corner0, corner1, corner2, corner3); + if(o != '0 0 0') { - pd = WarpZone_PlaneDist(e, warpzone_fixview_origin); - if(pd >= 0 && pd < nearclip) - { - warpzone_saved = 1; - warpzone_fixview_origin = warpzone_fixview_origin + e.warpzone_forward * (nearclip - pd); - } + warpzone_saved = 1; + warpzone_fixview_origin += o; } if(warpzone_saved == 1) -- 2.39.2