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