]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/hook.qc
use less memory :P
[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)
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 = 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         R_BeginPolygon("particles/nexbeam", DRAWFLAG_ADDITIVE);
51                 R_PolygonVertex(A, '0 0 0', '.5 1 0', 1);
52                 R_PolygonVertex(B, '1 0 0', '.5 1 0', 1);
53                 R_PolygonVertex(C, '1 0 0' + length_tex * '0 1 0', '.5 1 0', 1);
54                 R_PolygonVertex(D, '0 0 0' + length_tex * '0 1 0', '.5 1 0', 1);
55         R_EndPolygon();
56 }
57
58 void Draw_GrapplingHook()
59 {
60         float i;
61         vector a, b, o;
62         entity e;
63
64         o = pmove_org + '0 0 1' * getstati(STAT_VIEWHEIGHT);
65         makevectors(input_angles);
66
67         for(i = 0; i < 255; ++i)
68         {
69                 e = playerslots[i];
70                 if(!e)
71                         continue;
72                 if(time >= e.HookKillTime)
73                         continue;
74                 if(i == player_localentnum - 1)
75                         a = o + v_forward * 8 - v_right * 8 + v_up * -12;
76                 else
77                         a = e.HookStart;
78                 b = e.HookEnd;
79                 Draw_GrapplingHookLine(a, b, 8, o, v_forward);
80         }
81 }