]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/teamradar.qc
Merge branch 'master' into Mario/ons_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / teamradar.qc
1 float teamradar_angle; // player yaw angle
2 vector teamradar_origin3d_in_texcoord; // player origin
3 vector teamradar_origin2d; // 2D origin
4 vector teamradar_size2d; // 2D size
5 vector teamradar_extraclip_mins, teamradar_extraclip_maxs; // for non-centered radar display
6 float teamradar_size; // 2D scale factor
7 float hud_panel_radar_scale; // window size = ...qu
8 float v_flipped;
9
10 float vlen2d(vector v)
11 {
12         return sqrt(v_x * v_x + v_y * v_y);
13 }
14
15 float vlen_maxnorm2d(vector v)
16 {
17         return max(v_x, v_y, -v_x, -v_y);
18 }
19
20 float vlen_minnorm2d(vector v)
21 {
22         return min(max(v_x, -v_x), max(v_y, -v_y));
23 }
24
25 vector teamradar_3dcoord_to_texcoord(vector in)
26 {
27         vector out;
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);
30         out_z = 0;
31         return out;
32 }
33
34 vector teamradar_texcoord_to_2dcoord(vector in)
35 {
36         vector out;
37         in -= teamradar_origin3d_in_texcoord;
38
39         out = rotate(in, teamradar_angle * DEG2RAD);
40         out_y = - out_y; // screen space is reversed
41
42         out = out * teamradar_size;
43         if(v_flipped)
44                 out_x = -out_x;
45         out += teamradar_origin2d;
46         return out;
47 }
48
49
50 vector teamradar_2dcoord_to_texcoord(vector in)
51 {
52         vector out;
53         out = in;
54         
55         out -= teamradar_origin2d;
56         if(v_flipped)
57                 out_x = -out_x;
58         out = out / teamradar_size;
59         
60         out_y = - out_y; // screen space is reversed
61         out = rotate(out, -teamradar_angle * DEG2RAD);
62         
63         out += teamradar_origin3d_in_texcoord;
64
65         return out;
66 }
67
68 vector teamradar_texcoord_to_3dcoord(vector in,float z)
69 {
70         vector out;
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;
73         out_z = z;
74         return out;
75 }
76
77 vector yinvert(vector v)
78 {
79         v_y = 1 - v_y;
80         return v;
81 }
82
83 void draw_teamradar_background(float fg)
84 {
85         float fga;
86         vector fgc;
87
88         if(fg > 0 && minimapname != "")
89         {
90                 fga = 1;
91                 fgc = '1 1 1' * fg;
92                 R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP);
93                 if(v_flipped)
94                 {
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);
99                 }
100                 else
101                 {
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);
106                 }
107                 R_EndPolygon();
108         }
109 }
110
111 void draw_teamradar_player(vector coord3d, vector pangles, vector rgb)
112 {
113         vector coord, rgb2;
114
115         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
116
117         makevectors(pangles - '0 1 0' * teamradar_angle);
118         if(v_flipped)
119         {
120                 v_forward_x = -v_forward_x;
121                 v_right_x = -v_right_x;
122                 v_up_x = -v_up_x;
123         }
124         v_forward_z = 0;
125         v_forward = normalize(v_forward);
126         v_forward_y *= -1.0;
127         v_right_x = -v_forward_y;
128         v_right_y = v_forward_x;
129
130         if(rgb == '1 1 1')
131                 rgb2 = '0 0 0';
132         else
133                 rgb2 = '1 1 1';
134
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);
140         R_EndPolygon();
141
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);
147         R_EndPolygon();
148 }
149
150 void draw_teamradar_icon(vector coord, float icon, entity pingdata, vector rgb, float a)
151 {
152         float dt;
153         vector v;
154         float i;
155
156         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));
157         drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
158
159         if(pingdata)
160         {
161                 for(i = 0; i < MAX_TEAMRADAR_TIMES; ++i)
162                 {
163                         dt = pingdata.(teamradar_times[i]);
164                         if(dt == 0)
165                                 continue;
166                         dt = time - dt;
167                         if(dt >= 1 || dt <= 0)
168                                 continue;
169                         v = '2 2 0' * teamradar_size * dt;
170                         drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', (1 - dt) * a, DRAWFLAG_ADDITIVE);
171                 }
172         }
173 }
174
175 void draw_teamradar_link(vector start, vector end, float colors)
176 {
177         vector c0, c1, norm;
178
179         start = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(start));
180         end = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(end));
181         norm = normalize(start - end);
182         norm_z = norm_x;
183         norm_x = -norm_y;
184         norm_y = norm_z;
185         norm_z = 0;
186
187         c0 = colormapPaletteColor(colors & 0x0F, FALSE);
188         c1 = colormapPaletteColor((colors & 0xF0) / 0x10, FALSE);
189
190         R_BeginPolygon("", 0);
191         R_PolygonVertex(start - norm, '0 0 0', c0, panel_fg_alpha);
192         R_PolygonVertex(start + norm, '0 1 0', c0, panel_fg_alpha);
193         R_PolygonVertex(end + norm, '1 1 0', c1, panel_fg_alpha);
194         R_PolygonVertex(end - norm, '1 0 0', c1, panel_fg_alpha);
195         R_EndPolygon();
196 }
197
198 float hud_panel_radar_scale;
199 float hud_panel_radar_foreground_alpha;
200 float hud_panel_radar_rotation;
201 noref vector hud_panel_radar_size; // fteqcc sucks
202 float hud_panel_radar_zoommode;
203 float hud_panel_radar_maximized_zoommode;
204 float hud_panel_radar_maximized_rotation;
205
206 void teamradar_loadcvars()
207 {
208         v_flipped = autocvar_v_flipped;
209         hud_panel_radar_scale = autocvar_hud_panel_radar_scale;
210         if (hud_panel_radar_maximized && !autocvar__hud_configure)
211         {
212                 if (autocvar_hud_panel_radar_maximized_scale > 0)
213                         hud_panel_radar_scale = autocvar_hud_panel_radar_maximized_scale;
214         }
215         hud_panel_radar_foreground_alpha = autocvar_hud_panel_radar_foreground_alpha * panel_fg_alpha;
216         hud_panel_radar_rotation = autocvar_hud_panel_radar_rotation;
217         hud_panel_radar_zoommode = autocvar_hud_panel_radar_zoommode;
218         hud_panel_radar_maximized_rotation = autocvar_hud_panel_radar_maximized_rotation;
219         hud_panel_radar_maximized_zoommode = autocvar_hud_panel_radar_maximized_zoommode;
220
221         // others default to 0
222         // match this to defaultXonotic.cfg!
223         if(!hud_panel_radar_scale) hud_panel_radar_scale = 4096;
224         if(!hud_panel_radar_foreground_alpha) hud_panel_radar_foreground_alpha = 0.8 * panel_fg_alpha;
225         if(!hud_panel_radar_size_x) hud_panel_radar_size_x = 128;
226         if(!hud_panel_radar_size_y) hud_panel_radar_size_y = hud_panel_radar_size_x;
227 }
228
229 // radar links
230
231 void Ent_RadarLink()
232 {
233         float sendflags;
234         sendflags = ReadByte();
235
236         InterpolateOrigin_Undo();
237
238         self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
239         self.classname = "radarlink";
240
241         if(sendflags & 1)
242         {
243                 self.origin_x = ReadCoord();
244                 self.origin_y = ReadCoord();
245                 self.origin_z = ReadCoord();
246                 setorigin(self, self.origin);
247         }
248
249         if(sendflags & 2)
250         {
251                 self.velocity_x = ReadCoord();
252                 self.velocity_y = ReadCoord();
253                 self.velocity_z = ReadCoord();
254         }
255
256         if(sendflags & 4)
257         {
258                 self.team = ReadByte();
259         }
260
261         InterpolateOrigin_Note();
262 }