]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/csqcmodellib/interpolate.qc
Merge branch 'master' into divVerent/csad
[xonotic/xonotic-data.pk3dir.git] / qcsrc / csqcmodellib / interpolate.qc
1 /*
2  * Copyright (c) 2011 Rudolf Polzer
3  *
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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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
20  * IN THE SOFTWARE.
21  */
22
23 .vector iorigin1, iorigin2;
24 .vector ivelocity1, ivelocity2;
25 .vector iforward1, iforward2;
26 .vector iup1, iup2;
27 .float itime1, itime2;
28 void InterpolateOrigin_Reset()
29 {
30         self.iflags &~= IFLAG_INTERNALMASK;
31         self.itime1 = self.itime2 = 0;
32 }
33 void InterpolateOrigin_Note()
34 {
35         float dt;
36         float f0;
37
38         dt = time - self.itime2;
39
40         f0 = self.iflags;
41         if(self.iflags & IFLAG_PREVALID)
42                 self.iflags |= IFLAG_VALID;
43         else
44                 self.iflags |= IFLAG_PREVALID;
45
46         self.iorigin1 = self.iorigin2;
47         self.iorigin2 = self.origin;
48
49         if(self.iflags & IFLAG_AUTOANGLES)
50                 if(self.iorigin2 != self.iorigin1)
51                         self.angles = vectoangles(self.iorigin2 - self.iorigin1);
52
53         if(self.iflags & IFLAG_AUTOVELOCITY)
54                 if(self.itime2 != self.itime1)
55                         self.velocity = (self.iorigin2 - self.iorigin1) * (1.0 / (self.itime2 - self.itime1));
56
57         if(self.iflags & IFLAG_ANGLES)
58         {
59                 fixedmakevectors(self.angles);
60                 if(f0 & IFLAG_VALID)
61                 {
62                         self.iforward1 = self.iforward2;
63                         self.iup1 = self.iup2;
64                 }
65                 else
66                 {
67                         self.iforward1 = v_forward;
68                         self.iup1 = v_up;
69                 }
70                 self.iforward2 = v_forward;
71                 self.iup2 = v_up;
72         }
73
74         if(self.iflags & IFLAG_VELOCITY)
75         {
76                 self.ivelocity1 = self.ivelocity2;
77                 self.ivelocity2 = self.velocity;
78         }
79
80         if(self.iflags & IFLAG_TELEPORTED)
81         {
82                 self.iflags &~= IFLAG_TELEPORTED;
83                 self.itime1 = self.itime2 = time; // don't lerp
84         }
85         else if(vlen(self.iorigin2 - self.iorigin1) > 1000)
86         {
87                 self.itime1 = self.itime2 = time; // don't lerp
88         }
89         else if((self.iflags & IFLAG_VELOCITY) && (vlen(self.ivelocity2 - self.ivelocity1) > 1000))
90         {
91                 self.itime1 = self.itime2 = time; // don't lerp
92         }
93         else if(dt >= 0.2)
94         {
95                 self.itime1 = self.itime2 = time;
96         }
97         else
98         {
99                 self.itime1 = serverprevtime;
100                 self.itime2 = time;
101         }
102 }
103 void InterpolateOrigin_Do()
104 {
105         vector forward, up;
106         if(self.itime1 && self.itime2 && self.itime1 != self.itime2)
107         {
108                 float f;
109                 f = bound(0, (time - self.itime1) / (self.itime2 - self.itime1), 1 + autocvar_cl_lerpexcess);
110                 self.origin = (1 - f) * self.iorigin1 + f * self.iorigin2;
111                 if(self.iflags & IFLAG_ANGLES)
112                 {
113                         forward = (1 - f) * self.iforward1 + f * self.iforward2;
114                         up = (1 - f) * self.iup1 + f * self.iup2;
115                         self.angles = fixedvectoangles2(forward, up);
116                 }
117                 if(self.iflags & IFLAG_VELOCITY)
118                         self.velocity = (1 - f) * self.ivelocity1 + f * self.ivelocity2;
119         }
120 }
121 void InterpolateOrigin_Undo()
122 {
123         self.origin = self.iorigin2;
124         if(self.iflags & IFLAG_ANGLES)
125                 self.angles = fixedvectoangles2(self.iforward2, self.iup2);
126         if(self.iflags & IFLAG_VELOCITY)
127                 self.velocity = self.ivelocity2;
128 }
129