]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/teamradar.qc
experimental team radar (try: cl_teamradar 1)
[divverent/nexuiz.git] / data / qcsrc / client / teamradar.qc
1 float DEG2RAD = 0.01745329251994329576;
2
3 float teamradar_angle; // player yaw angle
4 vector teamradar_origin3d_in_texcoord; // player origin
5 vector teamradar_origin2d; // 2D origin
6 vector teamradar_size2d; // 2D size
7 float teamradar_size; // 2D scale factor
8 float teamradar_scale; // window size = ...qu
9
10 vector teamradar_3dcoord_to_texcoord(vector in)
11 {
12         vector out;
13         out_x = (in_x - mi_picmin_x) / (mi_picmax_x - mi_picmin_x);
14         out_y = (in_y - mi_picmin_y) / (mi_picmax_y - mi_picmin_y);
15         out_z = 0;
16         return out;
17 }
18
19 vector teamradar_texcoord_to_2dcoord(vector in)
20 {
21         vector out;
22         in -= teamradar_origin3d_in_texcoord;
23
24         out_x = in_y * sin(teamradar_angle * DEG2RAD) + in_x * cos(teamradar_angle * DEG2RAD);
25         out_y = in_y * cos(teamradar_angle * DEG2RAD) - in_x * sin(teamradar_angle * DEG2RAD);
26         out_y = - out_y; // WHY?!? TODO find out whether the map images are mirrored too
27
28         out = out * teamradar_size;
29         out += teamradar_origin2d;
30         return out;
31 }
32
33 vector yinvert(vector v)
34 {
35         v_y = -v_y;
36         return v;
37 }
38
39 void draw_teamradar_background()
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', 1);
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', 1);
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', 1);
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', 1);
46         R_EndPolygon();
47         R_BeginPolygon(minimapname, DRAWFLAG_ADDITIVE);
48         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), '1 1 1', 1);
49         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), '1 1 1', 1);
50         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), '1 1 1', 1);
51         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), '1 1 1', 1);
52         R_EndPolygon();
53 }
54
55 void(vector coord3d, vector pangles, vector rgb) draw_teamradar_player =
56 {
57         vector coord;
58
59         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
60
61         makevectors(pangles - '0 1 0' * teamradar_angle);
62         v_forward_z = 0;
63         v_forward = normalize(v_forward);
64         v_forward_y *= -1.0;
65         v_right_x = -v_forward_y;
66         v_right_y = v_forward_x;
67
68         R_BeginPolygon("", 0);
69         R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, 1);
70         R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, 1);
71         R_PolygonVertex(coord-v_forward, '1 0 0', rgb, 1);
72         R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, 1);
73         R_EndPolygon();
74 };
75
76 void() teamradar_view =
77 {
78         local float color;
79         local vector coord, rgb;
80         local entity tm;
81         float scale2d, normalsize, bigsize;
82
83         if(!cvar("cl_teamradar"))
84                 return;
85
86         color = GetPlayerColor(player_localentnum-1);
87         rgb = GetTeamRGB(color);
88
89         scale2d = max(
90                 mi_picmax_x - mi_picmin_x,
91                 mi_picmax_y - mi_picmin_y
92         );
93
94         teamradar_angle = input_angles_y - 90;
95         teamradar_origin2d = '64 64 0';
96         teamradar_size2d = '128 128 0';
97         teamradar_scale = 1024;
98
99         normalsize = teamradar_size2d_x * scale2d / teamradar_scale;
100         bigsize = teamradar_size2d_x * scale2d / max(teamradar_scale, vlen(mi_min - mi_max));
101         teamradar_size =
102                   current_zoomfraction * bigsize
103                 + (1 - current_zoomfraction) * normalsize;
104         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
105                   current_zoomfraction * (mi_min + mi_max) * 0.5
106                 + (1 - current_zoomfraction) * pmove_org);
107
108         drawsetcliparea(
109                 teamradar_origin2d_x - teamradar_size2d_x * 0.5,
110                 teamradar_origin2d_y - teamradar_size2d_y * 0.5,
111                 teamradar_size2d_x,
112                 teamradar_size2d_y
113         );
114
115         draw_teamradar_background();
116         draw_teamradar_player(pmove_org, input_angles, '1 1 1');
117         for(tm = gps_start; tm != world; tm = tm.chain)
118                 draw_teamradar_player(tm.origin, tm.angles, rgb);
119
120         drawresetcliparea();
121 };