aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs392
1 files changed, 392 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs b/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs
new file mode 100644
index 0000000..c4c3044
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs
@@ -0,0 +1,392 @@
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 System.Reflection;
31using System.Runtime.InteropServices;
32using log4net;
33using OpenMetaverse;
34using Ode.NET;
35using OpenSim.Framework;
36using OpenSim.Region.Physics.Manager;
37
38namespace OpenSim.Region.Physics.OdePlugin
39{
40 public class ODEVehicleSettings
41 {
42 public Vehicle Type
43 {
44 get { return m_type; }
45 }
46
47 private Vehicle m_type = Vehicle.TYPE_NONE;
48 private OdeScene m_parentScene = null;
49 private IntPtr m_body = IntPtr.Zero;
50 private IntPtr m_jointGroup = IntPtr.Zero;
51 private IntPtr m_aMotor = IntPtr.Zero;
52 private IntPtr m_lMotor = IntPtr.Zero;
53
54 // Vehicle properties
55 private Quaternion m_referenceFrame = Quaternion.Identity;
56 private Vector3 m_angularFrictionTimescale = Vector3.Zero;
57 private Vector3 m_angularMotorDirection = Vector3.Zero;
58 private Vector3 m_linearFrictionTimescale = Vector3.Zero;
59 private Vector3 m_linearMotorDirection = Vector3.Zero;
60 private Vector3 m_linearMotorOffset = Vector3.Zero;
61 private float m_angularDeflectionEfficiency = 0;
62 private float m_angularDeflectionTimescale = 0;
63 private float m_angularMotorDecayTimescale = 0;
64 private float m_angularMotorTimescale = 0;
65 private float m_bankingEfficiency = 0;
66 private float m_bankingMix = 0;
67 private float m_bankingTimescale = 0;
68 private float m_buoyancy = 0;
69 private float m_hoverHeight = 0;
70 private float m_hoverEfficiency = 0;
71 private float m_hoverTimescale = 0;
72 private float m_linearDeflectionEfficiency = 0;
73 private float m_linearDeflectionTimescale = 0;
74 private float m_linearMotorDecayTimescale = 0;
75 private float m_linearMotorTimescale = 0;
76 private float m_verticalAttractionEfficiency = 0;
77 private float m_verticalAttractionTimescale = 0;
78 private VehicleFlag m_flags = (VehicleFlag) 0;
79
80
81
82
83 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
84 {
85 switch (pParam)
86 {
87 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY:
88 m_angularDeflectionEfficiency = pValue;
89 break;
90 case Vehicle.ANGULAR_DEFLECTION_TIMESCALE:
91 m_angularDeflectionTimescale = pValue;
92 break;
93 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
94 m_angularMotorDecayTimescale = pValue;
95 break;
96 case Vehicle.ANGULAR_MOTOR_TIMESCALE:
97 m_angularMotorTimescale = pValue;
98 break;
99 case Vehicle.BANKING_EFFICIENCY:
100 m_bankingEfficiency = pValue;
101 break;
102 case Vehicle.BANKING_MIX:
103 m_bankingMix = pValue;
104 break;
105 case Vehicle.BANKING_TIMESCALE:
106 m_bankingTimescale = pValue;
107 break;
108 case Vehicle.BUOYANCY:
109 m_buoyancy = pValue;
110 break;
111 case Vehicle.HOVER_EFFICIENCY:
112 m_hoverEfficiency = pValue;
113 break;
114 case Vehicle.HOVER_HEIGHT:
115 m_hoverHeight = pValue;
116 break;
117 case Vehicle.HOVER_TIMESCALE:
118 m_hoverTimescale = pValue;
119 break;
120 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY:
121 m_linearDeflectionEfficiency = pValue;
122 break;
123 case Vehicle.LINEAR_DEFLECTION_TIMESCALE:
124 m_linearDeflectionTimescale = pValue;
125 break;
126 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
127 m_linearMotorDecayTimescale = pValue;
128 break;
129 case Vehicle.LINEAR_MOTOR_TIMESCALE:
130 m_linearMotorTimescale = pValue;
131 break;
132 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
133 m_verticalAttractionEfficiency = pValue;
134 break;
135 case Vehicle.VERTICAL_ATTRACTION_TIMESCALE:
136 m_verticalAttractionTimescale = pValue;
137 break;
138
139 // These are vector properties but the engine lets you use a single float value to
140 // set all of the components to the same value
141 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
142 m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue);
143 break;
144 case Vehicle.ANGULAR_MOTOR_DIRECTION:
145 m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
146 break;
147 case Vehicle.LINEAR_FRICTION_TIMESCALE:
148 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
149 break;
150 case Vehicle.LINEAR_MOTOR_DIRECTION:
151 m_linearMotorDirection = new Vector3(pValue, pValue, pValue);
152 break;
153 case Vehicle.LINEAR_MOTOR_OFFSET:
154 m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
155 break;
156
157 }
158 Reset();
159 }
160
161 internal void ProcessVectorVehicleParam(Vehicle pParam, PhysicsVector pValue)
162 {
163 switch (pParam)
164 {
165 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
166 m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
167 break;
168 case Vehicle.ANGULAR_MOTOR_DIRECTION:
169 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
170 break;
171 case Vehicle.LINEAR_FRICTION_TIMESCALE:
172 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
173 break;
174 case Vehicle.LINEAR_MOTOR_DIRECTION:
175 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
176 break;
177 case Vehicle.LINEAR_MOTOR_OFFSET:
178 m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
179 break;
180 }
181 Reset();
182 }
183
184 internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue)
185 {
186 switch (pParam)
187 {
188 case Vehicle.REFERENCE_FRAME:
189 m_referenceFrame = pValue;
190 break;
191 }
192 Reset();
193 }
194
195 internal void ProcessTypeChange(Vehicle pType)
196 {
197 if (m_type == Vehicle.TYPE_NONE && pType != Vehicle.TYPE_NONE)
198 {
199 // Activate whatever it is
200 SetDefaultsForType(pType);
201 Reset();
202 }
203 else if (m_type != Vehicle.TYPE_NONE && pType != Vehicle.TYPE_NONE )
204 {
205 // Set properties
206 SetDefaultsForType(pType);
207 // then reset
208 Reset();
209 }
210 else if (m_type != Vehicle.TYPE_NONE && pType == Vehicle.TYPE_NONE)
211 {
212 Destroy();
213 }
214 }
215
216 internal void Disable()
217 {
218 if (m_body == IntPtr.Zero || m_type == Vehicle.TYPE_NONE)
219 return;
220
221 }
222
223 internal void Enable(IntPtr pBody, OdeScene pParentScene)
224 {
225 if (pBody == IntPtr.Zero || m_type == Vehicle.TYPE_NONE)
226 return;
227 m_body = pBody;
228 m_parentScene = pParentScene;
229 }
230
231 internal void Reset()
232 {
233 if (m_body == IntPtr.Zero || m_type == Vehicle.TYPE_NONE)
234 return;
235
236 }
237
238 internal void Destroy()
239 {
240 if (m_body == IntPtr.Zero || m_type == Vehicle.TYPE_NONE)
241 return;
242
243 }
244
245 internal void Step(float pTimestep)
246 {
247 if (m_body == IntPtr.Zero || m_type == Vehicle.TYPE_NONE)
248 return;
249
250 }
251
252 private void SetDefaultsForType(Vehicle pType)
253 {
254 switch (pType)
255 {
256 case Vehicle.TYPE_SLED:
257 m_linearFrictionTimescale = new Vector3(30, 1, 1000);
258 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
259 m_linearMotorDirection = Vector3.Zero;
260 m_linearMotorTimescale = 1000;
261 m_linearMotorDecayTimescale = 120;
262 m_angularMotorDirection = Vector3.Zero;
263 m_angularMotorTimescale = 1000;
264 m_angularMotorDecayTimescale = 120;
265 m_hoverHeight = 0;
266 m_hoverEfficiency = 10;
267 m_hoverTimescale = 10;
268 m_buoyancy = 0;
269 m_linearDeflectionEfficiency = 1;
270 m_linearDeflectionTimescale = 1;
271 m_angularDeflectionEfficiency = 1;
272 m_angularDeflectionTimescale = 1000;
273 m_bankingEfficiency = 0;
274 m_bankingMix = 1;
275 m_bankingTimescale = 10;
276 m_referenceFrame = Quaternion.Identity;
277 m_flags &=
278 ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
279 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
280 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
281 break;
282 case Vehicle.TYPE_CAR:
283 m_linearFrictionTimescale = new Vector3(100, 2, 1000);
284 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
285 m_linearMotorDirection = Vector3.Zero;
286 m_linearMotorTimescale = 1;
287 m_linearMotorDecayTimescale = 60;
288 m_angularMotorDirection = Vector3.Zero;
289 m_angularMotorTimescale = 1;
290 m_angularMotorDecayTimescale = 0.8f;
291 m_hoverHeight = 0;
292 m_hoverEfficiency = 0;
293 m_hoverTimescale = 1000;
294 m_buoyancy = 0;
295 m_linearDeflectionEfficiency = 1;
296 m_linearDeflectionTimescale = 2;
297 m_angularDeflectionEfficiency = 0;
298 m_angularDeflectionTimescale = 10;
299 m_verticalAttractionEfficiency = 1;
300 m_verticalAttractionTimescale = 10;
301 m_bankingEfficiency = -0.2f;
302 m_bankingMix = 1;
303 m_bankingTimescale = 1;
304 m_referenceFrame = Quaternion.Identity;
305 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT);
306 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.HOVER_UP_ONLY |
307 VehicleFlag.LIMIT_MOTOR_UP);
308 break;
309 case Vehicle.TYPE_BOAT:
310 m_linearFrictionTimescale = new Vector3(10, 3, 2);
311 m_angularFrictionTimescale = new Vector3(10,10,10);
312 m_linearMotorDirection = Vector3.Zero;
313 m_linearMotorTimescale = 5;
314 m_linearMotorDecayTimescale = 60;
315 m_angularMotorDirection = Vector3.Zero;
316 m_angularMotorTimescale = 4;
317 m_angularMotorDecayTimescale = 4;
318 m_hoverHeight = 0;
319 m_hoverEfficiency = 0.5f;
320 m_hoverTimescale = 2;
321 m_buoyancy = 1;
322 m_linearDeflectionEfficiency = 0.5f;
323 m_linearDeflectionTimescale = 3;
324 m_angularDeflectionEfficiency = 0.5f;
325 m_angularDeflectionTimescale = 5;
326 m_verticalAttractionEfficiency = 0.5f;
327 m_verticalAttractionTimescale = 5;
328 m_bankingEfficiency = -0.3f;
329 m_bankingMix = 0.8f;
330 m_bankingTimescale = 1;
331 m_referenceFrame = Quaternion.Identity;
332 m_flags &= ~( VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT);
333 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_UP_ONLY |
334 VehicleFlag.LIMIT_MOTOR_UP);
335 break;
336 case Vehicle.TYPE_AIRPLANE:
337 m_linearFrictionTimescale = new Vector3(200, 10, 5);
338 m_angularFrictionTimescale = new Vector3(20, 20, 20);
339 m_linearMotorDirection = Vector3.Zero;
340 m_linearMotorTimescale = 2;
341 m_linearMotorDecayTimescale = 60;
342 m_angularMotorDirection = Vector3.Zero;
343 m_angularMotorTimescale = 4;
344 m_angularMotorDecayTimescale = 4;
345 m_hoverHeight = 0;
346 m_hoverEfficiency = 0.5f;
347 m_hoverTimescale = 1000;
348 m_buoyancy = 0;
349 m_linearDeflectionEfficiency = 0.5f;
350 m_linearDeflectionTimescale = 3;
351 m_angularDeflectionEfficiency = 1;
352 m_angularDeflectionTimescale = 2;
353 m_verticalAttractionEfficiency = 0.9f;
354 m_verticalAttractionTimescale = 2;
355 m_bankingEfficiency = 1;
356 m_bankingMix = 0.7f;
357 m_bankingTimescale = 2;
358 m_referenceFrame = Quaternion.Identity;
359 m_flags &= ~(VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
360 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
361 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY);
362 break;
363 case Vehicle.TYPE_BALLOON:
364 m_linearFrictionTimescale = new Vector3(5, 5, 5);
365 m_angularFrictionTimescale = new Vector3(10, 10, 10);
366 m_linearMotorDirection = Vector3.Zero;
367 m_linearMotorTimescale = 5;
368 m_linearMotorDecayTimescale = 60;
369 m_angularMotorDirection = Vector3.Zero;
370 m_angularMotorTimescale = 6;
371 m_angularMotorDecayTimescale = 10;
372 m_hoverHeight = 5;
373 m_hoverEfficiency = 0.8f;
374 m_hoverTimescale = 10;
375 m_buoyancy = 1;
376 m_linearDeflectionEfficiency = 0;
377 m_linearDeflectionTimescale = 5;
378 m_angularDeflectionEfficiency = 0;
379 m_angularDeflectionTimescale = 5;
380 m_verticalAttractionEfficiency = 1;
381 m_verticalAttractionTimescale = 1000;
382 m_bankingEfficiency = 0;
383 m_bankingMix = 0.7f;
384 m_bankingTimescale = 5;
385 m_referenceFrame = Quaternion.Identity;
386 m_flags = (VehicleFlag)0;
387 break;
388
389 }
390 }
391 }
392}