aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/SOGVehicle.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SOGVehicle.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/SOGVehicle.cs431
1 files changed, 431 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SOGVehicle.cs b/OpenSim/Region/Framework/Scenes/SOGVehicle.cs
new file mode 100644
index 0000000..d6e9a3a
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/SOGVehicle.cs
@@ -0,0 +1,431 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using OpenMetaverse;
30using OpenSim.Framework;
31using OpenSim.Region.Physics.Manager;
32
33
34namespace OpenSim.Region.Framework.Scenes
35{
36 public class SOGVehicle
37 {
38 public Vehicle Type
39 {
40 get { return m_type; }
41 }
42 private Quaternion m_referenceFrame = Quaternion.Identity; // Axis modifier
43 private Quaternion m_RollreferenceFrame = Quaternion.Identity; // what hell is this ?
44
45 private Vehicle m_type = Vehicle.TYPE_NONE; // If a 'VEHICLE', and what kind
46
47 private VehicleFlag m_flags = (VehicleFlag)0;
48 private Vector3 m_BlockingEndPoint = Vector3.Zero; // not sl
49
50 // Linear properties
51 private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time
52 private Vector3 m_linearFrictionTimescale = new Vector3(1000, 1000, 1000);
53 private float m_linearMotorDecayTimescale = 120;
54 private float m_linearMotorTimescale = 1000;
55 private Vector3 m_linearMotorOffset = Vector3.Zero;
56
57 //Angular properties
58 private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor
59 private float m_angularMotorTimescale = 1000; // motor angular velocity ramp up rate
60 private float m_angularMotorDecayTimescale = 120; // motor angular velocity decay rate
61 private Vector3 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000); // body angular velocity decay rate
62
63 //Deflection properties
64 private float m_angularDeflectionEfficiency = 0;
65 private float m_angularDeflectionTimescale = 1000;
66 private float m_linearDeflectionEfficiency = 0;
67 private float m_linearDeflectionTimescale = 1000;
68
69 //Banking properties
70 private float m_bankingEfficiency = 0;
71 private float m_bankingMix = 0;
72 private float m_bankingTimescale = 0;
73
74 //Hover and Buoyancy properties
75 private float m_VhoverHeight = 0f;
76 private float m_VhoverEfficiency = 0f;
77 private float m_VhoverTimescale = 1000f;
78 private float m_VehicleBuoyancy = 0f;
79
80 //Attractor properties
81 private float m_verticalAttractionEfficiency = 1.0f; // damped
82 private float m_verticalAttractionTimescale = 1000f; // Timescale > 300 means no vert attractor.
83
84 public void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
85 {
86 float len;
87 float timestep = 0.01f;
88 switch (pParam)
89 {
90 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY:
91 if (pValue < 0f) pValue = 0f;
92 if (pValue > 1f) pValue = 1f;
93 m_angularDeflectionEfficiency = pValue;
94 break;
95 case Vehicle.ANGULAR_DEFLECTION_TIMESCALE:
96 if (pValue < timestep) pValue = timestep;
97 m_angularDeflectionTimescale = pValue;
98 break;
99 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
100 if (pValue < timestep) pValue = timestep;
101 else if (pValue > 120) pValue = 120;
102 m_angularMotorDecayTimescale = pValue;
103 break;
104 case Vehicle.ANGULAR_MOTOR_TIMESCALE:
105 if (pValue < timestep) pValue = timestep;
106 m_angularMotorTimescale = pValue;
107 break;
108 case Vehicle.BANKING_EFFICIENCY:
109 if (pValue < -1f) pValue = -1f;
110 if (pValue > 1f) pValue = 1f;
111 m_bankingEfficiency = pValue;
112 break;
113 case Vehicle.BANKING_MIX:
114 if (pValue < 0f) pValue = 0f;
115 if (pValue > 1f) pValue = 1f;
116 m_bankingMix = pValue;
117 break;
118 case Vehicle.BANKING_TIMESCALE:
119 if (pValue < timestep) pValue = timestep;
120 m_bankingTimescale = pValue;
121 break;
122 case Vehicle.BUOYANCY:
123 if (pValue < -1f) pValue = -1f;
124 if (pValue > 1f) pValue = 1f;
125 m_VehicleBuoyancy = pValue;
126 break;
127 case Vehicle.HOVER_EFFICIENCY:
128 if (pValue < 0f) pValue = 0f;
129 if (pValue > 1f) pValue = 1f;
130 m_VhoverEfficiency = pValue;
131 break;
132 case Vehicle.HOVER_HEIGHT:
133 m_VhoverHeight = pValue;
134 break;
135 case Vehicle.HOVER_TIMESCALE:
136 if (pValue < timestep) pValue = timestep;
137 m_VhoverTimescale = pValue;
138 break;
139 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY:
140 if (pValue < 0f) pValue = 0f;
141 if (pValue > 1f) pValue = 1f;
142 m_linearDeflectionEfficiency = pValue;
143 break;
144 case Vehicle.LINEAR_DEFLECTION_TIMESCALE:
145 if (pValue < timestep) pValue = timestep;
146 m_linearDeflectionTimescale = pValue;
147 break;
148 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
149 // if (pValue < timestep) pValue = timestep;
150 // try to make impulses to work a bit better
151 if (pValue < timestep) pValue = timestep;
152 else if (pValue > 120) pValue = 120;
153 m_linearMotorDecayTimescale = pValue;
154 break;
155 case Vehicle.LINEAR_MOTOR_TIMESCALE:
156 if (pValue < timestep) pValue = timestep;
157 m_linearMotorTimescale = pValue;
158 break;
159 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
160 if (pValue < 0f) pValue = 0f;
161 if (pValue > 1f) pValue = 1f;
162 m_verticalAttractionEfficiency = pValue;
163 break;
164 case Vehicle.VERTICAL_ATTRACTION_TIMESCALE:
165 if (pValue < timestep) pValue = timestep;
166 m_verticalAttractionTimescale = pValue;
167 break;
168
169 // These are vector properties but the engine lets you use a single float value to
170 // set all of the components to the same value
171 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
172 if (pValue < timestep) pValue = timestep;
173 m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue);
174 break;
175 case Vehicle.ANGULAR_MOTOR_DIRECTION:
176 m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
177 len = m_angularMotorDirection.Length();
178 if (len > 12.566f)
179 m_angularMotorDirection *= (12.566f / len);
180 break;
181 case Vehicle.LINEAR_FRICTION_TIMESCALE:
182 if (pValue < timestep) pValue = timestep;
183 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
184 break;
185 case Vehicle.LINEAR_MOTOR_DIRECTION:
186 m_linearMotorDirection = new Vector3(pValue, pValue, pValue);
187 len = m_linearMotorDirection.Length();
188 if (len > 30.0f)
189 m_linearMotorDirection *= (30.0f / len);
190 break;
191 case Vehicle.LINEAR_MOTOR_OFFSET:
192 m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
193 len = m_linearMotorOffset.Length();
194 if (len > 100.0f)
195 m_linearMotorOffset *= (100.0f / len);
196 break;
197 }
198 }//end ProcessFloatVehicleParam
199
200 public void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue)
201 {
202 float len;
203 float timestep = 0.01f;
204 switch (pParam)
205 {
206 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
207 if (pValue.X < timestep) pValue.X = timestep;
208 if (pValue.Y < timestep) pValue.Y = timestep;
209 if (pValue.Z < timestep) pValue.Z = timestep;
210
211 m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
212 break;
213 case Vehicle.ANGULAR_MOTOR_DIRECTION:
214 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
215 // Limit requested angular speed to 2 rps= 4 pi rads/sec
216 len = m_angularMotorDirection.Length();
217 if (len > 12.566f)
218 m_angularMotorDirection *= (12.566f / len);
219 break;
220 case Vehicle.LINEAR_FRICTION_TIMESCALE:
221 if (pValue.X < timestep) pValue.X = timestep;
222 if (pValue.Y < timestep) pValue.Y = timestep;
223 if (pValue.Z < timestep) pValue.Z = timestep;
224 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
225 break;
226 case Vehicle.LINEAR_MOTOR_DIRECTION:
227 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
228 len = m_linearMotorDirection.Length();
229 if (len > 30.0f)
230 m_linearMotorDirection *= (30.0f / len);
231 break;
232 case Vehicle.LINEAR_MOTOR_OFFSET:
233 m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
234 len = m_linearMotorOffset.Length();
235 if (len > 100.0f)
236 m_linearMotorOffset *= (100.0f / len);
237 break;
238 case Vehicle.BLOCK_EXIT:
239 m_BlockingEndPoint = new Vector3(pValue.X, pValue.Y, pValue.Z);
240 break;
241 }
242 }//end ProcessVectorVehicleParam
243
244 public void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue)
245 {
246 switch (pParam)
247 {
248 case Vehicle.REFERENCE_FRAME:
249 m_referenceFrame = Quaternion.Inverse(pValue);
250 break;
251 case Vehicle.ROLL_FRAME:
252 m_RollreferenceFrame = pValue;
253 break;
254 }
255 }//end ProcessRotationVehicleParam
256
257 public void ProcessVehicleFlags(int pParam, bool remove)
258 {
259 if (remove)
260 {
261 m_flags &= ~((VehicleFlag)pParam);
262 }
263 else
264 {
265 m_flags |= (VehicleFlag)pParam;
266 }
267 }//end ProcessVehicleFlags
268
269 public void ProcessTypeChange(Vehicle pType)
270 {
271 m_linearMotorDirection = Vector3.Zero;
272 m_angularMotorDirection = Vector3.Zero;
273
274 m_BlockingEndPoint = Vector3.Zero;
275 m_RollreferenceFrame = Quaternion.Identity;
276 m_linearMotorOffset = Vector3.Zero;
277
278 m_referenceFrame = Quaternion.Identity;
279
280 // Set Defaults For Type
281 m_type = pType;
282 switch (pType)
283 {
284 case Vehicle.TYPE_NONE: // none sense this will never exist
285 m_linearFrictionTimescale = new Vector3(1000, 1000, 1000);
286 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
287 m_linearMotorTimescale = 1000;
288 m_linearMotorDecayTimescale = 120;
289 m_angularMotorTimescale = 1000;
290 m_angularMotorDecayTimescale = 1000;
291 m_VhoverHeight = 0;
292 m_VhoverTimescale = 1000;
293 m_VehicleBuoyancy = 0;
294 m_flags = (VehicleFlag)0;
295 break;
296
297 case Vehicle.TYPE_SLED:
298 m_linearFrictionTimescale = new Vector3(30, 1, 1000);
299 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
300 m_linearMotorTimescale = 1000;
301 m_linearMotorDecayTimescale = 120;
302 m_angularMotorTimescale = 1000;
303 m_angularMotorDecayTimescale = 120;
304 m_VhoverHeight = 0;
305 m_VhoverEfficiency = 1;
306 m_VhoverTimescale = 10;
307 m_VehicleBuoyancy = 0;
308 m_linearDeflectionEfficiency = 1;
309 m_linearDeflectionTimescale = 1;
310 m_angularDeflectionEfficiency = 0;
311 m_angularDeflectionTimescale = 1000;
312 m_bankingEfficiency = 0;
313 m_bankingMix = 1;
314 m_bankingTimescale = 10;
315 m_flags &=
316 ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
317 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
318 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
319 break;
320 case Vehicle.TYPE_CAR:
321 m_linearFrictionTimescale = new Vector3(100, 2, 1000);
322 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
323 m_linearMotorTimescale = 1;
324 m_linearMotorDecayTimescale = 60;
325 m_angularMotorTimescale = 1;
326 m_angularMotorDecayTimescale = 0.8f;
327 m_VhoverHeight = 0;
328 m_VhoverEfficiency = 0;
329 m_VhoverTimescale = 1000;
330 m_VehicleBuoyancy = 0;
331 m_linearDeflectionEfficiency = 1;
332 m_linearDeflectionTimescale = 2;
333 m_angularDeflectionEfficiency = 0;
334 m_angularDeflectionTimescale = 10;
335 m_verticalAttractionEfficiency = 1f;
336 m_verticalAttractionTimescale = 10f;
337 m_bankingEfficiency = -0.2f;
338 m_bankingMix = 1;
339 m_bankingTimescale = 1;
340 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT);
341 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY |
342 VehicleFlag.LIMIT_MOTOR_UP | VehicleFlag.HOVER_UP_ONLY);
343 break;
344 case Vehicle.TYPE_BOAT:
345 m_linearFrictionTimescale = new Vector3(10, 3, 2);
346 m_angularFrictionTimescale = new Vector3(10, 10, 10);
347 m_linearMotorTimescale = 5;
348 m_linearMotorDecayTimescale = 60;
349 m_angularMotorTimescale = 4;
350 m_angularMotorDecayTimescale = 4;
351 m_VhoverHeight = 0;
352 m_VhoverEfficiency = 0.5f;
353 m_VhoverTimescale = 2;
354 m_VehicleBuoyancy = 1;
355 m_linearDeflectionEfficiency = 0.5f;
356 m_linearDeflectionTimescale = 3;
357 m_angularDeflectionEfficiency = 0.5f;
358 m_angularDeflectionTimescale = 5;
359 m_verticalAttractionEfficiency = 0.5f;
360 m_verticalAttractionTimescale = 5f;
361 m_bankingEfficiency = -0.3f;
362 m_bankingMix = 0.8f;
363 m_bankingTimescale = 1;
364 m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY |
365 VehicleFlag.HOVER_GLOBAL_HEIGHT |
366 VehicleFlag.HOVER_UP_ONLY |
367 VehicleFlag.LIMIT_ROLL_ONLY);
368 m_flags |= (VehicleFlag.NO_DEFLECTION_UP |
369 VehicleFlag.LIMIT_MOTOR_UP |
370 VehicleFlag.HOVER_WATER_ONLY);
371 break;
372 case Vehicle.TYPE_AIRPLANE:
373 m_linearFrictionTimescale = new Vector3(200, 10, 5);
374 m_angularFrictionTimescale = new Vector3(20, 20, 20);
375 m_linearMotorTimescale = 2;
376 m_linearMotorDecayTimescale = 60;
377 m_angularMotorTimescale = 4;
378 m_angularMotorDecayTimescale = 8;
379 m_VhoverHeight = 0;
380 m_VhoverEfficiency = 0.5f;
381 m_VhoverTimescale = 1000;
382 m_VehicleBuoyancy = 0;
383 m_linearDeflectionEfficiency = 0.5f;
384 m_linearDeflectionTimescale = 0.5f;
385 m_angularDeflectionEfficiency = 1;
386 m_angularDeflectionTimescale = 2;
387 m_verticalAttractionEfficiency = 0.9f;
388 m_verticalAttractionTimescale = 2f;
389 m_bankingEfficiency = 1;
390 m_bankingMix = 0.7f;
391 m_bankingTimescale = 2;
392 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
393 VehicleFlag.HOVER_TERRAIN_ONLY |
394 VehicleFlag.HOVER_GLOBAL_HEIGHT |
395 VehicleFlag.HOVER_UP_ONLY |
396 VehicleFlag.NO_DEFLECTION_UP |
397 VehicleFlag.LIMIT_MOTOR_UP);
398 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY);
399 break;
400 case Vehicle.TYPE_BALLOON:
401 m_linearFrictionTimescale = new Vector3(5, 5, 5);
402 m_angularFrictionTimescale = new Vector3(10, 10, 10);
403 m_linearMotorTimescale = 5;
404 m_linearMotorDecayTimescale = 60;
405 m_angularMotorTimescale = 6;
406 m_angularMotorDecayTimescale = 10;
407 m_VhoverHeight = 5;
408 m_VhoverEfficiency = 0.8f;
409 m_VhoverTimescale = 10;
410 m_VehicleBuoyancy = 1;
411 m_linearDeflectionEfficiency = 0;
412 m_linearDeflectionTimescale = 5;
413 m_angularDeflectionEfficiency = 0;
414 m_angularDeflectionTimescale = 5;
415 m_verticalAttractionEfficiency = 0f;
416 m_verticalAttractionTimescale = 1000f;
417 m_bankingEfficiency = 0;
418 m_bankingMix = 0.7f;
419 m_bankingTimescale = 5;
420 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
421 VehicleFlag.HOVER_TERRAIN_ONLY |
422 VehicleFlag.HOVER_UP_ONLY |
423 VehicleFlag.NO_DEFLECTION_UP |
424 VehicleFlag.LIMIT_MOTOR_UP);
425 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY |
426 VehicleFlag.HOVER_GLOBAL_HEIGHT);
427 break;
428 }
429 }
430 }
431} \ No newline at end of file