1 #include "teamradar.qh"
3 #include "autocvars.qh"
7 #include "miscfunctions.qh"
8 #include "../common/util.qh"
9 #include "../csqcmodellib/interpolate.qh"
11 float vlen2d(vector v)
13 return sqrt(v.x * v.x + v.y * v.y);
16 float vlen_maxnorm2d(vector v)
18 return max(v.x, v.y, -v.x, -v.y);
21 float vlen_minnorm2d(vector v)
23 return min(max(v.x, -v.x), max(v.y, -v.y));
26 vector teamradar_3dcoord_to_texcoord(vector in)
29 out.x = (in.x - mi_picmin.x) / (mi_picmax.x - mi_picmin.x);
30 out.y = (in.y - mi_picmin.y) / (mi_picmax.y - mi_picmin.y);
35 vector teamradar_texcoord_to_2dcoord(vector in)
38 in -= teamradar_origin3d_in_texcoord;
40 out = rotate(in, teamradar_angle * DEG2RAD);
41 out.y = - out.y; // screen space is reversed
43 out = out * teamradar_size;
46 out += teamradar_origin2d;
50 vector yinvert(vector v)
56 void draw_teamradar_background(float fg)
61 if(fg > 0 && minimapname != "")
65 R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP);
68 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
69 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
70 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
71 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
75 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
76 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
77 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
78 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
84 void draw_teamradar_player(vector coord3d, vector pangles, vector rgb)
88 coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
90 makevectors(pangles - '0 1 0' * teamradar_angle);
93 v_forward.x = -v_forward.x;
94 v_right.x = -v_right.x;
98 v_forward = normalize(v_forward);
100 v_right.x = -v_forward.y;
101 v_right.y = v_forward.x;
108 R_BeginPolygon("", 0);
109 R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, panel_fg_alpha);
110 R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, panel_fg_alpha);
111 R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, panel_fg_alpha);
112 R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, panel_fg_alpha);
115 R_BeginPolygon("", 0);
116 R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, panel_fg_alpha);
117 R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, panel_fg_alpha);
118 R_PolygonVertex(coord-v_forward, '1 0 0', rgb, panel_fg_alpha);
119 R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, panel_fg_alpha);
123 void draw_teamradar_icon(vector coord, float icon, entity pingdata, vector rgb, float a)
125 coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));
126 drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
130 for(int i = 0; i < MAX_TEAMRADAR_TIMES; ++i)
132 float dt = pingdata.(teamradar_times[i]);
136 if(dt >= 1 || dt <= 0)
138 vector v = '2 2 0' * teamradar_size * dt;
139 drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', (1 - dt) * a, DRAWFLAG_ADDITIVE);
144 void draw_teamradar_link(vector start, vector end, int colors)
148 start = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(start));
149 end = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(end));
150 norm = normalize(start - end);
156 c0 = colormapPaletteColor(colors & 0x0F, false);
157 c1 = colormapPaletteColor((colors & 0xF0) / 0x10, false);
159 R_BeginPolygon("", 0);
160 R_PolygonVertex(start - norm, '0 0 0', c0, panel_fg_alpha);
161 R_PolygonVertex(start + norm, '0 1 0', c0, panel_fg_alpha);
162 R_PolygonVertex(end + norm, '1 1 0', c1, panel_fg_alpha);
163 R_PolygonVertex(end - norm, '1 0 0', c1, panel_fg_alpha);
167 void teamradar_loadcvars()
169 v_flipped = autocvar_v_flipped;
170 hud_panel_radar_scale = autocvar_hud_panel_radar_scale;
171 if (hud_panel_radar_maximized && !autocvar__hud_configure)
173 if (autocvar_hud_panel_radar_maximized_scale > 0)
174 hud_panel_radar_scale = autocvar_hud_panel_radar_maximized_scale;
176 hud_panel_radar_foreground_alpha = autocvar_hud_panel_radar_foreground_alpha * panel_fg_alpha;
177 hud_panel_radar_rotation = autocvar_hud_panel_radar_rotation;
178 hud_panel_radar_zoommode = autocvar_hud_panel_radar_zoommode;
179 hud_panel_radar_maximized_rotation = autocvar_hud_panel_radar_maximized_rotation;
180 hud_panel_radar_maximized_zoommode = autocvar_hud_panel_radar_maximized_zoommode;
182 // others default to 0
183 // match this to defaultXonotic.cfg!
184 if(!hud_panel_radar_scale) hud_panel_radar_scale = 4096;
185 if(!hud_panel_radar_foreground_alpha) hud_panel_radar_foreground_alpha = 0.8 * panel_fg_alpha;
186 if(!hud_panel_radar_size.x) hud_panel_radar_size.x = 128;
187 if(!hud_panel_radar_size.y) hud_panel_radar_size.y = hud_panel_radar_size.x;
194 int sendflags = ReadByte();
196 InterpolateOrigin_Undo();
198 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
199 self.classname = "radarlink";
203 self.origin_x = ReadCoord();
204 self.origin_y = ReadCoord();
205 self.origin_z = ReadCoord();
206 setorigin(self, self.origin);
211 self.velocity_x = ReadCoord();
212 self.velocity_y = ReadCoord();
213 self.velocity_z = ReadCoord();
218 self.team = ReadByte();
221 InterpolateOrigin_Note();