one step towards making the rifle the "standard sniper gun" instead of the Nex: on...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / interpolate.qc
1 // FIXME make this generic code, to be used for other entities too?
2 .vector iorigin1, iorigin2;
3 .vector ivelocity1, ivelocity2;
4 .vector iforward1, iforward2;
5 .vector iup1, iup2;
6 .float itime1, itime2;
7 void InterpolateOrigin_Reset()
8 {
9         self.iflags &~= (IFLAG_PREVALID | IFLAG_VALID);
10         self.itime1 = self.itime2 = 0;
11 }
12 void InterpolateOrigin_Note()
13 {
14         float dt;
15
16         dt = time - self.itime2;
17
18         if(self.iflags & IFLAG_PREVALID)
19                 self.iflags |= IFLAG_VALID;
20         else
21                 self.iflags |= IFLAG_PREVALID;
22
23         self.iorigin1 = self.iorigin2;
24         self.iorigin2 = self.origin;
25
26         if(self.iflags & IFLAG_AUTOANGLES)
27                 self.angles = vectoangles(self.iorigin2 - self.iorigin1);
28
29         if(self.iflags & IFLAG_ANGLES)
30         {
31                 fixedmakevectors(self.angles);
32                 self.iforward1 = self.iforward2;
33                 self.iup1 = self.iup2;
34                 self.iforward2 = v_forward;
35                 self.iup2 = v_up;
36         }
37
38         if(self.iflags & IFLAG_VELOCITY)
39         {
40                 self.ivelocity1 = self.ivelocity2;
41                 self.ivelocity2 = self.velocity;
42         }
43
44         if(vlen(self.iorigin2 - self.iorigin1) > 1000)
45         {
46                 self.itime1 = self.itime2 = time; // don't lerp
47         }
48
49         if((self.iflags & IFLAG_VELOCITY) && (vlen(self.ivelocity2 - self.ivelocity1) > 1000))
50         {
51                 self.itime1 = self.itime2 = time; // don't lerp
52         }
53
54         if(dt < 0.2)
55         {
56                 self.itime1 = serverprevtime;
57                 self.itime2 = time;
58         }
59         else
60         {
61                 // don't lerp
62                 self.itime1 = self.itime2 = time;
63         }
64 }
65 void InterpolateOrigin_Do()
66 {
67         vector forward, up;
68         if(self.itime1 && self.itime2 && self.itime1 != self.itime2)
69         {
70                 float f;
71                 f = bound(0, (time - self.itime1) / (self.itime2 - self.itime1), 1);
72                 self.origin = (1 - f) * self.iorigin1 + f * self.iorigin2;
73                 if(self.iflags & IFLAG_ANGLES)
74                 {
75                         forward = (1 - f) * self.iforward1 + f * self.iforward2;
76                         up = (1 - f) * self.iup1 + f * self.iup2;
77                         self.angles = fixedvectoangles2(forward, up);
78                 }
79                 if(self.iflags & IFLAG_VELOCITY)
80                         self.velocity = (1 - f) * self.ivelocity1 + f * self.ivelocity2;
81         }
82 }
83 void InterpolateOrigin_Undo()
84 {
85         self.origin = self.iorigin2;
86         if(self.iflags & IFLAG_ANGLES)
87                 self.angles = fixedvectoangles2(self.iforward2, self.iup2);
88         if(self.iflags & IFLAG_VELOCITY)
89                 self.velocity = self.ivelocity2;
90 }
91