float radar_angle; // player yaw angle vector radar_origin3d_in_texcoord; // player origin vector radar_origin2d; // 2D origin vector radar_size2d; // 2D size vector radar_extraclip_mins, radar_extraclip_maxs; // don't even ask float radar_size; // 2D scale factor float cl_radar_scale; // window size = ...qu float cl_radar_nohudhack; float v_flipped; float vlen2d(vector v) { return sqrt(v_x * v_x + v_y * v_y); } float vlen_maxnorm2d(vector v) { return max4(v_x, v_y, -v_x, -v_y); } float vlen_minnorm2d(vector v) { return min(max(v_x, -v_x), max(v_y, -v_y)); } vector radar_3dcoord_to_texcoord(vector in) { vector out; out_x = (in_x - mi_picmin_x) / (mi_picmax_x - mi_picmin_x); out_y = (in_y - mi_picmin_y) / (mi_picmax_y - mi_picmin_y); out_z = 0; return out; } vector radar_texcoord_to_2dcoord(vector in) { vector out; in -= radar_origin3d_in_texcoord; out = rotate(in, radar_angle * DEG2RAD); out_y = - out_y; // screen space is reversed out = out * radar_size; if(v_flipped) out_x = -out_x; out += radar_origin2d; return out; } vector yinvert(vector v) { v_y = 1 - v_y; return v; } void draw_radar_background(float ca, float bg) { vector col; vector pos1, pos2, pos3, pos4; 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); 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); 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); 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); if(bg > 0) { R_BeginPolygon("gfx/hud/bg_radar.tga", 0); R_PolygonVertex(pos1, yinvert('0 1 0'), '1 1 1', bg); R_PolygonVertex(pos2, yinvert('1 1 0'), '1 1 1', bg); R_PolygonVertex(pos3, yinvert('1 0 0'), '1 1 1', bg); R_PolygonVertex(pos4, yinvert('0 0 0'), '1 1 1', bg); R_EndPolygon(); } if(ca > 0 && minimapname != "") { col = '1 1 1' * ca; R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP); if(v_flipped) { R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), col, 1); R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), col, 1); R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), col, 1); R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), col, 1); } else { R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), col, 1); R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), col, 1); R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), col, 1); R_PolygonVertex(radar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), col, 1); } R_EndPolygon(); } } void draw_radar_foreground(float fg) { vector rgb; vector pos1, pos2, pos3, pos4; 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); 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); 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); 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); rgb = GetTeamRGB(GetPlayerColor(player_localentnum - 1)); if(fg > 0) { R_BeginPolygon("gfx/hud/fg_radar.tga", 0); R_PolygonVertex(pos1, yinvert('0 1 0'), '1 1 1', fg); R_PolygonVertex(pos2, yinvert('1 1 0'), '1 1 1', fg); R_PolygonVertex(pos3, yinvert('1 0 0'), '1 1 1', fg); R_PolygonVertex(pos4, yinvert('0 0 0'), '1 1 1', fg); R_EndPolygon(); R_BeginPolygon("gfx/hud/fg_radar_team.tga", 0); R_PolygonVertex(pos1, yinvert('0 1 0'), rgb, fg); R_PolygonVertex(pos2, yinvert('1 1 0'), rgb, fg); R_PolygonVertex(pos3, yinvert('1 0 0'), rgb, fg); R_PolygonVertex(pos4, yinvert('0 0 0'), rgb, fg); R_EndPolygon(); } } void(vector coord3d, vector pangles, vector rgb) draw_radar_player = { vector coord, rgb2; coord = radar_texcoord_to_2dcoord(radar_3dcoord_to_texcoord(coord3d)); makevectors(pangles - '0 1 0' * radar_angle); if(v_flipped) { v_forward_x = -v_forward_x; v_right_x = -v_right_x; v_up_x = -v_up_x; } v_forward_z = 0; v_forward = normalize(v_forward); v_forward_y *= -1.0; v_right_x = -v_forward_y; v_right_y = v_forward_x; if(rgb == '1 1 1') rgb2 = '0 0 0'; else rgb2 = '1 1 1'; R_BeginPolygon("", 0); R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, sbar_alpha_fg); R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, sbar_alpha_fg); R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, sbar_alpha_fg); R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, sbar_alpha_fg); R_EndPolygon(); R_BeginPolygon("", 0); R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, sbar_alpha_fg); R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, sbar_alpha_fg); R_PolygonVertex(coord-v_forward, '1 0 0', rgb, sbar_alpha_fg); R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, sbar_alpha_fg); R_EndPolygon(); }; void draw_radar_icon(vector coord, float icon, entity pingdata, vector rgb, float a) { float dt; vector v; float i; coord = radar_texcoord_to_2dcoord(radar_3dcoord_to_texcoord(coord)); drawpic(coord - '4 4 0', strcat("gfx/radar_icon_", ftos(icon)), '8 8 0', rgb, a, 0); if(pingdata) { for(i = 0; i < MAX_RADAR_TIMES; ++i) { dt = pingdata.(radar_times[i]); if(dt == 0) continue; dt = time - dt; if(dt >= 1 || dt <= 0) continue; v = '2 2 0' * radar_size * dt; drawpic(coord - 0.5 * v, "gfx/radar_ping", v, '1 1 1', (1 - dt) * a, DRAWFLAG_ADDITIVE); } } } void draw_radar_link(vector start, vector end, float colors) { vector c0, c1, norm; start = radar_texcoord_to_2dcoord(radar_3dcoord_to_texcoord(start)); end = radar_texcoord_to_2dcoord(radar_3dcoord_to_texcoord(end)); norm = normalize(start - end); norm_z = norm_x; norm_x = -norm_y; norm_y = norm_z; norm_z = 0; c0 = colormapPaletteColor(colors & 0x0F, FALSE); c1 = colormapPaletteColor((colors & 0xF0) / 0x10, FALSE); R_BeginPolygon("", 0); R_PolygonVertex(start - norm, '0 0 0', c0, sbar_alpha_fg); R_PolygonVertex(start + norm, '0 1 0', c0, sbar_alpha_fg); R_PolygonVertex(end + norm, '1 1 0', c1, sbar_alpha_fg); R_PolygonVertex(end - norm, '1 0 0', c1, sbar_alpha_fg); R_EndPolygon(); } float cl_radar_scale; float cl_radar_content_alpha; float cl_radar_background_alpha; float cl_radar_foreground_alpha; float cl_radar_rotation; vector cl_radar_size; vector cl_radar_position; float cl_radar_zoommode; void radar_loadcvars() { v_flipped = cvar("v_flipped"); if(showmap) { cl_radar_scale = 42; // dummy, not used (see zoommode) cl_radar_content_alpha = 1 * (1 - cvar("_menu_alpha")); cl_radar_background_alpha = 1 * (1 - cvar("_menu_alpha")); cl_radar_foreground_alpha = 1 * (1 - cvar("_menu_alpha")); cl_radar_rotation = cvar("cl_radar_rotation"); if(!cl_radar_rotation) cl_radar_rotation = 4; cl_radar_size = '256 256 0'; // TODO make somewhat variable? cl_radar_position = '0.5 0.5 0'; cl_radar_zoommode = 3; cl_radar_nohudhack = 0; } else { cl_radar_scale = cvar("cl_radar_scale"); cl_radar_content_alpha = cvar("cl_radar_content_alpha") * sbar_alpha_fg; cl_radar_background_alpha = cvar("cl_radar_background_alpha") * sbar_alpha_fg; cl_radar_foreground_alpha = cvar("cl_radar_foreground_alpha") * sbar_alpha_fg; cl_radar_rotation = cvar("cl_radar_rotation"); cl_radar_size = stov(cvar_string("cl_radar_size")); cl_radar_position = stov(cvar_string("cl_radar_position")); cl_radar_zoommode = cvar("cl_radar_zoommode"); // others default to 0 // match this to defaultVoretournament.cfg! if(!cl_radar_scale) cl_radar_scale = 4096; if(!cl_radar_content_alpha) cl_radar_content_alpha = 0.4 * sbar_alpha_fg; if(!cl_radar_background_alpha) cl_radar_background_alpha = 0.4 * sbar_alpha_fg; if(!cl_radar_foreground_alpha) cl_radar_foreground_alpha = 0.8 * sbar_alpha_fg; if(!cl_radar_size_x) cl_radar_size_x = 128; if(!cl_radar_size_y) cl_radar_size_y = cl_radar_size_x; cl_radar_size_z = 0; cl_radar_nohudhack = cl_radar_position_z; cl_radar_position_z = 0; } } void() radar_view = { local float col; // color already declared as a global in hud.qc local entity tm; float scale2d, normalsize, bigsize; float f; if(minimapname == "" && !showmap) return; radar_loadcvars(); switch(cl_radar_zoommode) { default: case 0: f = current_zoomfraction; break; case 1: f = 1 - current_zoomfraction; break; case 2: f = 0; break; case 3: f = 1; break; } switch(cl_radar_rotation) { case 0: radar_angle = view_angles_y - 90; break; default: radar_angle = 90 * cl_radar_rotation; break; } scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin); radar_size2d = cl_radar_size; radar_origin2d = '1 0 0' * (0.5 * radar_size2d_x + cl_radar_position_x * (vid_conwidth - radar_size2d_x)) + '0 1 0' * (0.5 * radar_size2d_y + cl_radar_position_y * (vid_conheight - radar_size2d_y)); radar_extraclip_mins = radar_extraclip_maxs = '0 0 0'; if(cl_radar_position == '1 0 0') { if(cl_radar_nohudhack < 2) radar_origin2d_y += 25; if(cl_radar_nohudhack < 1) radar_extraclip_mins_y -= 25; } else if(cl_radar_position == '0 1 0' || cl_radar_position == '1 1 0') { if(cl_radar_nohudhack < 2) radar_origin2d_y -= 50; //if(cl_radar_nohudhack < 1) //radar_extraclip_size_y += 50; // don't, the HUD looks nice } // pixels per world qu to match the radar_size2d_x range in the longest dimension if(cl_radar_rotation == 0) { // max-min distance must fit the radar in any rotation bigsize = vlen_minnorm2d(radar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min)); } else { vector c0, c1, c2, c3, span; c0 = rotate(mi_min, radar_angle * DEG2RAD); c1 = rotate(mi_max, radar_angle * DEG2RAD); c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, radar_angle * DEG2RAD); c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, radar_angle * DEG2RAD); span = '0 0 0'; span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x); span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y); // max-min distance must fit the radar in x=x, y=y bigsize = min( radar_size2d_x * scale2d / (1.05 * span_x), radar_size2d_y * scale2d / (1.05 * span_y) ); } normalsize = vlen_maxnorm2d(radar_size2d) * scale2d / cl_radar_scale; if(bigsize > normalsize) normalsize = bigsize; radar_size = f * bigsize + (1 - f) * normalsize; radar_origin3d_in_texcoord = radar_3dcoord_to_texcoord( f * (mi_min + mi_max) * 0.5 + (1 - f) * view_origin); drawsetcliparea( radar_origin2d_x - radar_size2d_x * 0.5 + radar_extraclip_mins_x, radar_origin2d_y - radar_size2d_y * 0.5 + radar_extraclip_mins_y, radar_size2d_x + radar_extraclip_maxs_x - radar_extraclip_mins_x, radar_size2d_y + radar_extraclip_maxs_y - radar_extraclip_mins_y ); draw_radar_background(cl_radar_content_alpha, cl_radar_background_alpha); if(showmap) { drawresetcliparea(); drawsetcliparea( radar_origin2d_x - radar_size2d_x * 0.5, radar_origin2d_y - radar_size2d_y * 0.5, radar_size2d_x, radar_size2d_y ); } for(tm = world; (tm = find(tm, classname, "radarlink")); ) draw_radar_link(tm.origin, tm.velocity, tm.team); for(tm = world; (tm = findflags(tm, radar_icon, 0xFFFFFF)); ) draw_radar_icon(tm.origin, tm.radar_icon, tm, tm.radar_color, tm.alpha * sbar_alpha_fg); for(tm = world; (tm = find(tm, classname, "entcs_receiver")); ) { col = GetPlayerColor(tm.sv_entnum); if(cvar("cl_radar_players") > 1 || (cvar("cl_radar_players") > 0 && teamplay && GetPlayerColor(player_localentnum - 1) == col)) if not(tm.eaten) // don't show prey on the radar draw_radar_player(tm.origin, tm.angles, GetTeamRGB(col)); } draw_radar_player(view_origin, view_angles, '1 1 1'); drawresetcliparea(); draw_radar_foreground(cl_radar_foreground_alpha); }; // radar links void Ent_RadarLink() { float sendflags; sendflags = ReadByte(); InterpolateOrigin_Undo(); self.iflags = IFLAG_VELOCITY; self.classname = "radarlink"; if(sendflags & 1) { self.origin_x = ReadCoord(); self.origin_y = ReadCoord(); self.origin_z = ReadCoord(); } if(sendflags & 2) { self.velocity_x = ReadCoord(); self.velocity_y = ReadCoord(); self.velocity_z = ReadCoord(); } if(sendflags & 4) { self.team = ReadByte(); } InterpolateOrigin_Note(); }