aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/SOPVehicle.cs
diff options
context:
space:
mode:
authoronefang2019-05-19 21:24:15 +1000
committeronefang2019-05-19 21:24:15 +1000
commit5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch)
treea9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Region/Framework/Scenes/SOPVehicle.cs
parentAdd a build script. (diff)
downloadopensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Framework/Scenes/SOPVehicle.cs803
1 files changed, 803 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SOPVehicle.cs b/OpenSim/Region/Framework/Scenes/SOPVehicle.cs
new file mode 100644
index 0000000..6683614
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/SOPVehicle.cs
@@ -0,0 +1,803 @@
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 System.Collections.Generic;
30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Region.PhysicsModules.SharedBase;
33using System.Text;
34using System.IO;
35using System.Xml;
36using OpenSim.Framework.Serialization;
37using OpenSim.Framework.Serialization.External;
38using OpenSim.Region.Framework.Scenes.Serialization;
39
40namespace OpenSim.Region.Framework.Scenes
41{
42 public class SOPVehicle
43 {
44 public VehicleData vd;
45
46 public Vehicle Type
47 {
48 get { return vd.m_type; }
49 }
50
51 public SOPVehicle()
52 {
53 vd = new VehicleData();
54 ProcessTypeChange(Vehicle.TYPE_NONE); // is needed?
55 }
56
57 public void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
58 {
59 float len;
60 float timestep = 0.01f;
61 switch (pParam)
62 {
63 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY:
64 if (pValue < 0f) pValue = 0f;
65 if (pValue > 1f) pValue = 1f;
66 vd.m_angularDeflectionEfficiency = pValue;
67 break;
68 case Vehicle.ANGULAR_DEFLECTION_TIMESCALE:
69 if (pValue < timestep) pValue = timestep;
70 vd.m_angularDeflectionTimescale = pValue;
71 break;
72 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
73 if (pValue < timestep) pValue = timestep;
74 else if (pValue > 120) pValue = 120;
75 vd.m_angularMotorDecayTimescale = pValue;
76 break;
77 case Vehicle.ANGULAR_MOTOR_TIMESCALE:
78 if (pValue < timestep) pValue = timestep;
79 vd.m_angularMotorTimescale = pValue;
80 break;
81 case Vehicle.BANKING_EFFICIENCY:
82 if (pValue < -1f) pValue = -1f;
83 if (pValue > 1f) pValue = 1f;
84 vd.m_bankingEfficiency = pValue;
85 break;
86 case Vehicle.BANKING_MIX:
87 if (pValue < 0f) pValue = 0f;
88 if (pValue > 1f) pValue = 1f;
89 vd.m_bankingMix = pValue;
90 break;
91 case Vehicle.BANKING_TIMESCALE:
92 if (pValue < timestep) pValue = timestep;
93 vd.m_bankingTimescale = pValue;
94 break;
95 case Vehicle.BUOYANCY:
96 if (pValue < -1f) pValue = -1f;
97 if (pValue > 1f) pValue = 1f;
98 vd.m_VehicleBuoyancy = pValue;
99 break;
100 case Vehicle.HOVER_EFFICIENCY:
101 if (pValue < 0f) pValue = 0f;
102 if (pValue > 1f) pValue = 1f;
103 vd.m_VhoverEfficiency = pValue;
104 break;
105 case Vehicle.HOVER_HEIGHT:
106 vd.m_VhoverHeight = pValue;
107 break;
108 case Vehicle.HOVER_TIMESCALE:
109 if (pValue < timestep) pValue = timestep;
110 vd.m_VhoverTimescale = pValue;
111 break;
112 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY:
113 if (pValue < 0f) pValue = 0f;
114 if (pValue > 1f) pValue = 1f;
115 vd.m_linearDeflectionEfficiency = pValue;
116 break;
117 case Vehicle.LINEAR_DEFLECTION_TIMESCALE:
118 if (pValue < timestep) pValue = timestep;
119 vd.m_linearDeflectionTimescale = pValue;
120 break;
121 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
122 if (pValue < timestep) pValue = timestep;
123 else if (pValue > 120) pValue = 120;
124 vd.m_linearMotorDecayTimescale = pValue;
125 break;
126 case Vehicle.LINEAR_MOTOR_TIMESCALE:
127 if (pValue < timestep) pValue = timestep;
128 vd.m_linearMotorTimescale = pValue;
129 break;
130 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
131 if (pValue < 0f) pValue = 0f;
132 if (pValue > 1f) pValue = 1f;
133 vd.m_verticalAttractionEfficiency = pValue;
134 break;
135 case Vehicle.VERTICAL_ATTRACTION_TIMESCALE:
136 if (pValue < timestep) pValue = timestep;
137 vd.m_verticalAttractionTimescale = pValue;
138 break;
139
140 // These are vector properties but the engine lets you use a single float value to
141 // set all of the components to the same value
142 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
143 if (pValue < timestep) pValue = timestep;
144 vd.m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue);
145 break;
146 case Vehicle.ANGULAR_MOTOR_DIRECTION:
147 vd.m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
148 len = vd.m_angularMotorDirection.Length();
149 if (len > 12.566f)
150 vd.m_angularMotorDirection *= (12.566f / len);
151 break;
152 case Vehicle.LINEAR_FRICTION_TIMESCALE:
153 if (pValue < timestep) pValue = timestep;
154 vd.m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
155 break;
156 case Vehicle.LINEAR_MOTOR_DIRECTION:
157 vd.m_linearMotorDirection = new Vector3(pValue, pValue, pValue);
158 len = vd.m_linearMotorDirection.Length();
159 if (len > 30.0f)
160 vd.m_linearMotorDirection *= (30.0f / len);
161 break;
162 case Vehicle.LINEAR_MOTOR_OFFSET:
163 vd.m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
164 len = vd.m_linearMotorOffset.Length();
165 if (len > 100.0f)
166 vd.m_linearMotorOffset *= (100.0f / len);
167 break;
168 }
169 }//end ProcessFloatVehicleParam
170
171 public void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue)
172 {
173 float len;
174 float timestep = 0.01f;
175 switch (pParam)
176 {
177 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
178 if (pValue.X < timestep) pValue.X = timestep;
179 if (pValue.Y < timestep) pValue.Y = timestep;
180 if (pValue.Z < timestep) pValue.Z = timestep;
181
182 vd.m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
183 break;
184 case Vehicle.ANGULAR_MOTOR_DIRECTION:
185 vd.m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
186 // Limit requested angular speed to 2 rps= 4 pi rads/sec
187 len = vd.m_angularMotorDirection.Length();
188 if (len > 12.566f)
189 vd.m_angularMotorDirection *= (12.566f / len);
190 break;
191 case Vehicle.LINEAR_FRICTION_TIMESCALE:
192 if (pValue.X < timestep) pValue.X = timestep;
193 if (pValue.Y < timestep) pValue.Y = timestep;
194 if (pValue.Z < timestep) pValue.Z = timestep;
195 vd.m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
196 break;
197 case Vehicle.LINEAR_MOTOR_DIRECTION:
198 vd.m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
199 len = vd.m_linearMotorDirection.Length();
200 if (len > 30.0f)
201 vd.m_linearMotorDirection *= (30.0f / len);
202 break;
203 case Vehicle.LINEAR_MOTOR_OFFSET:
204 vd.m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
205 len = vd.m_linearMotorOffset.Length();
206 if (len > 100.0f)
207 vd.m_linearMotorOffset *= (100.0f / len);
208 break;
209 }
210 }//end ProcessVectorVehicleParam
211
212 public void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue)
213 {
214 switch (pParam)
215 {
216 case Vehicle.REFERENCE_FRAME:
217 vd.m_referenceFrame = pValue;
218 break;
219 }
220 }//end ProcessRotationVehicleParam
221
222 public void ProcessVehicleFlags(int pParam, bool remove)
223 {
224 if (remove)
225 {
226 vd.m_flags &= ~((VehicleFlag)pParam);
227 }
228 else
229 {
230 vd.m_flags |= (VehicleFlag)pParam;
231 }
232 }//end ProcessVehicleFlags
233
234 public void ProcessTypeChange(Vehicle pType)
235 {
236 vd.m_linearMotorDirection = Vector3.Zero;
237 vd.m_angularMotorDirection = Vector3.Zero;
238 vd.m_linearMotorOffset = Vector3.Zero;
239 vd.m_referenceFrame = Quaternion.Identity;
240
241 // Set Defaults For Type
242 vd.m_type = pType;
243 switch (pType)
244 {
245 case Vehicle.TYPE_NONE:
246 vd.m_linearFrictionTimescale = new Vector3(1000, 1000, 1000);
247 vd.m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
248 vd.m_linearMotorTimescale = 1000;
249 vd.m_linearMotorDecayTimescale = 120;
250 vd.m_angularMotorTimescale = 1000;
251 vd.m_angularMotorDecayTimescale = 1000;
252 vd.m_VhoverHeight = 0;
253 vd.m_VhoverEfficiency = 1;
254 vd.m_VhoverTimescale = 1000;
255 vd.m_VehicleBuoyancy = 0;
256 vd.m_linearDeflectionEfficiency = 0;
257 vd.m_linearDeflectionTimescale = 1000;
258 vd.m_angularDeflectionEfficiency = 0;
259 vd.m_angularDeflectionTimescale = 1000;
260 vd.m_bankingEfficiency = 0;
261 vd.m_bankingMix = 1;
262 vd.m_bankingTimescale = 1000;
263 vd.m_verticalAttractionEfficiency = 0;
264 vd.m_verticalAttractionTimescale = 1000;
265
266 vd.m_flags = (VehicleFlag)0;
267 break;
268
269 case Vehicle.TYPE_SLED:
270 vd.m_linearFrictionTimescale = new Vector3(30, 1, 1000);
271 vd.m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
272 vd.m_linearMotorTimescale = 1000;
273 vd.m_linearMotorDecayTimescale = 120;
274 vd.m_angularMotorTimescale = 1000;
275 vd.m_angularMotorDecayTimescale = 120;
276 vd.m_VhoverHeight = 0;
277 vd.m_VhoverEfficiency = 1;
278 vd.m_VhoverTimescale = 10;
279 vd.m_VehicleBuoyancy = 0;
280 vd.m_linearDeflectionEfficiency = 1;
281 vd.m_linearDeflectionTimescale = 1;
282 vd.m_angularDeflectionEfficiency = 0;
283 vd.m_angularDeflectionTimescale = 1000;
284 vd.m_bankingEfficiency = 0;
285 vd.m_bankingMix = 1;
286 vd.m_bankingTimescale = 10;
287 vd.m_flags &=
288 ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
289 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
290 vd.m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
291 break;
292 case Vehicle.TYPE_CAR:
293 vd.m_linearFrictionTimescale = new Vector3(100, 2, 1000);
294 vd.m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
295 vd.m_linearMotorTimescale = 1;
296 vd.m_linearMotorDecayTimescale = 60;
297 vd.m_angularMotorTimescale = 1;
298 vd.m_angularMotorDecayTimescale = 0.8f;
299 vd.m_VhoverHeight = 0;
300 vd.m_VhoverEfficiency = 0;
301 vd.m_VhoverTimescale = 1000;
302 vd.m_VehicleBuoyancy = 0;
303 vd.m_linearDeflectionEfficiency = 1;
304 vd.m_linearDeflectionTimescale = 2;
305 vd.m_angularDeflectionEfficiency = 0;
306 vd.m_angularDeflectionTimescale = 10;
307 vd.m_verticalAttractionEfficiency = 1f;
308 vd.m_verticalAttractionTimescale = 10f;
309 vd.m_bankingEfficiency = -0.2f;
310 vd.m_bankingMix = 1;
311 vd.m_bankingTimescale = 1;
312 vd.m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT);
313 vd.m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY |
314 VehicleFlag.LIMIT_MOTOR_UP | VehicleFlag.HOVER_UP_ONLY);
315 break;
316 case Vehicle.TYPE_BOAT:
317 vd.m_linearFrictionTimescale = new Vector3(10, 3, 2);
318 vd.m_angularFrictionTimescale = new Vector3(10, 10, 10);
319 vd.m_linearMotorTimescale = 5;
320 vd.m_linearMotorDecayTimescale = 60;
321 vd.m_angularMotorTimescale = 4;
322 vd.m_angularMotorDecayTimescale = 4;
323 vd.m_VhoverHeight = 0;
324 vd.m_VhoverEfficiency = 0.5f;
325 vd.m_VhoverTimescale = 2;
326 vd.m_VehicleBuoyancy = 1;
327 vd.m_linearDeflectionEfficiency = 0.5f;
328 vd.m_linearDeflectionTimescale = 3;
329 vd.m_angularDeflectionEfficiency = 0.5f;
330 vd.m_angularDeflectionTimescale = 5;
331 vd.m_verticalAttractionEfficiency = 0.5f;
332 vd.m_verticalAttractionTimescale = 5f;
333 vd.m_bankingEfficiency = -0.3f;
334 vd.m_bankingMix = 0.8f;
335 vd.m_bankingTimescale = 1;
336 vd.m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY |
337 VehicleFlag.HOVER_GLOBAL_HEIGHT |
338 VehicleFlag.HOVER_UP_ONLY |
339 VehicleFlag.LIMIT_ROLL_ONLY);
340 vd.m_flags |= (VehicleFlag.NO_DEFLECTION_UP |
341 VehicleFlag.LIMIT_MOTOR_UP |
342 VehicleFlag.HOVER_WATER_ONLY);
343 break;
344 case Vehicle.TYPE_AIRPLANE:
345 vd.m_linearFrictionTimescale = new Vector3(200, 10, 5);
346 vd.m_angularFrictionTimescale = new Vector3(20, 20, 20);
347 vd.m_linearMotorTimescale = 2;
348 vd.m_linearMotorDecayTimescale = 60;
349 vd.m_angularMotorTimescale = 4;
350 vd.m_angularMotorDecayTimescale = 8;
351 vd.m_VhoverHeight = 0;
352 vd.m_VhoverEfficiency = 0.5f;
353 vd.m_VhoverTimescale = 1000;
354 vd.m_VehicleBuoyancy = 0;
355 vd.m_linearDeflectionEfficiency = 0.5f;
356 vd.m_linearDeflectionTimescale = 0.5f;
357 vd.m_angularDeflectionEfficiency = 1;
358 vd.m_angularDeflectionTimescale = 2;
359 vd.m_verticalAttractionEfficiency = 0.9f;
360 vd.m_verticalAttractionTimescale = 2f;
361 vd.m_bankingEfficiency = 1;
362 vd.m_bankingMix = 0.7f;
363 vd.m_bankingTimescale = 2;
364 vd.m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
365 VehicleFlag.HOVER_TERRAIN_ONLY |
366 VehicleFlag.HOVER_GLOBAL_HEIGHT |
367 VehicleFlag.HOVER_UP_ONLY |
368 VehicleFlag.NO_DEFLECTION_UP |
369 VehicleFlag.LIMIT_MOTOR_UP);
370 vd.m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY);
371 break;
372 case Vehicle.TYPE_BALLOON:
373 vd.m_linearFrictionTimescale = new Vector3(5, 5, 5);
374 vd.m_angularFrictionTimescale = new Vector3(10, 10, 10);
375 vd.m_linearMotorTimescale = 5;
376 vd.m_linearMotorDecayTimescale = 60;
377 vd.m_angularMotorTimescale = 6;
378 vd.m_angularMotorDecayTimescale = 10;
379 vd.m_VhoverHeight = 5;
380 vd.m_VhoverEfficiency = 0.8f;
381 vd.m_VhoverTimescale = 10;
382 vd.m_VehicleBuoyancy = 1;
383 vd.m_linearDeflectionEfficiency = 0;
384 vd.m_linearDeflectionTimescale = 5;
385 vd.m_angularDeflectionEfficiency = 0;
386 vd.m_angularDeflectionTimescale = 5;
387 vd.m_verticalAttractionEfficiency = 0f;
388 vd.m_verticalAttractionTimescale = 1000f;
389 vd.m_bankingEfficiency = 0;
390 vd.m_bankingMix = 0.7f;
391 vd.m_bankingTimescale = 5;
392 vd.m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
393 VehicleFlag.HOVER_TERRAIN_ONLY |
394 VehicleFlag.HOVER_UP_ONLY |
395 VehicleFlag.NO_DEFLECTION_UP |
396 VehicleFlag.LIMIT_MOTOR_UP);
397 vd.m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY |
398 VehicleFlag.HOVER_GLOBAL_HEIGHT);
399 break;
400 }
401 }
402 public void SetVehicle(PhysicsActor ph)
403 {
404 if (ph == null)
405 return;
406 ph.SetVehicle(vd);
407 }
408
409 public bool CameraDecoupled
410 {
411 get
412 {
413 if((vd.m_flags & VehicleFlag.CAMERA_DECOUPLED) != 0)
414 return true;
415 return false;
416 }
417 }
418
419 private XmlTextWriter writer;
420
421 private void XWint(string name, int i)
422 {
423 writer.WriteElementString(name, i.ToString());
424 }
425
426 private void XWfloat(string name, float f)
427 {
428 writer.WriteElementString(name, f.ToString(Culture.FormatProvider));
429 }
430
431 private void XWVector(string name, Vector3 vec)
432 {
433 writer.WriteStartElement(name);
434 writer.WriteElementString("X", vec.X.ToString(Culture.FormatProvider));
435 writer.WriteElementString("Y", vec.Y.ToString(Culture.FormatProvider));
436 writer.WriteElementString("Z", vec.Z.ToString(Culture.FormatProvider));
437 writer.WriteEndElement();
438 }
439
440 private void XWQuat(string name, Quaternion quat)
441 {
442 writer.WriteStartElement(name);
443 writer.WriteElementString("X", quat.X.ToString(Culture.FormatProvider));
444 writer.WriteElementString("Y", quat.Y.ToString(Culture.FormatProvider));
445 writer.WriteElementString("Z", quat.Z.ToString(Culture.FormatProvider));
446 writer.WriteElementString("W", quat.W.ToString(Culture.FormatProvider));
447 writer.WriteEndElement();
448 }
449
450 public void ToXml2(XmlTextWriter twriter)
451 {
452 writer = twriter;
453 writer.WriteStartElement("Vehicle");
454
455 XWint("TYPE", (int)vd.m_type);
456 XWint("FLAGS", (int)vd.m_flags);
457
458 // Linear properties
459 XWVector("LMDIR", vd.m_linearMotorDirection);
460 XWVector("LMFTIME", vd.m_linearFrictionTimescale);
461 XWfloat("LMDTIME", vd.m_linearMotorDecayTimescale);
462 XWfloat("LMTIME", vd.m_linearMotorTimescale);
463 XWVector("LMOFF", vd.m_linearMotorOffset);
464
465 //Angular properties
466 XWVector("AMDIR", vd.m_angularMotorDirection);
467 XWfloat("AMTIME", vd.m_angularMotorTimescale);
468 XWfloat("AMDTIME", vd.m_angularMotorDecayTimescale);
469 XWVector("AMFTIME", vd.m_angularFrictionTimescale);
470
471 //Deflection properties
472 XWfloat("ADEFF", vd.m_angularDeflectionEfficiency);
473 XWfloat("ADTIME", vd.m_angularDeflectionTimescale);
474 XWfloat("LDEFF", vd.m_linearDeflectionEfficiency);
475 XWfloat("LDTIME", vd.m_linearDeflectionTimescale);
476
477 //Banking properties
478 XWfloat("BEFF", vd.m_bankingEfficiency);
479 XWfloat("BMIX", vd.m_bankingMix);
480 XWfloat("BTIME", vd.m_bankingTimescale);
481
482 //Hover and Buoyancy properties
483 XWfloat("HHEI", vd.m_VhoverHeight);
484 XWfloat("HEFF", vd.m_VhoverEfficiency);
485 XWfloat("HTIME", vd.m_VhoverTimescale);
486 XWfloat("VBUO", vd.m_VehicleBuoyancy);
487
488 //Attractor properties
489 XWfloat("VAEFF", vd.m_verticalAttractionEfficiency);
490 XWfloat("VATIME", vd.m_verticalAttractionTimescale);
491
492 XWQuat("REF_FRAME", vd.m_referenceFrame);
493
494 writer.WriteEndElement();
495 writer = null;
496 }
497
498
499
500 XmlReader reader;
501
502 private int XRint()
503 {
504 return reader.ReadElementContentAsInt();
505 }
506
507 private float XRfloat()
508 {
509 return reader.ReadElementContentAsFloat();
510 }
511
512 public Vector3 XRvector()
513 {
514 Vector3 vec;
515 reader.ReadStartElement();
516 vec.X = reader.ReadElementContentAsFloat();
517 vec.Y = reader.ReadElementContentAsFloat();
518 vec.Z = reader.ReadElementContentAsFloat();
519 reader.ReadEndElement();
520 return vec;
521 }
522
523 public Quaternion XRquat()
524 {
525 Quaternion q;
526 reader.ReadStartElement();
527 q.X = reader.ReadElementContentAsFloat();
528 q.Y = reader.ReadElementContentAsFloat();
529 q.Z = reader.ReadElementContentAsFloat();
530 q.W = reader.ReadElementContentAsFloat();
531 reader.ReadEndElement();
532 return q;
533 }
534
535 public static bool EReadProcessors(
536 Dictionary<string, Action> processors,
537 XmlReader xtr)
538 {
539 bool errors = false;
540
541 string nodeName = string.Empty;
542 while (xtr.NodeType != XmlNodeType.EndElement)
543 {
544 nodeName = xtr.Name;
545
546 // m_log.DebugFormat("[ExternalRepresentationUtils]: Processing: {0}", nodeName);
547
548 Action p = null;
549 if (processors.TryGetValue(xtr.Name, out p))
550 {
551 // m_log.DebugFormat("[ExternalRepresentationUtils]: Found {0} processor, nodeName);
552
553 try
554 {
555 p();
556 }
557 catch
558 {
559 errors = true;
560 if (xtr.NodeType == XmlNodeType.EndElement)
561 xtr.Read();
562 }
563 }
564 else
565 {
566 // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName);
567 xtr.ReadOuterXml(); // ignore
568 }
569 }
570
571 return errors;
572 }
573
574
575 public string ToXml2()
576 {
577 using (StringWriter sw = new StringWriter())
578 {
579 using (XmlTextWriter xwriter = new XmlTextWriter(sw))
580 {
581 ToXml2(xwriter);
582 }
583
584 return sw.ToString();
585 }
586 }
587
588 public static SOPVehicle FromXml2(string text)
589 {
590 if (text == String.Empty)
591 return null;
592
593 UTF8Encoding enc = new UTF8Encoding();
594 MemoryStream ms = new MemoryStream(enc.GetBytes(text));
595 XmlTextReader xreader = new XmlTextReader(ms);
596 xreader.ProhibitDtd = true;
597
598 SOPVehicle v = new SOPVehicle();
599 bool error;
600
601 v.FromXml2(xreader, out error);
602
603 xreader.Close();
604
605 if (error)
606 {
607 v = null;
608 return null;
609 }
610 return v;
611 }
612
613 public static SOPVehicle FromXml2(XmlReader reader)
614 {
615 SOPVehicle vehicle = new SOPVehicle();
616
617 bool errors = false;
618
619 vehicle.FromXml2(reader, out errors);
620 if (errors)
621 return null;
622
623 return vehicle;
624 }
625
626 private void FromXml2(XmlReader _reader, out bool errors)
627 {
628 errors = false;
629 reader = _reader;
630
631 Dictionary<string, Action> m_VehicleXmlProcessors
632 = new Dictionary<string, Action>();
633
634 m_VehicleXmlProcessors.Add("TYPE", ProcessXR_type);
635 m_VehicleXmlProcessors.Add("FLAGS", ProcessXR_flags);
636
637 // Linear properties
638 m_VehicleXmlProcessors.Add("LMDIR", ProcessXR_linearMotorDirection);
639 m_VehicleXmlProcessors.Add("LMFTIME", ProcessXR_linearFrictionTimescale);
640 m_VehicleXmlProcessors.Add("LMDTIME", ProcessXR_linearMotorDecayTimescale);
641 m_VehicleXmlProcessors.Add("LMTIME", ProcessXR_linearMotorTimescale);
642 m_VehicleXmlProcessors.Add("LMOFF", ProcessXR_linearMotorOffset);
643
644 //Angular properties
645 m_VehicleXmlProcessors.Add("AMDIR", ProcessXR_angularMotorDirection);
646 m_VehicleXmlProcessors.Add("AMTIME", ProcessXR_angularMotorTimescale);
647 m_VehicleXmlProcessors.Add("AMDTIME", ProcessXR_angularMotorDecayTimescale);
648 m_VehicleXmlProcessors.Add("AMFTIME", ProcessXR_angularFrictionTimescale);
649
650 //Deflection properties
651 m_VehicleXmlProcessors.Add("ADEFF", ProcessXR_angularDeflectionEfficiency);
652 m_VehicleXmlProcessors.Add("ADTIME", ProcessXR_angularDeflectionTimescale);
653 m_VehicleXmlProcessors.Add("LDEFF", ProcessXR_linearDeflectionEfficiency);
654 m_VehicleXmlProcessors.Add("LDTIME", ProcessXR_linearDeflectionTimescale);
655
656 //Banking properties
657 m_VehicleXmlProcessors.Add("BEFF", ProcessXR_bankingEfficiency);
658 m_VehicleXmlProcessors.Add("BMIX", ProcessXR_bankingMix);
659 m_VehicleXmlProcessors.Add("BTIME", ProcessXR_bankingTimescale);
660
661 //Hover and Buoyancy properties
662 m_VehicleXmlProcessors.Add("HHEI", ProcessXR_VhoverHeight);
663 m_VehicleXmlProcessors.Add("HEFF", ProcessXR_VhoverEfficiency);
664 m_VehicleXmlProcessors.Add("HTIME", ProcessXR_VhoverTimescale);
665
666 m_VehicleXmlProcessors.Add("VBUO", ProcessXR_VehicleBuoyancy);
667
668 //Attractor properties
669 m_VehicleXmlProcessors.Add("VAEFF", ProcessXR_verticalAttractionEfficiency);
670 m_VehicleXmlProcessors.Add("VATIME", ProcessXR_verticalAttractionTimescale);
671
672 m_VehicleXmlProcessors.Add("REF_FRAME", ProcessXR_referenceFrame);
673
674 vd = new VehicleData();
675
676 reader.ReadStartElement("Vehicle", String.Empty);
677
678 errors = EReadProcessors(
679 m_VehicleXmlProcessors,
680 reader);
681
682 reader.ReadEndElement();
683 reader = null;
684 }
685
686 private void ProcessXR_type()
687 {
688 vd.m_type = (Vehicle)XRint();
689 }
690 private void ProcessXR_flags()
691 {
692 vd.m_flags = (VehicleFlag)XRint();
693 }
694 // Linear properties
695 private void ProcessXR_linearMotorDirection()
696 {
697 vd.m_linearMotorDirection = XRvector();
698 }
699
700 private void ProcessXR_linearFrictionTimescale()
701 {
702 vd.m_linearFrictionTimescale = XRvector();
703 }
704
705 private void ProcessXR_linearMotorDecayTimescale()
706 {
707 vd.m_linearMotorDecayTimescale = XRfloat();
708 }
709 private void ProcessXR_linearMotorTimescale()
710 {
711 vd.m_linearMotorTimescale = XRfloat();
712 }
713 private void ProcessXR_linearMotorOffset()
714 {
715 vd.m_linearMotorOffset = XRvector();
716 }
717
718
719 //Angular properties
720 private void ProcessXR_angularMotorDirection()
721 {
722 vd.m_angularMotorDirection = XRvector();
723 }
724 private void ProcessXR_angularMotorTimescale()
725 {
726 vd.m_angularMotorTimescale = XRfloat();
727 }
728 private void ProcessXR_angularMotorDecayTimescale()
729 {
730 vd.m_angularMotorDecayTimescale = XRfloat();
731 }
732 private void ProcessXR_angularFrictionTimescale()
733 {
734 vd.m_angularFrictionTimescale = XRvector();
735 }
736
737 //Deflection properties
738 private void ProcessXR_angularDeflectionEfficiency()
739 {
740 vd.m_angularDeflectionEfficiency = XRfloat();
741 }
742 private void ProcessXR_angularDeflectionTimescale()
743 {
744 vd.m_angularDeflectionTimescale = XRfloat();
745 }
746 private void ProcessXR_linearDeflectionEfficiency()
747 {
748 vd.m_linearDeflectionEfficiency = XRfloat();
749 }
750 private void ProcessXR_linearDeflectionTimescale()
751 {
752 vd.m_linearDeflectionTimescale = XRfloat();
753 }
754
755 //Banking properties
756 private void ProcessXR_bankingEfficiency()
757 {
758 vd.m_bankingEfficiency = XRfloat();
759 }
760 private void ProcessXR_bankingMix()
761 {
762 vd.m_bankingMix = XRfloat();
763 }
764 private void ProcessXR_bankingTimescale()
765 {
766 vd.m_bankingTimescale = XRfloat();
767 }
768
769 //Hover and Buoyancy properties
770 private void ProcessXR_VhoverHeight()
771 {
772 vd.m_VhoverHeight = XRfloat();
773 }
774 private void ProcessXR_VhoverEfficiency()
775 {
776 vd.m_VhoverEfficiency = XRfloat();
777 }
778 private void ProcessXR_VhoverTimescale()
779 {
780 vd.m_VhoverTimescale = XRfloat();
781 }
782
783 private void ProcessXR_VehicleBuoyancy()
784 {
785 vd.m_VehicleBuoyancy = XRfloat();
786 }
787
788 //Attractor properties
789 private void ProcessXR_verticalAttractionEfficiency()
790 {
791 vd.m_verticalAttractionEfficiency = XRfloat();
792 }
793 private void ProcessXR_verticalAttractionTimescale()
794 {
795 vd.m_verticalAttractionTimescale = XRfloat();
796 }
797
798 private void ProcessXR_referenceFrame()
799 {
800 vd.m_referenceFrame = XRquat();
801 }
802 }
803}