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 not(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))
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;