]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/hook.qc
new hook graphics
[divverent/nexuiz.git] / data / qcsrc / client / hook.qc
1 .vector HookStart;
2 .vector HookEnd;
3 .float HookKillTime;
4 void Net_GrapplingHook()
5 {
6         float i;
7         vector start, end;
8         entity p;
9
10         i = ReadShort();
11         end_x = ReadCoord();
12         end_y = ReadCoord();
13         end_z = ReadCoord();
14         start_x = ReadCoord();
15         start_y = ReadCoord();
16         start_z = ReadCoord();
17
18         if(i <= 0 || i >= 256) // not owned by a client
19                 return;
20         --i;
21
22         p = playerslots[i];
23         if(!p)
24                 return;
25
26         p.HookKillTime = time + 0.1;
27         p.HookStart = start;
28         p.HookEnd = end;
29 }
30
31 void Draw_GrapplingHookLine(vector from, vector to, float thickness, vector org, vector view_forward, string texture, float aspect, vector rgb)
32 {
33         // I want to draw a quad...
34         // from and to are MIDPOINTS.
35         
36         vector axis, thickdir, A, B, C, D;
37         float length_tex;
38
39         axis = normalize(to - from);
40         length_tex = aspect * vlen(to - from) / thickness;
41
42         // direction is perpendicular to the view normal, and perpendicular to the axis
43         thickdir = normalize(cross(axis, org - from));
44
45         A = from - thickdir * (thickness / 2);
46         B = from + thickdir * (thickness / 2);
47         C = to + thickdir * (thickness / 2);
48         D = to - thickdir * (thickness / 2);
49
50         if(checkextension("DP_SV_WRITEPICTURE"))
51                 R_BeginPolygon(texture, 0);
52         else
53                 R_BeginPolygon("", 0);
54         R_PolygonVertex(A, '0 0 0', rgb, 1);
55         R_PolygonVertex(B, '0 1 0', rgb, 1);
56         R_PolygonVertex(C, '0 1 0' + length_tex * '1 0 0', rgb, 1);
57         R_PolygonVertex(D, '0 0 0' + length_tex * '1 0 0', rgb, 1);
58         R_EndPolygon();
59 }
60
61 void Draw_GrapplingHook()
62 {
63         float i;
64         vector a, b, o;
65         entity e;
66
67         o = pmove_org + '0 0 1' * getstati(STAT_VIEWHEIGHT);
68         makevectors(input_angles);
69
70         for(i = 0; i < 255; ++i)
71         {
72                 e = playerslots[i];
73                 if(!e)
74                         continue;
75                 if(time >= e.HookKillTime)
76                         continue;
77                 if(i == player_localentnum - 1)
78                         a = o + v_forward * 8 - v_right * 8 + v_up * -12;
79                 else
80                         a = e.HookStart;
81                 b = e.HookEnd;
82                 Draw_GrapplingHookLine(b, a, 8, o, v_forward, "particles/hookbeam", 0.5, '1 1 1');
83         }
84 }