]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/teamradar.qc
make "cl_teamradar 2" use the new radar in Onslaught too, overriding ons_map (for...
[divverent/nexuiz.git] / data / 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 float teamradar_size; // 2D scale factor
6 float teamradar_scale; // window size = ...qu
7
8 vector teamradar_3dcoord_to_texcoord(vector in)
9 {
10         vector out;
11         out_x = (in_x - mi_picmin_x) / (mi_picmax_x - mi_picmin_x);
12         out_y = (in_y - mi_picmin_y) / (mi_picmax_y - mi_picmin_y);
13         out_z = 0;
14         return out;
15 }
16
17 vector teamradar_texcoord_to_2dcoord(vector in)
18 {
19         vector out;
20         in -= teamradar_origin3d_in_texcoord;
21
22         out = rotate(in, teamradar_angle * DEG2RAD);
23         out_y = - out_y; // screen space is reversed
24
25         out = out * teamradar_size;
26         out += teamradar_origin2d;
27         return out;
28 }
29
30 vector yinvert(vector v)
31 {
32         v_y = 1 - v_y;
33         return v;
34 }
35
36 void draw_teamradar_background(float a)
37 {
38         if(a <= 0)
39                 return;
40
41         R_BeginPolygon(minimapname, 0);
42         R_PolygonVertex('1 0 0' * (teamradar_origin2d_x - teamradar_size2d_x * 0.5) + '0 1 0' * (teamradar_origin2d_y - teamradar_size2d_y * 0.5), '0 0 0', '0 0 0', a);
43         R_PolygonVertex('1 0 0' * (teamradar_origin2d_x + teamradar_size2d_x * 0.5) + '0 1 0' * (teamradar_origin2d_y - teamradar_size2d_y * 0.5), '0 0 0', '0 0 0', a);
44         R_PolygonVertex('1 0 0' * (teamradar_origin2d_x + teamradar_size2d_x * 0.5) + '0 1 0' * (teamradar_origin2d_y + teamradar_size2d_y * 0.5), '0 0 0', '0 0 0', a);
45         R_PolygonVertex('1 0 0' * (teamradar_origin2d_x - teamradar_size2d_x * 0.5) + '0 1 0' * (teamradar_origin2d_y + teamradar_size2d_y * 0.5), '0 0 0', '0 0 0', a);
46         R_EndPolygon();
47
48         R_BeginPolygon(minimapname, DRAWFLAG_ADDITIVE);
49         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), '1 1 1', 1);
50         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), '1 1 1', 1);
51         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), '1 1 1', 1);
52         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), '1 1 1', 1);
53         R_EndPolygon();
54 }
55
56 void(vector coord3d, vector pangles, vector rgb) draw_teamradar_player =
57 {
58         vector coord, rgb2;
59
60         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
61
62         makevectors(pangles - '0 1 0' * teamradar_angle);
63         v_forward_z = 0;
64         v_forward = normalize(v_forward);
65         v_forward_y *= -1.0;
66         v_right_x = -v_forward_y;
67         v_right_y = v_forward_x;
68
69         if(rgb == '1 1 1')
70                 rgb2 = '0 0 0';
71         else
72                 rgb2 = '1 1 1';
73
74         R_BeginPolygon("", 0);
75         R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, 1);
76         R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, 1);
77         R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, 1);
78         R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, 1);
79         R_EndPolygon();
80
81         R_BeginPolygon("", 0);
82         R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, 1);
83         R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, 1);
84         R_PolygonVertex(coord-v_forward, '1 0 0', rgb, 1);
85         R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, 1);
86         R_EndPolygon();
87 };
88
89 void draw_teamradar_icon(vector coord, float icon, float pingtime, vector rgb, float a)
90 {
91         float dt;
92         vector v;
93
94         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));
95         drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
96         if(pingtime != 0)
97         {
98                 dt = time - pingtime;
99                 if(dt > 1)
100                         return;
101                 v = '2 2 0' * teamradar_size * dt;
102                 drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', 1 - dt, DRAWFLAG_ADDITIVE);
103         }
104 }
105
106 void() teamradar_view =
107 {
108         local float color;
109         local vector rgb;
110         local entity tm;
111         float scale2d, normalsize, bigsize;
112         float a, f;
113
114         color = GetPlayerColor(player_localentnum-1);
115         rgb = GetTeamRGB(color);
116
117         scale2d = max(
118                 mi_picmax_x - mi_picmin_x,
119                 mi_picmax_y - mi_picmin_y
120         );
121
122         f = current_zoomfraction;
123         teamradar_scale = cvar("cl_teamradar_scale");
124         a = cvar("cl_teamradar_background_alpha");
125         teamradar_angle = cvar("cl_teamradar_rotation") * 90;
126
127         // fix undefined cvars first
128         if(!teamradar_scale)
129                 teamradar_scale = 4096;
130         if(!a)
131                 a = 0.75;
132
133         if(teamradar_scale < 0)
134         {
135                 current_zoomfraction = 1 - current_zoomfraction;
136                 teamradar_scale = -teamradar_scale;
137         }
138
139         if(!teamradar_angle)
140                 teamradar_angle = input_angles_y - 90;
141         teamradar_origin2d = '64 64 0';
142         teamradar_size2d = '128 128 0';
143
144         normalsize = teamradar_size2d_x * scale2d / teamradar_scale;
145         bigsize = teamradar_size2d_x * scale2d / vlen(mi_min - mi_max);
146         if(bigsize > normalsize)
147                 normalsize = bigsize;
148         teamradar_size =
149                   f * bigsize
150                 + (1 - f) * normalsize;
151         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
152                   f * (mi_min + mi_max) * 0.5
153                 + (1 - f) * pmove_org);
154
155         drawsetcliparea(
156                 teamradar_origin2d_x - teamradar_size2d_x * 0.5,
157                 teamradar_origin2d_y - teamradar_size2d_y * 0.5,
158                 teamradar_size2d_x,
159                 teamradar_size2d_y
160         );
161
162         draw_teamradar_background(a);
163         for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
164                 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm.teamradar_time, tm.teamradar_color, tm.alpha);
165         for(tm = gps_start; tm != world; tm = tm.chain)
166                 draw_teamradar_player(tm.origin, tm.angles, rgb);
167         draw_teamradar_player(pmove_org, input_angles, '1 1 1');
168
169         drawresetcliparea();
170 };