1 #include "teamradar.qh"
6 #include "../common/util.qh"
8 #include "../csqcmodellib/interpolate.qh"
10 float vlen2d(vector v)
12 return sqrt(v.x * v.x + v.y * v.y);
15 float vlen_maxnorm2d(vector v)
17 return max(v.x, v.y, -v.x, -v.y);
20 float vlen_minnorm2d(vector v)
22 return min(max(v.x, -v.x), max(v.y, -v.y));
25 vector teamradar_3dcoord_to_texcoord(vector in)
28 out.x = (in.x - mi_picmin.x) / (mi_picmax.x - mi_picmin.x);
29 out.y = (in.y - mi_picmin.y) / (mi_picmax.y - mi_picmin.y);
34 vector teamradar_texcoord_to_2dcoord(vector in)
37 in -= teamradar_origin3d_in_texcoord;
39 out = rotate(in, teamradar_angle * DEG2RAD);
40 out.y = - out.y; // screen space is reversed
42 out = out * teamradar_size;
45 out += teamradar_origin2d;
50 vector teamradar_2dcoord_to_texcoord(vector in)
55 out -= teamradar_origin2d;
58 out = out / teamradar_size;
60 out_y = - out_y; // screen space is reversed
61 out = rotate(out, -teamradar_angle * DEG2RAD);
63 out += teamradar_origin3d_in_texcoord;
68 vector teamradar_texcoord_to_3dcoord(vector in,float z)
71 out_x = in_x * (mi_picmax_x - mi_picmin_x) + mi_picmin_x;
72 out_y = in_y * (mi_picmax_y - mi_picmin_y) + mi_picmin_y;
77 vector yinvert(vector v)
83 void draw_teamradar_background(float fg)
88 if(fg > 0 && minimapname != "")
92 R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP);
95 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
96 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
97 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
98 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
102 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
103 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
104 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
105 R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
111 void draw_teamradar_player(vector coord3d, vector pangles, vector rgb)
115 coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
117 makevectors(pangles - '0 1 0' * teamradar_angle);
120 v_forward.x = -v_forward.x;
121 v_right.x = -v_right.x;
125 v_forward = normalize(v_forward);
127 v_right.x = -v_forward.y;
128 v_right.y = v_forward.x;
135 R_BeginPolygon("", 0);
136 R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, panel_fg_alpha);
137 R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, panel_fg_alpha);
138 R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, panel_fg_alpha);
139 R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, panel_fg_alpha);
142 R_BeginPolygon("", 0);
143 R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, panel_fg_alpha);
144 R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, panel_fg_alpha);
145 R_PolygonVertex(coord-v_forward, '1 0 0', rgb, panel_fg_alpha);
146 R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, panel_fg_alpha);
150 void draw_teamradar_icon(vector coord, float icon, entity pingdata, vector rgb, float a)
152 coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));
153 drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
157 for(int i = 0; i < MAX_TEAMRADAR_TIMES; ++i)
159 float dt = pingdata.(teamradar_times[i]);
163 if(dt >= 1 || dt <= 0)
165 vector v = '2 2 0' * teamradar_size * dt;
166 drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', (1 - dt) * a, DRAWFLAG_ADDITIVE);
171 void draw_teamradar_link(vector start, vector end, int colors)
175 start = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(start));
176 end = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(end));
177 norm = normalize(start - end);
183 c0 = colormapPaletteColor(colors & 0x0F, false);
184 c1 = colormapPaletteColor((colors & 0xF0) / 0x10, false);
186 R_BeginPolygon("", 0);
187 R_PolygonVertex(start - norm, '0 0 0', c0, panel_fg_alpha);
188 R_PolygonVertex(start + norm, '0 1 0', c0, panel_fg_alpha);
189 R_PolygonVertex(end + norm, '1 1 0', c1, panel_fg_alpha);
190 R_PolygonVertex(end - norm, '1 0 0', c1, panel_fg_alpha);
194 void teamradar_loadcvars()
196 v_flipped = autocvar_v_flipped;
197 hud_panel_radar_scale = autocvar_hud_panel_radar_scale;
198 if (hud_panel_radar_maximized && !autocvar__hud_configure)
200 if (autocvar_hud_panel_radar_maximized_scale > 0)
201 hud_panel_radar_scale = autocvar_hud_panel_radar_maximized_scale;
203 hud_panel_radar_foreground_alpha = autocvar_hud_panel_radar_foreground_alpha * panel_fg_alpha;
204 hud_panel_radar_rotation = autocvar_hud_panel_radar_rotation;
205 hud_panel_radar_zoommode = autocvar_hud_panel_radar_zoommode;
206 hud_panel_radar_maximized_rotation = autocvar_hud_panel_radar_maximized_rotation;
207 hud_panel_radar_maximized_zoommode = autocvar_hud_panel_radar_maximized_zoommode;
209 // others default to 0
210 // match this to defaultXonotic.cfg!
211 if(!hud_panel_radar_scale) hud_panel_radar_scale = 4096;
212 if(!hud_panel_radar_foreground_alpha) hud_panel_radar_foreground_alpha = 0.8 * panel_fg_alpha;
213 if(!hud_panel_radar_size.x) hud_panel_radar_size.x = 128;
214 if(!hud_panel_radar_size.y) hud_panel_radar_size.y = hud_panel_radar_size.x;
221 int sendflags = ReadByte();
223 InterpolateOrigin_Undo();
225 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
226 self.classname = "radarlink";
230 self.origin_x = ReadCoord();
231 self.origin_y = ReadCoord();
232 self.origin_z = ReadCoord();
233 setorigin(self, self.origin);
238 self.velocity_x = ReadCoord();
239 self.velocity_y = ReadCoord();
240 self.velocity_z = ReadCoord();
245 self.team = ReadByte();
248 InterpolateOrigin_Note();