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)
\r
59 vector pos1, pos2, pos3, pos4;
\r
60 pos1 = '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);
\r
61 pos2 = '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);
\r
62 pos3 = '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);
\r
63 pos4 = '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);
\r
67 R_BeginPolygon("gfx/hud/bg_radar.tga", 0);
\r
68 R_PolygonVertex(pos1, yinvert('0 1 0'), '1 1 1', bg);
\r
69 R_PolygonVertex(pos2, yinvert('1 1 0'), '1 1 1', bg);
\r
70 R_PolygonVertex(pos3, yinvert('1 0 0'), '1 1 1', bg);
\r
71 R_PolygonVertex(pos4, yinvert('0 0 0'), '1 1 1', bg);
\r
75 if(ca > 0 && minimapname != "")
\r
78 R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP);
\r
81 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), col, 1);
\r
82 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), col, 1);
\r
83 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), col, 1);
\r
84 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), col, 1);
\r
88 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), col, 1);
\r
89 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), col, 1);
\r
90 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), col, 1);
\r
91 R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), col, 1);
\r
97 void draw_radar_foreground(float fg)
\r
100 vector pos1, pos2, pos3, pos4;
\r
101 pos1 = '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);
\r
102 pos2 = '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);
\r
103 pos3 = '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);
\r
104 pos4 = '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);
\r
105 rgb = GetTeamRGB(GetPlayerColor(player_localentnum - 1));
\r
109 R_BeginPolygon("gfx/hud/fg_radar.tga", 0);
\r
110 R_PolygonVertex(pos1, yinvert('0 1 0'), '1 1 1', fg);
\r
111 R_PolygonVertex(pos2, yinvert('1 1 0'), '1 1 1', fg);
\r
112 R_PolygonVertex(pos3, yinvert('1 0 0'), '1 1 1', fg);
\r
113 R_PolygonVertex(pos4, yinvert('0 0 0'), '1 1 1', fg);
\r
116 R_BeginPolygon("gfx/hud/fg_radar_team.tga", 0);
\r
117 R_PolygonVertex(pos1, yinvert('0 1 0'), rgb, fg);
\r
118 R_PolygonVertex(pos2, yinvert('1 1 0'), rgb, fg);
\r
119 R_PolygonVertex(pos3, yinvert('1 0 0'), rgb, fg);
\r
120 R_PolygonVertex(pos4, yinvert('0 0 0'), rgb, fg);
\r
125 void(vector coord3d, vector pangles, vector rgb) draw_radar_player =
\r
127 vector coord, rgb2;
\r
129 coord = radar_texcoord_to_2dcoord(radar_3dcoord_to_texcoord(coord3d));
\r
131 makevectors(pangles - '0 1 0' * radar_angle);
\r
134 v_forward_x = -v_forward_x;
\r
135 v_right_x = -v_right_x;
\r
139 v_forward = normalize(v_forward);
\r
140 v_forward_y *= -1.0;
\r
141 v_right_x = -v_forward_y;
\r
142 v_right_y = v_forward_x;
\r
149 R_BeginPolygon("", 0);
\r
150 R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, sbar_alpha_fg);
\r
151 R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, sbar_alpha_fg);
\r
152 R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, sbar_alpha_fg);
\r
153 R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, sbar_alpha_fg);
\r
156 R_BeginPolygon("", 0);
\r
157 R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, sbar_alpha_fg);
\r
158 R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, sbar_alpha_fg);
\r
159 R_PolygonVertex(coord-v_forward, '1 0 0', rgb, sbar_alpha_fg);
\r
160 R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, sbar_alpha_fg);
\r
164 void draw_radar_icon(vector coord, float icon, entity pingdata, vector rgb, float a)
\r
170 coord = radar_texcoord_to_2dcoord(radar_3dcoord_to_texcoord(coord));
\r
171 drawpic(coord - '4 4 0', strcat("gfx/radar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
\r
175 for(i = 0; i < MAX_RADAR_TIMES; ++i)
\r
177 dt = pingdata.(radar_times[i]);
\r
181 if(dt >= 1 || dt <= 0)
\r
183 v = '2 2 0' * radar_size * dt;
\r
184 drawpic(coord - 0.5 * v, "gfx/radar_ping", v, '1 1 1', (1 - dt) * a, DRAWFLAG_ADDITIVE);
\r
189 void draw_radar_link(vector start, vector end, float colors)
\r
191 vector c0, c1, norm;
\r
193 start = radar_texcoord_to_2dcoord(radar_3dcoord_to_texcoord(start));
\r
194 end = radar_texcoord_to_2dcoord(radar_3dcoord_to_texcoord(end));
\r
195 norm = normalize(start - end);
\r
201 c0 = colormapPaletteColor(colors & 0x0F, FALSE);
\r
202 c1 = colormapPaletteColor((colors & 0xF0) / 0x10, FALSE);
\r
204 R_BeginPolygon("", 0);
\r
205 R_PolygonVertex(start - norm, '0 0 0', c0, sbar_alpha_fg);
\r
206 R_PolygonVertex(start + norm, '0 1 0', c0, sbar_alpha_fg);
\r
207 R_PolygonVertex(end + norm, '1 1 0', c1, sbar_alpha_fg);
\r
208 R_PolygonVertex(end - norm, '1 0 0', c1, sbar_alpha_fg);
\r
212 float cl_radar_scale;
\r
213 float cl_radar_content_alpha;
\r
214 float cl_radar_background_alpha;
\r
215 float cl_radar_foreground_alpha;
\r
216 float cl_radar_rotation;
\r
217 vector cl_radar_size;
\r
218 vector cl_radar_position;
\r
219 float cl_radar_zoommode;
\r
221 void radar_loadcvars()
\r
223 v_flipped = cvar("v_flipped");
\r
226 cl_radar_scale = 42; // dummy, not used (see zoommode)
\r
227 cl_radar_content_alpha = 1 * (1 - cvar("_menu_alpha"));
\r
228 cl_radar_background_alpha = 1 * (1 - cvar("_menu_alpha"));
\r
229 cl_radar_foreground_alpha = 1 * (1 - cvar("_menu_alpha"));
\r
230 cl_radar_rotation = cvar("cl_radar_rotation");
\r
231 if(!cl_radar_rotation)
\r
232 cl_radar_rotation = 4;
\r
233 cl_radar_size = '256 256 0'; // TODO make somewhat variable?
\r
234 cl_radar_position = '0.5 0.5 0';
\r
235 cl_radar_zoommode = 3;
\r
236 cl_radar_nohudhack = 0;
\r
240 cl_radar_scale = cvar("cl_radar_scale");
\r
241 cl_radar_content_alpha = cvar("cl_radar_content_alpha") * sbar_alpha_fg;
\r
242 cl_radar_background_alpha = cvar("cl_radar_background_alpha") * sbar_alpha_fg;
\r
243 cl_radar_foreground_alpha = cvar("cl_radar_foreground_alpha") * sbar_alpha_fg;
\r
244 cl_radar_rotation = cvar("cl_radar_rotation");
\r
245 cl_radar_size = stov(cvar_string("cl_radar_size"));
\r
246 cl_radar_position = stov(cvar_string("cl_radar_position"));
\r
247 cl_radar_zoommode = cvar("cl_radar_zoommode");
\r
249 // others default to 0
\r
250 // match this to defaultVoretournament.cfg!
\r
251 if(!cl_radar_scale) cl_radar_scale = 4096;
\r
252 if(!cl_radar_content_alpha) cl_radar_content_alpha = 0.4 * sbar_alpha_fg;
\r
253 if(!cl_radar_background_alpha) cl_radar_background_alpha = 0.4 * sbar_alpha_fg;
\r
254 if(!cl_radar_foreground_alpha) cl_radar_foreground_alpha = 0.8 * sbar_alpha_fg;
\r
255 if(!cl_radar_size_x) cl_radar_size_x = 128;
\r
256 if(!cl_radar_size_y) cl_radar_size_y = cl_radar_size_x;
\r
258 cl_radar_size_z = 0;
\r
259 cl_radar_nohudhack = cl_radar_position_z;
\r
260 cl_radar_position_z = 0;
\r
264 void() radar_view =
\r
266 local float col; // color already declared as a global in hud.qc
\r
268 float scale2d, normalsize, bigsize;
\r
271 if(minimapname == "" && !showmap)
\r
276 switch(cl_radar_zoommode)
\r
280 f = current_zoomfraction;
\r
283 f = 1 - current_zoomfraction;
\r
293 switch(cl_radar_rotation)
\r
296 radar_angle = view_angles_y - 90;
\r
299 radar_angle = 90 * cl_radar_rotation;
\r
303 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
\r
304 radar_size2d = cl_radar_size;
\r
307 '1 0 0' * (0.5 * radar_size2d_x + cl_radar_position_x * (vid_conwidth - radar_size2d_x))
\r
308 + '0 1 0' * (0.5 * radar_size2d_y + cl_radar_position_y * (vid_conheight - radar_size2d_y));
\r
310 radar_extraclip_mins = radar_extraclip_maxs = '0 0 0';
\r
311 if(cl_radar_position == '1 0 0')
\r
313 if(cl_radar_nohudhack < 2)
\r
314 radar_origin2d_y += 25;
\r
315 if(cl_radar_nohudhack < 1)
\r
316 radar_extraclip_mins_y -= 25;
\r
318 else if(cl_radar_position == '0 1 0' || cl_radar_position == '1 1 0')
\r
320 if(cl_radar_nohudhack < 2)
\r
321 radar_origin2d_y -= 50;
\r
322 //if(cl_radar_nohudhack < 1)
\r
323 //radar_extraclip_size_y += 50; // don't, the HUD looks nice
\r
326 // pixels per world qu to match the radar_size2d_x range in the longest dimension
\r
327 if(cl_radar_rotation == 0)
\r
329 // max-min distance must fit the radar in any rotation
\r
330 bigsize = vlen_minnorm2d(radar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
\r
334 vector c0, c1, c2, c3, span;
\r
335 c0 = rotate(mi_min, radar_angle * DEG2RAD);
\r
336 c1 = rotate(mi_max, radar_angle * DEG2RAD);
\r
337 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, radar_angle * DEG2RAD);
\r
338 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, radar_angle * DEG2RAD);
\r
340 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
\r
341 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
\r
343 // max-min distance must fit the radar in x=x, y=y
\r
345 radar_size2d_x * scale2d / (1.05 * span_x),
\r
346 radar_size2d_y * scale2d / (1.05 * span_y)
\r
350 normalsize = vlen_maxnorm2d(radar_size2d) * scale2d / cl_radar_scale;
\r
351 if(bigsize > normalsize)
\r
352 normalsize = bigsize;
\r
356 + (1 - f) * normalsize;
\r
357 radar_origin3d_in_texcoord = radar_3dcoord_to_texcoord(
\r
358 f * (mi_min + mi_max) * 0.5
\r
359 + (1 - f) * view_origin);
\r
362 radar_origin2d_x - radar_size2d_x * 0.5 + radar_extraclip_mins_x,
\r
363 radar_origin2d_y - radar_size2d_y * 0.5 + radar_extraclip_mins_y,
\r
364 radar_size2d_x + radar_extraclip_maxs_x - radar_extraclip_mins_x,
\r
365 radar_size2d_y + radar_extraclip_maxs_y - radar_extraclip_mins_y
\r
368 draw_radar_background(cl_radar_content_alpha, cl_radar_background_alpha);
\r
372 drawresetcliparea();
\r
374 radar_origin2d_x - radar_size2d_x * 0.5,
\r
375 radar_origin2d_y - radar_size2d_y * 0.5,
\r
381 for(tm = world; (tm = find(tm, classname, "radarlink")); )
\r
382 draw_radar_link(tm.origin, tm.velocity, tm.team);
\r
383 for(tm = world; (tm = findflags(tm, radar_icon, 0xFFFFFF)); )
\r
384 draw_radar_icon(tm.origin, tm.radar_icon, tm, tm.radar_color, tm.alpha * sbar_alpha_fg);
\r
385 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
\r
387 col = GetPlayerColor(tm.sv_entnum);
\r
388 //if(color == COLOR_SPECTATOR || color == col)
\r
389 draw_radar_player(tm.origin, tm.angles, GetTeamRGB(col));
\r
391 draw_radar_player(view_origin, view_angles, '1 1 1');
\r
393 drawresetcliparea();
\r
395 draw_radar_foreground(cl_radar_foreground_alpha);
\r
402 void Ent_RadarLink()
\r
405 sendflags = ReadByte();
\r
407 InterpolateOrigin_Undo();
\r
409 self.iflags = IFLAG_VELOCITY;
\r
410 self.classname = "radarlink";
\r
414 self.origin_x = ReadCoord();
\r
415 self.origin_y = ReadCoord();
\r
416 self.origin_z = ReadCoord();
\r
421 self.velocity_x = ReadCoord();
\r
422 self.velocity_y = ReadCoord();
\r
423 self.velocity_z = ReadCoord();
\r
428 self.team = ReadByte();
\r
431 InterpolateOrigin_Note();
\r