]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/interpolate.qc
Merge branch 'master' into tzork/ents-onoff
[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                 if(self.iorigin2 != self.iorigin1)
28                         self.angles = vectoangles(self.iorigin2 - self.iorigin1);
29
30         if(self.iflags & IFLAG_ANGLES)
31         {
32                 fixedmakevectors(self.angles);
33                 self.iforward1 = self.iforward2;
34                 self.iup1 = self.iup2;
35                 self.iforward2 = v_forward;
36                 self.iup2 = v_up;
37         }
38
39         if(self.iflags & IFLAG_VELOCITY)
40         {
41                 self.ivelocity1 = self.ivelocity2;
42                 self.ivelocity2 = self.velocity;
43         }
44
45         if(vlen(self.iorigin2 - self.iorigin1) > 1000)
46         {
47                 self.itime1 = self.itime2 = time; // don't lerp
48         }
49
50         if((self.iflags & IFLAG_VELOCITY) && (vlen(self.ivelocity2 - self.ivelocity1) > 1000))
51         {
52                 self.itime1 = self.itime2 = time; // don't lerp
53         }
54
55         if(dt < 0.2)
56         {
57                 self.itime1 = serverprevtime;
58                 self.itime2 = time;
59         }
60         else
61         {
62                 // don't lerp
63                 self.itime1 = self.itime2 = time;
64         }
65 }
66 void InterpolateOrigin_Do()
67 {
68         vector forward, up;
69         if(self.itime1 && self.itime2 && self.itime1 != self.itime2)
70         {
71                 float f;
72                 f = bound(0, (time - self.itime1) / (self.itime2 - self.itime1), 1);
73                 self.origin = (1 - f) * self.iorigin1 + f * self.iorigin2;
74                 if(self.iflags & IFLAG_ANGLES)
75                 {
76                         forward = (1 - f) * self.iforward1 + f * self.iforward2;
77                         up = (1 - f) * self.iup1 + f * self.iup2;
78                         self.angles = fixedvectoangles2(forward, up);
79                 }
80                 if(self.iflags & IFLAG_VELOCITY)
81                         self.velocity = (1 - f) * self.ivelocity1 + f * self.ivelocity2;
82         }
83 }
84 void InterpolateOrigin_Undo()
85 {
86         self.origin = self.iorigin2;
87         if(self.iflags & IFLAG_ANGLES)
88                 self.angles = fixedvectoangles2(self.iforward2, self.iup2);
89         if(self.iflags & IFLAG_VELOCITY)
90                 self.velocity = self.ivelocity2;
91 }
92