more laser madness (now: dark lasers, pulsating laser, laser beam interpolation)
[divverent/nexuiz.git] / data / qcsrc / client / hook.qc
1 .vector HookStart;
2 .vector HookEnd;
3 .float HookKillTime;
4
5 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float alpha, float drawflag)
6 {
7         // I want to draw a quad...
8         // from and to are MIDPOINTS.
9         
10         vector axis, thickdir, A, B, C, D;
11         float length_tex;
12
13         axis = normalize(to - from);
14         length_tex = aspect * vlen(to - from) / thickness;
15
16         // direction is perpendicular to the view normal, and perpendicular to the axis
17         thickdir = normalize(cross(axis, view_origin - from));
18
19         A = from - thickdir * (thickness / 2);
20         B = from + thickdir * (thickness / 2);
21         C = to + thickdir * (thickness / 2);
22         D = to - thickdir * (thickness / 2);
23
24         R_BeginPolygon(texture, drawflag);
25         R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, alpha);
26         R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, alpha);
27         R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, alpha);
28         R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, alpha);
29         R_EndPolygon();
30 }
31
32 void Draw_GrapplingHook()
33 {
34         vector a, b, o;
35         string tex;
36         vector rgb;
37
38         if(time >= self.HookKillTime)
39                 return;
40         if(self.sv_entnum == player_localentnum - 1)
41                 a = view_origin + view_forward * 8 - view_right * 8 + view_up * -12;
42         else
43                 a = self.HookStart;
44         b = self.HookEnd;
45         if(self.team == COLOR_TEAM1)
46         {
47                 tex = "particles/hook_red";
48                 rgb = '1 .3 .3';
49         }
50         else if(self.team == COLOR_TEAM2)
51         {
52                 tex = "particles/hook_blue";
53                 rgb = '.3 .3 1';
54         }
55         else if(self.team == COLOR_TEAM3)
56         {
57                 tex = "particles/hook_yellow";
58                 rgb = '1 1 .3';
59         }
60         else if(self.team == COLOR_TEAM4)
61         {
62                 tex = "particles/hook_pink";
63                 rgb = '1 .3 1';
64         }
65         else
66         {
67                 tex = "particles/hook_green";
68                 rgb = '.3 1 .3';
69         }
70         if(checkextension("DP_SV_WRITEPICTURE"))
71                 Draw_CylindricLine(b, a, 8, tex, 0.25, random(), '1 1 1', 1, DRAWFLAG_NORMAL);
72         else
73                 Draw_CylindricLine(b, a, 1, "", 0.25, 0, rgb, 1, DRAWFLAG_NORMAL);
74 }
75
76 void Net_GrapplingHook()
77 {
78         float i;
79         vector start, end;
80         entity p;
81
82         i = ReadShort();
83         end_x = ReadCoord();
84         end_y = ReadCoord();
85         end_z = ReadCoord();
86         start_x = ReadCoord();
87         start_y = ReadCoord();
88         start_z = ReadCoord();
89
90         if(i <= 0 || i >= 256) // not owned by a client
91                 return;
92         --i;
93
94         p = playerslots[i];
95         if(!p)
96                 return;
97
98         p.HookKillTime = time + 0.1;
99         p.HookStart = start;
100         p.HookEnd = end;
101         p.draw = Draw_GrapplingHook;
102 }