]> 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 #if defined(CSQC)
2         #include "teamradar.qh"
3 #elif defined(MENUQC)
4 #elif defined(SVQC)
5 #endif
6
7 float vlen2d(vector v)
8 {
9         return sqrt(v.x * v.x + v.y * v.y);
10 }
11
12 float vlen_maxnorm2d(vector v)
13 {
14         return max(v.x, v.y, -v.x, -v.y);
15 }
16
17 float vlen_minnorm2d(vector v)
18 {
19         return min(max(v.x, -v.x), max(v.y, -v.y));
20 }
21
22 vector teamradar_3dcoord_to_texcoord(vector in)
23 {
24         vector out;
25         out.x = (in.x - mi_picmin.x) / (mi_picmax.x - mi_picmin.x);
26         out.y = (in.y - mi_picmin.y) / (mi_picmax.y - mi_picmin.y);
27         out.z = 0;
28         return out;
29 }
30
31 vector teamradar_texcoord_to_2dcoord(vector in)
32 {
33         vector out;
34         in -= teamradar_origin3d_in_texcoord;
35
36         out = rotate(in, teamradar_angle * DEG2RAD);
37         out.y = - out.y; // screen space is reversed
38
39         out = out * teamradar_size;
40         if(v_flipped)
41                 out.x = -out.x;
42         out += teamradar_origin2d;
43         return out;
44 }
45
46
47 vector teamradar_2dcoord_to_texcoord(vector in)
48 {
49         vector out;
50         out = in;
51         
52         out -= teamradar_origin2d;
53         if(v_flipped)
54                 out_x = -out_x;
55         out = out / teamradar_size;
56         
57         out_y = - out_y; // screen space is reversed
58         out = rotate(out, -teamradar_angle * DEG2RAD);
59         
60         out += teamradar_origin3d_in_texcoord;
61
62         return out;
63 }
64
65 vector teamradar_texcoord_to_3dcoord(vector in,float z)
66 {
67         vector out;
68         out_x = in_x * (mi_picmax_x - mi_picmin_x) + mi_picmin_x;
69         out_y = in_y * (mi_picmax_y - mi_picmin_y) + mi_picmin_y;
70         out_z = z;
71         return out;
72 }
73
74 vector yinvert(vector v)
75 {
76         v.y = 1 - v.y;
77         return v;
78 }
79
80 void draw_teamradar_background(float fg)
81 {
82         float fga;
83         vector fgc;
84
85         if(fg > 0 && minimapname != "")
86         {
87                 fga = 1;
88                 fgc = '1 1 1' * fg;
89                 R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP);
90                 if(v_flipped)
91                 {
92                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
93                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
94                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
95                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
96                 }
97                 else
98                 {
99                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
100                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
101                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
102                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
103                 }
104                 R_EndPolygon();
105         }
106 }
107
108 void draw_teamradar_player(vector coord3d, vector pangles, vector rgb)
109 {
110         vector coord, rgb2;
111
112         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
113
114         makevectors(pangles - '0 1 0' * teamradar_angle);
115         if(v_flipped)
116         {
117                 v_forward.x = -v_forward.x;
118                 v_right.x = -v_right.x;
119                 v_up.x = -v_up.x;
120         }
121         v_forward.z = 0;
122         v_forward = normalize(v_forward);
123         v_forward.y *= -1.0;
124         v_right.x = -v_forward.y;
125         v_right.y = v_forward.x;
126
127         if(rgb == '1 1 1')
128                 rgb2 = '0 0 0';
129         else
130                 rgb2 = '1 1 1';
131
132         R_BeginPolygon("", 0);
133         R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, panel_fg_alpha);
134         R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, panel_fg_alpha);
135         R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, panel_fg_alpha);
136         R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, panel_fg_alpha);
137         R_EndPolygon();
138
139         R_BeginPolygon("", 0);
140         R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, panel_fg_alpha);
141         R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, panel_fg_alpha);
142         R_PolygonVertex(coord-v_forward, '1 0 0', rgb, panel_fg_alpha);
143         R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, panel_fg_alpha);
144         R_EndPolygon();
145 }
146
147 void draw_teamradar_icon(vector coord, float icon, entity pingdata, vector rgb, float a)
148 {
149         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));
150         drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
151
152         if(pingdata)
153         {
154                 for(int i = 0; i < MAX_TEAMRADAR_TIMES; ++i)
155                 {
156                         float dt = pingdata.(teamradar_times[i]);
157                         if(dt == 0)
158                                 continue;
159                         dt = time - dt;
160                         if(dt >= 1 || dt <= 0)
161                                 continue;
162                         vector v = '2 2 0' * teamradar_size * dt;
163                         drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', (1 - dt) * a, DRAWFLAG_ADDITIVE);
164                 }
165         }
166 }
167
168 void draw_teamradar_link(vector start, vector end, int colors)
169 {
170         vector c0, c1, norm;
171
172         start = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(start));
173         end = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(end));
174         norm = normalize(start - end);
175         norm.z = norm.x;
176         norm.x = -norm.y;
177         norm.y = norm.z;
178         norm.z = 0;
179
180         c0 = colormapPaletteColor(colors & 0x0F, false);
181         c1 = colormapPaletteColor((colors & 0xF0) / 0x10, false);
182
183         R_BeginPolygon("", 0);
184         R_PolygonVertex(start - norm, '0 0 0', c0, panel_fg_alpha);
185         R_PolygonVertex(start + norm, '0 1 0', c0, panel_fg_alpha);
186         R_PolygonVertex(end + norm, '1 1 0', c1, panel_fg_alpha);
187         R_PolygonVertex(end - norm, '1 0 0', c1, panel_fg_alpha);
188         R_EndPolygon();
189 }
190
191 void teamradar_loadcvars()
192 {
193         v_flipped = autocvar_v_flipped;
194         hud_panel_radar_scale = autocvar_hud_panel_radar_scale;
195         if (hud_panel_radar_maximized && !autocvar__hud_configure)
196         {
197                 if (autocvar_hud_panel_radar_maximized_scale > 0)
198                         hud_panel_radar_scale = autocvar_hud_panel_radar_maximized_scale;
199         }
200         hud_panel_radar_foreground_alpha = autocvar_hud_panel_radar_foreground_alpha * panel_fg_alpha;
201         hud_panel_radar_rotation = autocvar_hud_panel_radar_rotation;
202         hud_panel_radar_zoommode = autocvar_hud_panel_radar_zoommode;
203         hud_panel_radar_maximized_rotation = autocvar_hud_panel_radar_maximized_rotation;
204         hud_panel_radar_maximized_zoommode = autocvar_hud_panel_radar_maximized_zoommode;
205
206         // others default to 0
207         // match this to defaultXonotic.cfg!
208         if(!hud_panel_radar_scale) hud_panel_radar_scale = 4096;
209         if(!hud_panel_radar_foreground_alpha) hud_panel_radar_foreground_alpha = 0.8 * panel_fg_alpha;
210         if(!hud_panel_radar_size.x) hud_panel_radar_size.x = 128;
211         if(!hud_panel_radar_size.y) hud_panel_radar_size.y = hud_panel_radar_size.x;
212 }
213
214 // radar links
215
216 void Ent_RadarLink()
217 {
218         int sendflags = ReadByte();
219
220         InterpolateOrigin_Undo();
221
222         self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
223         self.classname = "radarlink";
224
225         if(sendflags & 1)
226         {
227                 self.origin_x = ReadCoord();
228                 self.origin_y = ReadCoord();
229                 self.origin_z = ReadCoord();
230                 setorigin(self, self.origin);
231         }
232
233         if(sendflags & 2)
234         {
235                 self.velocity_x = ReadCoord();
236                 self.velocity_y = ReadCoord();
237                 self.velocity_z = ReadCoord();
238         }
239
240         if(sendflags & 4)
241         {
242                 self.team = ReadByte();
243         }
244
245         InterpolateOrigin_Note();
246 }