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;
7 void InterpolateOrigin_Reset()
9 self.iflags &~= (IFLAG_PREVALID | IFLAG_VALID);
10 self.itime1 = self.itime2 = 0;
12 void InterpolateOrigin_Note()
16 dt = time - self.itime2;
18 if(self.iflags & IFLAG_PREVALID)
19 self.iflags |= IFLAG_VALID;
21 self.iflags |= IFLAG_PREVALID;
23 self.iorigin1 = self.iorigin2;
24 self.iorigin2 = self.origin;
26 if(self.iflags & IFLAG_AUTOANGLES)
27 if(self.iorigin2 != self.iorigin1)
28 self.angles = vectoangles(self.iorigin2 - self.iorigin1);
30 if(self.iflags & IFLAG_ANGLES)
32 fixedmakevectors(self.angles);
33 self.iforward1 = self.iforward2;
34 self.iup1 = self.iup2;
35 self.iforward2 = v_forward;
39 if(self.iflags & IFLAG_VELOCITY)
41 self.ivelocity1 = self.ivelocity2;
42 self.ivelocity2 = self.velocity;
45 if(vlen(self.iorigin2 - self.iorigin1) > 1000)
47 self.itime1 = self.itime2 = time; // don't lerp
50 if((self.iflags & IFLAG_VELOCITY) && (vlen(self.ivelocity2 - self.ivelocity1) > 1000))
52 self.itime1 = self.itime2 = time; // don't lerp
57 self.itime1 = serverprevtime;
63 self.itime1 = self.itime2 = time;
66 void InterpolateOrigin_Do()
69 if(self.itime1 && self.itime2 && self.itime1 != self.itime2)
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)
76 forward = (1 - f) * self.iforward1 + f * self.iforward2;
77 up = (1 - f) * self.iup1 + f * self.iup2;
78 self.angles = fixedvectoangles2(forward, up);
80 if(self.iflags & IFLAG_VELOCITY)
81 self.velocity = (1 - f) * self.ivelocity1 + f * self.ivelocity2;
84 void InterpolateOrigin_Undo()
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;