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
9 float vlen_maxnorm2d(vector v)
11 return max4(v_x, v_y, -v_x, -v_y);
14 float vlen_minnorm2d(vector v)
16 return min(max(v_x, -v_x), max(v_y, -v_y));
19 vector teamradar_3dcoord_to_texcoord(vector in)
22 out_x = (in_x - mi_picmin_x) / (mi_picmax_x - mi_picmin_x);
23 out_y = (in_y - mi_picmin_y) / (mi_picmax_y - mi_picmin_y);
28 vector teamradar_texcoord_to_2dcoord(vector in)
31 in -= teamradar_origin3d_in_texcoord;
33 out = rotate(in, teamradar_angle * DEG2RAD);
34 out_y = - out_y; // screen space is reversed
36 out = out * teamradar_size;
39 out += teamradar_origin2d;
43 vector yinvert(vector v)
49 void draw_teamradar_background(float bg, float fg)
53 R_BeginPolygon("", 0);
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', bg);
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', bg);
56 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);
57 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);
61 if(fg > 0 && minimapname != "")
63 if(csqc_flags & CSQC_FLAG_READPICTURE) // not 2.4.2
64 R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP);
66 R_BeginPolygon(minimapname, DRAWFLAG_ADDITIVE);
69 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), '1 1 1', fg);
70 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), '1 1 1', fg);
71 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), '1 1 1', fg);
72 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), '1 1 1', fg);
76 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), '1 1 1', fg);
77 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), '1 1 1', fg);
78 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), '1 1 1', fg);
79 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), '1 1 1', fg);
85 void(vector coord3d, vector pangles, vector rgb) draw_teamradar_player =
89 coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
91 makevectors(pangles - '0 1 0' * teamradar_angle);
94 v_forward_x = -v_forward_x;
95 v_right_x = -v_right_x;
99 v_forward = normalize(v_forward);
101 v_right_x = -v_forward_y;
102 v_right_y = v_forward_x;
109 R_BeginPolygon("", 0);
110 R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, 1);
111 R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, 1);
112 R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, 1);
113 R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, 1);
116 R_BeginPolygon("", 0);
117 R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, 1);
118 R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, 1);
119 R_PolygonVertex(coord-v_forward, '1 0 0', rgb, 1);
120 R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, 1);
124 void draw_teamradar_icon(vector coord, float icon, float pingtime, vector rgb, float a)
129 coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));
130 drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
133 dt = time - pingtime;
136 v = '2 2 0' * teamradar_size * dt;
137 drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', 1 - dt, DRAWFLAG_ADDITIVE);
141 void draw_teamradar_link(vector start, vector end, float colors)
145 start = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(start));
146 end = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(end));
147 norm = normalize(start - end);
153 c0 = colormapPaletteColor(colors & 0x0F, FALSE);
154 c1 = colormapPaletteColor((colors & 0xF0) / 0x10, FALSE);
156 R_BeginPolygon("", 0);
157 R_PolygonVertex(start - norm, '0 0 0', c0, 1);
158 R_PolygonVertex(start + norm, '0 1 0', c0, 1);
159 R_PolygonVertex(end + norm, '1 1 0', c1, 1);
160 R_PolygonVertex(end - norm, '1 0 0', c1, 1);
164 float cl_teamradar_scale;
165 float cl_teamradar_background_alpha;
166 float cl_teamradar_foreground_alpha;
167 float cl_teamradar_rotation;
168 vector cl_teamradar_size;
169 vector cl_teamradar_position;
170 float cl_teamradar_zoommode;
172 void teamradar_loadcvars()
174 v_flipped = cvar("v_flipped");
177 cl_teamradar_scale = 42; // dummy, not used (see zoommode)
178 cl_teamradar_background_alpha = 1;
179 cl_teamradar_foreground_alpha = 1;
180 cl_teamradar_rotation = cvar("cl_teamradar_rotation");
181 if(!cl_teamradar_rotation)
182 cl_teamradar_rotation = 4;
183 cl_teamradar_size = '256 256 0'; // TODO make somewhat variable?
184 cl_teamradar_position = '0.5 0.5 0';
185 cl_teamradar_zoommode = 3;
189 cl_teamradar_scale = cvar("cl_teamradar_scale");
190 cl_teamradar_background_alpha = cvar("cl_teamradar_background_alpha");
191 cl_teamradar_foreground_alpha = cvar("cl_teamradar_foreground_alpha");
192 cl_teamradar_rotation = cvar("cl_teamradar_rotation");
193 cl_teamradar_size = stov(cvar_string("cl_teamradar_size"));
194 cl_teamradar_position = stov(cvar_string("cl_teamradar_position"));
195 cl_teamradar_zoommode = cvar("cl_teamradar_zoommode");
197 // others default to 0
198 // match this to defaultNexuiz.cfg!
199 if(!cl_teamradar_scale) cl_teamradar_scale = 4096;
200 if(!cl_teamradar_background_alpha) cl_teamradar_background_alpha = 0.4;
201 if(!cl_teamradar_foreground_alpha) cl_teamradar_foreground_alpha = 0.8;
202 if(!cl_teamradar_size_x) cl_teamradar_size_x = 128;
203 if(!cl_teamradar_size_y) cl_teamradar_size_y = cl_teamradar_size_x;
205 cl_teamradar_size_z = 0;
206 cl_teamradar_position_z = 0;
210 void() teamradar_view =
212 local float color, color2;
215 float scale2d, normalsize, bigsize;
218 if(minimapname == "" && !ons_showmap)
221 teamradar_loadcvars();
223 switch(cl_teamradar_zoommode)
227 f = current_zoomfraction;
230 f = 1 - current_zoomfraction;
240 switch(cl_teamradar_rotation)
243 teamradar_angle = input_angles_y - 90;
246 teamradar_angle = 90 * cl_teamradar_rotation;
250 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
251 teamradar_size2d = cl_teamradar_size;
253 '1 0 0' * (0.5 * teamradar_size2d_x + cl_teamradar_position_x * (vid_conwidth - teamradar_size2d_x))
254 + '0 1 0' * (0.5 * teamradar_size2d_y + cl_teamradar_position_y * (vid_conheight - teamradar_size2d_y));
256 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
257 if(cl_teamradar_rotation == 0)
259 // max-min distance must fit the radar in any rotation
260 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen(mi_max - mi_min));
264 vector c0, c1, c2, c3, span;
265 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
266 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
267 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
268 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
270 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
271 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
273 // max-min distance must fit the radar in x=x, y=y
275 teamradar_size2d_x * scale2d / (1.05 * span_x),
276 teamradar_size2d_y * scale2d / (1.05 * span_y)
280 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / cl_teamradar_scale;
281 if(bigsize > normalsize)
282 normalsize = bigsize;
286 + (1 - f) * normalsize;
287 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
288 f * (mi_min + mi_max) * 0.5
289 + (1 - f) * pmove_org);
291 color = GetPlayerColor(player_localentnum-1);
292 rgb = GetTeamRGB(color);
295 teamradar_origin2d_x - teamradar_size2d_x * 0.5,
296 teamradar_origin2d_y - teamradar_size2d_y * 0.5,
301 draw_teamradar_background(cl_teamradar_background_alpha, cl_teamradar_foreground_alpha);
307 vector frame_origin, frame_size;
308 frame_origin = frame_size = '0 0 0';
310 frame_origin_x = teamradar_origin2d_x - teamradar_size2d_x * 0.55859375;
311 frame_origin_y = teamradar_origin2d_y - teamradar_size2d_y * 0.55859375;
312 frame_size_x = teamradar_size2d_x * 1.1171875;
313 frame_size_y = teamradar_size2d_y * 1.1171875;
314 drawpic(frame_origin, "gfx/ons-frame.tga", frame_size, '1 1 1', 1, 0);
315 drawpic(frame_origin, "gfx/ons-frame-team.tga", frame_size, rgb, 1, 0);
318 teamradar_origin2d_x - teamradar_size2d_x * 0.5,
319 teamradar_origin2d_y - teamradar_size2d_y * 0.5,
325 for(tm = world; (tm = find(tm, classname, "radarlink")); )
326 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
327 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
328 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm.teamradar_time, tm.teamradar_color, tm.alpha);
329 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
331 color2 = GetPlayerColor(tm.sv_entnum);
332 //if(color == COLOR_SPECTATOR || color == color2)
333 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
335 draw_teamradar_player(pmove_org, input_angles, '1 1 1');
347 sendflags = ReadByte();
349 InterpolateOrigin_Undo();
351 self.iflags = IFLAG_VELOCITY;
352 self.classname = "radarlink";
356 self.origin_x = ReadCoord();
357 self.origin_y = ReadCoord();
358 self.origin_z = ReadCoord();
363 self.velocity_x = ReadCoord();
364 self.velocity_y = ReadCoord();
365 self.velocity_z = ReadCoord();
370 self.team = ReadByte();
373 InterpolateOrigin_Note();