]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/movelib.qc
improve waypointsprites for speccers
[divverent/nexuiz.git] / data / qcsrc / server / movelib.qc
1 .vector moveto;\r
2 \r
3 /**\r
4     Simulate drag\r
5     self.velocity = movelib_vdrag(self.velocity,0.02,0.5);\r
6 **/\r
7 vector movelib_dragvec(float drag, float exp)\r
8 {\r
9     float lspeed,ldrag;\r
10 \r
11     lspeed = vlen(self.velocity);\r
12     ldrag = lspeed * drag;\r
13     ldrag = ldrag * (drag * exp);\r
14     ldrag = 1 - (ldrag / lspeed);\r
15 \r
16     return self.velocity * ldrag;\r
17 }\r
18 \r
19 /**\r
20     Simulate drag\r
21     self.velocity = movelib_vdrag(somespeed,0.01,0.7);\r
22 **/\r
23 float movelib_dragflt(float fspeed,float drag,float exp)\r
24 {\r
25     float ldrag;\r
26 \r
27     ldrag = fspeed * drag;\r
28     ldrag = ldrag * ldrag * exp;\r
29     ldrag = 1 - (ldrag / fspeed);\r
30 \r
31     return ldrag;\r
32 }\r
33 \r
34 /**\r
35     Do a inertia simulation based on velocity.\r
36     Basicaly, this allows you to simulate loss of steering with higher speed.\r
37     self.velocity = movelib_inertia_fromspeed(self.velocity,newvel,1000,0.1,0.9);\r
38 **/\r
39 vector movelib_inertmove_byspeed(vector vel_new, float vel_max,float newmin,float oldmax)\r
40 {\r
41     float influense;\r
42 \r
43     influense = vlen(self.velocity) * (1 / vel_max);\r
44 \r
45     influense = bound(newmin,influense,oldmax);\r
46 \r
47     return (vel_new * (1 - influense)) + (self.velocity * influense);\r
48 }\r
49 \r
50 vector movelib_inertmove(vector new_vel,float new_bias)\r
51 {\r
52     return new_vel * new_bias + self.velocity * (1-new_bias);\r
53 }\r
54 \r
55 .float  movelib_lastupdate;\r
56 void movelib_move(vector force,float max_velocity,float drag,float mass,float breakforce)\r
57 {\r
58     float deltatime;\r
59     float acceleration;\r
60     float mspeed;\r
61     vector breakvec;\r
62 \r
63     deltatime = time - self.movelib_lastupdate;\r
64     if (deltatime > 0.15) deltatime = 0;\r
65     self.movelib_lastupdate = time;\r
66     if (!deltatime) return;\r
67 \r
68     mspeed = vlen(self.velocity);\r
69 \r
70     if (mass)\r
71         acceleration = vlen(force) / mass;\r
72     else\r
73         acceleration = vlen(force);\r
74 \r
75     if (self.flags & FL_ONGROUND)\r
76     {\r
77         if (breakforce)\r
78         {\r
79             breakvec = (normalize(self.velocity) * (breakforce / mass) * deltatime);\r
80             self.velocity = self.velocity - breakvec;\r
81         }\r
82 \r
83         self.velocity = self.velocity + force * (acceleration * deltatime);\r
84     }\r
85 \r
86     if (drag)\r
87         self.velocity = movelib_dragvec(drag, 1);\r
88 \r
89     if (self.waterlevel > 1)\r
90     {\r
91         self.velocity = self.velocity + force * (acceleration * deltatime);\r
92         self.velocity = self.velocity + '0 0 0.05' * sv_gravity * deltatime;\r
93     }\r
94     else\r
95         self.velocity = self.velocity + '0 0 -1' * sv_gravity * deltatime;\r
96 \r
97     mspeed = vlen(self.velocity);\r
98 \r
99     if (max_velocity)\r
100         if (mspeed > max_velocity)\r
101             self.velocity = normalize(self.velocity) * (mspeed - 50);//* max_velocity;\r
102 }\r
103 \r
104 /*\r
105 .float mass;\r
106 .float side_friction;\r
107 .float ground_friction;\r
108 .float air_friction;\r
109 .float water_friction;\r
110 .float buoyancy;\r
111 float movelib_deltatime;\r
112 \r
113 void movelib_startupdate()\r
114 {\r
115     movelib_deltatime = time - self.movelib_lastupdate;\r
116 \r
117     if (movelib_deltatime > 0.5)\r
118         movelib_deltatime = 0;\r
119 \r
120     self.movelib_lastupdate = time;\r
121 }\r
122 \r
123 void movelib_update(vector dir,float force)\r
124 {\r
125     vector acceleration;\r
126     float old_speed;\r
127     float ffriction,v_z;\r
128 \r
129     vector breakvec;\r
130     vector old_dir;\r
131     vector ggravity;\r
132     vector old;\r
133 \r
134     if(!movelib_deltatime)\r
135         return;\r
136     v_z = self.velocity_z;\r
137     old_speed    = vlen(self.velocity);\r
138     old_dir      = normalize(self.velocity);\r
139 \r
140     //ggravity      =  (sv_gravity / self.mass) * '0 0 100';\r
141     acceleration =  (force / self.mass) * dir;\r
142     //acceleration -= old_dir * (old_speed / self.mass);\r
143     acceleration -= ggravity;\r
144 \r
145     if(self.waterlevel > 1)\r
146     {\r
147         ffriction = self.water_friction;\r
148         acceleration += self.buoyancy * '0 0 1';\r
149     }\r
150     else\r
151         if(self.flags & FL_ONGROUND)\r
152             ffriction = self.ground_friction;\r
153         else\r
154             ffriction = self.air_friction;\r
155 \r
156     acceleration *= ffriction;\r
157     //self.velocity = self.velocity * (ffriction * movelib_deltatime);\r
158     self.velocity += acceleration * movelib_deltatime;\r
159     self.velocity_z = v_z;\r
160 \r
161 }\r
162 */\r
163 \r
164 void movelib_move_simple(vector newdir,float velo,float blendrate)\r
165 {\r
166     self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo;\r
167 }\r
168 void movelib_beak_simple(float force)\r
169 {\r
170     float mspeed;\r
171     vector mdir;\r
172 \r
173     mspeed = max(0,vlen(self.velocity) - force);\r
174     mdir   = normalize(self.velocity);\r
175     self.velocity = mdir * mspeed;\r
176 }\r
177 \r
178 \r
179 void movelib_groundalign4point(float spring_length,float spring_up)\r
180 {\r
181     vector a,b,c,d,e,r,push_angle, ahead,side;\r
182 \r
183     push_angle_y = 0;\r
184     r = (self.absmax + self.absmin) * 0.5 + (v_up * spring_up);\r
185     e = v_up * spring_length;\r
186 \r
187     // Put springs slightly inside bbox\r
188     ahead = v_forward * (self.maxs_x * 0.85);\r
189     side  = v_right   * (self.maxs_y * 0.85);\r
190 \r
191     a = r + ahead + side;\r
192     b = r + ahead - side;\r
193     c = r - ahead + side;\r
194     d = r - ahead - side;\r
195 \r
196     traceline(a, a - e,MOVE_NORMAL,self);\r
197     a_z =  (1 - trace_fraction);\r
198     r = trace_endpos;\r
199 \r
200     traceline(b, b - e,MOVE_NORMAL,self);\r
201     b_z =  (1 - trace_fraction);\r
202     r += trace_endpos;\r
203 \r
204     traceline(c, c - e,MOVE_NORMAL,self);\r
205     c_z =  (1 - trace_fraction);\r
206     r += trace_endpos;\r
207 \r
208     traceline(d, d - e,MOVE_NORMAL,self);\r
209     d_z =  (1 - trace_fraction);\r
210     r += trace_endpos;\r
211 \r
212     a_x = r_z;\r
213     r = self.origin;\r
214     r_z = r_z;\r
215 \r
216     push_angle_x = (a_z - c_z) * 45;\r
217     push_angle_x += (b_z - d_z) * 45;\r
218 \r
219     push_angle_z = (b_z - a_z) * 45;\r
220     push_angle_z += (d_z - c_z) * 45;\r
221 \r
222     self.angles_x += push_angle_x * 0.95;\r
223     self.angles_z += push_angle_z * 0.95;\r
224 \r
225     setorigin(self,r);\r
226 }\r
227 \r