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