2 * Copyright (c) 2011 Rudolf Polzer
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 .vector iorigin1, iorigin2;
24 .vector ivelocity1, ivelocity2;
25 .vector iforward1, iforward2;
27 .vector ivforward1, ivforward2;
29 .float itime1, itime2;
30 void InterpolateOrigin_Reset()
32 self.iflags &~= IFLAG_INTERNALMASK;
33 self.itime1 = self.itime2 = 0;
35 void InterpolateOrigin_Note()
40 dt = time - self.itime2;
43 if(self.iflags & IFLAG_PREVALID)
44 self.iflags |= IFLAG_VALID;
46 self.iflags |= IFLAG_PREVALID;
48 if(self.iflags & IFLAG_ORIGIN)
50 self.iorigin1 = self.iorigin2;
51 self.iorigin2 = self.origin;
54 if(self.iflags & IFLAG_AUTOANGLES)
55 if(self.iorigin2 != self.iorigin1)
56 self.angles = vectoangles(self.iorigin2 - self.iorigin1);
58 if(self.iflags & IFLAG_AUTOVELOCITY)
59 if(self.itime2 != self.itime1)
60 self.velocity = (self.iorigin2 - self.iorigin1) * (1.0 / (self.itime2 - self.itime1));
62 if(self.iflags & IFLAG_ANGLES)
64 fixedmakevectors(self.angles);
67 self.iforward1 = self.iforward2;
68 self.iup1 = self.iup2;
72 self.iforward1 = v_forward;
75 self.iforward2 = v_forward;
79 if(self.iflags & IFLAG_V_ANGLE)
81 fixedmakevectors(self.v_angle);
84 self.ivforward1 = self.ivforward2;
85 self.ivup1 = self.ivup2;
89 self.ivforward1 = v_forward;
92 self.ivforward2 = v_forward;
95 else if(self.iflags & IFLAG_V_ANGLE_X)
97 self.ivforward1_x = self.ivforward2_x;
98 self.ivforward2_x = self.v_angle_x;
101 if(self.iflags & IFLAG_VELOCITY)
103 self.ivelocity1 = self.ivelocity2;
104 self.ivelocity2 = self.velocity;
107 if(self.iflags & IFLAG_TELEPORTED)
109 self.iflags &~= IFLAG_TELEPORTED;
110 self.itime1 = self.itime2 = time; // don't lerp
112 else if(vlen(self.iorigin2 - self.iorigin1) > 1000)
114 self.itime1 = self.itime2 = time; // don't lerp
116 else if((self.iflags & IFLAG_VELOCITY) && (vlen(self.ivelocity2 - self.ivelocity1) > 1000))
118 self.itime1 = self.itime2 = time; // don't lerp
122 self.itime1 = self.itime2 = time;
126 self.itime1 = serverprevtime;
130 void InterpolateOrigin_Do()
133 if(self.itime1 && self.itime2 && self.itime1 != self.itime2)
136 f = bound(0, (time - self.itime1) / (self.itime2 - self.itime1), 1 + autocvar_cl_lerpexcess);
137 if(self.iflags & IFLAG_ORIGIN)
138 setorigin(self, (1 - f) * self.iorigin1 + f * self.iorigin2);
139 if(self.iflags & IFLAG_ANGLES)
141 forward = (1 - f) * self.iforward1 + f * self.iforward2;
142 up = (1 - f) * self.iup1 + f * self.iup2;
143 self.angles = fixedvectoangles2(forward, up);
145 if(self.iflags & IFLAG_V_ANGLE)
147 forward = (1 - f) * self.ivforward1 + f * self.ivforward2;
148 up = (1 - f) * self.ivup1 + f * self.ivup2;
149 self.v_angle = fixedvectoangles2(forward, up);
151 else if(self.iflags & IFLAG_V_ANGLE_X)
152 self.v_angle_x = (1 - f) * self.ivforward1_x + f * self.ivforward2_x;
153 if(self.iflags & IFLAG_VELOCITY)
154 self.velocity = (1 - f) * self.ivelocity1 + f * self.ivelocity2;
157 void InterpolateOrigin_Undo()
159 if(self.iflags & IFLAG_ORIGIN)
160 setorigin(self, self.iorigin2);
161 if(self.iflags & IFLAG_ANGLES)
162 self.angles = fixedvectoangles2(self.iforward2, self.iup2);
163 if(self.iflags & IFLAG_V_ANGLE)
164 self.v_angle = fixedvectoangles2(self.ivforward2, self.ivup2);
165 else if(self.iflags & IFLAG_V_ANGLE_X)
166 self.v_angle_x = self.ivforward2_x;
167 if(self.iflags & IFLAG_VELOCITY)
168 self.velocity = self.ivelocity2;