]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/teamradar.qc
new waypointsprite system, onslaught not yet supported
[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 = -v_y;
33         return v;
34 }
35
36 void draw_teamradar_background(float a)
37 {
38         R_BeginPolygon(minimapname, 0);
39         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);
40         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);
41         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);
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_EndPolygon();
44         R_BeginPolygon(minimapname, DRAWFLAG_ADDITIVE);
45         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), '1 1 1', 1);
46         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), '1 1 1', 1);
47         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), '1 1 1', 1);
48         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), '1 1 1', 1);
49         R_EndPolygon();
50 }
51
52 void(vector coord3d, vector pangles, vector rgb) draw_teamradar_player =
53 {
54         vector coord, rgb2;
55
56         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
57
58         makevectors(pangles - '0 1 0' * teamradar_angle);
59         v_forward_z = 0;
60         v_forward = normalize(v_forward);
61         v_forward_y *= -1.0;
62         v_right_x = -v_forward_y;
63         v_right_y = v_forward_x;
64
65         if(rgb != '1 1 1')
66         {
67                 rgb2 = '1 1 1';
68                 R_BeginPolygon("", 0);
69                 R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, 1);
70                 R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, 1);
71                 R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, 1);
72                 R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, 1);
73                 R_EndPolygon();
74         }
75
76         R_BeginPolygon("", 0);
77         R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, 1);
78         R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, 1);
79         R_PolygonVertex(coord-v_forward, '1 0 0', rgb, 1);
80         R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, 1);
81         R_EndPolygon();
82 };
83
84 void draw_teamradar_icon(vector coord, float icon, float pingtime, vector rgb, float a)
85 {
86         float dt;
87         vector v;
88
89         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));
90         drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
91         if(pingtime != 0)
92         {
93                 dt = time - pingtime;
94                 if(dt > 1)
95                         return;
96                 v = '2 2 0' * teamradar_size * dt;
97                 drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', 1 - dt, DRAWFLAG_ADDITIVE);
98         }
99 }
100
101 void() teamradar_view =
102 {
103         local float color;
104         local vector coord, rgb;
105         local entity tm;
106         float scale2d, normalsize, bigsize;
107
108         if(!cvar("cl_teamradar"))
109                 return;
110
111         color = GetPlayerColor(player_localentnum-1);
112         rgb = GetTeamRGB(color);
113
114         scale2d = max(
115                 mi_picmax_x - mi_picmin_x,
116                 mi_picmax_y - mi_picmin_y
117         );
118
119         teamradar_angle = cvar("cl_teamradar_rotation") * 4;
120         if(!teamradar_angle)
121                 teamradar_angle = input_angles_y - 90;
122         teamradar_origin2d = '64 64 0';
123         teamradar_size2d = '128 128 0';
124         teamradar_scale = 2048;
125
126         normalsize = teamradar_size2d_x * scale2d / teamradar_scale;
127         bigsize = teamradar_size2d_x * scale2d / max(teamradar_scale, vlen(mi_min - mi_max));
128         teamradar_size =
129                   current_zoomfraction * bigsize
130                 + (1 - current_zoomfraction) * normalsize;
131         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
132                   current_zoomfraction * (mi_min + mi_max) * 0.5
133                 + (1 - current_zoomfraction) * pmove_org);
134
135         drawsetcliparea(
136                 teamradar_origin2d_x - teamradar_size2d_x * 0.5,
137                 teamradar_origin2d_y - teamradar_size2d_y * 0.5,
138                 teamradar_size2d_x,
139                 teamradar_size2d_y
140         );
141
142         draw_teamradar_background(cvar("cl_teamradar_background_alpha"));
143         draw_teamradar_player(pmove_org, input_angles, '1 1 1');
144         for(tm = gps_start; tm != world; tm = tm.chain)
145                 draw_teamradar_player(tm.origin, tm.angles, rgb);
146         for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
147                 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm.teamradar_time, tm.teamradar_color, tm.alpha);
148
149         drawresetcliparea();
150 };