1 vector W_HitPlotUnnormalizedUntransform(vector screenforward, vector screenright, vector screenup, vector v)
4 ret_x = screenright * v;
6 ret_z = screenforward * v;
10 vector W_HitPlotNormalizedUntransform(vector org, entity targ, vector screenforward, vector screenright, vector screenup, vector v)
13 vector mi, ma, thisv, myv, ret;
15 myv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, org);
17 // x = 0..1 relative to hitbox; y = 0..1 relative to hitbox; z = distance
19 mi = ma = targ.origin + 0.5 * (targ.mins + targ.maxs);
20 for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) for(k = 0; k < 2; ++k)
23 if(i) thisv.x += targ.maxs.x; else thisv.x += targ.mins.x;
24 if(j) thisv.y += targ.maxs.y; else thisv.y += targ.mins.y;
25 if(k) thisv.z += targ.maxs.z; else thisv.z += targ.mins.z;
26 thisv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, thisv);
29 if(mi.x > thisv.x) mi_x = thisv.x; if(ma.x < thisv.x) ma_x = thisv.x;
30 if(mi.y > thisv.y) mi_y = thisv.y; if(ma.y < thisv.y) ma_y = thisv.y;
31 //if(mi_z > thisv_z) mi_z = thisv_z; if(ma_z < thisv_z) ma_y = thisv_z;
40 thisv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, v);
41 ret_x = (thisv.x - mi.x) / (ma.x - mi.x);
42 ret_y = (thisv.y - mi.y) / (ma.y - mi.y);
43 ret_z = thisv.z - myv.z;
47 void W_HitPlotAnalysis(entity player, vector screenforward, vector screenright, vector screenup)
53 if(player.hitplotfh >= 0)
55 lag = ANTILAG_LATENCY(player);
58 if(!IS_REAL_CLIENT(player))
59 lag = 0; // only antilag for clients
61 org = player.origin + player.view_ofs;
62 traceline_antilag_force(player, org, org + screenforward * MAX_SHOT_DISTANCE, MOVE_NORMAL, player, lag);
63 if(IS_CLIENT(trace_ent) || (trace_ent.flags & FL_MONSTER))
65 antilag_takeback(trace_ent, time - lag);
66 hitplot = W_HitPlotNormalizedUntransform(org, trace_ent, screenforward, screenright, screenup, trace_endpos);
67 antilag_restore(trace_ent);
68 fputs(player.hitplotfh, strcat(ftos(hitplot.x), " ", ftos(hitplot.y), " ", ftos(hitplot.z), " ", ftos(player.switchweapon), "\n"));
69 //print(strcat(ftos(hitplot_x), " ", ftos(hitplot_y), " ", ftos(hitplot_z), "\n"));
74 void W_HitPlotOpen(entity player)
76 if(autocvar_g_hitplots || strstrofs(strcat(" ", autocvar_g_hitplots_individuals, " "), strcat(" ", player.netaddress, " "), 0) >= 0)
78 player.hitplotfh = fopen(strcat("hits-", matchid, "-", player.netaddress, "-", ftos(player.playerid), ".plot"), FILE_WRITE);
79 fputs(player.hitplotfh, strcat("#name ", player.netname, "\n"));
81 else { player.hitplotfh = -1; }
84 void W_HitPlotClose(entity player)
86 if(player.hitplotfh >= 0)
88 fclose(player.hitplotfh);
89 player.hitplotfh = -1;