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
11 return sqrt(v_x * v_x + v_y * v_y);
14 float vlen_maxnorm2d(vector v)
16 return max4(v_x, v_y, -v_x, -v_y);
19 float vlen_minnorm2d(vector v)
21 return min(max(v_x, -v_x), max(v_y, -v_y));
24 vector teamradar_3dcoord_to_texcoord(vector in)
27 out_x = (in_x - mi_picmin_x) / (mi_picmax_x - mi_picmin_x);
28 out_y = (in_y - mi_picmin_y) / (mi_picmax_y - mi_picmin_y);
33 vector teamradar_texcoord_to_2dcoord(vector in)
36 in -= teamradar_origin3d_in_texcoord;
38 out = rotate(in, teamradar_angle * DEG2RAD);
39 out_y = - out_y; // screen space is reversed
41 out = out * teamradar_size;
44 out += teamradar_origin2d;
48 vector yinvert(vector v)
54 void draw_teamradar_background(float bg, float fg)
60 R_BeginPolygon("", 0);
61 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', bg);
62 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', bg);
63 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', bg);
64 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', bg);
68 if(fg > 0 && minimapname != "")
70 if(csqc_flags & CSQC_FLAG_READPICTURE) // not 2.4.2
74 R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP);
80 R_BeginPolygon(minimapname, DRAWFLAG_ADDITIVE);
84 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
85 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
86 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
87 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
91 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
92 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
93 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
94 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
100 void(vector coord3d, vector pangles, vector rgb) draw_teamradar_player =
104 coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
106 makevectors(pangles - '0 1 0' * teamradar_angle);
109 v_forward_x = -v_forward_x;
110 v_right_x = -v_right_x;
114 v_forward = normalize(v_forward);
116 v_right_x = -v_forward_y;
117 v_right_y = v_forward_x;
124 R_BeginPolygon("", 0);
125 R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, 1);
126 R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, 1);
127 R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, 1);
128 R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, 1);
131 R_BeginPolygon("", 0);
132 R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, 1);
133 R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, 1);
134 R_PolygonVertex(coord-v_forward, '1 0 0', rgb, 1);
135 R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, 1);
139 void draw_teamradar_icon(vector coord, float icon, entity pingdata, vector rgb, float a)
145 coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));
146 drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
150 for(i = 0; i < MAX_TEAMRADAR_TIMES; ++i)
152 dt = pingdata.(teamradar_times[i]);
158 v = '2 2 0' * teamradar_size * dt;
159 drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', 1 - dt, DRAWFLAG_ADDITIVE);
164 void draw_teamradar_link(vector start, vector end, float colors)
168 start = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(start));
169 end = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(end));
170 norm = normalize(start - end);
176 c0 = colormapPaletteColor(colors & 0x0F, FALSE);
177 c1 = colormapPaletteColor((colors & 0xF0) / 0x10, FALSE);
179 R_BeginPolygon("", 0);
180 R_PolygonVertex(start - norm, '0 0 0', c0, 1);
181 R_PolygonVertex(start + norm, '0 1 0', c0, 1);
182 R_PolygonVertex(end + norm, '1 1 0', c1, 1);
183 R_PolygonVertex(end - norm, '1 0 0', c1, 1);
187 float cl_teamradar_scale;
188 float cl_teamradar_background_alpha;
189 float cl_teamradar_foreground_alpha;
190 float cl_teamradar_rotation;
191 vector cl_teamradar_size;
192 vector cl_teamradar_position;
193 float cl_teamradar_zoommode;
195 void teamradar_loadcvars()
197 v_flipped = cvar("v_flipped");
200 cl_teamradar_scale = 42; // dummy, not used (see zoommode)
201 cl_teamradar_background_alpha = 1;
202 cl_teamradar_foreground_alpha = 1;
203 cl_teamradar_rotation = cvar("cl_teamradar_rotation");
204 if(!cl_teamradar_rotation)
205 cl_teamradar_rotation = 4;
206 cl_teamradar_size = '256 256 0'; // TODO make somewhat variable?
207 cl_teamradar_position = '0.5 0.5 0';
208 cl_teamradar_zoommode = 3;
212 cl_teamradar_scale = cvar("cl_teamradar_scale");
213 cl_teamradar_background_alpha = cvar("cl_teamradar_background_alpha");
214 cl_teamradar_foreground_alpha = cvar("cl_teamradar_foreground_alpha");
215 cl_teamradar_rotation = cvar("cl_teamradar_rotation");
216 cl_teamradar_size = stov(cvar_string("cl_teamradar_size"));
217 cl_teamradar_position = stov(cvar_string("cl_teamradar_position"));
218 cl_teamradar_zoommode = cvar("cl_teamradar_zoommode");
220 // others default to 0
221 // match this to defaultNexuiz.cfg!
222 if(!cl_teamradar_scale) cl_teamradar_scale = 4096;
223 if(!cl_teamradar_background_alpha) cl_teamradar_background_alpha = 0.4;
224 if(!cl_teamradar_foreground_alpha) cl_teamradar_foreground_alpha = 0.8;
225 if(!cl_teamradar_size_x) cl_teamradar_size_x = 128;
226 if(!cl_teamradar_size_y) cl_teamradar_size_y = cl_teamradar_size_x;
228 cl_teamradar_size_z = 0;
229 cl_teamradar_position_z = 0;
233 void() teamradar_view =
235 local float color, color2;
238 float scale2d, normalsize, bigsize;
241 if(minimapname == "" && !ons_showmap)
244 teamradar_loadcvars();
246 switch(cl_teamradar_zoommode)
250 f = current_zoomfraction;
253 f = 1 - current_zoomfraction;
263 switch(cl_teamradar_rotation)
266 teamradar_angle = view_angles_y - 90;
269 teamradar_angle = 90 * cl_teamradar_rotation;
273 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
274 teamradar_size2d = cl_teamradar_size;
276 '1 0 0' * (0.5 * teamradar_size2d_x + cl_teamradar_position_x * (vid_conwidth - teamradar_size2d_x))
277 + '0 1 0' * (0.5 * teamradar_size2d_y + cl_teamradar_position_y * (vid_conheight - teamradar_size2d_y));
279 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
280 if(cl_teamradar_rotation == 0)
282 // max-min distance must fit the radar in any rotation
283 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
287 vector c0, c1, c2, c3, span;
288 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
289 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
290 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
291 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
293 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
294 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
296 // max-min distance must fit the radar in x=x, y=y
298 teamradar_size2d_x * scale2d / (1.05 * span_x),
299 teamradar_size2d_y * scale2d / (1.05 * span_y)
303 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / cl_teamradar_scale;
304 if(bigsize > normalsize)
305 normalsize = bigsize;
309 + (1 - f) * normalsize;
310 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
311 f * (mi_min + mi_max) * 0.5
312 + (1 - f) * view_origin);
314 color = GetPlayerColor(player_localentnum-1);
315 rgb = GetTeamRGB(color);
318 teamradar_origin2d_x - teamradar_size2d_x * 0.5,
319 teamradar_origin2d_y - teamradar_size2d_y * 0.5,
324 draw_teamradar_background(cl_teamradar_background_alpha, cl_teamradar_foreground_alpha);
330 vector frame_origin, frame_size;
331 frame_origin = frame_size = '0 0 0';
333 frame_origin_x = teamradar_origin2d_x - teamradar_size2d_x * 0.55859375;
334 frame_origin_y = teamradar_origin2d_y - teamradar_size2d_y * 0.55859375;
335 frame_size_x = teamradar_size2d_x * 1.1171875;
336 frame_size_y = teamradar_size2d_y * 1.1171875;
337 drawpic(frame_origin, "gfx/ons-frame.tga", frame_size, '1 1 1', 1, 0);
338 drawpic(frame_origin, "gfx/ons-frame-team.tga", frame_size, rgb, 1, 0);
341 teamradar_origin2d_x - teamradar_size2d_x * 0.5,
342 teamradar_origin2d_y - teamradar_size2d_y * 0.5,
348 for(tm = world; (tm = find(tm, classname, "radarlink")); )
349 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
350 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
351 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, tm.alpha);
352 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
354 color2 = GetPlayerColor(tm.sv_entnum);
355 //if(color == COLOR_SPECTATOR || color == color2)
356 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
358 draw_teamradar_player(view_origin, view_angles, '1 1 1');
370 sendflags = ReadByte();
372 InterpolateOrigin_Undo();
374 self.iflags = IFLAG_VELOCITY;
375 self.classname = "radarlink";
379 self.origin_x = ReadCoord();
380 self.origin_y = ReadCoord();
381 self.origin_z = ReadCoord();
386 self.velocity_x = ReadCoord();
387 self.velocity_y = ReadCoord();
388 self.velocity_z = ReadCoord();
393 self.team = ReadByte();
396 InterpolateOrigin_Note();