1 float radar_angle; // player yaw angle
\r
2 vector radar_origin3d_in_texcoord; // player origin
\r
3 vector radar_origin2d; // 2D origin
\r
4 vector radar_size2d; // 2D size
\r
5 vector radar_extraclip_mins, radar_extraclip_maxs; // don't even ask
\r
6 float radar_size; // 2D scale factor
\r
7 float cl_radar_scale; // window size = ...qu
\r
8 float cl_radar_nohudhack;
\r
11 float vlen2d(vector v)
\r
13 return sqrt(v_x * v_x + v_y * v_y);
\r
16 float vlen_maxnorm2d(vector v)
\r
18 return max4(v_x, v_y, -v_x, -v_y);
\r
21 float vlen_minnorm2d(vector v)
\r
23 return min(max(v_x, -v_x), max(v_y, -v_y));
\r
26 vector radar_3dcoord_to_texcoord(vector in)
\r
29 out_x = (in_x - mi_picmin_x) / (mi_picmax_x - mi_picmin_x);
\r
30 out_y = (in_y - mi_picmin_y) / (mi_picmax_y - mi_picmin_y);
\r
35 vector radar_texcoord_to_2dcoord(vector in)
\r
38 in -= radar_origin3d_in_texcoord;
\r
40 out = rotate(in, radar_angle * DEG2RAD);
\r
41 out_y = - out_y; // screen space is reversed
\r
43 out = out * radar_size;
\r
46 out += radar_origin2d;
\r
50 vector yinvert(vector v)
\r
56 void draw_radar_background(float ca, float bg, float fg)
\r
61 R_BeginPolygon("gfx/hud/bg_radar.tga", DRAWFLAG_NORMAL);
\r
62 R_PolygonVertex('1 0 0' * (radar_origin2d_x - radar_size2d_x * 0.5 + radar_extraclip_mins_x) + '0 1 0' * (radar_origin2d_y - radar_size2d_y * 0.5 + radar_extraclip_mins_y), yinvert(mi_pictexcoord1), '1 1 1', bg);
\r
63 R_PolygonVertex('1 0 0' * (radar_origin2d_x + radar_size2d_x * 0.5 + radar_extraclip_maxs_x) + '0 1 0' * (radar_origin2d_y - radar_size2d_y * 0.5 + radar_extraclip_mins_y), yinvert(mi_pictexcoord2), '1 1 1', bg);
\r
64 R_PolygonVertex('1 0 0' * (radar_origin2d_x + radar_size2d_x * 0.5 + radar_extraclip_maxs_x) + '0 1 0' * (radar_origin2d_y + radar_size2d_y * 0.5 + radar_extraclip_maxs_y), yinvert(mi_pictexcoord3), '1 1 1', bg);
\r
65 R_PolygonVertex('1 0 0' * (radar_origin2d_x - radar_size2d_x * 0.5 + radar_extraclip_mins_x) + '0 1 0' * (radar_origin2d_y + radar_size2d_y * 0.5 + radar_extraclip_maxs_y), yinvert(mi_pictexcoord0), '1 1 1', bg);
\r
69 if(ca > 0 && minimapname != "")
\r
72 R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP);
\r
75 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), cgc, 1);
\r
76 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), cgc, 1);
\r
77 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), cgc, 1);
\r
78 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), cgc, 1);
\r
82 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), cgc, 1);
\r
83 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), cgc, 1);
\r
84 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), cgc, 1);
\r
85 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), cgc, 1);
\r
92 R_BeginPolygon("gfx/hud/fg_radar.tga", DRAWFLAG_NORMAL);
\r
93 R_PolygonVertex('1 0 0' * (radar_origin2d_x - radar_size2d_x * 0.5 + radar_extraclip_mins_x) + '0 1 0' * (radar_origin2d_y - radar_size2d_y * 0.5 + radar_extraclip_mins_y), yinvert(mi_pictexcoord1), '1 1 1', fg);
\r
94 R_PolygonVertex('1 0 0' * (radar_origin2d_x + radar_size2d_x * 0.5 + radar_extraclip_maxs_x) + '0 1 0' * (radar_origin2d_y - radar_size2d_y * 0.5 + radar_extraclip_mins_y), yinvert(mi_pictexcoord2), '1 1 1', fg);
\r
95 R_PolygonVertex('1 0 0' * (radar_origin2d_x + radar_size2d_x * 0.5 + radar_extraclip_maxs_x) + '0 1 0' * (radar_origin2d_y + radar_size2d_y * 0.5 + radar_extraclip_maxs_y), yinvert(mi_pictexcoord3), '1 1 1', fg);
\r
96 R_PolygonVertex('1 0 0' * (radar_origin2d_x - radar_size2d_x * 0.5 + radar_extraclip_mins_x) + '0 1 0' * (radar_origin2d_y + radar_size2d_y * 0.5 + radar_extraclip_maxs_y), yinvert(mi_pictexcoord0), '1 1 1', fg);
\r
100 rgb = GetTeamRGB(GetPlayerColor(player_localentnum - 1));
\r
103 R_BeginPolygon("gfx/hud/fg_radar_team.tga", DRAWFLAG_NORMAL);
\r
104 R_PolygonVertex('1 0 0' * (radar_origin2d_x - radar_size2d_x * 0.5 + radar_extraclip_mins_x) + '0 1 0' * (radar_origin2d_y - radar_size2d_y * 0.5 + radar_extraclip_mins_y), yinvert(mi_pictexcoord1), rgb, fg);
\r
105 R_PolygonVertex('1 0 0' * (radar_origin2d_x + radar_size2d_x * 0.5 + radar_extraclip_maxs_x) + '0 1 0' * (radar_origin2d_y - radar_size2d_y * 0.5 + radar_extraclip_mins_y), yinvert(mi_pictexcoord2), rgb, fg);
\r
106 R_PolygonVertex('1 0 0' * (radar_origin2d_x + radar_size2d_x * 0.5 + radar_extraclip_maxs_x) + '0 1 0' * (radar_origin2d_y + radar_size2d_y * 0.5 + radar_extraclip_maxs_y), yinvert(mi_pictexcoord3), rgb, fg);
\r
107 R_PolygonVertex('1 0 0' * (radar_origin2d_x - radar_size2d_x * 0.5 + radar_extraclip_mins_x) + '0 1 0' * (radar_origin2d_y + radar_size2d_y * 0.5 + radar_extraclip_maxs_y), yinvert(mi_pictexcoord0), rgb, fg);
\r
112 void(vector coord3d, vector pangles, vector rgb) draw_radar_player =
\r
114 vector coord, rgb2;
\r
116 coord = radar_texcoord_to_2dcoord(radar_3dcoord_to_texcoord(coord3d));
\r
118 makevectors(pangles - '0 1 0' * radar_angle);
\r
121 v_forward_x = -v_forward_x;
\r
122 v_right_x = -v_right_x;
\r
126 v_forward = normalize(v_forward);
\r
127 v_forward_y *= -1.0;
\r
128 v_right_x = -v_forward_y;
\r
129 v_right_y = v_forward_x;
\r
136 R_BeginPolygon("", 0);
\r
137 R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, sbar_alpha_fg);
\r
138 R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, sbar_alpha_fg);
\r
139 R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, sbar_alpha_fg);
\r
140 R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, sbar_alpha_fg);
\r
143 R_BeginPolygon("", 0);
\r
144 R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, sbar_alpha_fg);
\r
145 R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, sbar_alpha_fg);
\r
146 R_PolygonVertex(coord-v_forward, '1 0 0', rgb, sbar_alpha_fg);
\r
147 R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, sbar_alpha_fg);
\r
151 void draw_radar_icon(vector coord, float icon, entity pingdata, vector rgb, float a)
\r
157 coord = radar_texcoord_to_2dcoord(radar_3dcoord_to_texcoord(coord));
\r
158 drawpic(coord - '4 4 0', strcat("gfx/radar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
\r
162 for(i = 0; i < MAX_RADAR_TIMES; ++i)
\r
164 dt = pingdata.(radar_times[i]);
\r
168 if(dt >= 1 || dt <= 0)
\r
170 v = '2 2 0' * radar_size * dt;
\r
171 drawpic(coord - 0.5 * v, "gfx/radar_ping", v, '1 1 1', (1 - dt) * a, DRAWFLAG_ADDITIVE);
\r
176 void draw_radar_link(vector start, vector end, float colors)
\r
178 vector c0, c1, norm;
\r
180 start = radar_texcoord_to_2dcoord(radar_3dcoord_to_texcoord(start));
\r
181 end = radar_texcoord_to_2dcoord(radar_3dcoord_to_texcoord(end));
\r
182 norm = normalize(start - end);
\r
188 c0 = colormapPaletteColor(colors & 0x0F, FALSE);
\r
189 c1 = colormapPaletteColor((colors & 0xF0) / 0x10, FALSE);
\r
191 R_BeginPolygon("", 0);
\r
192 R_PolygonVertex(start - norm, '0 0 0', c0, sbar_alpha_fg);
\r
193 R_PolygonVertex(start + norm, '0 1 0', c0, sbar_alpha_fg);
\r
194 R_PolygonVertex(end + norm, '1 1 0', c1, sbar_alpha_fg);
\r
195 R_PolygonVertex(end - norm, '1 0 0', c1, sbar_alpha_fg);
\r
199 float cl_radar_scale;
\r
200 float cl_radar_content_alpha;
\r
201 float cl_radar_background_alpha;
\r
202 float cl_radar_foreground_alpha;
\r
203 float cl_radar_rotation;
\r
204 vector cl_radar_size;
\r
205 vector cl_radar_position;
\r
206 float cl_radar_zoommode;
\r
208 void radar_loadcvars()
\r
210 v_flipped = cvar("v_flipped");
\r
213 cl_radar_scale = 42; // dummy, not used (see zoommode)
\r
214 cl_radar_content_alpha = 1 * (1 - cvar("_menu_alpha"));
\r
215 cl_radar_background_alpha = 1 * (1 - cvar("_menu_alpha"));
\r
216 cl_radar_foreground_alpha = 1 * (1 - cvar("_menu_alpha"));
\r
217 cl_radar_rotation = cvar("cl_radar_rotation");
\r
218 if(!cl_radar_rotation)
\r
219 cl_radar_rotation = 4;
\r
220 cl_radar_size = '256 256 0'; // TODO make somewhat variable?
\r
221 cl_radar_position = '0.5 0.5 0';
\r
222 cl_radar_zoommode = 3;
\r
223 cl_radar_nohudhack = 0;
\r
227 cl_radar_scale = cvar("cl_radar_scale");
\r
228 cl_radar_content_alpha = cvar("cl_radar_content_alpha") * sbar_alpha_fg;
\r
229 cl_radar_background_alpha = cvar("cl_radar_background_alpha") * sbar_alpha_fg;
\r
230 cl_radar_foreground_alpha = cvar("cl_radar_foreground_alpha") * sbar_alpha_fg;
\r
231 cl_radar_rotation = cvar("cl_radar_rotation");
\r
232 cl_radar_size = stov(cvar_string("cl_radar_size"));
\r
233 cl_radar_position = stov(cvar_string("cl_radar_position"));
\r
234 cl_radar_zoommode = cvar("cl_radar_zoommode");
\r
236 // others default to 0
\r
237 // match this to defaultVoretournament.cfg!
\r
238 if(!cl_radar_scale) cl_radar_scale = 4096;
\r
239 if(!cl_radar_content_alpha) cl_radar_content_alpha = 0.4 * sbar_alpha_fg;
\r
240 if(!cl_radar_background_alpha) cl_radar_background_alpha = 0.4 * sbar_alpha_fg;
\r
241 if(!cl_radar_foreground_alpha) cl_radar_foreground_alpha = 0.8 * sbar_alpha_fg;
\r
242 if(!cl_radar_size_x) cl_radar_size_x = 128;
\r
243 if(!cl_radar_size_y) cl_radar_size_y = cl_radar_size_x;
\r
245 cl_radar_size_z = 0;
\r
246 cl_radar_nohudhack = cl_radar_position_z;
\r
247 cl_radar_position_z = 0;
\r
251 void() radar_view =
\r
253 local float color1; // color already declared as a global in hud.qc
\r
255 float scale2d, normalsize, bigsize;
\r
258 if(minimapname == "" && !ons_showmap)
\r
263 switch(cl_radar_zoommode)
\r
267 f = current_zoomfraction;
\r
270 f = 1 - current_zoomfraction;
\r
280 switch(cl_radar_rotation)
\r
283 radar_angle = view_angles_y - 90;
\r
286 radar_angle = 90 * cl_radar_rotation;
\r
290 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
\r
291 radar_size2d = cl_radar_size;
\r
294 '1 0 0' * (0.5 * radar_size2d_x + cl_radar_position_x * (vid_conwidth - radar_size2d_x))
\r
295 + '0 1 0' * (0.5 * radar_size2d_y + cl_radar_position_y * (vid_conheight - radar_size2d_y));
\r
297 radar_extraclip_mins = radar_extraclip_maxs = '0 0 0';
\r
298 if(cl_radar_position == '1 0 0')
\r
300 if(cl_radar_nohudhack < 2)
\r
301 radar_origin2d_y += 25;
\r
302 if(cl_radar_nohudhack < 1)
\r
303 radar_extraclip_mins_y -= 25;
\r
305 else if(cl_radar_position == '0 1 0' || cl_radar_position == '1 1 0')
\r
307 if(cl_radar_nohudhack < 2)
\r
308 radar_origin2d_y -= 50;
\r
309 //if(cl_radar_nohudhack < 1)
\r
310 //radar_extraclip_size_y += 50; // don't, the HUD looks nice
\r
313 // pixels per world qu to match the radar_size2d_x range in the longest dimension
\r
314 if(cl_radar_rotation == 0)
\r
316 // max-min distance must fit the radar in any rotation
\r
317 bigsize = vlen_minnorm2d(radar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
\r
321 vector c0, c1, c2, c3, span;
\r
322 c0 = rotate(mi_min, radar_angle * DEG2RAD);
\r
323 c1 = rotate(mi_max, radar_angle * DEG2RAD);
\r
324 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, radar_angle * DEG2RAD);
\r
325 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, radar_angle * DEG2RAD);
\r
327 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
\r
328 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
\r
330 // max-min distance must fit the radar in x=x, y=y
\r
332 radar_size2d_x * scale2d / (1.05 * span_x),
\r
333 radar_size2d_y * scale2d / (1.05 * span_y)
\r
337 normalsize = vlen_maxnorm2d(radar_size2d) * scale2d / cl_radar_scale;
\r
338 if(bigsize > normalsize)
\r
339 normalsize = bigsize;
\r
343 + (1 - f) * normalsize;
\r
344 radar_origin3d_in_texcoord = radar_3dcoord_to_texcoord(
\r
345 f * (mi_min + mi_max) * 0.5
\r
346 + (1 - f) * view_origin);
\r
349 radar_origin2d_x - radar_size2d_x * 0.5 + radar_extraclip_mins_x,
\r
350 radar_origin2d_y - radar_size2d_y * 0.5 + radar_extraclip_mins_y,
\r
351 radar_size2d_x + radar_extraclip_maxs_x - radar_extraclip_mins_x,
\r
352 radar_size2d_y + radar_extraclip_maxs_y - radar_extraclip_mins_y
\r
355 draw_radar_background(cl_radar_content_alpha, cl_radar_background_alpha, cl_radar_foreground_alpha);
\r
359 drawresetcliparea();
\r
361 radar_origin2d_x - radar_size2d_x * 0.5,
\r
362 radar_origin2d_y - radar_size2d_y * 0.5,
\r
368 for(tm = world; (tm = find(tm, classname, "radarlink")); )
\r
369 draw_radar_link(tm.origin, tm.velocity, tm.team);
\r
370 for(tm = world; (tm = findflags(tm, radar_icon, 0xFFFFFF)); )
\r
371 draw_radar_icon(tm.origin, tm.radar_icon, tm, tm.radar_color, tm.alpha * sbar_alpha_fg);
\r
372 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
\r
374 color1 = GetPlayerColor(tm.sv_entnum);
\r
375 //if(color == COLOR_SPECTATOR || color == color1)
\r
376 draw_radar_player(tm.origin, tm.angles, GetTeamRGB(color1));
\r
378 draw_radar_player(view_origin, view_angles, '1 1 1');
\r
380 drawresetcliparea();
\r
387 void Ent_RadarLink()
\r
390 sendflags = ReadByte();
\r
392 InterpolateOrigin_Undo();
\r
394 self.iflags = IFLAG_VELOCITY;
\r
395 self.classname = "radarlink";
\r
399 self.origin_x = ReadCoord();
\r
400 self.origin_y = ReadCoord();
\r
401 self.origin_z = ReadCoord();
\r
406 self.velocity_x = ReadCoord();
\r
407 self.velocity_y = ReadCoord();
\r
408 self.velocity_z = ReadCoord();
\r
413 self.team = ReadByte();
\r
416 InterpolateOrigin_Note();
\r