1 float teamradar_angle; // player yaw angle
2 vector teamradar_origin3d_in_texcoord; // player origin
3 vector teamradar_origin2d; // 2D origin
4 vector teamradar_size2d; // 2D size
5 float teamradar_size; // 2D scale factor
6 float cl_teamradar_scale; // window size = ...qu
8 float vlen_maxnorm2d(vector v)
10 return max4(v_x, v_y, -v_x, -v_y);
13 float vlen_minnorm2d(vector v)
15 return min(max(v_x, -v_x), max(v_y, -v_y));
18 vector teamradar_3dcoord_to_texcoord(vector in)
21 out_x = (in_x - mi_picmin_x) / (mi_picmax_x - mi_picmin_x);
22 out_y = (in_y - mi_picmin_y) / (mi_picmax_y - mi_picmin_y);
27 vector teamradar_texcoord_to_2dcoord(vector in)
30 in -= teamradar_origin3d_in_texcoord;
32 out = rotate(in, teamradar_angle * DEG2RAD);
33 out_y = - out_y; // screen space is reversed
35 out = out * teamradar_size;
36 out += teamradar_origin2d;
40 vector yinvert(vector v)
46 void draw_teamradar_background(float a)
51 R_BeginPolygon("", 0);
52 R_PolygonVertex('1 0 0' * (teamradar_origin2d_x - teamradar_size2d_x * 0.5) + '0 1 0' * (teamradar_origin2d_y - teamradar_size2d_y * 0.5), '0 0 0', '0 0 0', a);
53 R_PolygonVertex('1 0 0' * (teamradar_origin2d_x + teamradar_size2d_x * 0.5) + '0 1 0' * (teamradar_origin2d_y - teamradar_size2d_y * 0.5), '0 0 0', '0 0 0', a);
54 R_PolygonVertex('1 0 0' * (teamradar_origin2d_x + teamradar_size2d_x * 0.5) + '0 1 0' * (teamradar_origin2d_y + teamradar_size2d_y * 0.5), '0 0 0', '0 0 0', a);
55 R_PolygonVertex('1 0 0' * (teamradar_origin2d_x - teamradar_size2d_x * 0.5) + '0 1 0' * (teamradar_origin2d_y + teamradar_size2d_y * 0.5), '0 0 0', '0 0 0', a);
58 if(csqc_flags & CSQC_FLAG_READPICTURE) // not 2.4.2
59 R_BeginPolygon(minimapname, DRAWFLAG_ADDITIVE | DRAWFLAG_MIPMAP);
61 R_BeginPolygon(minimapname, DRAWFLAG_ADDITIVE);
62 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), '1 1 1', 1);
63 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), '1 1 1', 1);
64 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), '1 1 1', 1);
65 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), '1 1 1', 1);
69 void(vector coord3d, vector pangles, vector rgb) draw_teamradar_player =
73 coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
75 makevectors(pangles - '0 1 0' * teamradar_angle);
77 v_forward = normalize(v_forward);
79 v_right_x = -v_forward_y;
80 v_right_y = v_forward_x;
87 R_BeginPolygon("", 0);
88 R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, 1);
89 R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, 1);
90 R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, 1);
91 R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, 1);
94 R_BeginPolygon("", 0);
95 R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, 1);
96 R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, 1);
97 R_PolygonVertex(coord-v_forward, '1 0 0', rgb, 1);
98 R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, 1);
102 void draw_teamradar_icon(vector coord, float icon, float pingtime, vector rgb, float a)
107 coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));
108 drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
111 dt = time - pingtime;
114 v = '2 2 0' * teamradar_size * dt;
115 drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', 1 - dt, DRAWFLAG_ADDITIVE);
119 float cl_teamradar_scale;
120 float cl_teamradar_background_alpha;
121 float cl_teamradar_rotation;
122 vector cl_teamradar_size;
123 vector cl_teamradar_position;
124 float cl_teamradar_zoommode;
126 void teamradar_loadcvars()
128 cl_teamradar_scale = cvar("cl_teamradar_scale");
129 cl_teamradar_background_alpha = cvar("cl_teamradar_background_alpha");
130 cl_teamradar_rotation = cvar("cl_teamradar_rotation");
131 cl_teamradar_size = stov(cvar_string("cl_teamradar_size"));
132 cl_teamradar_position = stov(cvar_string("cl_teamradar_position"));
133 cl_teamradar_zoommode = cvar("cl_teamradar_zoommode");
135 // others default to 0
136 // match this to defaultNexuiz.cfg!
137 if(!cl_teamradar_scale) cl_teamradar_scale = 4096;
138 if(!cl_teamradar_background_alpha) cl_teamradar_background_alpha = 0.25;
139 if(!cl_teamradar_size_x) cl_teamradar_size_x = 128;
140 if(!cl_teamradar_size_y) cl_teamradar_size_y = cl_teamradar_size_x;
142 cl_teamradar_size_z = 0;
143 cl_teamradar_position_z = 0;
146 void() teamradar_view =
148 local float color, color2;
151 float scale2d, normalsize, bigsize;
154 if(minimapname == "")
157 teamradar_loadcvars();
159 switch(cl_teamradar_zoommode)
163 f = current_zoomfraction;
166 f = 1 - current_zoomfraction;
176 switch(cl_teamradar_rotation)
179 teamradar_angle = input_angles_y - 90;
182 teamradar_angle = 90 * cl_teamradar_rotation;
186 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
187 teamradar_size2d = cl_teamradar_size;
189 '1 0 0' * (0.5 * teamradar_size2d_x + cl_teamradar_position_x * (vid_conwidth - teamradar_size2d_x))
190 + '0 1 0' * (0.5 * teamradar_size2d_y + cl_teamradar_position_y * (vid_conheight - teamradar_size2d_y));
192 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
193 if(cl_teamradar_rotation == 0)
195 // max-min distance must fit the radar in any rotation
196 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen(mi_max - mi_min));
200 vector c0, c1, c2, c3, span;
201 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
202 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
203 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
204 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
206 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
207 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
209 // max-min distance must fit the radar in x=x, y=y
211 teamradar_size2d_x * scale2d / (1.05 * span_x),
212 teamradar_size2d_y * scale2d / (1.05 * span_y)
216 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / cl_teamradar_scale;
217 if(bigsize > normalsize)
218 normalsize = bigsize;
222 + (1 - f) * normalsize;
223 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
224 f * (mi_min + mi_max) * 0.5
225 + (1 - f) * pmove_org);
227 color = GetPlayerColor(player_localentnum-1);
228 rgb = GetTeamRGB(color);
231 teamradar_origin2d_x - teamradar_size2d_x * 0.5,
232 teamradar_origin2d_y - teamradar_size2d_y * 0.5,
237 draw_teamradar_background(cl_teamradar_background_alpha);
238 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
239 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm.teamradar_time, tm.teamradar_color, tm.alpha);
240 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
242 color2 = GetPlayerColor(tm.sv_entnum);
243 //if(color == COLOR_SPECTATOR || color == color2)
244 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
246 draw_teamradar_player(pmove_org, input_angles, '1 1 1');