aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorUbitUmarov2012-02-08 15:24:10 +0000
committerUbitUmarov2012-02-08 15:24:10 +0000
commit815f3af1d7b3bf16e81dd3a03e0c69c8e49f2f91 (patch)
tree84a2cd2a6c76c23923388d629b54eab4b49b4cf7 /OpenSim/Region
parentPush more NPC stuff into threads (diff)
downloadopensim-SC-815f3af1d7b3bf16e81dd3a03e0c69c8e49f2f91.zip
opensim-SC-815f3af1d7b3bf16e81dd3a03e0c69c8e49f2f91.tar.gz
opensim-SC-815f3af1d7b3bf16e81dd3a03e0c69c8e49f2f91.tar.bz2
opensim-SC-815f3af1d7b3bf16e81dd3a03e0c69c8e49f2f91.tar.xz
UbitODE plugin initial commit
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/AssemblyInfo.cs58
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs1301
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.c_comments630
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs1035
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs3260
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs443
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs1903
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdePlugin.cs86
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs2741
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/drawstuff.cs99
10 files changed, 11556 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/UbitOdePlugin/AssemblyInfo.cs
new file mode 100644
index 0000000..d46341b
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/AssemblyInfo.cs
@@ -0,0 +1,58 @@
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.Reflection;
29using System.Runtime.InteropServices;
30
31// Information about this assembly is defined by the following
32// attributes.
33//
34// change them to the information which is associated with the assembly
35// you compile.
36
37[assembly : AssemblyTitle("OdePlugin")]
38[assembly : AssemblyDescription("Ubit Variation")]
39[assembly : AssemblyConfiguration("")]
40[assembly : AssemblyCompany("http://opensimulator.org")]
41[assembly : AssemblyProduct("OdePlugin")]
42[assembly : AssemblyCopyright("Copyright (c) OpenSimulator.org Developers 2007-2009")]
43[assembly : AssemblyTrademark("")]
44[assembly : AssemblyCulture("")]
45
46// This sets the default COM visibility of types in the assembly to invisible.
47// If you need to expose a type to COM, use [ComVisible(true)] on that type.
48
49[assembly : ComVisible(false)]
50
51// The assembly version has following format :
52//
53// Major.Minor.Build.Revision
54//
55// You can specify all values by your own or you can build default build and revision
56// numbers with the '*' character (the default):
57
58[assembly : AssemblyVersion("0.6.5.*")]
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs
new file mode 100644
index 0000000..c8f7c76
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs
@@ -0,0 +1,1301 @@
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
28
29// Revision by Ubit 2011
30
31using System;
32using System.Collections.Generic;
33using System.Reflection;
34using OpenMetaverse;
35using OdeAPI;
36using OpenSim.Framework;
37using OpenSim.Region.Physics.Manager;
38using log4net;
39
40namespace OpenSim.Region.Physics.OdePlugin
41{
42 /// <summary>
43 /// Various properties that ODE uses for AMotors but isn't exposed in ODE.NET so we must define them ourselves.
44 /// </summary>
45
46 public enum dParam : int
47 {
48 LowStop = 0,
49 HiStop = 1,
50 Vel = 2,
51 FMax = 3,
52 FudgeFactor = 4,
53 Bounce = 5,
54 CFM = 6,
55 StopERP = 7,
56 StopCFM = 8,
57 LoStop2 = 256,
58 HiStop2 = 257,
59 Vel2 = 258,
60 FMax2 = 259,
61 StopERP2 = 7 + 256,
62 StopCFM2 = 8 + 256,
63 LoStop3 = 512,
64 HiStop3 = 513,
65 Vel3 = 514,
66 FMax3 = 515,
67 StopERP3 = 7 + 512,
68 StopCFM3 = 8 + 512
69 }
70
71 public class OdeCharacter : PhysicsActor
72 {
73 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
74
75 private Vector3 _position;
76 private Vector3 _zeroPosition;
77 private bool _zeroFlag = false;
78 private Vector3 _velocity;
79 private Vector3 _target_velocity;
80 private Vector3 _acceleration;
81 private Vector3 m_rotationalVelocity;
82 private float m_mass = 80f;
83 public float m_density = 60f;
84 private bool m_pidControllerActive = true;
85 public float PID_D = 800.0f;
86 public float PID_P = 900.0f;
87 //private static float POSTURE_SERVO = 10000.0f;
88 public float CAPSULE_RADIUS = 0.37f;
89 public float CAPSULE_LENGTH = 2.140599f;
90 public float walkDivisor = 1.3f;
91 public float runDivisor = 0.8f;
92 private bool flying = false;
93 private bool m_iscolliding = false;
94 private bool m_iscollidingGround = false;
95 private bool m_iscollidingObj = false;
96 private bool m_alwaysRun = false;
97 private int m_requestedUpdateFrequency = 0;
98 private Vector3 m_taintPosition = Vector3.Zero;
99 private bool m_hasTaintPosition = false;
100 public uint m_localID = 0;
101 public bool m_returnCollisions = false;
102 // taints and their non-tainted counterparts
103 public bool m_isPhysical = false; // the current physical status
104 public bool m_tainted_isPhysical = false; // set when the physical status is tainted (false=not existing in physics engine, true=existing)
105 public float MinimumGroundFlightOffset = 3f;
106
107
108 private Vector3 m_taintForce;
109 private bool m_hasTaintForce;
110 private float m_tainted_CAPSULE_LENGTH; // set when the capsule length changes.
111
112
113 private float m_buoyancy = 0f;
114
115 // private CollisionLocker ode;
116
117 private string m_name = String.Empty;
118 // other filter control
119 int m_colliderfilter = 0;
120 // int m_colliderGroundfilter = 0;
121 int m_colliderObjectfilter = 0;
122
123 // Default we're a Character
124 private CollisionCategories m_collisionCategories = (CollisionCategories.Character);
125
126 // Default, Collide with Other Geometries, spaces, bodies and characters.
127 private CollisionCategories m_collisionFlags = (CollisionCategories.Geom
128 | CollisionCategories.Space
129 | CollisionCategories.Body
130 | CollisionCategories.Character
131 );
132 // we do land collisions not ode | CollisionCategories.Land);
133 public IntPtr Body = IntPtr.Zero;
134 private OdeScene _parent_scene;
135 public IntPtr Shell = IntPtr.Zero;
136 public IntPtr Amotor = IntPtr.Zero;
137 public d.Mass ShellMass;
138 public bool collidelock = false;
139
140 private bool m_haseventsubscription = false;
141 public int m_eventsubscription = 0;
142 private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();
143
144 // unique UUID of this character object
145 public UUID m_uuid;
146 public bool bad = false;
147
148 public ContactData AvatarContactData = new ContactData(10f, 0.3f);
149
150 public OdeCharacter(String avName, OdeScene parent_scene, Vector3 pos, Vector3 size, float pid_d, float pid_p, float capsule_radius, float density, float walk_divisor, float rundivisor)
151 {
152 m_uuid = UUID.Random();
153
154 m_hasTaintPosition = false;
155
156 if (pos.IsFinite())
157 {
158 if (pos.Z > 9999999f)
159 {
160 pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
161 }
162 if (pos.Z < -90000f)
163 {
164 pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
165 }
166 _position = pos;
167 }
168 else
169 {
170 _position = new Vector3(((float)_parent_scene.WorldExtents.X * 0.5f), ((float)_parent_scene.WorldExtents.Y * 0.5f), parent_scene.GetTerrainHeightAtXY(128f, 128f) + 10f);
171 m_log.Warn("[PHYSICS]: Got NaN Position on Character Create");
172 }
173
174 _parent_scene = parent_scene;
175
176 PID_D = pid_d;
177 PID_P = pid_p;
178 CAPSULE_RADIUS = capsule_radius;
179 m_density = density;
180 m_mass = 80f; // sure we have a default
181
182 AvatarContactData.mu = parent_scene.AvatarFriction;
183 AvatarContactData.bounce = parent_scene.AvatarBounce;
184
185 walkDivisor = walk_divisor;
186 runDivisor = rundivisor;
187
188 CAPSULE_LENGTH = size.Z * 1.15f - CAPSULE_RADIUS * 2.0f;
189 //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString());
190 m_tainted_CAPSULE_LENGTH = CAPSULE_LENGTH;
191
192 m_isPhysical = false; // current status: no ODE information exists
193 m_tainted_isPhysical = true; // new tainted status: need to create ODE information
194
195 m_hasTaintForce = false;
196 _parent_scene.AddPhysicsActorTaint(this);
197
198 m_name = avName;
199 }
200
201 public override int PhysicsActorType
202 {
203 get { return (int)ActorTypes.Agent; }
204 set { return; }
205 }
206
207 public override ContactData ContactData
208 {
209 get { return AvatarContactData; }
210 }
211
212 public override bool Building { get; set; }
213
214 /// <summary>
215 /// If this is set, the avatar will move faster
216 /// </summary>
217 public override bool SetAlwaysRun
218 {
219 get { return m_alwaysRun; }
220 set { m_alwaysRun = value; }
221 }
222
223 public override uint LocalID
224 {
225 set { m_localID = value; }
226 }
227
228 public override bool Grabbed
229 {
230 set { return; }
231 }
232
233 public override bool Selected
234 {
235 set { return; }
236 }
237
238 public override float Buoyancy
239 {
240 get { return m_buoyancy; }
241 set { m_buoyancy = value; }
242 }
243
244 public override bool FloatOnWater
245 {
246 set { return; }
247 }
248
249 public override bool IsPhysical
250 {
251 get { return false; }
252 set { return; }
253 }
254
255 public override bool ThrottleUpdates
256 {
257 get { return false; }
258 set { return; }
259 }
260
261 public override bool Flying
262 {
263 get { return flying; }
264 set
265 {
266 flying = value;
267 // m_log.DebugFormat("[PHYSICS]: Set OdeCharacter Flying to {0}", flying);
268 }
269 }
270
271 /// <summary>
272 /// Returns if the avatar is colliding in general.
273 /// This includes the ground and objects and avatar.
274 /// </summary>
275 public override bool IsColliding
276 {
277 get { return (m_iscolliding || m_iscollidingGround); }
278 set
279 {
280 if (value)
281 {
282 m_colliderfilter += 2;
283 if (m_colliderfilter > 2)
284 m_colliderfilter = 2;
285 }
286 else
287 {
288 m_colliderfilter--;
289 if (m_colliderfilter < 0)
290 m_colliderfilter = 0;
291 }
292
293 if (m_colliderfilter == 0)
294 m_iscolliding = false;
295 else
296 {
297// SetPidStatus(false);
298 m_pidControllerActive = true;
299 m_iscolliding = true;
300 }
301 }
302 }
303
304 /// <summary>
305 /// Returns if an avatar is colliding with the ground
306 /// </summary>
307 public override bool CollidingGround
308 {
309 get { return m_iscollidingGround; }
310 set
311 {
312 /* we now control this
313 if (value)
314 {
315 m_colliderGroundfilter += 2;
316 if (m_colliderGroundfilter > 2)
317 m_colliderGroundfilter = 2;
318 }
319 else
320 {
321 m_colliderGroundfilter--;
322 if (m_colliderGroundfilter < 0)
323 m_colliderGroundfilter = 0;
324 }
325
326 if (m_colliderGroundfilter == 0)
327 m_iscollidingGround = false;
328 else
329 m_iscollidingGround = true;
330 */
331 }
332
333 }
334
335 /// <summary>
336 /// Returns if the avatar is colliding with an object
337 /// </summary>
338 public override bool CollidingObj
339 {
340 get { return m_iscollidingObj; }
341 set
342 {
343 // Ubit filter this also
344 if (value)
345 {
346 m_colliderObjectfilter += 2;
347 if (m_colliderObjectfilter > 2)
348 m_colliderObjectfilter = 2;
349 }
350 else
351 {
352 m_colliderObjectfilter--;
353 if (m_colliderObjectfilter < 0)
354 m_colliderObjectfilter = 0;
355 }
356
357 if (m_colliderObjectfilter == 0)
358 m_iscollidingObj = false;
359 else
360 m_iscollidingObj = true;
361
362 // m_iscollidingObj = value;
363/*
364 if (m_iscollidingObj)
365 m_pidControllerActive = false;
366 else
367 m_pidControllerActive = true;
368 */
369 }
370 }
371
372 /// <summary>
373 /// turn the PID controller on or off.
374 /// The PID Controller will turn on all by itself in many situations
375 /// </summary>
376 /// <param name="status"></param>
377 public void SetPidStatus(bool status)
378 {
379 m_pidControllerActive = status;
380 }
381
382 public override bool Stopped
383 {
384 get { return _zeroFlag; }
385 }
386
387 /// <summary>
388 /// This 'puts' an avatar somewhere in the physics space.
389 /// Not really a good choice unless you 'know' it's a good
390 /// spot otherwise you're likely to orbit the avatar.
391 /// </summary>
392 public override Vector3 Position
393 {
394 get { return _position; }
395 set
396 {
397 if (Body == IntPtr.Zero || Shell == IntPtr.Zero)
398 {
399 if (value.IsFinite())
400 {
401 if (value.Z > 9999999f)
402 {
403 value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
404 }
405 if (value.Z < -90000f)
406 {
407 value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
408 }
409
410 m_taintPosition.X = value.X;
411 m_taintPosition.Y = value.Y;
412 m_taintPosition.Z = value.Z;
413 m_hasTaintPosition = true;
414 _parent_scene.AddPhysicsActorTaint(this);
415 }
416 else
417 {
418 m_log.Warn("[PHYSICS]: Got a NaN Position from Scene on a Character");
419 }
420 }
421 }
422 }
423
424 public override Vector3 RotationalVelocity
425 {
426 get { return m_rotationalVelocity; }
427 set { m_rotationalVelocity = value; }
428 }
429
430 /// <summary>
431 /// This property sets the height of the avatar only. We use the height to make sure the avatar stands up straight
432 /// and use it to offset landings properly
433 /// </summary>
434 public override Vector3 Size
435 {
436 get {
437 float d = CAPSULE_RADIUS * 2;
438 return new Vector3(d, d, (CAPSULE_LENGTH +d)/1.15f); }
439 set
440 {
441 if (value.IsFinite())
442 {
443 m_pidControllerActive = true;
444
445 Vector3 SetSize = value;
446 m_tainted_CAPSULE_LENGTH = SetSize.Z *1.15f - CAPSULE_RADIUS * 2.0f;
447 _parent_scene.AddPhysicsActorTaint(this);
448 }
449 else
450 {
451 m_log.Warn("[PHYSICS]: Got a NaN Size from Scene on a Character");
452 }
453 }
454 }
455
456 /// <summary>
457 /// This creates the Avatar's physical Surrogate at the position supplied
458 /// </summary>
459 /// <param name="npositionX"></param>
460 /// <param name="npositionY"></param>
461 /// <param name="npositionZ"></param>
462
463 // WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access
464 // to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only
465 // place that is safe to call this routine AvatarGeomAndBodyCreation.
466 private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ)
467 {
468 _parent_scene.waitForSpaceUnlock(_parent_scene.ActiveSpace);
469 if (CAPSULE_LENGTH <= 0)
470 {
471 m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!");
472 CAPSULE_LENGTH = 0.01f;
473
474 }
475
476 if (CAPSULE_RADIUS <= 0)
477 {
478 m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!");
479 CAPSULE_RADIUS = 0.01f;
480
481 }
482 Shell = d.CreateCapsule(_parent_scene.ActiveSpace, CAPSULE_RADIUS, CAPSULE_LENGTH);
483
484 d.GeomSetCategoryBits(Shell, (int)m_collisionCategories);
485 d.GeomSetCollideBits(Shell, (int)m_collisionFlags);
486
487 d.MassSetCapsule(out ShellMass, m_density, 3, CAPSULE_RADIUS, CAPSULE_LENGTH);
488
489 m_mass = ShellMass.mass; // update mass
490
491 // rescale PID parameters
492 PID_D = _parent_scene.avPIDD;
493 PID_P = _parent_scene.avPIDP;
494
495 // rescale PID parameters so that this aren't affected by mass
496 // and so don't get unstable for some masses
497 // also scale by ode time step so you don't need to refix them
498
499 PID_D /= 50 * 80; //scale to original mass of around 80 and 50 ODE fps
500 PID_D *= m_mass / _parent_scene.ODE_STEPSIZE;
501 PID_P /= 50 * 80;
502 PID_P *= m_mass / _parent_scene.ODE_STEPSIZE;
503
504 Body = d.BodyCreate(_parent_scene.world);
505
506 d.BodySetAutoDisableFlag(Body, false);
507 d.BodySetPosition(Body, npositionX, npositionY, npositionZ);
508
509 _position.X = npositionX;
510 _position.Y = npositionY;
511 _position.Z = npositionZ;
512
513 m_hasTaintPosition = false;
514
515 d.BodySetMass(Body, ref ShellMass);
516 d.GeomSetBody(Shell, Body);
517
518 // The purpose of the AMotor here is to keep the avatar's physical
519 // surrogate from rotating while moving
520 Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
521 d.JointAttach(Amotor, Body, IntPtr.Zero);
522
523 d.JointSetAMotorMode(Amotor, 0);
524 d.JointSetAMotorNumAxes(Amotor, 3);
525 d.JointSetAMotorAxis(Amotor, 0, 0 , 1, 0, 0);
526 d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0);
527 d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1);
528
529 d.JointSetAMotorAngle(Amotor, 0, 0);
530 d.JointSetAMotorAngle(Amotor, 1, 0);
531 d.JointSetAMotorAngle(Amotor, 2, 0);
532
533 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM, 0f); // make it HARD
534 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM2, 0f);
535 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM3, 0f);
536 d.JointSetAMotorParam(Amotor, (int)dParam.StopERP, 0.8f);
537 d.JointSetAMotorParam(Amotor, (int)dParam.StopERP2, 0.8f);
538 d.JointSetAMotorParam(Amotor, (int)dParam.StopERP3, 0.8f);
539
540 // These lowstops and high stops are effectively (no wiggle room)
541 d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -1e-5f);
542 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 1e-5f);
543 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -1e-5f);
544 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 1e-5f);
545 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -1e-5f);
546 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 1e-5f);
547
548 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel, 0);
549 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel2, 0);
550 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel3, 0);
551
552 d.JointSetAMotorParam(Amotor, (int)dParam.FMax, 5e6f);
553 d.JointSetAMotorParam(Amotor, (int)dParam.FMax2, 5e6f);
554 d.JointSetAMotorParam(Amotor, (int)dParam.FMax3, 5e6f);
555 }
556
557 /// <summary>
558 /// Destroys the avatar body and geom
559
560 private void AvatarGeomAndBodyDestroy()
561 {
562 // Kill the Amotor
563 if (Amotor != IntPtr.Zero)
564 {
565 d.JointDestroy(Amotor);
566 Amotor = IntPtr.Zero;
567 }
568
569 if (Body != IntPtr.Zero)
570 {
571 //kill the body
572 d.BodyDestroy(Body);
573 Body = IntPtr.Zero;
574 }
575
576 //kill the Geometry
577 if (Shell != IntPtr.Zero)
578 {
579 _parent_scene.geom_name_map.Remove(Shell);
580 _parent_scene.waitForSpaceUnlock(_parent_scene.ActiveSpace);
581 d.GeomDestroy(Shell);
582 _parent_scene.geom_name_map.Remove(Shell);
583 Shell = IntPtr.Zero;
584 }
585 }
586 //
587 /// <summary>
588 /// Uses the capped cyllinder volume formula to calculate the avatar's mass.
589 /// This may be used in calculations in the scene/scenepresence
590 /// </summary>
591 public override float Mass
592 {
593 get
594 {
595 float AVvolume = (float)(Math.PI * CAPSULE_RADIUS * CAPSULE_RADIUS * (1.3333333333f * CAPSULE_RADIUS + CAPSULE_LENGTH));
596 return m_density * AVvolume;
597 }
598 }
599 public override void link(PhysicsActor obj)
600 {
601
602 }
603
604 public override void delink()
605 {
606
607 }
608
609 public override void LockAngularMotion(Vector3 axis)
610 {
611
612 }
613
614
615 public override Vector3 Force
616 {
617 get { return _target_velocity; }
618 set { return; }
619 }
620
621 public override int VehicleType
622 {
623 get { return 0; }
624 set { return; }
625 }
626
627 public override void VehicleFloatParam(int param, float value)
628 {
629
630 }
631
632 public override void VehicleVectorParam(int param, Vector3 value)
633 {
634
635 }
636
637 public override void VehicleRotationParam(int param, Quaternion rotation)
638 {
639
640 }
641
642 public override void VehicleFlags(int param, bool remove)
643 {
644
645 }
646
647 public override void SetVolumeDetect(int param)
648 {
649
650 }
651
652 public override Vector3 CenterOfMass
653 {
654 get
655 {
656 Vector3 pos = _position;
657 return pos;
658 }
659 }
660
661 public override Vector3 GeometricCenter
662 {
663 get
664 {
665 Vector3 pos = _position;
666 return pos;
667 }
668 }
669
670 //UBit mess
671 /* for later use
672 public override Vector3 PrimOOBsize
673 {
674 get
675 {
676 Vector3 s=Size;
677 s.X *=0.5f;
678 s.Y *=0.5f;
679 s.Z *=0.5f;
680 return s;
681 }
682 }
683
684 public override Vector3 PrimOOBoffset
685 {
686 get
687 {
688 return Vector3.Zero;
689 }
690 }
691 */
692
693 public override PrimitiveBaseShape Shape
694 {
695 set { return; }
696 }
697
698 public override Vector3 Velocity
699 {
700 get
701 {
702 return _velocity;
703 }
704 set
705 {
706 if (value.IsFinite())
707 {
708 m_pidControllerActive = true;
709 _target_velocity = value;
710 }
711 else
712 {
713 m_log.Warn("[PHYSICS]: Got a NaN velocity from Scene in a Character");
714 }
715 }
716 }
717
718 public override Vector3 Torque
719 {
720 get { return Vector3.Zero; }
721 set { return; }
722 }
723
724 public override float CollisionScore
725 {
726 get { return 0f; }
727 set { }
728 }
729
730 public override bool Kinematic
731 {
732 get { return false; }
733 set { }
734 }
735
736 public override Quaternion Orientation
737 {
738 get { return Quaternion.Identity; }
739 set
740 {
741 //Matrix3 or = Orientation.ToRotationMatrix();
742 //d.Matrix3 ord = new d.Matrix3(or.m00, or.m10, or.m20, or.m01, or.m11, or.m21, or.m02, or.m12, or.m22);
743 //d.BodySetRotation(Body, ref ord);
744 }
745 }
746
747 public override Vector3 Acceleration
748 {
749 get { return _acceleration; }
750 set { }
751 }
752
753 public void SetAcceleration(Vector3 accel)
754 {
755 m_pidControllerActive = true;
756 _acceleration = accel;
757 }
758
759 /// <summary>
760 /// Adds the force supplied to the Target Velocity
761 /// The PID controller takes this target velocity and tries to make it a reality
762 /// </summary>
763 /// <param name="force"></param>
764 public override void AddForce(Vector3 force, bool pushforce)
765 {
766 if (force.IsFinite())
767 {
768 if (pushforce)
769 {
770 m_pidControllerActive = false;
771 m_taintForce = force / _parent_scene.ODE_STEPSIZE;
772 m_hasTaintForce = true;
773 _parent_scene.AddPhysicsActorTaint(this);
774 }
775 else
776 {
777 m_pidControllerActive = true;
778 _target_velocity.X += force.X;
779 _target_velocity.Y += force.Y;
780 _target_velocity.Z += force.Z;
781 }
782 }
783 else
784 {
785 m_log.Warn("[PHYSICS]: Got a NaN force applied to a Character");
786 }
787 //m_lastUpdateSent = false;
788 }
789
790 public override void AddAngularForce(Vector3 force, bool pushforce)
791 {
792
793 }
794
795 public override void SetMomentum(Vector3 momentum)
796 {
797 }
798
799
800 /// <summary>
801 /// Called from Simulate
802 /// This is the avatar's movement control + PID Controller
803 /// </summary>
804 /// <param name="timeStep"></param>
805 public void Move(float timeStep, List<OdeCharacter> defects)
806 {
807 // no lock; for now it's only called from within Simulate()
808
809 // If the PID Controller isn't active then we set our force
810 // calculating base velocity to the current position
811
812 if (Body == IntPtr.Zero)
813 return;
814
815 d.Vector3 dtmp;
816 d.BodyCopyPosition(Body, out dtmp);
817 Vector3 localpos = new Vector3(dtmp.X, dtmp.Y, dtmp.Z);
818
819 // the Amotor still lets avatar rotation to drift during colisions
820 // so force it back to identity
821
822 d.Quaternion qtmp;
823 qtmp.W = 1;
824 qtmp.X = 0;
825 qtmp.Y = 0;
826 qtmp.Z = 0;
827 d.BodySetQuaternion(Body, ref qtmp);
828
829 if (m_pidControllerActive == false)
830 {
831 _zeroPosition = localpos;
832 }
833 //PidStatus = true;
834
835
836 if (!localpos.IsFinite())
837 {
838
839 m_log.Warn("[PHYSICS]: Avatar Position is non-finite!");
840 defects.Add(this);
841 // _parent_scene.RemoveCharacter(this);
842
843 // destroy avatar capsule and related ODE data
844 AvatarGeomAndBodyDestroy();
845
846 return;
847 }
848
849 Vector3 vec = Vector3.Zero;
850 dtmp = d.BodyGetLinearVel(Body);
851 Vector3 vel = new Vector3(dtmp.X, dtmp.Y, dtmp.Z);
852
853 float movementdivisor = 1f;
854 //Ubit change divisions into multiplications below
855 if (!m_alwaysRun)
856 {
857 movementdivisor = 1 / walkDivisor;
858 }
859 else
860 {
861 movementdivisor = 1 / runDivisor;
862 }
863
864 // colide with land
865
866 d.AABB aabb;
867 d.GeomGetAABB(Shell, out aabb);
868 float chrminZ = aabb.MinZ;
869
870 Vector3 posch = localpos;
871
872 float ftmp;
873
874 if (flying)
875 {
876 ftmp = timeStep;
877 posch.X += vel.X * ftmp;
878 posch.Y += vel.Y * ftmp;
879 }
880
881 float terrainheight = _parent_scene.GetTerrainHeightAtXY(posch.X, posch.Y);
882 if (chrminZ < terrainheight)
883 {
884 float depth = terrainheight - chrminZ;
885 if (!flying)
886 {
887 vec.Z = -vel.Z * PID_D * 1.5f + depth * PID_P * 50;
888 }
889 else
890 vec.Z = depth * PID_P * 50;
891
892 /*
893 Vector3 vtmp;
894 vtmp.X = _target_velocity.X * timeStep;
895 vtmp.Y = _target_velocity.Y * timeStep;
896 // fake and avoid squares
897 float k = (Math.Abs(vtmp.X) + Math.Abs(vtmp.Y));
898 if (k > 0)
899 {
900 posch.X += vtmp.X;
901 posch.Y += vtmp.Y;
902 terrainheight -= _parent_scene.GetTerrainHeightAtXY(posch.X, posch.Y);
903 k = 1 + Math.Abs(terrainheight) / k;
904 movementdivisor /= k;
905
906 if (k < 1)
907 k = 1;
908 }
909 */
910
911
912 if (depth < 0.1f)
913 {
914 m_iscolliding = true;
915 m_colliderfilter = 2;
916 m_iscollidingGround = true;
917
918 ContactPoint contact = new ContactPoint();
919 contact.PenetrationDepth = depth;
920 contact.Position.X = localpos.X;
921 contact.Position.Y = localpos.Y;
922 contact.Position.Z = chrminZ;
923 contact.SurfaceNormal.X = 0f;
924 contact.SurfaceNormal.Y = 0f;
925 contact.SurfaceNormal.Z = -1f;
926 AddCollisionEvent(0, contact);
927
928 vec.Z *= 0.5f;
929 }
930
931 else
932 m_iscollidingGround = false;
933 }
934 else
935 m_iscollidingGround = false;
936
937
938 // if velocity is zero, use position control; otherwise, velocity control
939 if (_target_velocity.X == 0.0f && _target_velocity.Y == 0.0f && _target_velocity.Z == 0.0f
940 && m_iscolliding)
941 {
942 // keep track of where we stopped. No more slippin' & slidin'
943 if (!_zeroFlag)
944 {
945 _zeroFlag = true;
946 _zeroPosition = localpos;
947 }
948 if (m_pidControllerActive)
949 {
950 // We only want to deactivate the PID Controller if we think we want to have our surrogate
951 // react to the physics scene by moving it's position.
952 // Avatar to Avatar collisions
953 // Prim to avatar collisions
954
955 vec.X = -vel.X * PID_D + (_zeroPosition.X - localpos.X) * (PID_P * 2);
956 vec.Y = -vel.Y * PID_D + (_zeroPosition.Y - localpos.Y) * (PID_P * 2);
957 if (flying)
958 {
959 vec.Z += -vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P;
960 }
961 }
962 //PidStatus = true;
963 }
964 else
965 {
966 m_pidControllerActive = true;
967 _zeroFlag = false;
968
969 if (m_iscolliding)
970 {
971 if (!flying)
972 {
973 if (_target_velocity.Z > 0.0f)
974 {
975 // We're colliding with something and we're not flying but we're moving
976 // This means we're walking or running. JUMPING
977 vec.Z += (_target_velocity.Z - vel.Z) * PID_D * 1.2f;// +(_zeroPosition.Z - localpos.Z) * PID_P;
978 }
979 // We're standing on something
980 vec.X = ((_target_velocity.X * movementdivisor) - vel.X) * (PID_D);
981 vec.Y = ((_target_velocity.Y * movementdivisor) - vel.Y) * (PID_D);
982 }
983 else
984 {
985 // We're flying and colliding with something
986 vec.X = ((_target_velocity.X * movementdivisor) - vel.X) * (PID_D * 0.0625f);
987 vec.Y = ((_target_velocity.Y * movementdivisor) - vel.Y) * (PID_D * 0.0625f);
988 vec.Z += (_target_velocity.Z - vel.Z) * (PID_D);
989 }
990 }
991 else // ie not colliding
992 {
993 if (flying) //(!m_iscolliding && flying)
994 {
995 // we're in mid air suspended
996 vec.X = ((_target_velocity.X * movementdivisor) - vel.X) * (PID_D * 1.667f);
997 vec.Y = ((_target_velocity.Y * movementdivisor) - vel.Y) * (PID_D * 1.667f);
998 vec.Z += (_target_velocity.Z - vel.Z) * (PID_D);
999 }
1000
1001 else
1002 {
1003 // we're not colliding and we're not flying so that means we're falling!
1004 // m_iscolliding includes collisions with the ground.
1005
1006 // d.Vector3 pos = d.BodyGetPosition(Body);
1007 vec.X = (_target_velocity.X - vel.X) * PID_D * 0.833f;
1008 vec.Y = (_target_velocity.Y - vel.Y) * PID_D * 0.833f;
1009 }
1010 }
1011 }
1012
1013 if (flying)
1014 {
1015 vec.Z -= _parent_scene.gravityz * m_mass;
1016
1017 //Added for auto fly height. Kitto Flora
1018 float target_altitude = _parent_scene.GetTerrainHeightAtXY(localpos.X, localpos.Y) + MinimumGroundFlightOffset;
1019
1020 if (localpos.Z < target_altitude)
1021 {
1022 vec.Z += (target_altitude - localpos.Z) * PID_P * 5.0f;
1023 }
1024 // end add Kitto Flora
1025 }
1026
1027 if (vec.IsFinite())
1028 {
1029 if (vec.X != 0 || vec.Y !=0 || vec.Z !=0)
1030 d.BodyAddForce(Body, vec.X, vec.Y, vec.Z);
1031 }
1032 else
1033 {
1034 m_log.Warn("[PHYSICS]: Got a NaN force vector in Move()");
1035 m_log.Warn("[PHYSICS]: Avatar Position is non-finite!");
1036 defects.Add(this);
1037 // _parent_scene.RemoveCharacter(this);
1038 // destroy avatar capsule and related ODE data
1039 AvatarGeomAndBodyDestroy();
1040 }
1041 }
1042
1043 /// <summary>
1044 /// Updates the reported position and velocity. This essentially sends the data up to ScenePresence.
1045 /// </summary>
1046 public void UpdatePositionAndVelocity()
1047 {
1048 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
1049 if (Body == IntPtr.Zero)
1050 return;
1051
1052 d.Vector3 vec;
1053 try
1054 {
1055 d.BodyCopyPosition(Body, out vec);
1056 }
1057 catch (NullReferenceException)
1058 {
1059 bad = true;
1060 _parent_scene.BadCharacter(this);
1061 vec = new d.Vector3(_position.X, _position.Y, _position.Z);
1062 base.RaiseOutOfBounds(_position); // Tells ScenePresence that there's a problem!
1063 m_log.WarnFormat("[ODEPLUGIN]: Avatar Null reference for Avatar {0}, physical actor {1}", m_name, m_uuid);
1064 }
1065
1066 _position.X = vec.X;
1067 _position.Y = vec.Y;
1068 _position.Z = vec.Z;
1069
1070 bool fixbody = false;
1071
1072 if (_position.X < 0.0f)
1073 {
1074 fixbody = true;
1075 _position.X = 0.1f;
1076 }
1077 else if (_position.X > (int)_parent_scene.WorldExtents.X - 0.1f)
1078 {
1079 fixbody = true;
1080 _position.X = (int)_parent_scene.WorldExtents.X - 0.1f;
1081 }
1082
1083 if (_position.Y < 0.0f)
1084 {
1085 fixbody = true;
1086 _position.Y = 0.1f;
1087 }
1088 else if (_position.Y > (int)_parent_scene.WorldExtents.Y - 0.1)
1089 {
1090 fixbody = true;
1091 _position.Y = (int)_parent_scene.WorldExtents.Y - 0.1f;
1092 }
1093
1094 if (fixbody)
1095 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
1096
1097 // Did we move last? = zeroflag
1098 // This helps keep us from sliding all over
1099/*
1100 if (_zeroFlag)
1101 {
1102 _velocity.X = 0.0f;
1103 _velocity.Y = 0.0f;
1104 _velocity.Z = 0.0f;
1105
1106 // Did we send out the 'stopped' message?
1107 if (!m_lastUpdateSent)
1108 {
1109 m_lastUpdateSent = true;
1110 base.RequestPhysicsterseUpdate();
1111 }
1112 }
1113 else
1114 {
1115 m_lastUpdateSent = false;
1116 */
1117 try
1118 {
1119 vec = d.BodyGetLinearVel(Body);
1120 }
1121 catch (NullReferenceException)
1122 {
1123 vec.X = _velocity.X;
1124 vec.Y = _velocity.Y;
1125 vec.Z = _velocity.Z;
1126 }
1127 _velocity.X = (vec.X);
1128 _velocity.Y = (vec.Y);
1129 _velocity.Z = (vec.Z);
1130 // }
1131 }
1132
1133 /// <summary>
1134 /// Cleanup the things we use in the scene.
1135 /// </summary>
1136 public void Destroy()
1137 {
1138 m_tainted_isPhysical = false;
1139 _parent_scene.AddPhysicsActorTaint(this);
1140 }
1141
1142 public override void CrossingFailure()
1143 {
1144 }
1145
1146 public override Vector3 PIDTarget { set { return; } }
1147 public override bool PIDActive { set { return; } }
1148 public override float PIDTau { set { return; } }
1149
1150 public override float PIDHoverHeight { set { return; } }
1151 public override bool PIDHoverActive { set { return; } }
1152 public override PIDHoverType PIDHoverType { set { return; } }
1153 public override float PIDHoverTau { set { return; } }
1154
1155 public override Quaternion APIDTarget { set { return; } }
1156
1157 public override bool APIDActive { set { return; } }
1158
1159 public override float APIDStrength { set { return; } }
1160
1161 public override float APIDDamping { set { return; } }
1162
1163
1164 public override void SubscribeEvents(int ms)
1165 {
1166 m_requestedUpdateFrequency = ms;
1167 m_eventsubscription = ms;
1168 _parent_scene.AddCollisionEventReporting(this);
1169 m_haseventsubscription = true;
1170 }
1171
1172 public override void UnSubscribeEvents()
1173 {
1174 m_haseventsubscription = false;
1175 _parent_scene.RemoveCollisionEventReporting(this);
1176 m_requestedUpdateFrequency = 0;
1177 m_eventsubscription = 0;
1178 }
1179
1180 public void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
1181 {
1182 if (m_haseventsubscription)
1183 {
1184 // m_log.DebugFormat(
1185 // "[PHYSICS]: Adding collision event for {0}, collidedWith {1}, contact {2}", "", CollidedWith, contact);
1186
1187 CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
1188 }
1189 }
1190
1191 public void SendCollisions()
1192 {
1193 if (m_haseventsubscription && m_eventsubscription > m_requestedUpdateFrequency)
1194 {
1195 if (CollisionEventsThisFrame != null)
1196 {
1197 base.SendCollisionUpdate(CollisionEventsThisFrame);
1198 }
1199 CollisionEventsThisFrame = new CollisionEventUpdate();
1200 m_eventsubscription = 0;
1201 }
1202 }
1203
1204 public override bool SubscribedEvents()
1205 {
1206 return m_haseventsubscription;
1207 }
1208
1209 public void ProcessTaints(float timestep)
1210 {
1211
1212 if (m_tainted_isPhysical != m_isPhysical)
1213 {
1214 if (m_tainted_isPhysical)
1215 {
1216 // Create avatar capsule and related ODE data
1217 if ((Shell != IntPtr.Zero))
1218 {
1219 // a lost shell ?
1220 m_log.Warn("[PHYSICS]: re-creating the following avatar ODE data, even though it already exists - "
1221 + (Shell != IntPtr.Zero ? "Shell " : "")
1222 + (Body != IntPtr.Zero ? "Body " : "")
1223 + (Amotor != IntPtr.Zero ? "Amotor " : ""));
1224 AvatarGeomAndBodyDestroy();
1225 }
1226
1227 AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z);
1228 _parent_scene.geom_name_map[Shell] = m_name;
1229 _parent_scene.actor_name_map[Shell] = (PhysicsActor)this;
1230 _parent_scene.AddCharacter(this);
1231 }
1232 else
1233 {
1234 _parent_scene.RemoveCharacter(this);
1235 // destroy avatar capsule and related ODE data
1236 AvatarGeomAndBodyDestroy();
1237 }
1238
1239 m_isPhysical = m_tainted_isPhysical;
1240 }
1241
1242 if (m_tainted_CAPSULE_LENGTH != CAPSULE_LENGTH)
1243 {
1244 if (Shell != IntPtr.Zero && Body != IntPtr.Zero && Amotor != IntPtr.Zero)
1245 {
1246 AvatarGeomAndBodyDestroy();
1247
1248 m_pidControllerActive = true;
1249
1250 float prevCapsule = CAPSULE_LENGTH;
1251 CAPSULE_LENGTH = m_tainted_CAPSULE_LENGTH;
1252
1253 AvatarGeomAndBodyCreation(_position.X, _position.Y,
1254 _position.Z + (Math.Abs(CAPSULE_LENGTH - prevCapsule) * 2));
1255
1256 Velocity = Vector3.Zero;
1257
1258 _parent_scene.geom_name_map[Shell] = m_name;
1259 _parent_scene.actor_name_map[Shell] = (PhysicsActor)this;
1260 }
1261 else
1262 {
1263 m_log.Warn("[PHYSICS]: trying to change capsule size, but the following ODE data is missing - "
1264 + (Shell == IntPtr.Zero ? "Shell " : "")
1265 + (Body == IntPtr.Zero ? "Body " : "")
1266 + (Amotor == IntPtr.Zero ? "Amotor " : ""));
1267 }
1268 }
1269
1270 if (m_hasTaintPosition)
1271 {
1272 if (Body != IntPtr.Zero)
1273 d.BodySetPosition(Body, m_taintPosition.X, m_taintPosition.Y, m_taintPosition.Z);
1274
1275 _position.X = m_taintPosition.X;
1276 _position.Y = m_taintPosition.Y;
1277 _position.Z = m_taintPosition.Z;
1278 m_hasTaintPosition = false;
1279 }
1280
1281 if (m_hasTaintForce)
1282 {
1283 if (Body != IntPtr.Zero)
1284 {
1285 if(m_taintForce.X !=0f || m_taintForce.Y !=0f || m_taintForce.Z !=0)
1286 d.BodyAddForce(Body, m_taintForce.X, m_taintForce.Y, m_taintForce.Z);
1287 m_hasTaintForce = false;
1288 }
1289 }
1290
1291 }
1292
1293 internal void AddCollisionFrameTime(int p)
1294 {
1295 // protect it from overflow crashing
1296 if (m_eventsubscription + p >= int.MaxValue)
1297 m_eventsubscription = 0;
1298 m_eventsubscription += p;
1299 }
1300 }
1301}
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.c_comments b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.c_comments
new file mode 100644
index 0000000..1060aa6
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.c_comments
@@ -0,0 +1,630 @@
1/*
2 * Revised August 26 2009 by Kitto Flora. ODEDynamics.cs replaces
3 * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
4 * ODEPrim.cs contains methods dealing with Prim editing, Prim
5 * characteristics and Kinetic motion.
6 * ODEDynamics.cs contains methods dealing with Prim Physical motion
7 * (dynamics) and the associated settings. Old Linear and angular
8 * motors for dynamic motion have been replace with MoveLinear()
9 * and MoveAngular(); 'Physical' is used only to switch ODE dynamic
10 * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
11 * switch between 'VEHICLE' parameter use and general dynamics
12 * settings use.
13 *
14 * Copyright (c) Contributors, http://opensimulator.org/
15 * See CONTRIBUTORS.TXT for a full list of copyright holders.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are met:
19 * * Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * * Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * * Neither the name of the OpenSimulator Project nor the
25 * names of its contributors may be used to endorse or promote products
26 * derived from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
29 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */
39
40using System;
41using System.Collections.Generic;
42using System.Reflection;
43using System.Runtime.InteropServices;
44using log4net;
45using OpenMetaverse;
46using Ode.NET;
47using OpenSim.Framework;
48using OpenSim.Region.Physics.Manager;
49
50namespace OpenSim.Region.Physics.OdePlugin
51{
52 public class ODEDynamics
53 {
54 public Vehicle Type
55 {
56 get { return m_type; }
57 }
58
59 public IntPtr Body
60 {
61 get { return m_body; }
62 }
63
64 private int frcount = 0; // Used to limit dynamics debug output to
65 // every 100th frame
66
67 // private OdeScene m_parentScene = null;
68 private IntPtr m_body = IntPtr.Zero;
69 private IntPtr m_jointGroup = IntPtr.Zero;
70 private IntPtr m_aMotor = IntPtr.Zero;
71
72
73 // Vehicle properties
74 private Vehicle m_type = Vehicle.TYPE_NONE; // If a 'VEHICLE', and what kind
75 // private Quaternion m_referenceFrame = Quaternion.Identity; // Axis modifier
76 private VehicleFlag m_flags = (VehicleFlag) 0; // Boolean settings:
77 // HOVER_TERRAIN_ONLY
78 // HOVER_GLOBAL_HEIGHT
79 // NO_DEFLECTION_UP
80 // HOVER_WATER_ONLY
81 // HOVER_UP_ONLY
82 // LIMIT_MOTOR_UP
83 // LIMIT_ROLL_ONLY
84
85 // Linear properties
86 private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time
87 private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL
88 private Vector3 m_dir = Vector3.Zero; // velocity applied to body
89 private Vector3 m_linearFrictionTimescale = Vector3.Zero;
90 private float m_linearMotorDecayTimescale = 0;
91 private float m_linearMotorTimescale = 0;
92 private Vector3 m_lastLinearVelocityVector = Vector3.Zero;
93 // private bool m_LinearMotorSetLastFrame = false;
94 // private Vector3 m_linearMotorOffset = Vector3.Zero;
95
96 //Angular properties
97 private Vector3 m_angularMotorDirection = Vector3.Zero;
98 private Vector3 m_angularMotorDirectionLASTSET = Vector3.Zero;
99 private Vector3 m_angularFrictionTimescale = Vector3.Zero;
100 private float m_angularMotorDecayTimescale = 0;
101 private float m_angularMotorTimescale = 0;
102 private Vector3 m_lastAngularVelocityVector = Vector3.Zero;
103
104 //Deflection properties
105 // private float m_angularDeflectionEfficiency = 0;
106 // private float m_angularDeflectionTimescale = 0;
107 // private float m_linearDeflectionEfficiency = 0;
108 // private float m_linearDeflectionTimescale = 0;
109
110 //Banking properties
111 // private float m_bankingEfficiency = 0;
112 // private float m_bankingMix = 0;
113 // private float m_bankingTimescale = 0;
114
115 //Hover and Buoyancy properties
116 private float m_VhoverHeight = 0f;
117 private float m_VhoverEfficiency = 0f;
118 private float m_VhoverTimescale = 0f;
119 private float m_VhoverTargetHeight = -1.0f; // if <0 then no hover, else its the current target height
120 private float m_VehicleBuoyancy = 0f; //KF: m_VehicleBuoyancy is set by VEHICLE_BUOYANCY for a vehicle.
121 // Modifies gravity. Slider between -1 (double-gravity) and 1 (full anti-gravity)
122 // KF: So far I have found no good method to combine a script-requested .Z velocity and gravity.
123 // Therefore only m_VehicleBuoyancy=1 (0g) will use the script-requested .Z velocity.
124
125 //Attractor properties
126 private float m_verticalAttractionEfficiency = 0;
127 private float m_verticalAttractionTimescale = 0;
128
129
130
131
132
133 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
134 {
135 switch (pParam)
136 {
137 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY:
138 if (pValue < 0.01f) pValue = 0.01f;
139 // m_angularDeflectionEfficiency = pValue;
140 break;
141 case Vehicle.ANGULAR_DEFLECTION_TIMESCALE:
142 if (pValue < 0.01f) pValue = 0.01f;
143 // m_angularDeflectionTimescale = pValue;
144 break;
145 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
146 if (pValue < 0.01f) pValue = 0.01f;
147 m_angularMotorDecayTimescale = pValue;
148 break;
149 case Vehicle.ANGULAR_MOTOR_TIMESCALE:
150 if (pValue < 0.01f) pValue = 0.01f;
151 m_angularMotorTimescale = pValue;
152 break;
153 case Vehicle.BANKING_EFFICIENCY:
154 if (pValue < 0.01f) pValue = 0.01f;
155 // m_bankingEfficiency = pValue;
156 break;
157 case Vehicle.BANKING_MIX:
158 if (pValue < 0.01f) pValue = 0.01f;
159 // m_bankingMix = pValue;
160 break;
161 case Vehicle.BANKING_TIMESCALE:
162 if (pValue < 0.01f) pValue = 0.01f;
163 // m_bankingTimescale = pValue;
164 break;
165 case Vehicle.BUOYANCY:
166 if (pValue < -1f) pValue = -1f;
167 if (pValue > 1f) pValue = 1f;
168 m_VehicleBuoyancy = pValue;
169 break;
170 case Vehicle.HOVER_EFFICIENCY:
171 if (pValue < 0f) pValue = 0f;
172 if (pValue > 1f) pValue = 1f;
173 m_VhoverEfficiency = pValue;
174 break;
175 case Vehicle.HOVER_HEIGHT:
176 m_VhoverHeight = pValue;
177 break;
178 case Vehicle.HOVER_TIMESCALE:
179 if (pValue < 0.01f) pValue = 0.01f;
180 m_VhoverTimescale = pValue;
181 break;
182 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY:
183 if (pValue < 0.01f) pValue = 0.01f;
184 // m_linearDeflectionEfficiency = pValue;
185 break;
186 case Vehicle.LINEAR_DEFLECTION_TIMESCALE:
187 if (pValue < 0.01f) pValue = 0.01f;
188 // m_linearDeflectionTimescale = pValue;
189 break;
190 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
191 if (pValue < 0.01f) pValue = 0.01f;
192 m_linearMotorDecayTimescale = pValue;
193 break;
194 case Vehicle.LINEAR_MOTOR_TIMESCALE:
195 if (pValue < 0.01f) pValue = 0.01f;
196 m_linearMotorTimescale = pValue;
197 break;
198 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
199 if (pValue < 0.0f) pValue = 0.0f;
200 if (pValue > 1.0f) pValue = 1.0f;
201 m_verticalAttractionEfficiency = pValue;
202 break;
203 case Vehicle.VERTICAL_ATTRACTION_TIMESCALE:
204 if (pValue < 0.01f) pValue = 0.01f;
205 m_verticalAttractionTimescale = pValue;
206 break;
207
208 // These are vector properties but the engine lets you use a single float value to
209 // set all of the components to the same value
210 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
211 m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue);
212 break;
213 case Vehicle.ANGULAR_MOTOR_DIRECTION:
214 m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
215 m_angularMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue);
216 break;
217 case Vehicle.LINEAR_FRICTION_TIMESCALE:
218 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
219 break;
220 case Vehicle.LINEAR_MOTOR_DIRECTION:
221 m_linearMotorDirection = new Vector3(pValue, pValue, pValue);
222 m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue);
223 break;
224 case Vehicle.LINEAR_MOTOR_OFFSET:
225 // m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
226 break;
227
228 }
229
230 }//end ProcessFloatVehicleParam
231
232 internal void ProcessVectorVehicleParam(Vehicle pParam, PhysicsVector pValue)
233 {
234 switch (pParam)
235 {
236 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
237 m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
238 break;
239 case Vehicle.ANGULAR_MOTOR_DIRECTION:
240 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
241 m_angularMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z);
242 break;
243 case Vehicle.LINEAR_FRICTION_TIMESCALE:
244 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
245 break;
246 case Vehicle.LINEAR_MOTOR_DIRECTION:
247 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
248 m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z);
249 break;
250 case Vehicle.LINEAR_MOTOR_OFFSET:
251 // m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
252 break;
253 }
254
255 }//end ProcessVectorVehicleParam
256
257 internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue)
258 {
259 switch (pParam)
260 {
261 case Vehicle.REFERENCE_FRAME:
262 // m_referenceFrame = pValue;
263 break;
264 }
265
266 }//end ProcessRotationVehicleParam
267
268 internal void ProcessTypeChange(Vehicle pType)
269 {
270Console.WriteLine("ProcessTypeChange to " + pType);
271
272 // Set Defaults For Type
273 m_type = pType;
274 switch (pType)
275 {
276 case Vehicle.TYPE_SLED:
277 m_linearFrictionTimescale = new Vector3(30, 1, 1000);
278 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
279 m_linearMotorDirection = Vector3.Zero;
280 m_linearMotorTimescale = 1000;
281 m_linearMotorDecayTimescale = 120;
282 m_angularMotorDirection = Vector3.Zero;
283 m_angularMotorTimescale = 1000;
284 m_angularMotorDecayTimescale = 120;
285 m_VhoverHeight = 0;
286 m_VhoverEfficiency = 1;
287 m_VhoverTimescale = 10;
288 m_VehicleBuoyancy = 0;
289 // m_linearDeflectionEfficiency = 1;
290 // m_linearDeflectionTimescale = 1;
291 // m_angularDeflectionEfficiency = 1;
292 // m_angularDeflectionTimescale = 1000;
293 // m_bankingEfficiency = 0;
294 // m_bankingMix = 1;
295 // m_bankingTimescale = 10;
296 // m_referenceFrame = Quaternion.Identity;
297 m_flags &=
298 ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
299 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
300 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
301 break;
302 case Vehicle.TYPE_CAR:
303 m_linearFrictionTimescale = new Vector3(100, 2, 1000);
304 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
305 m_linearMotorDirection = Vector3.Zero;
306 m_linearMotorTimescale = 1;
307 m_linearMotorDecayTimescale = 60;
308 m_angularMotorDirection = Vector3.Zero;
309 m_angularMotorTimescale = 1;
310 m_angularMotorDecayTimescale = 0.8f;
311 m_VhoverHeight = 0;
312 m_VhoverEfficiency = 0;
313 m_VhoverTimescale = 1000;
314 m_VehicleBuoyancy = 0;
315 // // m_linearDeflectionEfficiency = 1;
316 // // m_linearDeflectionTimescale = 2;
317 // // m_angularDeflectionEfficiency = 0;
318 // m_angularDeflectionTimescale = 10;
319 m_verticalAttractionEfficiency = 1;
320 m_verticalAttractionTimescale = 10;
321 // m_bankingEfficiency = -0.2f;
322 // m_bankingMix = 1;
323 // m_bankingTimescale = 1;
324 // m_referenceFrame = Quaternion.Identity;
325 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT);
326 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.HOVER_UP_ONLY |
327 VehicleFlag.LIMIT_MOTOR_UP);
328 break;
329 case Vehicle.TYPE_BOAT:
330 m_linearFrictionTimescale = new Vector3(10, 3, 2);
331 m_angularFrictionTimescale = new Vector3(10,10,10);
332 m_linearMotorDirection = Vector3.Zero;
333 m_linearMotorTimescale = 5;
334 m_linearMotorDecayTimescale = 60;
335 m_angularMotorDirection = Vector3.Zero;
336 m_angularMotorTimescale = 4;
337 m_angularMotorDecayTimescale = 4;
338 m_VhoverHeight = 0;
339 m_VhoverEfficiency = 0.5f;
340 m_VhoverTimescale = 2;
341 m_VehicleBuoyancy = 1;
342 // m_linearDeflectionEfficiency = 0.5f;
343 // m_linearDeflectionTimescale = 3;
344 // m_angularDeflectionEfficiency = 0.5f;
345 // m_angularDeflectionTimescale = 5;
346 m_verticalAttractionEfficiency = 0.5f;
347 m_verticalAttractionTimescale = 5;
348 // m_bankingEfficiency = -0.3f;
349 // m_bankingMix = 0.8f;
350 // m_bankingTimescale = 1;
351 // m_referenceFrame = Quaternion.Identity;
352 m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.LIMIT_ROLL_ONLY |
353 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
354 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.HOVER_WATER_ONLY |
355 VehicleFlag.LIMIT_MOTOR_UP);
356 break;
357 case Vehicle.TYPE_AIRPLANE:
358 m_linearFrictionTimescale = new Vector3(200, 10, 5);
359 m_angularFrictionTimescale = new Vector3(20, 20, 20);
360 m_linearMotorDirection = Vector3.Zero;
361 m_linearMotorTimescale = 2;
362 m_linearMotorDecayTimescale = 60;
363 m_angularMotorDirection = Vector3.Zero;
364 m_angularMotorTimescale = 4;
365 m_angularMotorDecayTimescale = 4;
366 m_VhoverHeight = 0;
367 m_VhoverEfficiency = 0.5f;
368 m_VhoverTimescale = 1000;
369 m_VehicleBuoyancy = 0;
370 // m_linearDeflectionEfficiency = 0.5f;
371 // m_linearDeflectionTimescale = 3;
372 // m_angularDeflectionEfficiency = 1;
373 // m_angularDeflectionTimescale = 2;
374 m_verticalAttractionEfficiency = 0.9f;
375 m_verticalAttractionTimescale = 2;
376 // m_bankingEfficiency = 1;
377 // m_bankingMix = 0.7f;
378 // m_bankingTimescale = 2;
379 // m_referenceFrame = Quaternion.Identity;
380 m_flags &= ~(VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
381 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
382 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY);
383 break;
384 case Vehicle.TYPE_BALLOON:
385 m_linearFrictionTimescale = new Vector3(5, 5, 5);
386 m_angularFrictionTimescale = new Vector3(10, 10, 10);
387 m_linearMotorDirection = Vector3.Zero;
388 m_linearMotorTimescale = 5;
389 m_linearMotorDecayTimescale = 60;
390 m_angularMotorDirection = Vector3.Zero;
391 m_angularMotorTimescale = 6;
392 m_angularMotorDecayTimescale = 10;
393 m_VhoverHeight = 5;
394 m_VhoverEfficiency = 0.8f;
395 m_VhoverTimescale = 10;
396 m_VehicleBuoyancy = 1;
397 // m_linearDeflectionEfficiency = 0;
398 // m_linearDeflectionTimescale = 5;
399 // m_angularDeflectionEfficiency = 0;
400 // m_angularDeflectionTimescale = 5;
401 m_verticalAttractionEfficiency = 1;
402 m_verticalAttractionTimescale = 1000;
403 // m_bankingEfficiency = 0;
404 // m_bankingMix = 0.7f;
405 // m_bankingTimescale = 5;
406 // m_referenceFrame = Quaternion.Identity;
407 m_flags &= ~(VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
408 VehicleFlag.HOVER_UP_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
409 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT);
410 break;
411
412 }
413 }//end SetDefaultsForType
414
415 internal void Enable(IntPtr pBody, OdeScene pParentScene)
416 {
417//Console.WriteLine("Enable m_type=" + m_type + " m_VehicleBuoyancy=" + m_VehicleBuoyancy);
418 if (m_type == Vehicle.TYPE_NONE)
419 return;
420
421 m_body = pBody;
422 //KF: This used to set up the linear and angular joints
423 }
424
425 internal void Step(float pTimestep, OdeScene pParentScene)
426 {
427 if (m_body == IntPtr.Zero || m_type == Vehicle.TYPE_NONE)
428 return;
429 frcount++; // used to limit debug comment output
430 if (frcount > 100)
431 frcount = 0;
432
433 MoveLinear(pTimestep, pParentScene);
434 MoveAngular(pTimestep);
435 }// end Step
436
437 private void MoveLinear(float pTimestep, OdeScene _pParentScene)
438 {
439 if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) // requested m_linearMotorDirection is significant
440 {
441 if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body);
442
443 // add drive to body
444 Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep);
445 m_lastLinearVelocityVector += (addAmount*10); // lastLinearVelocityVector is the current body velocity vector?
446
447 // This will work temporarily, but we really need to compare speed on an axis
448 // KF: Limit body velocity to applied velocity?
449 if (Math.Abs(m_lastLinearVelocityVector.X) > Math.Abs(m_linearMotorDirectionLASTSET.X))
450 m_lastLinearVelocityVector.X = m_linearMotorDirectionLASTSET.X;
451 if (Math.Abs(m_lastLinearVelocityVector.Y) > Math.Abs(m_linearMotorDirectionLASTSET.Y))
452 m_lastLinearVelocityVector.Y = m_linearMotorDirectionLASTSET.Y;
453 if (Math.Abs(m_lastLinearVelocityVector.Z) > Math.Abs(m_linearMotorDirectionLASTSET.Z))
454 m_lastLinearVelocityVector.Z = m_linearMotorDirectionLASTSET.Z;
455
456 // decay applied velocity
457 Vector3 decayfraction = ((Vector3.One/(m_linearMotorDecayTimescale/pTimestep)));
458 //Console.WriteLine("decay: " + decayfraction);
459 m_linearMotorDirection -= m_linearMotorDirection * decayfraction;
460 //Console.WriteLine("actual: " + m_linearMotorDirection);
461 }
462 else
463 { // requested is not significant
464 // if what remains of applied is small, zero it.
465 if (m_lastLinearVelocityVector.ApproxEquals(Vector3.Zero, 0.01f))
466 m_lastLinearVelocityVector = Vector3.Zero;
467 }
468
469
470 // convert requested object velocity to world-referenced vector
471 m_dir = m_lastLinearVelocityVector;
472 d.Quaternion rot = d.BodyGetQuaternion(Body);
473 Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object
474 m_dir *= rotq; // apply obj rotation to velocity vector
475
476 // add Gravity andBuoyancy
477 // KF: So far I have found no good method to combine a script-requested
478 // .Z velocity and gravity. Therefore only 0g will used script-requested
479 // .Z velocity. >0g (m_VehicleBuoyancy < 1) will used modified gravity only.
480 Vector3 grav = Vector3.Zero;
481 if(m_VehicleBuoyancy < 1.0f)
482 {
483 // There is some gravity, make a gravity force vector
484 // that is applied after object velocity.
485 d.Mass objMass;
486 d.BodyGetMass(Body, out objMass);
487 // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g;
488 grav.Z = _pParentScene.gravityz * objMass.mass * (1f - m_VehicleBuoyancy);
489 // Preserve the current Z velocity
490 d.Vector3 vel_now = d.BodyGetLinearVel(Body);
491 m_dir.Z = vel_now.Z; // Preserve the accumulated falling velocity
492 } // else its 1.0, no gravity.
493
494 // Check if hovering
495 if( (m_flags & (VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT)) != 0)
496 {
497 // We should hover, get the target height
498 d.Vector3 pos = d.BodyGetPosition(Body);
499 if((m_flags & VehicleFlag.HOVER_WATER_ONLY) == VehicleFlag.HOVER_WATER_ONLY)
500 {
501 m_VhoverTargetHeight = _pParentScene.GetWaterLevel() + m_VhoverHeight;
502 }
503 else if((m_flags & VehicleFlag.HOVER_TERRAIN_ONLY) == VehicleFlag.HOVER_TERRAIN_ONLY)
504 {
505 m_VhoverTargetHeight = _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y) + m_VhoverHeight;
506 }
507 else if((m_flags & VehicleFlag.HOVER_GLOBAL_HEIGHT) == VehicleFlag.HOVER_GLOBAL_HEIGHT)
508 {
509 m_VhoverTargetHeight = m_VhoverHeight;
510 }
511
512 if((m_flags & VehicleFlag.HOVER_UP_ONLY) == VehicleFlag.HOVER_UP_ONLY)
513 {
514 // If body is aready heigher, use its height as target height
515 if(pos.Z > m_VhoverTargetHeight) m_VhoverTargetHeight = pos.Z;
516 }
517
518// m_VhoverEfficiency = 0f; // 0=boucy, 1=Crit.damped
519// m_VhoverTimescale = 0f; // time to acheive height
520// pTimestep is time since last frame,in secs
521 float herr0 = pos.Z - m_VhoverTargetHeight;
522//if(frcount == 0) Console.WriteLine("herr0=" + herr0);
523 // Replace Vertical speed with correction figure if significant
524 if(Math.Abs(herr0) > 0.01f )
525 {
526 d.Mass objMass;
527 d.BodyGetMass(Body, out objMass);
528 m_dir.Z = - ( (herr0 * pTimestep * 50.0f) / m_VhoverTimescale);
529 // m_VhoverEfficiency is not yet implemented
530 }
531 else
532 {
533 m_dir.Z = 0f;
534 }
535 }
536
537 // Apply velocity
538 d.BodySetLinearVel(Body, m_dir.X, m_dir.Y, m_dir.Z);
539//if(frcount == 0) Console.WriteLine("Move " + Body + ":"+ m_dir.X + " " + m_dir.Y + " " + m_dir.Z);
540 // apply gravity force
541 d.BodyAddForce(Body, grav.X, grav.Y, grav.Z);
542//if(frcount == 0) Console.WriteLine("Force " + Body + ":" + grav.X + " " + grav.Y + " " + grav.Z);
543
544
545 // apply friction
546 Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep);
547 m_lastLinearVelocityVector -= m_lastLinearVelocityVector * decayamount;
548 } // end MoveLinear()
549
550 private void MoveAngular(float pTimestep)
551 {
552
553 // m_angularMotorDirection is the latest value from the script, and is decayed here
554 // m_angularMotorDirectionLASTSET is the latest value from the script
555 // m_lastAngularVelocityVector is what is being applied to the Body, varied up and down here
556
557 if (!m_angularMotorDirection.ApproxEquals(Vector3.Zero, 0.01f))
558 {
559 if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body);
560 // ramp up to new value
561 Vector3 addAmount = m_angularMotorDirection / (m_angularMotorTimescale / pTimestep);
562 m_lastAngularVelocityVector += (addAmount * 10f);
563//if(frcount == 0) Console.WriteLine("add: " + addAmount);
564
565 // limit applied value to what was set by script
566 // This will work temporarily, but we really need to compare speed on an axis
567 if (Math.Abs(m_lastAngularVelocityVector.X) > Math.Abs(m_angularMotorDirectionLASTSET.X))
568 m_lastAngularVelocityVector.X = m_angularMotorDirectionLASTSET.X;
569 if (Math.Abs(m_lastAngularVelocityVector.Y) > Math.Abs(m_angularMotorDirectionLASTSET.Y))
570 m_lastAngularVelocityVector.Y = m_angularMotorDirectionLASTSET.Y;
571 if (Math.Abs(m_lastAngularVelocityVector.Z) > Math.Abs(m_angularMotorDirectionLASTSET.Z))
572 m_lastAngularVelocityVector.Z = m_angularMotorDirectionLASTSET.Z;
573
574 // decay the requested value
575 Vector3 decayfraction = ((Vector3.One / (m_angularMotorDecayTimescale / pTimestep)));
576 //Console.WriteLine("decay: " + decayfraction);
577 m_angularMotorDirection -= m_angularMotorDirection * decayfraction;
578 //Console.WriteLine("actual: " + m_linearMotorDirection);
579 }
580 // KF: m_lastAngularVelocityVector is rotational speed in rad/sec ?
581
582 // Vertical attractor section
583
584// d.Mass objMass;
585// d.BodyGetMass(Body, out objMass);
586// float servo = 100f * objMass.mass * m_verticalAttractionEfficiency / (m_verticalAttractionTimescale * pTimestep);
587 float servo = 0.1f * m_verticalAttractionEfficiency / (m_verticalAttractionTimescale * pTimestep);
588 // get present body rotation
589 d.Quaternion rot = d.BodyGetQuaternion(Body);
590 Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W);
591 // make a vector pointing up
592 Vector3 verterr = Vector3.Zero;
593 verterr.Z = 1.0f;
594 // rotate it to Body Angle
595 verterr = verterr * rotq;
596 // verterr.X and .Y are the World error ammounts. They are 0 when there is no error (Vehicle Body is 'vertical'), and .Z will be 1.
597 // As the body leans to its side |.X| will increase to 1 and .Z fall to 0. As body inverts |.X| will fall and .Z will go
598 // negative. Similar for tilt and |.Y|. .X and .Y must be modulated to prevent a stable inverted body.
599 if (verterr.Z < 0.0f)
600 {
601 verterr.X = 2.0f - verterr.X;
602 verterr.Y = 2.0f - verterr.Y;
603 }
604 // Error is 0 (no error) to +/- 2 (max error)
605 // scale it by servo
606 verterr = verterr * servo;
607
608 // rotate to object frame
609 // verterr = verterr * rotq;
610
611 // As the body rotates around the X axis, then verterr.Y increases; Rotated around Y then .X increases, so
612 // Change Body angular velocity X based on Y, and Y based on X. Z is not changed.
613 m_lastAngularVelocityVector.X += verterr.Y;
614 m_lastAngularVelocityVector.Y -= verterr.X;
615/*
616if(frcount == 0)
617 {
618// Console.WriteLine("AngleMotor " + m_lastAngularVelocityVector);
619 Console.WriteLine(String.Format("VA Body:{0} servo:{1} err:<{2},{3},{4}> VAE:{5}",
620 Body, servo, verterr.X, verterr.Y, verterr.Z, m_verticalAttractionEfficiency));
621 }
622 */
623 d.BodySetAngularVel (Body, m_lastAngularVelocityVector.X, m_lastAngularVelocityVector.Y, m_lastAngularVelocityVector.Z);
624 // apply friction
625 Vector3 decayamount = Vector3.One / (m_angularFrictionTimescale / pTimestep);
626 m_lastAngularVelocityVector -= m_lastAngularVelocityVector * decayamount;
627
628 } //end MoveAngular
629 }
630}
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs
new file mode 100644
index 0000000..363cbef
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs
@@ -0,0 +1,1035 @@
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
28/* Revised Aug, Sept 2009 by Kitto Flora. ODEDynamics.cs replaces
29 * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
30 * ODEPrim.cs contains methods dealing with Prim editing, Prim
31 * characteristics and Kinetic motion.
32 * ODEDynamics.cs contains methods dealing with Prim Physical motion
33 * (dynamics) and the associated settings. Old Linear and angular
34 * motors for dynamic motion have been replace with MoveLinear()
35 * and MoveAngular(); 'Physical' is used only to switch ODE dynamic
36 * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
37 * switch between 'VEHICLE' parameter use and general dynamics
38 * settings use.
39 */
40
41using System;
42using System.Collections.Generic;
43using System.Reflection;
44using System.Runtime.InteropServices;
45using log4net;
46using OpenMetaverse;
47using OdeAPI;
48using OpenSim.Framework;
49using OpenSim.Region.Physics.Manager;
50
51namespace OpenSim.Region.Physics.OdePlugin
52{
53 public class ODEDynamics
54 {
55 public Vehicle Type
56 {
57 get { return m_type; }
58 }
59
60// private OdeScene m_parentScene = null;
61// private IntPtr m_aMotor = IntPtr.Zero;
62
63
64 private OdePrim rootPrim;
65 private OdeScene _pParentScene;
66
67
68
69
70 private Vector3 refUpAxis = new Vector3(0, 0, 1);
71 private Vector3 refAtAxis = new Vector3(1, 0, 0);
72
73
74 // Vehicle properties
75 private Vehicle m_type = Vehicle.TYPE_NONE; // If a 'VEHICLE', and what kind
76
77 private Quaternion m_referenceFrame = Quaternion.Identity; // Axis modifier
78 private VehicleFlag m_flags = (VehicleFlag) 0; // Boolean settings:
79 // HOVER_TERRAIN_ONLY
80 // HOVER_GLOBAL_HEIGHT
81 // NO_DEFLECTION_UP
82 // HOVER_WATER_ONLY
83 // HOVER_UP_ONLY
84 // LIMIT_MOTOR_UP
85 // LIMIT_ROLL_ONLY
86 private Vector3 m_BlockingEndPoint = Vector3.Zero; // not sl
87 private Quaternion m_RollreferenceFrame = Quaternion.Identity;
88
89 // Linear properties
90 private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time
91 private Vector3 m_linearFrictionTimescale = new Vector3(1000, 1000, 1000);
92 private float m_linearMotorDecayTimescale = 120;
93 private float m_linearMotorTimescale = 1000;
94 private Vector3 m_lastLinearVelocityVector = Vector3.Zero;
95 private Vector3 m_linearMotorOffset = Vector3.Zero;
96
97 //Angular properties
98 private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor
99 private float m_angularMotorTimescale = 1000; // motor angular velocity ramp up rate
100 private float m_angularMotorDecayTimescale = 120; // motor angular velocity decay rate
101 private Vector3 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000); // body angular velocity decay rate
102 private Vector3 m_lastAngularVelocity = Vector3.Zero; // what was last applied to body
103
104 //Deflection properties
105 private float m_angularDeflectionEfficiency = 0;
106 private float m_angularDeflectionTimescale = 1000;
107 private float m_linearDeflectionEfficiency = 0;
108 private float m_linearDeflectionTimescale = 1000;
109
110 //Banking properties
111 private float m_bankingEfficiency = 0;
112 private float m_bankingMix = 0;
113 private float m_bankingTimescale = 0;
114
115 //Hover and Buoyancy properties
116 private float m_VhoverHeight = 0f;
117 private float m_VhoverEfficiency = 0f;
118 private float m_VhoverTimescale = 1000f;
119 private float m_VhoverTargetHeight = -1.0f; // if <0 then no hover, else its the current target height
120 private float m_VehicleBuoyancy = 0f; //KF: m_VehicleBuoyancy is set by VEHICLE_BUOYANCY for a vehicle.
121 // Modifies gravity. Slider between -1 (double-gravity) and 1 (full anti-gravity)
122 // KF: So far I have found no good method to combine a script-requested .Z velocity and gravity.
123 // Therefore only m_VehicleBuoyancy=1 (0g) will use the script-requested .Z velocity.
124
125 //Attractor properties
126 private float m_verticalAttractionEfficiency = 1.0f; // damped
127 private float m_verticalAttractionTimescale = 1000f; // Timescale > 300 means no vert attractor.
128
129 // special contact data for vehicles
130 public ContactData VehiculeContactData = new ContactData(0f, 0.1f);
131
132 // auxiliar
133 private Vector3 m_dir = Vector3.Zero; // velocity applied to body
134
135 private float m_lmEfect = 0; // current linear motor eficiency
136 private float m_amEfect = 0; // current angular motor eficiency
137
138
139 public ODEDynamics(OdePrim rootp)
140 {
141 rootPrim = rootp;
142 _pParentScene = rootPrim._parent_scene;
143 }
144
145 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
146 {
147 float len;
148 float invtimestep = 1.0f / _pParentScene.ODE_STEPSIZE;
149 float timestep = _pParentScene.ODE_STEPSIZE;
150
151 switch (pParam)
152 {
153 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY:
154 if (pValue < 0f) pValue = 0f;
155 if (pValue > 1f) pValue = 1f;
156 m_angularDeflectionEfficiency = pValue;
157 break;
158 case Vehicle.ANGULAR_DEFLECTION_TIMESCALE:
159 if (pValue < timestep) pValue = timestep;
160 m_angularDeflectionTimescale = pValue;
161 break;
162 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
163 if (pValue < timestep) pValue = timestep;
164 else if (pValue > 120) pValue = 120;
165 m_angularMotorDecayTimescale = pValue * invtimestep;
166 break;
167 case Vehicle.ANGULAR_MOTOR_TIMESCALE:
168 if (pValue < timestep) pValue = timestep;
169 m_angularMotorTimescale = pValue;
170 break;
171 case Vehicle.BANKING_EFFICIENCY:
172 if (pValue < -1f) pValue = -1f;
173 if (pValue > 1f) pValue = 1f;
174 m_bankingEfficiency = pValue;
175 break;
176 case Vehicle.BANKING_MIX:
177 if (pValue < 0f) pValue = 0f;
178 if (pValue > 1f) pValue = 1f;
179 m_bankingMix = pValue;
180 break;
181 case Vehicle.BANKING_TIMESCALE:
182 if (pValue < timestep) pValue = timestep;
183 m_bankingTimescale = pValue;
184 break;
185 case Vehicle.BUOYANCY:
186 if (pValue < -1f) pValue = -1f;
187 if (pValue > 1f) pValue = 1f;
188 m_VehicleBuoyancy = pValue;
189 break;
190 case Vehicle.HOVER_EFFICIENCY:
191 if (pValue < 0f) pValue = 0f;
192 if (pValue > 1f) pValue = 1f;
193 m_VhoverEfficiency = pValue;
194 break;
195 case Vehicle.HOVER_HEIGHT:
196 m_VhoverHeight = pValue;
197 break;
198 case Vehicle.HOVER_TIMESCALE:
199 if (pValue < timestep) pValue = timestep;
200 m_VhoverTimescale = pValue;
201 break;
202 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY:
203 if (pValue < 0f) pValue = 0f;
204 if (pValue > 1f) pValue = 1f;
205 m_linearDeflectionEfficiency = pValue;
206 break;
207 case Vehicle.LINEAR_DEFLECTION_TIMESCALE:
208 if (pValue < timestep) pValue = timestep;
209 m_linearDeflectionTimescale = pValue;
210 break;
211 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
212 if (pValue < timestep) pValue = timestep;
213 else if (pValue > 120) pValue = 120;
214 m_linearMotorDecayTimescale = pValue * invtimestep;
215 break;
216 case Vehicle.LINEAR_MOTOR_TIMESCALE:
217 if (pValue < timestep) pValue = timestep;
218 m_linearMotorTimescale = pValue;
219 break;
220 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
221 if (pValue < 0f) pValue = 0f;
222 if (pValue > 1f) pValue = 1f;
223 m_verticalAttractionEfficiency = pValue;
224 break;
225 case Vehicle.VERTICAL_ATTRACTION_TIMESCALE:
226 if (pValue < timestep) pValue = timestep;
227 m_verticalAttractionTimescale = pValue;
228 break;
229
230 // These are vector properties but the engine lets you use a single float value to
231 // set all of the components to the same value
232 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
233 if (pValue < timestep) pValue = timestep;
234 m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue);
235 break;
236 case Vehicle.ANGULAR_MOTOR_DIRECTION:
237 m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
238 len = m_angularMotorDirection.Length();
239 if (len > 12.566f)
240 m_angularMotorDirection *= (12.566f / len);
241 m_amEfect = 1.0f; // turn it on
242 break;
243 case Vehicle.LINEAR_FRICTION_TIMESCALE:
244 if (pValue < timestep) pValue = timestep;
245 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
246 break;
247 case Vehicle.LINEAR_MOTOR_DIRECTION:
248 m_linearMotorDirection = new Vector3(pValue, pValue, pValue);
249 len = m_linearMotorDirection.Length();
250 if (len > 30.0f)
251 m_linearMotorDirection *= (30.0f / len);
252 m_lmEfect = 1.0f; // turn it on
253 break;
254 case Vehicle.LINEAR_MOTOR_OFFSET:
255 m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
256 len = m_linearMotorOffset.Length();
257 if (len > 100.0f)
258 m_linearMotorOffset *= (100.0f / len);
259 break;
260 }
261 }//end ProcessFloatVehicleParam
262
263 internal void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue)
264 {
265 float len;
266 float invtimestep = 1.0f / _pParentScene.ODE_STEPSIZE;
267 float timestep = _pParentScene.ODE_STEPSIZE;
268 switch (pParam)
269 {
270
271 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
272 if (pValue.X < timestep) pValue.X = timestep;
273 if (pValue.Y < timestep) pValue.Y = timestep;
274 if (pValue.Z < timestep) pValue.Z = timestep;
275
276 m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
277 break;
278 case Vehicle.ANGULAR_MOTOR_DIRECTION:
279 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
280 // Limit requested angular speed to 2 rps= 4 pi rads/sec
281 len = m_angularMotorDirection.Length();
282 if (len > 12.566f)
283 m_angularMotorDirection *= (12.566f / len);
284 m_amEfect = 1.0f; // turn it on
285 break;
286 case Vehicle.LINEAR_FRICTION_TIMESCALE:
287 if (pValue.X < timestep) pValue.X = timestep;
288 if (pValue.Y < timestep) pValue.Y = timestep;
289 if (pValue.Z < timestep) pValue.Z = timestep;
290 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
291 break;
292 case Vehicle.LINEAR_MOTOR_DIRECTION:
293 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
294 len = m_linearMotorDirection.Length();
295 if (len > 30.0f)
296 m_linearMotorDirection *= (30.0f / len);
297 m_lmEfect = 1.0f; // turn it on
298 break;
299 case Vehicle.LINEAR_MOTOR_OFFSET:
300 m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
301 len = m_linearMotorOffset.Length();
302 if (len > 100.0f)
303 m_linearMotorOffset *= (100.0f / len);
304 break;
305 case Vehicle.BLOCK_EXIT:
306 m_BlockingEndPoint = new Vector3(pValue.X, pValue.Y, pValue.Z);
307 break;
308 }
309 }//end ProcessVectorVehicleParam
310
311 internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue)
312 {
313 switch (pParam)
314 {
315 case Vehicle.REFERENCE_FRAME:
316 m_referenceFrame = Quaternion.Inverse(pValue);
317 break;
318 case Vehicle.ROLL_FRAME:
319 m_RollreferenceFrame = pValue;
320 break;
321 }
322 }//end ProcessRotationVehicleParam
323
324 internal void ProcessVehicleFlags(int pParam, bool remove)
325 {
326 if (remove)
327 {
328 m_flags &= ~((VehicleFlag)pParam);
329 }
330 else
331 {
332 m_flags |= (VehicleFlag)pParam;
333 }
334 }//end ProcessVehicleFlags
335
336 internal void ProcessTypeChange(Vehicle pType)
337 {
338 float invtimestep = _pParentScene.ODE_STEPSIZE;
339 m_lmEfect = 0;
340 m_amEfect = 0;
341
342 m_linearMotorDirection = Vector3.Zero;
343 m_angularMotorDirection = Vector3.Zero;
344
345 m_BlockingEndPoint = Vector3.Zero;
346 m_RollreferenceFrame = Quaternion.Identity;
347 m_linearMotorOffset = Vector3.Zero;
348
349 m_referenceFrame = Quaternion.Identity;
350
351 // Set Defaults For Type
352 m_type = pType;
353 switch (pType)
354 {
355 case Vehicle.TYPE_NONE:
356 m_linearFrictionTimescale = new Vector3(1000, 1000, 1000);
357 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
358 m_linearMotorTimescale = 1000;
359 m_linearMotorDecayTimescale = 120 * invtimestep;
360 m_angularMotorTimescale = 1000;
361 m_angularMotorDecayTimescale = 1000 * invtimestep;
362 m_VhoverHeight = 0;
363 m_VhoverTimescale = 1000;
364 m_VehicleBuoyancy = 0;
365 m_flags = (VehicleFlag)0;
366 break;
367
368 case Vehicle.TYPE_SLED:
369 m_linearFrictionTimescale = new Vector3(30, 1, 1000);
370 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
371 m_linearMotorTimescale = 1000;
372 m_linearMotorDecayTimescale = 120 * invtimestep;
373 m_angularMotorTimescale = 1000;
374 m_angularMotorDecayTimescale = 120 * invtimestep;
375 m_VhoverHeight = 0;
376 m_VhoverEfficiency = 1;
377 m_VhoverTimescale = 10;
378 m_VehicleBuoyancy = 0;
379 m_linearDeflectionEfficiency = 1;
380 m_linearDeflectionTimescale = 1;
381 m_angularDeflectionEfficiency = 0;
382 m_angularDeflectionTimescale = 1000;
383 m_bankingEfficiency = 0;
384 m_bankingMix = 1;
385 m_bankingTimescale = 10;
386 m_flags &=
387 ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
388 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
389 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
390 break;
391 case Vehicle.TYPE_CAR:
392 m_linearFrictionTimescale = new Vector3(100, 2, 1000);
393 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
394 m_linearMotorTimescale = 1;
395 m_linearMotorDecayTimescale = 60 * invtimestep;
396 m_angularMotorTimescale = 1;
397 m_angularMotorDecayTimescale = 0.8f * invtimestep;
398 m_VhoverHeight = 0;
399 m_VhoverEfficiency = 0;
400 m_VhoverTimescale = 1000;
401 m_VehicleBuoyancy = 0;
402 m_linearDeflectionEfficiency = 1;
403 m_linearDeflectionTimescale = 2;
404 m_angularDeflectionEfficiency = 0;
405 m_angularDeflectionTimescale = 10;
406 m_verticalAttractionEfficiency = 1f;
407 m_verticalAttractionTimescale = 10f;
408 m_bankingEfficiency = -0.2f;
409 m_bankingMix = 1;
410 m_bankingTimescale = 1;
411 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT);
412 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY |
413 VehicleFlag.LIMIT_MOTOR_UP | VehicleFlag.HOVER_UP_ONLY);
414 break;
415 case Vehicle.TYPE_BOAT:
416 m_linearFrictionTimescale = new Vector3(10, 3, 2);
417 m_angularFrictionTimescale = new Vector3(10, 10, 10);
418 m_linearMotorTimescale = 5;
419 m_linearMotorDecayTimescale = 60 * invtimestep;
420 m_angularMotorTimescale = 4;
421 m_angularMotorDecayTimescale = 4 * invtimestep;
422 m_VhoverHeight = 0;
423 m_VhoverEfficiency = 0.5f;
424 m_VhoverTimescale = 2;
425 m_VehicleBuoyancy = 1;
426 m_linearDeflectionEfficiency = 0.5f;
427 m_linearDeflectionTimescale = 3;
428 m_angularDeflectionEfficiency = 0.5f;
429 m_angularDeflectionTimescale = 5;
430 m_verticalAttractionEfficiency = 0.5f;
431 m_verticalAttractionTimescale = 5f;
432 m_bankingEfficiency = -0.3f;
433 m_bankingMix = 0.8f;
434 m_bankingTimescale = 1;
435 m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY |
436 VehicleFlag.HOVER_GLOBAL_HEIGHT |
437 VehicleFlag.HOVER_UP_ONLY |
438 VehicleFlag.LIMIT_ROLL_ONLY);
439 m_flags |= (VehicleFlag.NO_DEFLECTION_UP |
440 VehicleFlag.LIMIT_MOTOR_UP |
441 VehicleFlag.HOVER_WATER_ONLY);
442 break;
443 case Vehicle.TYPE_AIRPLANE:
444 m_linearFrictionTimescale = new Vector3(200, 10, 5);
445 m_angularFrictionTimescale = new Vector3(20, 20, 20);
446 m_linearMotorTimescale = 2;
447 m_linearMotorDecayTimescale = 60 * invtimestep;
448 m_angularMotorTimescale = 4;
449 m_angularMotorDecayTimescale = 8 * invtimestep;
450 m_VhoverHeight = 0;
451 m_VhoverEfficiency = 0.5f;
452 m_VhoverTimescale = 1000;
453 m_VehicleBuoyancy = 0;
454 m_linearDeflectionEfficiency = 0.5f;
455 m_linearDeflectionTimescale = 0.5f;
456 m_angularDeflectionEfficiency = 1;
457 m_angularDeflectionTimescale = 2;
458 m_verticalAttractionEfficiency = 0.9f;
459 m_verticalAttractionTimescale = 2f;
460 m_bankingEfficiency = 1;
461 m_bankingMix = 0.7f;
462 m_bankingTimescale = 2;
463 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
464 VehicleFlag.HOVER_TERRAIN_ONLY |
465 VehicleFlag.HOVER_GLOBAL_HEIGHT |
466 VehicleFlag.HOVER_UP_ONLY |
467 VehicleFlag.NO_DEFLECTION_UP |
468 VehicleFlag.LIMIT_MOTOR_UP);
469 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY);
470 break;
471 case Vehicle.TYPE_BALLOON:
472 m_linearFrictionTimescale = new Vector3(5, 5, 5);
473 m_angularFrictionTimescale = new Vector3(10, 10, 10);
474 m_linearMotorTimescale = 5;
475 m_linearMotorDecayTimescale = 60 * invtimestep;
476 m_angularMotorTimescale = 6;
477 m_angularMotorDecayTimescale = 10 * invtimestep;
478 m_VhoverHeight = 5;
479 m_VhoverEfficiency = 0.8f;
480 m_VhoverTimescale = 10;
481 m_VehicleBuoyancy = 1;
482 m_linearDeflectionEfficiency = 0;
483 m_linearDeflectionTimescale = 5 * invtimestep;
484 m_angularDeflectionEfficiency = 0;
485 m_angularDeflectionTimescale = 5;
486 m_verticalAttractionEfficiency = 0f;
487 m_verticalAttractionTimescale = 1000f;
488 m_bankingEfficiency = 0;
489 m_bankingMix = 0.7f;
490 m_bankingTimescale = 5;
491 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
492 VehicleFlag.HOVER_TERRAIN_ONLY |
493 VehicleFlag.HOVER_UP_ONLY |
494 VehicleFlag.NO_DEFLECTION_UP |
495 VehicleFlag.LIMIT_MOTOR_UP);
496 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY |
497 VehicleFlag.HOVER_GLOBAL_HEIGHT);
498 break;
499 }
500
501 }//end SetDefaultsForType
502
503 internal void Stop()
504 {
505 m_lmEfect = 0;
506 m_amEfect = 0;
507 }
508
509 public static Vector3 Xrot(Quaternion rot)
510 {
511 Vector3 vec;
512 rot.Normalize(); // just in case
513 vec.X = 2 * (rot.X * rot.X + rot.W * rot.W) - 1;
514 vec.Y = 2 * (rot.X * rot.Y + rot.Z * rot.W);
515 vec.Z = 2 * (rot.X * rot.Z - rot.Y * rot.W);
516 return vec;
517 }
518
519 public static Vector3 Zrot(Quaternion rot)
520 {
521 Vector3 vec;
522 rot.Normalize(); // just in case
523 vec.X = 2 * (rot.X * rot.Z + rot.Y * rot.W);
524 vec.Y = 2 * (rot.Y * rot.Z - rot.X * rot.W);
525 vec.Z = 2 * (rot.Z * rot.Z + rot.W * rot.W) - 1;
526
527 return vec;
528 }
529
530 private const float halfpi = 0.5f * (float)Math.PI;
531
532 public static Vector3 ubitRot2Euler(Quaternion rot)
533 {
534 // returns roll in X
535 // pitch in Y
536 // yaw in Z
537 Vector3 vec;
538
539 // assuming rot is normalised
540 // rot.Normalize();
541
542 float zX = rot.X * rot.Z + rot.Y * rot.W;
543
544 if (zX < -0.49999f)
545 {
546 vec.X = 0;
547 vec.Y = -halfpi;
548 vec.Z = (float)(-2d * Math.Atan(rot.X / rot.W));
549 }
550 else if (zX > 0.49999f)
551 {
552 vec.X = 0;
553 vec.Y = halfpi;
554 vec.Z = (float)(2d * Math.Atan(rot.X / rot.W));
555 }
556 else
557 {
558 vec.Y = (float)Math.Asin(2 * zX);
559
560 float sqw = rot.W * rot.W;
561
562 float minuszY = rot.X * rot.W - rot.Y * rot.Z;
563 float zZ = rot.Z * rot.Z + sqw - 0.5f;
564
565 vec.X = (float)Math.Atan2(minuszY, zZ);
566
567 float yX = rot.Z * rot.W - rot.X * rot.Y; //( have negative ?)
568 float yY = rot.X * rot.X + sqw - 0.5f;
569 vec.Z = (float)Math.Atan2(yX, yY);
570 }
571 return vec;
572 }
573
574
575 public static void GetRollPitch(Quaternion rot, out float roll, out float pitch)
576 {
577 // assuming rot is normalised
578 // rot.Normalize();
579
580 float zX = rot.X * rot.Z + rot.Y * rot.W;
581
582 if (zX < -0.49999f)
583 {
584 roll = 0;
585 pitch = -halfpi;
586 }
587 else if (zX > 0.49999f)
588 {
589 roll = 0;
590 pitch = halfpi;
591 }
592 else
593 {
594 pitch = (float)Math.Asin(2 * zX);
595
596 float minuszY = rot.X * rot.W - rot.Y * rot.Z;
597 float zZ = rot.Z * rot.Z + rot.W * rot.W - 0.5f;
598
599 roll = (float)Math.Atan2(minuszY, zZ);
600 }
601 return ;
602 }
603
604 internal void Step()//float pTimestep)
605 {
606 IntPtr Body = rootPrim.Body;
607
608 d.Quaternion rot = d.BodyGetQuaternion(Body);
609 Quaternion objrotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object
610 Quaternion rotq = objrotq; // rotq = rotation of object
611 rotq *= m_referenceFrame; // rotq is now rotation in vehicle reference frame
612 Quaternion irotq = Quaternion.Inverse(rotq);
613
614 d.Vector3 dvtmp;
615 Vector3 tmpV;
616 dvtmp = d.BodyGetLinearVel(Body);
617 Vector3 curVel;
618 curVel.X = dvtmp.X;
619 curVel.Y = dvtmp.Y;
620 curVel.Z = dvtmp.Z;
621 Vector3 curLocalVel = curVel * irotq; // current velocity in local
622
623 dvtmp = d.BodyGetAngularVel(Body);
624 Vector3 curAngVel;
625 curAngVel.X = dvtmp.X;
626 curAngVel.Y = dvtmp.Y;
627 curAngVel.Z = dvtmp.Z;
628 Vector3 curLocalAngVel = curAngVel * irotq; // current velocity in local
629
630 Vector3 force = Vector3.Zero; // actually linear aceleration until mult by mass in world frame
631 Vector3 torque = Vector3.Zero;// actually angular aceleration until mult by Inertia in object frame
632 d.Vector3 dtorque = new d.Vector3();// actually angular aceleration until mult by Inertia in object frame
633
634 bool doathing = false;
635
636 // linear motor
637 if (m_lmEfect > 0.01 && m_linearMotorTimescale < 1000)
638 {
639 tmpV = m_linearMotorDirection - curLocalVel; // velocity error
640 if (tmpV.LengthSquared() > 1e-6f)
641 {
642 tmpV = tmpV * (m_lmEfect / m_linearMotorTimescale); // error to correct in this timestep
643 tmpV *= rotq; // to world
644
645 if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0)
646 tmpV.Z = 0;
647
648 if (m_linearMotorOffset.X != 0 && m_linearMotorOffset.Y != 0 && m_linearMotorOffset.Z != 0)
649 {
650 // have offset, do it now
651 tmpV *= rootPrim.Mass;
652 d.BodyAddForceAtRelPos(Body, tmpV.X, tmpV.Y, tmpV.Z, m_linearMotorOffset.X, m_linearMotorOffset.Y, m_linearMotorOffset.Z);
653 }
654 else
655 {
656 force.X += tmpV.X;
657 force.Y += tmpV.Y;
658 force.Z += tmpV.Z;
659 }
660 }
661 m_lmEfect *= (1 - 1.0f / m_linearMotorDecayTimescale);
662 }
663 else
664 m_lmEfect = 0;
665
666 // friction
667 if (curLocalVel.X != 0 || curLocalVel.Y != 0 || curLocalVel.Z != 0)
668 {
669 tmpV.X = -curLocalVel.X / m_linearFrictionTimescale.X;
670 tmpV.Y = -curLocalVel.Y / m_linearFrictionTimescale.Y;
671 tmpV.Z = -curLocalVel.Z / m_linearFrictionTimescale.Z;
672 tmpV *= rotq; // to world
673 force.X += tmpV.X;
674 force.Y += tmpV.Y;
675 force.Z += tmpV.Z;
676 }
677
678 // hover
679 if (m_VhoverTimescale < 300)
680 {
681 d.Vector3 pos = d.BodyGetPosition(Body);
682
683 // default to global
684 float perr = m_VhoverHeight - pos.Z;;
685
686 if ((m_flags & VehicleFlag.HOVER_TERRAIN_ONLY) != 0)
687 {
688 perr += _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y);
689 }
690 else if ((m_flags & VehicleFlag.HOVER_WATER_ONLY) != 0)
691 {
692 perr += _pParentScene.GetWaterLevel();
693 }
694 else if ((m_flags & VehicleFlag.HOVER_GLOBAL_HEIGHT) == 0)
695 {
696 float t = _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y);
697 float w = _pParentScene.GetWaterLevel();
698 if (t > w)
699 perr += t;
700 else
701 perr += w;
702 }
703
704 if ((m_flags & VehicleFlag.HOVER_UP_ONLY) == 0 || perr > 0)
705 {
706 force.Z += (perr / m_VhoverTimescale / m_VhoverTimescale - curVel.Z * m_VhoverEfficiency) / _pParentScene.ODE_STEPSIZE;
707 force.Z += _pParentScene.gravityz * (1f - m_VehicleBuoyancy);
708 }
709 else // no buoyancy
710 force.Z += _pParentScene.gravityz;
711 }
712 else
713 {
714 // default gravity and buoancy
715 force.Z += _pParentScene.gravityz * (1f - m_VehicleBuoyancy);
716 }
717
718 // linear deflection
719 if (m_linearDeflectionEfficiency > 0)
720 {
721 float len = curVel.Length();
722 Vector3 atAxis = refAtAxis;
723 atAxis *= rotq; // at axis rotated to world
724 atAxis = Xrot(rotq);
725 tmpV = atAxis * len;
726 tmpV -= curVel; // velocity error
727 tmpV *= (m_linearDeflectionEfficiency / m_linearDeflectionTimescale); // error to correct in this timestep
728 force.X += tmpV.X;
729 force.Y += tmpV.Y;
730 if((m_flags & VehicleFlag.NO_DEFLECTION_UP) ==0)
731 force.Z += tmpV.Z;
732 }
733
734 // angular motor
735 if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000)
736 {
737 tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error
738 if (tmpV.LengthSquared() > 1e-6f)
739 {
740 tmpV = tmpV * (m_amEfect / m_angularMotorTimescale); // error to correct in this timestep
741 tmpV *= m_referenceFrame; // to object
742 dtorque.X += tmpV.X;
743 dtorque.Y += tmpV.Y;
744 dtorque.Z += tmpV.Z;
745 }
746 m_amEfect *= (1 - 1.0f / m_angularMotorDecayTimescale);
747 }
748 else
749 m_amEfect = 0;
750
751 // angular friction
752 if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0)
753 {
754 tmpV.X = -curLocalAngVel.X / m_angularFrictionTimescale.X;
755 tmpV.Y = -curLocalAngVel.Y / m_angularFrictionTimescale.Y;
756 tmpV.Z = -curLocalAngVel.Z / m_angularFrictionTimescale.Z;
757 tmpV *= m_referenceFrame; // to object
758 dtorque.X += tmpV.X;
759 dtorque.Y += tmpV.Y;
760 dtorque.Z += tmpV.Z;
761 }
762
763 // angular deflection
764 if (m_angularDeflectionEfficiency > 0)
765 {
766 doathing = false;
767 float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale / m_angularDeflectionTimescale /_pParentScene.ODE_STEPSIZE;
768 tmpV.X = 0;
769 if (Math.Abs(curLocalVel.Z) > 0.01)
770 {
771 tmpV.Y = -(float)Math.Atan2(curLocalVel.Z, curLocalVel.X) * ftmp;
772 doathing = true;
773 }
774 else
775 tmpV.Y = 0;
776 if (Math.Abs(curLocalVel.Y) > 0.01)
777 {
778 tmpV.Z = (float)Math.Atan2(curLocalVel.Y, curLocalVel.X) * ftmp;
779 doathing = true;
780 }
781 else
782 tmpV.Z = 0;
783
784 if (doathing)
785 {
786 tmpV *= m_referenceFrame; // to object
787 dtorque.X += tmpV.X;
788 dtorque.Y += tmpV.Y;
789 dtorque.Z += tmpV.Z;
790 }
791 }
792
793 // vertical atractor
794 if (m_verticalAttractionTimescale < 300)
795 {
796 doathing = false;
797 float roll;
798 float pitch;
799
800 GetRollPitch(rotq, out roll, out pitch);
801
802
803 float ftmp = 1.0f / m_verticalAttractionTimescale / m_verticalAttractionTimescale / _pParentScene.ODE_STEPSIZE;
804 float ftmp2 = m_verticalAttractionEfficiency / _pParentScene.ODE_STEPSIZE;
805
806 if (Math.Abs(roll) > 0.01) // roll
807 {
808 tmpV.X = -roll * ftmp;
809 tmpV.X -= curLocalAngVel.X * ftmp2;
810 doathing = true;
811 }
812 else
813 {
814 tmpV.X = 0;
815 }
816
817 if (Math.Abs(pitch) > 0.01 && ((m_flags & VehicleFlag.LIMIT_ROLL_ONLY) == 0)) // pitch
818 {
819 tmpV.Y = -pitch * ftmp;
820 tmpV.Y -= curLocalAngVel.Y * ftmp2;
821 doathing = true;
822 }
823 else
824 {
825 tmpV.Y = 0;
826 }
827
828 tmpV.Z = 0;
829
830 if (m_bankingEfficiency == 0 || Math.Abs(roll) < 0.01)
831 tmpV.Z = 0;
832 else
833 {
834 float broll = -roll * m_bankingEfficiency; ;
835 if (m_bankingMix != 0)
836 {
837 float vfact = m_bankingMix * Math.Abs(curLocalVel.X) / 10.0f;
838 if (vfact < m_bankingMix)
839 broll *= ((1 - m_bankingMix) + vfact);
840 }
841
842 tmpV.Z = (broll - curLocalAngVel.Z) / m_bankingTimescale;
843 doathing = true;
844 }
845
846 if (doathing)
847 {
848
849 tmpV *= m_referenceFrame; // to object
850 dtorque.X += tmpV.X;
851 dtorque.Y += tmpV.Y;
852 dtorque.Z += tmpV.Z;
853 }
854 }
855 /*
856 d.Vector3 pos = d.BodyGetPosition(Body);
857 // Vector3 accel = new Vector3(-(m_dir.X - m_lastLinearVelocityVector.X / 0.1f), -(m_dir.Y - m_lastLinearVelocityVector.Y / 0.1f), m_dir.Z - m_lastLinearVelocityVector.Z / 0.1f);
858 Vector3 posChange = new Vector3();
859 posChange.X = pos.X - m_lastPositionVector.X;
860 posChange.Y = pos.Y - m_lastPositionVector.Y;
861 posChange.Z = pos.Z - m_lastPositionVector.Z;
862 double Zchange = Math.Abs(posChange.Z);
863 if (m_BlockingEndPoint != Vector3.Zero)
864 {
865 if (pos.X >= (m_BlockingEndPoint.X - (float)1))
866 {
867 pos.X -= posChange.X + 1;
868 d.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
869 }
870 if (pos.Y >= (m_BlockingEndPoint.Y - (float)1))
871 {
872 pos.Y -= posChange.Y + 1;
873 d.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
874 }
875 if (pos.Z >= (m_BlockingEndPoint.Z - (float)1))
876 {
877 pos.Z -= posChange.Z + 1;
878 d.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
879 }
880 if (pos.X <= 0)
881 {
882 pos.X += posChange.X + 1;
883 d.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
884 }
885 if (pos.Y <= 0)
886 {
887 pos.Y += posChange.Y + 1;
888 d.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
889 }
890 }
891 if (pos.Z < _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y))
892 {
893 pos.Z = _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y) + 2;
894 d.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
895 }
896
897 }
898 if ((m_flags & (VehicleFlag.NO_X)) != 0)
899 {
900 m_dir.X = 0;
901 }
902 if ((m_flags & (VehicleFlag.NO_Y)) != 0)
903 {
904 m_dir.Y = 0;
905 }
906 if ((m_flags & (VehicleFlag.NO_Z)) != 0)
907 {
908 m_dir.Z = 0;
909 }
910
911
912 */
913 // angular part
914 /*
915
916 // Get what the body is doing, this includes 'external' influences
917/*
918 Vector3 angularVelocity = Vector3.Zero;
919
920 // Vertical attractor section
921 Vector3 vertattr = Vector3.Zero;
922
923 if (m_verticalAttractionTimescale < 300)
924 {
925 float VAservo = 0.2f / m_verticalAttractionTimescale;
926 // get present body rotation
927 // make a vector pointing up
928 Vector3 verterr = Vector3.Zero;
929 verterr.Z = 1.0f;
930 // rotate it to Body Angle
931 verterr = verterr * rotq;
932 // verterr.X and .Y are the World error ammounts. They are 0 when there is no error (Vehicle Body is 'vertical'), and .Z will be 1.
933 // As the body leans to its side |.X| will increase to 1 and .Z fall to 0. As body inverts |.X| will fall and .Z will go
934 // negative. Similar for tilt and |.Y|. .X and .Y must be modulated to prevent a stable inverted body.
935 if (verterr.Z < 0.0f)
936 {
937 verterr.X = 2.0f - verterr.X;
938 verterr.Y = 2.0f - verterr.Y;
939 }
940 // Error is 0 (no error) to +/- 2 (max error)
941 // scale it by VAservo
942 verterr = verterr * VAservo;
943//if (frcount == 0) Console.WriteLine("VAerr=" + verterr);
944
945 // As the body rotates around the X axis, then verterr.Y increases; Rotated around Y then .X increases, so
946 // Change Body angular velocity X based on Y, and Y based on X. Z is not changed.
947 vertattr.X = verterr.Y;
948 vertattr.Y = - verterr.X;
949 vertattr.Z = 0f;
950
951 // scaling appears better usingsquare-law
952 float bounce = 1.0f - (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency);
953 vertattr.X += bounce * angularVelocity.X;
954 vertattr.Y += bounce * angularVelocity.Y;
955
956 } // else vertical attractor is off
957
958 // m_lastVertAttractor = vertattr;
959
960 // Bank section tba
961 // Deflection section tba
962
963 // Sum velocities
964 m_lastAngularVelocity = angularVelocity + vertattr; // + bank + deflection
965
966 if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0)
967 {
968 m_lastAngularVelocity.X = 0;
969 m_lastAngularVelocity.Y = 0;
970 }
971
972 if (!m_lastAngularVelocity.ApproxEquals(Vector3.Zero, 0.01f))
973 {
974 if (!d.BodyIsEnabled (Body)) d.BodyEnable (Body);
975 }
976 else
977 {
978 m_lastAngularVelocity = Vector3.Zero; // Reduce small value to zero.
979 }
980*/
981
982 d.Mass dmass;
983 d.BodyGetMass(Body,out dmass);
984
985 if (force.X != 0 || force.Y != 0 || force.Z != 0)
986 {
987 force *= dmass.mass;
988 d.BodySetForce(Body, force.X, force.Y, force.Z);
989 }
990
991 if (dtorque.X != 0 || dtorque.Y != 0 || dtorque.Z != 0)
992 {
993 d.MultiplyM3V3(out dvtmp, ref dmass.I, ref dtorque);
994 d.BodyAddRelTorque(Body, dvtmp.X, dvtmp.Y, dvtmp.Z); // add torque in object frame
995 }
996
997 //end MoveAngular
998
999 // limit rotations
1000/*
1001 bool changed = false;
1002
1003 if (m_RollreferenceFrame != Quaternion.Identity)
1004 {
1005 if (rotq.X >= m_RollreferenceFrame.X)
1006 {
1007 rot.X = rotq.X - (m_RollreferenceFrame.X / 2);
1008 }
1009 if (rotq.Y >= m_RollreferenceFrame.Y)
1010 {
1011 rot.Y = rotq.Y - (m_RollreferenceFrame.Y / 2);
1012 }
1013 if (rotq.X <= -m_RollreferenceFrame.X)
1014 {
1015 rot.X = rotq.X + (m_RollreferenceFrame.X / 2);
1016 }
1017 if (rotq.Y <= -m_RollreferenceFrame.Y)
1018 {
1019 rot.Y = rotq.Y + (m_RollreferenceFrame.Y / 2);
1020 }
1021 changed = true;
1022 }
1023
1024 if ((m_flags & VehicleFlag.LOCK_ROTATION) != 0)
1025 {
1026 rot.X = 0;
1027 rot.Y = 0;
1028 changed = true;
1029 }
1030 if (changed)
1031 d.BodySetQuaternion(Body, ref rot);
1032*/
1033 }
1034 }
1035}
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
new file mode 100644
index 0000000..1a53c99
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
@@ -0,0 +1,3260 @@
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
28/* Revision 2011 by Ubit Umarov
29 *
30 *
31 */
32
33/*
34 * Revised August 26 2009 by Kitto Flora. ODEDynamics.cs replaces
35 * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
36 * ODEPrim.cs contains methods dealing with Prim editing, Prim
37 * characteristics and Kinetic motion.
38 * ODEDynamics.cs contains methods dealing with Prim Physical motion
39 * (dynamics) and the associated settings. Old Linear and angular
40 * motors for dynamic motion have been replace with MoveLinear()
41 * and MoveAngular(); 'Physical' is used only to switch ODE dynamic
42 * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
43 * switch between 'VEHICLE' parameter use and general dynamics
44 * settings use.
45 */
46
47//#define SPAM
48
49using System;
50using System.Collections.Generic;
51using System.Reflection;
52using System.Runtime.InteropServices;
53using System.Threading;
54using log4net;
55using OpenMetaverse;
56using OdeAPI;
57using OpenSim.Framework;
58using OpenSim.Region.Physics.Manager;
59
60
61namespace OpenSim.Region.Physics.OdePlugin
62{
63 public class OdePrim : PhysicsActor
64 {
65 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
66
67 private bool m_isphysical;
68 private bool m_fakeisphysical;
69
70 protected bool m_building;
71 private Quaternion m_lastorientation = new Quaternion();
72 private Quaternion _orientation;
73
74 private Vector3 _position;
75 private Vector3 _velocity;
76 private Vector3 _torque;
77 private Vector3 m_lastVelocity;
78 private Vector3 m_lastposition;
79 private Vector3 m_rotationalVelocity;
80 private Vector3 _size;
81 private Vector3 _acceleration;
82 private Vector3 m_angularlock = Vector3.One;
83 private IntPtr Amotor = IntPtr.Zero;
84
85 private Vector3 m_force;
86 private Vector3 m_forceacc;
87 private Vector3 m_angularForceacc;
88
89 private Vector3 m_PIDTarget;
90 private float m_PIDTau;
91 private float PID_D = 35f;
92 private float PID_G = 25f;
93 private bool m_usePID;
94
95 // KF: These next 7 params apply to llSetHoverHeight(float height, integer water, float tau),
96 // and are for non-VEHICLES only.
97
98 private float m_PIDHoverHeight;
99 private float m_PIDHoverTau;
100 private bool m_useHoverPID;
101 private PIDHoverType m_PIDHoverType = PIDHoverType.Ground;
102 private float m_targetHoverHeight;
103 private float m_groundHeight;
104 private float m_waterHeight;
105 private float m_buoyancy; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle.
106
107 private int body_autodisable_frames = 20;
108
109 private const CollisionCategories m_default_collisionFlags = (CollisionCategories.Geom
110 | CollisionCategories.Space
111 | CollisionCategories.Body
112 | CollisionCategories.Character
113 );
114 private bool m_collidesLand = true;
115 private bool m_collidesWater;
116 public bool m_returnCollisions;
117
118 // Default we're a Geometry
119 private CollisionCategories m_collisionCategories = (CollisionCategories.Geom);
120
121 // Default, Collide with Other Geometries, spaces and Bodies
122 private CollisionCategories m_collisionFlags = m_default_collisionFlags;
123
124 public bool m_disabled;
125 public bool m_taintselected;
126
127 public uint m_localID;
128
129 private PrimitiveBaseShape _pbs;
130 public OdeScene _parent_scene;
131
132 /// <summary>
133 /// The physics space which contains prim geometry
134 /// </summary>
135 public IntPtr m_targetSpace = IntPtr.Zero;
136
137 public IntPtr prim_geom;
138 public IntPtr _triMeshData;
139
140 private PhysicsActor _parent;
141
142 private List<OdePrim> childrenPrim = new List<OdePrim>();
143
144 private bool m_iscolliding;
145 private bool m_wascolliding;
146 private bool m_isSelected;
147
148 internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively
149
150 private bool m_throttleUpdates;
151 private int throttleCounter;
152 public int m_interpenetrationcount;
153 public float m_collisionscore;
154 int m_colliderfilter = 0;
155 public int m_roundsUnderMotionThreshold;
156 private int m_crossingfailures;
157
158 public bool outofBounds;
159 private float m_density = 10.000006836f; // Aluminum g/cm3;
160
161 public bool _zeroFlag;
162 private bool m_lastUpdateSent;
163
164 public IntPtr Body = IntPtr.Zero;
165 public String Name { get; private set; }
166 private Vector3 _target_velocity;
167
168 public Vector3 primOOBsize; // prim real dimensions from mesh
169 public Vector3 primOOBoffset; // is centroid out of mesh or rest aabb
170 public float primOOBradiusSQ;
171 public d.Mass primdMass; // prim inertia information on it's own referencial
172 float primMass; // prim own mass
173 float _mass; // object mass acording to case
174 public d.Mass objectpMass; // object last computed inertia
175 private bool hasOOBoffsetFromMesh = false; // if true we did compute it form mesh centroid, else from aabb
176
177 public int givefakepos = 0;
178 private Vector3 fakepos;
179 public int givefakeori = 0;
180 private Quaternion fakeori;
181
182 public int m_eventsubscription;
183 private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();
184
185 private IntPtr m_linkJoint = IntPtr.Zero;
186 private IntPtr _linkJointGroup = IntPtr.Zero;
187
188 public volatile bool childPrim;
189
190 public ODEDynamics m_vehicle;
191
192 internal int m_material = (int)Material.Wood;
193 protected ContactData primContactData = new ContactData { mu = 0f, bounce = 0.1f};
194
195 /// <summary>
196 /// Is this prim subject to physics? Even if not, it's still solid for collision purposes.
197 /// </summary>
198 public override bool IsPhysical // this is not reliable for internal use
199 {
200 get { return m_fakeisphysical; }
201 set
202 {
203 m_fakeisphysical = value; // we show imediatly to outside that we changed physical
204 // and also to stop imediatly some updates
205 // but real change will only happen in taintprocessing
206
207 if (!value) // Zero the remembered last velocity
208 m_lastVelocity = Vector3.Zero;
209 AddChange(changes.Physical, value);
210 }
211 }
212
213 public override bool Building // this is not reliable for internal use
214 {
215 get { return m_building; }
216 set
217 {
218 if (value)
219 m_building = true;
220 AddChange(changes.building, value);
221 }
222 }
223
224 public override ContactData ContactData
225 {
226 get
227 {
228/*
229 ODEDynamics v;
230 if(childPrim && _parent !=null)
231 {
232 v =((OdePrim)_parent).m_vehicle;
233 if(v != null && v.Type != Vehicle.TYPE_NONE)
234 return v.VehiculeContactData;
235 return primContactData;
236 }
237
238 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
239 return m_vehicle.VehiculeContactData;
240*/
241 return primContactData;
242 }
243 }
244
245 public override int PhysicsActorType
246 {
247 get { return (int)ActorTypes.Prim; }
248 set { return; }
249 }
250
251 public override bool SetAlwaysRun
252 {
253 get { return false; }
254 set { return; }
255 }
256
257 public override uint LocalID
258 {
259 get
260 {
261 return m_localID;
262 }
263 set
264 {
265 //m_log.Info("[PHYSICS]: Setting TrackerID: " + value);
266 m_localID = value;
267 }
268 }
269
270 public override bool Grabbed
271 {
272 set { return; }
273 }
274
275 public override bool Selected
276 {
277 set
278 {
279 if(value)
280 m_isSelected = value;
281 AddChange(changes.Selected, value);
282 }
283 }
284
285 public override bool Flying
286 {
287 // no flying prims for you
288 get { return false; }
289 set { }
290 }
291
292 public override bool IsColliding
293 {
294 get { return m_iscolliding; }
295 set
296 {
297 if (value)
298 {
299 m_colliderfilter += 2;
300 if (m_colliderfilter > 2)
301 m_colliderfilter = 2;
302 }
303 else
304 {
305 m_colliderfilter--;
306 if (m_colliderfilter < 0)
307 m_colliderfilter = 0;
308 }
309
310 if (m_colliderfilter == 0)
311 m_iscolliding = false;
312 else
313 m_iscolliding = true;
314
315 if (m_wascolliding != m_iscolliding)
316 {
317 if (m_wascolliding && !m_isSelected && Body != IntPtr.Zero)
318 d.BodyEnable(Body);
319 m_wascolliding = m_iscolliding;
320 }
321 }
322 }
323
324 public override bool CollidingGround
325 {
326 get { return false; }
327 set { return; }
328 }
329
330 public override bool CollidingObj
331 {
332 get { return false; }
333 set { return; }
334 }
335
336 public override bool ThrottleUpdates
337 {
338 get { return m_throttleUpdates; }
339 set { m_throttleUpdates = value; }
340 }
341
342 public override bool Stopped
343 {
344 get { return _zeroFlag; }
345 }
346
347 public override Vector3 Position
348 {
349 get
350 {
351 if (givefakepos > 0)
352 return fakepos;
353 else
354 return _position;
355 }
356
357 set
358 {
359 fakepos = value;
360 givefakepos++;
361 AddChange(changes.Position, value);
362 }
363 }
364
365 public override Vector3 Size
366 {
367 get { return _size; }
368 set
369 {
370 if (value.IsFinite())
371 {
372 AddChange(changes.Size, value);
373 }
374 else
375 {
376 m_log.WarnFormat("[PHYSICS]: Got NaN Size on object {0}", Name);
377 }
378 }
379 }
380
381 public override float Mass
382 {
383 get { return _mass; }
384 }
385
386 public override Vector3 Force
387 {
388 //get { return Vector3.Zero; }
389 get { return m_force; }
390 set
391 {
392 if (value.IsFinite())
393 {
394 AddChange(changes.Force, value);
395 }
396 else
397 {
398 m_log.WarnFormat("[PHYSICS]: NaN in Force Applied to an Object {0}", Name);
399 }
400 }
401 }
402
403
404 public override void SetVolumeDetect(int param)
405 {
406 AddChange(changes.VolumeDtc,(param != 0));
407 }
408
409 public override Vector3 GeometricCenter
410 {
411 get
412 {
413 return Vector3.Zero;
414 }
415 }
416
417 public override Vector3 CenterOfMass
418 {
419 get
420 {
421 d.Vector3 dtmp;
422 if (IsPhysical && !childPrim && Body != IntPtr.Zero)
423 {
424 dtmp = d.BodyGetPosition(Body);
425 return new Vector3(dtmp.X, dtmp.Y, dtmp.Z);
426 }
427 else if (prim_geom != IntPtr.Zero)
428 {
429 d.Quaternion dq;
430 d.GeomCopyQuaternion(prim_geom, out dq);
431 Quaternion q;
432 q.X = dq.X;
433 q.Y = dq.Y;
434 q.Z = dq.Z;
435 q.W = dq.W;
436
437 Vector3 vtmp = primOOBoffset * q;
438 dtmp = d.GeomGetPosition(prim_geom);
439 return new Vector3(dtmp.X + vtmp.X, dtmp.Y + vtmp.Y, dtmp.Z + vtmp.Z);
440 }
441 else
442 return Vector3.Zero;
443 }
444 }
445 /*
446 public override Vector3 PrimOOBsize
447 {
448 get
449 {
450 return primOOBsize;
451 }
452 }
453
454 public override Vector3 PrimOOBoffset
455 {
456 get
457 {
458 return primOOBoffset;
459 }
460 }
461
462 public override float PrimOOBRadiusSQ
463 {
464 get
465 {
466 return primOOBradiusSQ;
467 }
468 }
469 */
470 public override PrimitiveBaseShape Shape
471 {
472 set
473 {
474 AddChange(changes.Shape, value);
475 }
476 }
477
478 public override Vector3 Velocity
479 {
480 get
481 {
482 // Averate previous velocity with the new one so
483 // client object interpolation works a 'little' better
484 if (_zeroFlag)
485 return Vector3.Zero;
486/*
487 Vector3 returnVelocity = Vector3.Zero;
488 returnVelocity.X = (m_lastVelocity.X + _velocity.X) / 2;
489 returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y) / 2;
490 returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z) / 2;
491
492 return returnVelocity;
493 */
494 return _velocity;
495 }
496 set
497 {
498 if (value.IsFinite())
499 {
500 AddChange(changes.Velocity, value);
501// _velocity = value;
502
503 }
504 else
505 {
506 m_log.WarnFormat("[PHYSICS]: Got NaN Velocity in Object {0}", Name);
507 }
508
509 }
510 }
511
512 public override Vector3 Torque
513 {
514 get
515 {
516 if (!IsPhysical || Body == IntPtr.Zero)
517 return Vector3.Zero;
518
519 return _torque;
520 }
521
522 set
523 {
524 if (value.IsFinite())
525 {
526 AddChange(changes.Torque, value);
527 }
528 else
529 {
530 m_log.WarnFormat("[PHYSICS]: Got NaN Torque in Object {0}", Name);
531 }
532 }
533 }
534
535 public override float CollisionScore
536 {
537 get { return m_collisionscore; }
538 set { m_collisionscore = value; }
539 }
540
541 public override bool Kinematic
542 {
543 get { return false; }
544 set { }
545 }
546
547 public override Quaternion Orientation
548 {
549 get
550 {
551 if (givefakeori>0)
552 return fakeori;
553 else
554
555 return _orientation;
556 }
557 set
558 {
559 if (QuaternionIsFinite(value))
560 {
561 fakeori = value;
562 givefakeori++;
563 AddChange(changes.Orientation, value);
564 }
565 else
566 m_log.WarnFormat("[PHYSICS]: Got NaN quaternion Orientation from Scene in Object {0}", Name);
567
568 }
569 }
570
571 public override Vector3 Acceleration
572 {
573 get { return _acceleration; }
574 set { }
575 }
576
577 public override Vector3 RotationalVelocity
578 {
579 get
580 {
581 Vector3 pv = Vector3.Zero;
582 if (_zeroFlag)
583 return pv;
584 m_lastUpdateSent = false;
585
586 if (m_rotationalVelocity.ApproxEquals(pv, 0.0001f))
587 return pv;
588
589 return m_rotationalVelocity;
590 }
591 set
592 {
593 if (value.IsFinite())
594 {
595 m_rotationalVelocity = value;
596 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
597 d.BodyEnable(Body);
598 }
599 else
600 {
601 m_log.WarnFormat("[PHYSICS]: Got NaN RotationalVelocity in Object {0}", Name);
602 }
603 }
604 }
605
606
607 public override float Buoyancy
608 {
609 get { return m_buoyancy; }
610 set
611 {
612 m_buoyancy = value;
613 }
614 }
615
616 public override bool FloatOnWater
617 {
618 set
619 {
620 AddChange(changes.CollidesWater, value);
621 }
622 }
623
624 public override Vector3 PIDTarget
625 {
626 set
627 {
628 if (value.IsFinite())
629 {
630 m_PIDTarget = value;
631 }
632 else
633 m_log.WarnFormat("[PHYSICS]: Got NaN PIDTarget from Scene on Object {0}", Name);
634 }
635 }
636
637 public override bool PIDActive { set { m_usePID = value; } }
638 public override float PIDTau { set { m_PIDTau = value; } }
639
640 public override float PIDHoverHeight { set { m_PIDHoverHeight = value; ; } }
641 public override bool PIDHoverActive { set { m_useHoverPID = value; } }
642 public override PIDHoverType PIDHoverType { set { m_PIDHoverType = value; } }
643 public override float PIDHoverTau { set { m_PIDHoverTau = value; } }
644
645 public override Quaternion APIDTarget { set { return; } }
646
647 public override bool APIDActive { set { return; } }
648
649 public override float APIDStrength { set { return; } }
650
651 public override float APIDDamping { set { return; } }
652
653 public override int VehicleType
654 {
655 get
656 {
657 if (m_vehicle == null)
658 return (int)Vehicle.TYPE_NONE;
659 else
660 return (int)m_vehicle.Type;
661 }
662 set
663 {
664 if (m_vehicle == null)
665 {
666 if (value != (int)Vehicle.TYPE_NONE)
667 {
668 m_vehicle = new ODEDynamics(this);
669 m_vehicle.ProcessTypeChange((Vehicle)value);
670 }
671 }
672 else
673 m_vehicle.ProcessTypeChange((Vehicle)value);
674 }
675 }
676
677 public override void VehicleFloatParam(int param, float value)
678 {
679 if (m_vehicle == null)
680 return;
681 m_vehicle.ProcessFloatVehicleParam((Vehicle)param, value);
682 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
683 d.BodyEnable(Body);
684 }
685
686 public override void VehicleVectorParam(int param, Vector3 value)
687 {
688 if (m_vehicle == null)
689 return;
690 m_vehicle.ProcessVectorVehicleParam((Vehicle)param, value);
691 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
692 d.BodyEnable(Body);
693 }
694
695 public override void VehicleRotationParam(int param, Quaternion rotation)
696 {
697 if (m_vehicle == null)
698 return;
699 m_vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation);
700 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
701 d.BodyEnable(Body);
702 }
703
704 public override void VehicleFlags(int param, bool remove)
705 {
706 if (m_vehicle == null)
707 return;
708 m_vehicle.ProcessVehicleFlags(param, remove);
709 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
710 d.BodyEnable(Body);
711 }
712
713 public void SetAcceleration(Vector3 accel)
714 {
715 _acceleration = accel;
716 }
717
718 public override void AddForce(Vector3 force, bool pushforce)
719 {
720 if (force.IsFinite())
721 {
722 AddChange(changes.AddForce, force / _parent_scene.ODE_STEPSIZE);
723 }
724 else
725 {
726 m_log.WarnFormat("[PHYSICS]: Got Invalid linear force vector from Scene in Object {0}", Name);
727 }
728 //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString());
729 }
730
731 public override void AddAngularForce(Vector3 force, bool pushforce)
732 {
733 if (force.IsFinite())
734 {
735 AddChange(changes.AddAngForce, force / _parent_scene.ODE_STEPSIZE);
736 }
737 else
738 {
739 m_log.WarnFormat("[PHYSICS]: Got Invalid Angular force vector from Scene in Object {0}", Name);
740 }
741 }
742
743 public override void CrossingFailure()
744 {
745 m_crossingfailures++;
746 changeDisable(false);
747 }
748
749 public override void SetMomentum(Vector3 momentum)
750 {
751 }
752
753 public override void SetMaterial(int pMaterial)
754 {
755 m_material = pMaterial;
756 primContactData.mu = _parent_scene.m_materialContactsData[pMaterial].mu;
757 primContactData.bounce = _parent_scene.m_materialContactsData[pMaterial].bounce;
758 }
759
760 public void setPrimForRemoval()
761 {
762 AddChange(changes.Remove, null);
763 }
764
765 public override void link(PhysicsActor obj)
766 {
767 AddChange(changes.Link, obj);
768 }
769
770 public override void delink()
771 {
772 AddChange(changes.DeLink, null);
773 }
774
775 public override void LockAngularMotion(Vector3 axis)
776 {
777 // reverse the zero/non zero values for ODE.
778 if (axis.IsFinite())
779 {
780 axis.X = (axis.X > 0) ? 1f : 0f;
781 axis.Y = (axis.Y > 0) ? 1f : 0f;
782 axis.Z = (axis.Z > 0) ? 1f : 0f;
783 m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z);
784 AddChange(changes.AngLock, axis);
785 }
786 else
787 {
788 m_log.WarnFormat("[PHYSICS]: Got NaN locking axis from Scene on Object {0}", Name);
789 }
790 }
791
792 public override void SubscribeEvents(int ms)
793 {
794 m_eventsubscription = ms;
795 _parent_scene.AddCollisionEventReporting(this);
796 }
797
798 public override void UnSubscribeEvents()
799 {
800 _parent_scene.RemoveCollisionEventReporting(this);
801 m_eventsubscription = 0;
802 }
803
804 public void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
805 {
806 if (CollisionEventsThisFrame == null)
807 CollisionEventsThisFrame = new CollisionEventUpdate();
808
809 CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
810 }
811
812 public void SendCollisions()
813 {
814 if (CollisionEventsThisFrame == null)
815 return;
816
817 base.SendCollisionUpdate(CollisionEventsThisFrame);
818
819 if (CollisionEventsThisFrame.m_objCollisionList.Count == 0)
820 CollisionEventsThisFrame = null;
821 else
822 CollisionEventsThisFrame = new CollisionEventUpdate();
823 }
824
825 public override bool SubscribedEvents()
826 {
827 if (m_eventsubscription > 0)
828 return true;
829 return false;
830 }
831
832
833 public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size,
834 Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
835 {
836 Name = primName;
837
838 m_vehicle = null;
839
840 if (!pos.IsFinite())
841 {
842 pos = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f),
843 parent_scene.GetTerrainHeightAtXY(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f)) + 0.5f);
844 m_log.WarnFormat("[PHYSICS]: Got nonFinite Object create Position for {0}", Name);
845 }
846 _position = pos;
847 givefakepos = 0;
848
849 PID_D = parent_scene.bodyPIDD;
850 PID_G = parent_scene.bodyPIDG;
851 m_density = parent_scene.geomDefaultDensity;
852 // m_tensor = parent_scene.bodyMotorJointMaxforceTensor;
853 body_autodisable_frames = parent_scene.bodyFramesAutoDisable;
854
855 prim_geom = IntPtr.Zero;
856 Body = IntPtr.Zero;
857
858 if (!size.IsFinite())
859 {
860 size = new Vector3(0.5f, 0.5f, 0.5f);
861 m_log.WarnFormat("[PHYSICS]: Got nonFinite Object create Size for {0}", Name);
862 }
863
864 if (size.X <= 0) size.X = 0.01f;
865 if (size.Y <= 0) size.Y = 0.01f;
866 if (size.Z <= 0) size.Z = 0.01f;
867
868 _size = size;
869
870
871 if (!QuaternionIsFinite(rotation))
872 {
873 rotation = Quaternion.Identity;
874 m_log.WarnFormat("[PHYSICS]: Got nonFinite Object create Rotation for {0}", Name);
875 }
876
877 _orientation = rotation;
878 givefakeori = 0;
879
880 _pbs = pbs;
881
882 _parent_scene = parent_scene;
883 m_targetSpace = IntPtr.Zero;
884
885 if (pos.Z < 0)
886 {
887 m_isphysical = false;
888 }
889 else
890 {
891 m_isphysical = pisPhysical;
892 }
893 m_fakeisphysical = m_isphysical;
894
895 m_isVolumeDetect = false;
896
897 m_force = Vector3.Zero;
898
899 m_iscolliding = false;
900 m_wascolliding = false;
901 m_colliderfilter = 0;
902
903 hasOOBoffsetFromMesh = false;
904 _triMeshData = IntPtr.Zero;
905
906
907 primContactData.mu = parent_scene.m_materialContactsData[(int)Material.Wood].mu;
908 primContactData.bounce = parent_scene.m_materialContactsData[(int)Material.Wood].bounce;
909
910 CalcPrimBodyData();
911
912 m_building = true; // control must set this to false when done
913
914 AddChange(changes.Add, null);
915 }
916
917 private void resetCollisionAccounting()
918 {
919 m_collisionscore = 0;
920 m_interpenetrationcount = 0;
921 m_disabled = false;
922 }
923
924 private void createAMotor(Vector3 axis)
925 {
926 if (Body == IntPtr.Zero)
927 return;
928
929 if (Amotor != IntPtr.Zero)
930 {
931 d.JointDestroy(Amotor);
932 Amotor = IntPtr.Zero;
933 }
934
935 int axisnum = 3 - (int)(axis.X + axis.Y + axis.Z);
936
937 if (axisnum <= 0)
938 return;
939
940 // stop it
941 d.BodySetTorque(Body, 0, 0, 0);
942 d.BodySetAngularVel(Body, 0, 0, 0);
943
944 Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
945 d.JointAttach(Amotor, Body, IntPtr.Zero);
946
947 d.JointSetAMotorMode(Amotor, 0);
948
949 d.JointSetAMotorNumAxes(Amotor, axisnum);
950
951 // get current orientation to lock
952
953 d.Quaternion dcur = d.BodyGetQuaternion(Body);
954 Quaternion curr; // crap convertion between identical things
955 curr.X = dcur.X;
956 curr.Y = dcur.Y;
957 curr.Z = dcur.Z;
958 curr.W = dcur.W;
959 Vector3 ax;
960
961 const int StopERP = 7;
962 const int StopCFM = 8;
963
964 int i = 0;
965 int j = 0;
966 if (axis.X == 0)
967 {
968 ax = (new Vector3(1, 0, 0)) * curr; // rotate world X to current local X
969 // ODE should do this with axis relative to body 1 but seems to fail
970 d.JointSetAMotorAxis(Amotor, 0, 0, ax.X, ax.Y, ax.Z);
971 d.JointSetAMotorAngle(Amotor, 0, 0);
972 d.JointSetAMotorParam(Amotor, (int)d.JointParam.LoStop, -0.000001f);
973 d.JointSetAMotorParam(Amotor, (int)d.JointParam.HiStop, 0.000001f);
974 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel, 0);
975 d.JointSetAMotorParam(Amotor, (int)d.JointParam.FudgeFactor, 0.0001f);
976 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Bounce, 0f);
977 d.JointSetAMotorParam(Amotor, (int)d.JointParam.FMax, 5e8f);
978 d.JointSetAMotorParam(Amotor, (int)StopCFM, 0f);
979 d.JointSetAMotorParam(Amotor, (int)StopERP, 0.8f);
980 i++;
981 j = 256; // odeplugin.cs doesn't have all parameters so this moves to next axis set
982 }
983
984 if (axis.Y == 0)
985 {
986 ax = (new Vector3(0, 1, 0)) * curr;
987 d.JointSetAMotorAxis(Amotor, i, 0, ax.X, ax.Y, ax.Z);
988 d.JointSetAMotorAngle(Amotor, i, 0);
989 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.LoStop, -0.000001f);
990 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.HiStop, 0.000001f);
991 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Vel, 0);
992 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FudgeFactor, 0.0001f);
993 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Bounce, 0f);
994 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FMax, 5e8f);
995 d.JointSetAMotorParam(Amotor, j + (int)StopCFM, 0f);
996 d.JointSetAMotorParam(Amotor, j + (int)StopERP, 0.8f);
997 i++;
998 j += 256;
999 }
1000
1001 if (axis.Z == 0)
1002 {
1003 ax = (new Vector3(0, 0, 1)) * curr;
1004 d.JointSetAMotorAxis(Amotor, i, 0, ax.X, ax.Y, ax.Z);
1005 d.JointSetAMotorAngle(Amotor, i, 0);
1006 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.LoStop, -0.000001f);
1007 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.HiStop, 0.000001f);
1008 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Vel, 0);
1009 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FudgeFactor, 0.0001f);
1010 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Bounce, 0f);
1011 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FMax, 5e8f);
1012 d.JointSetAMotorParam(Amotor, j + (int)StopCFM, 0f);
1013 d.JointSetAMotorParam(Amotor, j + (int)StopERP, 0.8f);
1014 }
1015 }
1016
1017 private bool setMesh(OdeScene parent_scene)
1018 {
1019 if (Body != IntPtr.Zero)
1020 {
1021 if (childPrim)
1022 {
1023 if (_parent != null)
1024 {
1025 OdePrim parent = (OdePrim)_parent;
1026 parent.ChildDelink(this,false);
1027 }
1028 }
1029 else
1030 {
1031 DestroyBody();
1032 }
1033 }
1034
1035 IMesh mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, (int)LevelOfDetail.High, true);
1036 if (mesh == null)
1037 {
1038 m_log.WarnFormat("[PHYSICS]: CreateMesh Failed on prim {0} at <{1},{2},{3}>.", Name, _position.X, _position.Y, _position.Z);
1039 return false;
1040 }
1041
1042 IntPtr vertices, indices;
1043 int vertexCount, indexCount;
1044 int vertexStride, triStride;
1045
1046 mesh.getVertexListAsPtrToFloatArray(out vertices, out vertexStride, out vertexCount); // Note, that vertices are fixed in unmanaged heap
1047 mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage
1048
1049 if (vertexCount == 0 || indexCount == 0)
1050 {
1051 m_log.WarnFormat("[PHYSICS]: Got invalid mesh on prim {0} at <{1},{2},{3}>. It can be a sculp with alpha channel in map. Replacing it by a small box.", Name, _position.X, _position.Y, _position.Z);
1052 _size.X = 0.01f;
1053 _size.Y = 0.01f;
1054 _size.Z = 0.01f;
1055 return false;
1056 }
1057
1058// primOOBoffset = mesh.GetCentroid();
1059// hasOOBoffsetFromMesh = true;
1060 hasOOBoffsetFromMesh = false;
1061
1062 _triMeshData = d.GeomTriMeshDataCreate();
1063
1064 d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
1065 d.GeomTriMeshDataPreprocess(_triMeshData);
1066
1067 mesh.releaseSourceMeshData();
1068
1069 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1070 try
1071 {
1072 SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, null, null, null));
1073 }
1074
1075 catch (Exception e)
1076 {
1077 m_log.ErrorFormat("[PHYSICS]: SetGeom Mesh failed for {0} exception: {1}", Name, e);
1078 return false;
1079 }
1080 return true;
1081 }
1082
1083 private void SetGeom(IntPtr geom)
1084 {
1085 prim_geom = geom;
1086 //Console.WriteLine("SetGeom to " + prim_geom + " for " + Name);
1087 if (prim_geom != IntPtr.Zero)
1088 {
1089 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1090 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1091
1092 CalcPrimBodyData();
1093
1094 _parent_scene.geom_name_map[prim_geom] = Name;
1095 _parent_scene.actor_name_map[prim_geom] = this;
1096
1097/*
1098 if (childPrim)
1099 {
1100 if (_parent != null && _parent is OdePrim)
1101 {
1102 OdePrim parent = (OdePrim)_parent;
1103 //Console.WriteLine("SetGeom calls ChildSetGeom");
1104 parent.ChildSetGeom(this);
1105 }
1106 }
1107 */
1108 }
1109 else
1110 m_log.Warn("Setting bad Geom");
1111 }
1112
1113
1114 /// <summary>
1115 /// Create a geometry for the given mesh in the given target space.
1116 /// </summary>
1117 /// <param name="m_targetSpace"></param>
1118 /// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param>
1119 private void CreateGeom()
1120 {
1121 if (_triMeshData != IntPtr.Zero)
1122 {
1123 d.GeomTriMeshDataDestroy(_triMeshData);
1124 _triMeshData = IntPtr.Zero;
1125 }
1126
1127 bool haveMesh = false;
1128 hasOOBoffsetFromMesh = false;
1129
1130 if (_parent_scene.needsMeshing(_pbs))
1131 {
1132 haveMesh = setMesh(_parent_scene); // this will give a mesh to non trivial known prims
1133 }
1134
1135 if(!haveMesh)
1136 {
1137 if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1
1138 && _size.X == _size.Y && _size.Y == _size.Z)
1139 { // it's a sphere
1140 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1141 try
1142 {
1143 SetGeom(d.CreateSphere(m_targetSpace, _size.X * 0.5f));
1144 }
1145 catch (Exception e)
1146 {
1147 m_log.WarnFormat("[PHYSICS]: Create sphere failed: {0}", e);
1148 return;
1149 }
1150 }
1151 else
1152 {// do it as a box
1153 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1154 try
1155 {
1156 //Console.WriteLine(" CreateGeom 4");
1157 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
1158 }
1159 catch (Exception e)
1160 {
1161 m_log.Warn("[PHYSICS]: Create box failed: {0}", e);
1162 return;
1163 }
1164 }
1165 }
1166 }
1167
1168 /// <summary>
1169 /// Set a new geometry for this prim.
1170 /// </summary>
1171 /// <param name="geom"></param>
1172 private void RemoveGeom()
1173 {
1174 if (prim_geom != IntPtr.Zero)
1175 {
1176 _parent_scene.geom_name_map.Remove(prim_geom);
1177 _parent_scene.actor_name_map.Remove(prim_geom);
1178 try
1179 {
1180 d.GeomDestroy(prim_geom);
1181 if (_triMeshData != IntPtr.Zero)
1182 {
1183 d.GeomTriMeshDataDestroy(_triMeshData);
1184 _triMeshData = IntPtr.Zero;
1185 }
1186 }
1187 // catch (System.AccessViolationException)
1188 catch (Exception e)
1189 {
1190 m_log.ErrorFormat("[PHYSICS]: PrimGeom destruction failed for {0} exception {1}", Name,e);
1191 }
1192
1193 prim_geom = IntPtr.Zero;
1194 }
1195 else
1196 {
1197 m_log.ErrorFormat("[PHYSICS]: PrimGeom destruction BAD {0}", Name);
1198 }
1199 Body = IntPtr.Zero;
1200 hasOOBoffsetFromMesh = false;
1201// CalcPrimBodyData();
1202 }
1203
1204 private void ChildSetGeom(OdePrim odePrim)
1205 {
1206 // well..
1207 DestroyBody();
1208 MakeBody();
1209 }
1210
1211 //sets non physical prim m_targetSpace to right space in spaces grid for static prims
1212 // should only be called for non physical prims unless they are becoming non physical
1213 private void SetInStaticSpace(OdePrim prim)
1214 {
1215 IntPtr targetSpace = _parent_scene.MoveGeomToStaticSpace(prim.prim_geom, prim._position, prim.m_targetSpace);
1216 prim.m_targetSpace = targetSpace;
1217 d.GeomEnable(prim_geom);
1218 }
1219
1220 public void enableBodySoft()
1221 {
1222 if (!childPrim)
1223 {
1224 if (m_isphysical && Body != IntPtr.Zero && prim_geom != IntPtr.Zero)
1225 {
1226 /*
1227 if (m_targetSpace != _parent_scene.ActiveSpace)
1228 {
1229 m_targetSpace = _parent_scene.ActiveSpace;
1230
1231 foreach (OdePrim prm in childrenPrim)
1232 {
1233 if (prm.prim_geom != IntPtr.Zero)
1234 {
1235 d.SpaceAdd(m_targetSpace, prm.prim_geom);
1236 prm.m_targetSpace = m_targetSpace;
1237 }
1238 }
1239 d.SpaceAdd(m_targetSpace, prim_geom);
1240 }
1241 */
1242 d.GeomEnable(prim_geom);
1243 foreach (OdePrim prm in childrenPrim)
1244 d.GeomEnable(prm.prim_geom);
1245
1246 d.BodyEnable(Body);
1247 }
1248 }
1249 resetCollisionAccounting(); // this sets m_disable to false
1250 }
1251
1252 private void disableBodySoft()
1253 {
1254 m_disabled = true;
1255 if (!childPrim)
1256 {
1257 if (m_isphysical && Body != IntPtr.Zero && prim_geom != IntPtr.Zero)
1258 {
1259 /*
1260 if (m_targetSpace == _parent_scene.ActiveSpace)
1261 {
1262 foreach (OdePrim prm in childrenPrim)
1263 {
1264 if (prm.m_targetSpace != IntPtr.Zero && prm.prim_geom != IntPtr.Zero)
1265 {
1266 d.SpaceRemove(prm.m_targetSpace, prm.prim_geom);
1267 prm.m_targetSpace = IntPtr.Zero;
1268 }
1269 }
1270 d.SpaceRemove(m_targetSpace, prim_geom);
1271 m_targetSpace = IntPtr.Zero;
1272 }
1273 */
1274 d.GeomDisable(prim_geom);
1275 foreach (OdePrim prm in childrenPrim)
1276 d.GeomDisable(prm.prim_geom);
1277 d.BodyDisable(Body);
1278 }
1279 }
1280 }
1281
1282 private void MakeBody()
1283 {
1284 if (!m_isphysical) // only physical get bodies
1285 return;
1286
1287 if (childPrim) // child prims don't get bodies;
1288 return;
1289
1290 if (m_building)
1291 return;
1292
1293 if (prim_geom == IntPtr.Zero)
1294 {
1295 m_log.Warn("[PHYSICS]: Unable to link the linkset. Root has no geom yet");
1296 return;
1297 }
1298
1299 if (Body != IntPtr.Zero)
1300 {
1301 d.BodyDestroy(Body);
1302 Body = IntPtr.Zero;
1303 m_log.Warn("[PHYSICS]: MakeBody called having a body");
1304 }
1305
1306
1307 if (d.GeomGetBody(prim_geom) != IntPtr.Zero)
1308 {
1309 d.GeomSetBody(prim_geom, IntPtr.Zero);
1310 m_log.Warn("[PHYSICS]: MakeBody root geom already had a body");
1311 }
1312
1313 d.Matrix3 mymat = new d.Matrix3();
1314 d.Quaternion myrot = new d.Quaternion();
1315 d.Mass objdmass = new d.Mass { };
1316
1317 Body = d.BodyCreate(_parent_scene.world);
1318
1319 DMassDup(ref primdMass, out objdmass);
1320
1321 // rotate inertia
1322 myrot.X = _orientation.X;
1323 myrot.Y = _orientation.Y;
1324 myrot.Z = _orientation.Z;
1325 myrot.W = _orientation.W;
1326
1327 d.RfromQ(out mymat, ref myrot);
1328 d.MassRotate(ref objdmass, ref mymat);
1329
1330 // set the body rotation and position
1331 d.BodySetRotation(Body, ref mymat);
1332
1333 // recompute full object inertia if needed
1334 if (childrenPrim.Count > 0)
1335 {
1336 d.Matrix3 mat = new d.Matrix3();
1337 d.Quaternion quat = new d.Quaternion();
1338 d.Mass tmpdmass = new d.Mass { };
1339 Vector3 rcm;
1340
1341 rcm.X = _position.X + objdmass.c.X;
1342 rcm.Y = _position.Y + objdmass.c.Y;
1343 rcm.Z = _position.Z + objdmass.c.Z;
1344
1345 lock (childrenPrim)
1346 {
1347 foreach (OdePrim prm in childrenPrim)
1348 {
1349 if (prm.prim_geom == IntPtr.Zero)
1350 {
1351 m_log.Warn("[PHYSICS]: Unable to link one of the linkset elements, skipping it. No geom yet");
1352 continue;
1353 }
1354
1355
1356
1357 DMassCopy(ref prm.primdMass, ref tmpdmass);
1358
1359 // apply prim current rotation to inertia
1360 quat.X = prm._orientation.X;
1361 quat.Y = prm._orientation.Y;
1362 quat.Z = prm._orientation.Z;
1363 quat.W = prm._orientation.W;
1364 d.RfromQ(out mat, ref quat);
1365 d.MassRotate(ref tmpdmass, ref mat);
1366
1367 Vector3 ppos = prm._position;
1368 ppos.X += tmpdmass.c.X - rcm.X;
1369 ppos.Y += tmpdmass.c.Y - rcm.Y;
1370 ppos.Z += tmpdmass.c.Z - rcm.Z;
1371
1372 // refer inertia to root prim center of mass position
1373 d.MassTranslate(ref tmpdmass,
1374 ppos.X,
1375 ppos.Y,
1376 ppos.Z);
1377
1378 d.MassAdd(ref objdmass, ref tmpdmass); // add to total object inertia
1379 // fix prim colision cats
1380
1381 if (d.GeomGetBody(prm.prim_geom) != IntPtr.Zero)
1382 {
1383 d.GeomSetBody(prm.prim_geom, IntPtr.Zero);
1384 m_log.Warn("[PHYSICS]: MakeBody child geom already had a body");
1385 }
1386
1387 d.GeomClearOffset(prm.prim_geom);
1388 d.GeomSetBody(prm.prim_geom, Body);
1389 prm.Body = Body;
1390 d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat); // set relative rotation
1391 }
1392 }
1393 }
1394
1395 d.GeomClearOffset(prim_geom); // make sure we don't have a hidden offset
1396 // associate root geom with body
1397 d.GeomSetBody(prim_geom, Body);
1398
1399 d.BodySetPosition(Body, _position.X + objdmass.c.X, _position.Y + objdmass.c.Y, _position.Z + objdmass.c.Z);
1400 d.GeomSetOffsetWorldPosition(prim_geom, _position.X, _position.Y, _position.Z);
1401
1402 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
1403 myrot.W = -myrot.W;
1404 d.RfromQ(out mymat, ref myrot);
1405 d.MassRotate(ref objdmass, ref mymat);
1406 d.BodySetMass(Body, ref objdmass);
1407 _mass = objdmass.mass;
1408
1409 m_collisionCategories |= CollisionCategories.Body;
1410 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1411
1412 // disconnect from world gravity so we can apply buoyancy
1413 d.BodySetGravityMode(Body, false);
1414
1415 d.BodySetAutoDisableFlag(Body, true);
1416 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1417 // d.BodySetLinearDampingThreshold(Body, 0.01f);
1418 // d.BodySetAngularDampingThreshold(Body, 0.001f);
1419 d.BodySetDamping(Body, .001f, .0002f);
1420
1421 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1422 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1423
1424 m_interpenetrationcount = 0;
1425 m_collisionscore = 0;
1426
1427 m_disabled = false;
1428
1429 if (m_targetSpace != _parent_scene.ActiveSpace)
1430 {
1431 if (m_targetSpace != IntPtr.Zero)
1432 {
1433 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1434 if (d.SpaceQuery(m_targetSpace, prim_geom))
1435 d.SpaceRemove(m_targetSpace, prim_geom);
1436 }
1437
1438 m_targetSpace = _parent_scene.ActiveSpace;
1439 d.SpaceAdd(m_targetSpace, prim_geom);
1440 }
1441
1442 lock (childrenPrim)
1443 {
1444 foreach (OdePrim prm in childrenPrim)
1445 {
1446 if (prm.prim_geom == IntPtr.Zero)
1447 continue;
1448
1449 Vector3 ppos = prm._position;
1450 d.GeomSetOffsetWorldPosition(prm.prim_geom, ppos.X, ppos.Y, ppos.Z); // set relative position
1451
1452 prm.m_collisionCategories |= CollisionCategories.Body;
1453 prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1454 d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories);
1455 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
1456
1457 if (prm.m_targetSpace != _parent_scene.ActiveSpace)
1458 {
1459 if (prm.m_targetSpace != IntPtr.Zero)
1460 {
1461 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1462 if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom))
1463 d.SpaceRemove(prm.m_targetSpace, prm.prim_geom);
1464 }
1465 prm.m_targetSpace = _parent_scene.ActiveSpace;
1466 d.SpaceAdd(m_targetSpace, prm.prim_geom);
1467 }
1468 d.GeomEnable(prm.prim_geom);
1469 prm.m_disabled = false;
1470 prm.m_interpenetrationcount = 0;
1471 prm.m_collisionscore = 0;
1472 _parent_scene.addActivePrim(prm);
1473 }
1474 }
1475
1476 // The body doesn't already have a finite rotation mode set here
1477 if ((!m_angularlock.ApproxEquals(Vector3.One, 0.0f)) && _parent == null)
1478 {
1479 createAMotor(m_angularlock);
1480 }
1481
1482 d.GeomEnable(prim_geom);
1483 m_disabled = false;
1484 _parent_scene.addActivePrim(this);
1485 }
1486
1487 private void DestroyBody()
1488 {
1489 if (Body != IntPtr.Zero)
1490 {
1491 _parent_scene.remActivePrim(this);
1492 m_collisionCategories &= ~CollisionCategories.Body;
1493 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
1494 if (prim_geom != IntPtr.Zero)
1495 {
1496 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1497 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1498 UpdateDataFromGeom();
1499 d.GeomSetBody(prim_geom, IntPtr.Zero);
1500 SetInStaticSpace(this);
1501 }
1502
1503 if (!childPrim)
1504 {
1505 lock (childrenPrim)
1506 {
1507 foreach (OdePrim prm in childrenPrim)
1508 {
1509 _parent_scene.remActivePrim(prm);
1510 prm.m_collisionCategories &= ~CollisionCategories.Body;
1511 prm.m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
1512 if (prm.prim_geom != IntPtr.Zero)
1513 {
1514 d.GeomSetCategoryBits(prm.prim_geom, (int)m_collisionCategories);
1515 d.GeomSetCollideBits(prm.prim_geom, (int)m_collisionFlags);
1516 prm.UpdateDataFromGeom();
1517 SetInStaticSpace(prm);
1518 }
1519 prm.Body = IntPtr.Zero;
1520 prm._mass = prm.primMass;
1521 prm.m_collisionscore = 0;
1522 }
1523 }
1524 d.BodyDestroy(Body);
1525 }
1526 Body = IntPtr.Zero;
1527 }
1528 _mass = primMass;
1529 m_disabled = true;
1530 m_collisionscore = 0;
1531 }
1532
1533 #region Mass Calculation
1534
1535 private float CalculatePrimVolume()
1536 {
1537 float volume = _size.X * _size.Y * _size.Z; // default
1538 float tmp;
1539
1540 float hollowAmount = (float)_pbs.ProfileHollow * 2.0e-5f;
1541 float hollowVolume = hollowAmount * hollowAmount;
1542
1543 switch (_pbs.ProfileShape)
1544 {
1545 case ProfileShape.Square:
1546 // default box
1547
1548 if (_pbs.PathCurve == (byte)Extrusion.Straight)
1549 {
1550 if (hollowAmount > 0.0)
1551 {
1552 switch (_pbs.HollowShape)
1553 {
1554 case HollowShape.Square:
1555 case HollowShape.Same:
1556 break;
1557
1558 case HollowShape.Circle:
1559
1560 hollowVolume *= 0.78539816339f;
1561 break;
1562
1563 case HollowShape.Triangle:
1564
1565 hollowVolume *= (0.5f * .5f);
1566 break;
1567
1568 default:
1569 hollowVolume = 0;
1570 break;
1571 }
1572 volume *= (1.0f - hollowVolume);
1573 }
1574 }
1575
1576 else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1577 {
1578 //a tube
1579
1580 volume *= 0.78539816339e-2f * (float)(200 - _pbs.PathScaleX);
1581 tmp = 1.0f - 2.0e-2f * (float)(200 - _pbs.PathScaleY);
1582 volume -= volume * tmp * tmp;
1583
1584 if (hollowAmount > 0.0)
1585 {
1586 hollowVolume *= hollowAmount;
1587
1588 switch (_pbs.HollowShape)
1589 {
1590 case HollowShape.Square:
1591 case HollowShape.Same:
1592 break;
1593
1594 case HollowShape.Circle:
1595 hollowVolume *= 0.78539816339f;
1596 break;
1597
1598 case HollowShape.Triangle:
1599 hollowVolume *= 0.5f * 0.5f;
1600 break;
1601 default:
1602 hollowVolume = 0;
1603 break;
1604 }
1605 volume *= (1.0f - hollowVolume);
1606 }
1607 }
1608
1609 break;
1610
1611 case ProfileShape.Circle:
1612
1613 if (_pbs.PathCurve == (byte)Extrusion.Straight)
1614 {
1615 volume *= 0.78539816339f; // elipse base
1616
1617 if (hollowAmount > 0.0)
1618 {
1619 switch (_pbs.HollowShape)
1620 {
1621 case HollowShape.Same:
1622 case HollowShape.Circle:
1623 break;
1624
1625 case HollowShape.Square:
1626 hollowVolume *= 0.5f * 2.5984480504799f;
1627 break;
1628
1629 case HollowShape.Triangle:
1630 hollowVolume *= .5f * 1.27323954473516f;
1631 break;
1632
1633 default:
1634 hollowVolume = 0;
1635 break;
1636 }
1637 volume *= (1.0f - hollowVolume);
1638 }
1639 }
1640
1641 else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1642 {
1643 volume *= 0.61685027506808491367715568749226e-2f * (float)(200 - _pbs.PathScaleX);
1644 tmp = 1.0f - .02f * (float)(200 - _pbs.PathScaleY);
1645 volume *= (1.0f - tmp * tmp);
1646
1647 if (hollowAmount > 0.0)
1648 {
1649
1650 // calculate the hollow volume by it's shape compared to the prim shape
1651 hollowVolume *= hollowAmount;
1652
1653 switch (_pbs.HollowShape)
1654 {
1655 case HollowShape.Same:
1656 case HollowShape.Circle:
1657 break;
1658
1659 case HollowShape.Square:
1660 hollowVolume *= 0.5f * 2.5984480504799f;
1661 break;
1662
1663 case HollowShape.Triangle:
1664 hollowVolume *= .5f * 1.27323954473516f;
1665 break;
1666
1667 default:
1668 hollowVolume = 0;
1669 break;
1670 }
1671 volume *= (1.0f - hollowVolume);
1672 }
1673 }
1674 break;
1675
1676 case ProfileShape.HalfCircle:
1677 if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1678 {
1679 volume *= 0.52359877559829887307710723054658f;
1680 }
1681 break;
1682
1683 case ProfileShape.EquilateralTriangle:
1684
1685 if (_pbs.PathCurve == (byte)Extrusion.Straight)
1686 {
1687 volume *= 0.32475953f;
1688
1689 if (hollowAmount > 0.0)
1690 {
1691
1692 // calculate the hollow volume by it's shape compared to the prim shape
1693 switch (_pbs.HollowShape)
1694 {
1695 case HollowShape.Same:
1696 case HollowShape.Triangle:
1697 hollowVolume *= .25f;
1698 break;
1699
1700 case HollowShape.Square:
1701 hollowVolume *= 0.499849f * 3.07920140172638f;
1702 break;
1703
1704 case HollowShape.Circle:
1705 // Hollow shape is a perfect cyllinder in respect to the cube's scale
1706 // Cyllinder hollow volume calculation
1707
1708 hollowVolume *= 0.1963495f * 3.07920140172638f;
1709 break;
1710
1711 default:
1712 hollowVolume = 0;
1713 break;
1714 }
1715 volume *= (1.0f - hollowVolume);
1716 }
1717 }
1718 else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1719 {
1720 volume *= 0.32475953f;
1721 volume *= 0.01f * (float)(200 - _pbs.PathScaleX);
1722 tmp = 1.0f - .02f * (float)(200 - _pbs.PathScaleY);
1723 volume *= (1.0f - tmp * tmp);
1724
1725 if (hollowAmount > 0.0)
1726 {
1727
1728 hollowVolume *= hollowAmount;
1729
1730 switch (_pbs.HollowShape)
1731 {
1732 case HollowShape.Same:
1733 case HollowShape.Triangle:
1734 hollowVolume *= .25f;
1735 break;
1736
1737 case HollowShape.Square:
1738 hollowVolume *= 0.499849f * 3.07920140172638f;
1739 break;
1740
1741 case HollowShape.Circle:
1742
1743 hollowVolume *= 0.1963495f * 3.07920140172638f;
1744 break;
1745
1746 default:
1747 hollowVolume = 0;
1748 break;
1749 }
1750 volume *= (1.0f - hollowVolume);
1751 }
1752 }
1753 break;
1754
1755 default:
1756 break;
1757 }
1758
1759 float taperX1;
1760 float taperY1;
1761 float taperX;
1762 float taperY;
1763 float pathBegin;
1764 float pathEnd;
1765 float profileBegin;
1766 float profileEnd;
1767
1768 if (_pbs.PathCurve == (byte)Extrusion.Straight || _pbs.PathCurve == (byte)Extrusion.Flexible)
1769 {
1770 taperX1 = _pbs.PathScaleX * 0.01f;
1771 if (taperX1 > 1.0f)
1772 taperX1 = 2.0f - taperX1;
1773 taperX = 1.0f - taperX1;
1774
1775 taperY1 = _pbs.PathScaleY * 0.01f;
1776 if (taperY1 > 1.0f)
1777 taperY1 = 2.0f - taperY1;
1778 taperY = 1.0f - taperY1;
1779 }
1780 else
1781 {
1782 taperX = _pbs.PathTaperX * 0.01f;
1783 if (taperX < 0.0f)
1784 taperX = -taperX;
1785 taperX1 = 1.0f - taperX;
1786
1787 taperY = _pbs.PathTaperY * 0.01f;
1788 if (taperY < 0.0f)
1789 taperY = -taperY;
1790 taperY1 = 1.0f - taperY;
1791 }
1792
1793 volume *= (taperX1 * taperY1 + 0.5f * (taperX1 * taperY + taperX * taperY1) + 0.3333333333f * taperX * taperY);
1794
1795 pathBegin = (float)_pbs.PathBegin * 2.0e-5f;
1796 pathEnd = 1.0f - (float)_pbs.PathEnd * 2.0e-5f;
1797 volume *= (pathEnd - pathBegin);
1798
1799 // this is crude aproximation
1800 profileBegin = (float)_pbs.ProfileBegin * 2.0e-5f;
1801 profileEnd = 1.0f - (float)_pbs.ProfileEnd * 2.0e-5f;
1802 volume *= (profileEnd - profileBegin);
1803
1804 return volume;
1805 }
1806
1807
1808 private void CalcPrimBodyData()
1809 {
1810 float volume;
1811
1812 if (prim_geom == IntPtr.Zero)
1813 {
1814 // Ubit let's have a initial basic OOB
1815 primOOBsize.X = _size.X;
1816 primOOBsize.Y = _size.Y;
1817 primOOBsize.Z = _size.Z;
1818 primOOBoffset = Vector3.Zero;
1819 }
1820 else
1821 {
1822 d.AABB AABB;
1823 d.GeomGetAABB(prim_geom, out AABB); // get the AABB from engine geom
1824
1825 primOOBsize.X = (AABB.MaxX - AABB.MinX);
1826 primOOBsize.Y = (AABB.MaxY - AABB.MinY);
1827 primOOBsize.Z = (AABB.MaxZ - AABB.MinZ);
1828 if (!hasOOBoffsetFromMesh)
1829 {
1830 primOOBoffset.X = (AABB.MaxX + AABB.MinX) * 0.5f;
1831 primOOBoffset.Y = (AABB.MaxY + AABB.MinY) * 0.5f;
1832 primOOBoffset.Z = (AABB.MaxZ + AABB.MinZ) * 0.5f;
1833 }
1834 }
1835
1836 // also its own inertia and mass
1837 // keep using basic shape mass for now
1838 volume = CalculatePrimVolume();
1839
1840 primMass = m_density * volume;
1841
1842 if (primMass <= 0)
1843 primMass = 0.0001f;//ckrinke: Mass must be greater then zero.
1844 if (primMass > _parent_scene.maximumMassObject)
1845 primMass = _parent_scene.maximumMassObject;
1846
1847 _mass = primMass; // just in case
1848
1849 d.MassSetBoxTotal(out primdMass, primMass, primOOBsize.X, primOOBsize.Y, primOOBsize.Z);
1850
1851 d.MassTranslate(ref primdMass,
1852 primOOBoffset.X,
1853 primOOBoffset.Y,
1854 primOOBoffset.Z);
1855
1856 primOOBsize *= 0.5f; // let obb size be a corner coords
1857 primOOBradiusSQ = primOOBsize.LengthSquared();
1858 }
1859
1860
1861 #endregion
1862
1863
1864 /// <summary>
1865 /// Add a child prim to this parent prim.
1866 /// </summary>
1867 /// <param name="prim">Child prim</param>
1868 // I'm the parent
1869 // prim is the child
1870 public void ParentPrim(OdePrim prim)
1871 {
1872 //Console.WriteLine("ParentPrim " + m_primName);
1873 if (this.m_localID != prim.m_localID)
1874 {
1875 DestroyBody(); // for now we need to rebuil entire object on link change
1876
1877 lock (childrenPrim)
1878 {
1879 // adopt the prim
1880 if (!childrenPrim.Contains(prim))
1881 childrenPrim.Add(prim);
1882
1883 // see if this prim has kids and adopt them also
1884 // should not happen for now
1885 foreach (OdePrim prm in prim.childrenPrim)
1886 {
1887 if (!childrenPrim.Contains(prm))
1888 {
1889 if (prm.Body != IntPtr.Zero)
1890 {
1891 if (prm.prim_geom != IntPtr.Zero)
1892 d.GeomSetBody(prm.prim_geom, IntPtr.Zero);
1893 if(prm.Body != prim.Body)
1894 prm.DestroyBody(); // don't loose bodies around
1895 prm.Body = IntPtr.Zero;
1896 }
1897
1898 childrenPrim.Add(prm);
1899 prm._parent = this;
1900 }
1901 }
1902 }
1903 //Remove old children from the prim
1904 prim.childrenPrim.Clear();
1905
1906 if (prim.Body != IntPtr.Zero)
1907 {
1908 if (prim.prim_geom != IntPtr.Zero)
1909 d.GeomSetBody(prim.prim_geom, IntPtr.Zero);
1910 prim.DestroyBody(); // don't loose bodies around
1911 prim.Body = IntPtr.Zero;
1912 }
1913
1914 prim.childPrim = true;
1915 prim._parent = this;
1916
1917 MakeBody(); // full nasty reconstruction
1918 }
1919 }
1920
1921 private void UpdateChildsfromgeom()
1922 {
1923 if (childrenPrim.Count > 0)
1924 {
1925 foreach (OdePrim prm in childrenPrim)
1926 prm.UpdateDataFromGeom();
1927 }
1928 }
1929
1930 private void UpdateDataFromGeom()
1931 {
1932 if (prim_geom != IntPtr.Zero)
1933 {
1934 d.Vector3 lpos;
1935 d.GeomCopyPosition(prim_geom, out lpos);
1936 _position.X = lpos.X;
1937 _position.Y = lpos.Y;
1938 _position.Z = lpos.Z;
1939 d.Quaternion qtmp = new d.Quaternion { };
1940 d.GeomCopyQuaternion(prim_geom, out qtmp);
1941 _orientation.W = qtmp.W;
1942 _orientation.X = qtmp.X;
1943 _orientation.Y = qtmp.Y;
1944 _orientation.Z = qtmp.Z;
1945 }
1946 }
1947
1948 private void ChildDelink(OdePrim odePrim, bool remakebodies)
1949 {
1950 // Okay, we have a delinked child.. destroy all body and remake
1951 if (odePrim != this && !childrenPrim.Contains(odePrim))
1952 return;
1953
1954 DestroyBody();
1955
1956 if (odePrim == this) // delinking the root prim
1957 {
1958 OdePrim newroot = null;
1959 lock (childrenPrim)
1960 {
1961 if (childrenPrim.Count > 0)
1962 {
1963 newroot = childrenPrim[0];
1964 childrenPrim.RemoveAt(0);
1965 foreach (OdePrim prm in childrenPrim)
1966 {
1967 newroot.childrenPrim.Add(prm);
1968 }
1969 childrenPrim.Clear();
1970 }
1971 if (newroot != null)
1972 {
1973 newroot.childPrim = false;
1974 newroot._parent = null;
1975 if (remakebodies)
1976 newroot.MakeBody();
1977 }
1978 }
1979 }
1980
1981 else
1982 {
1983 lock (childrenPrim)
1984 {
1985 childrenPrim.Remove(odePrim);
1986 odePrim.childPrim = false;
1987 odePrim._parent = null;
1988 // odePrim.UpdateDataFromGeom();
1989 if (remakebodies)
1990 odePrim.MakeBody();
1991 }
1992 }
1993 if (remakebodies)
1994 MakeBody();
1995 }
1996
1997 protected void ChildRemove(OdePrim odePrim, bool reMakeBody)
1998 {
1999 // Okay, we have a delinked child.. destroy all body and remake
2000 if (odePrim != this && !childrenPrim.Contains(odePrim))
2001 return;
2002
2003 DestroyBody();
2004
2005 if (odePrim == this)
2006 {
2007 OdePrim newroot = null;
2008 lock (childrenPrim)
2009 {
2010 if (childrenPrim.Count > 0)
2011 {
2012 newroot = childrenPrim[0];
2013 childrenPrim.RemoveAt(0);
2014 foreach (OdePrim prm in childrenPrim)
2015 {
2016 newroot.childrenPrim.Add(prm);
2017 }
2018 childrenPrim.Clear();
2019 }
2020 if (newroot != null)
2021 {
2022 newroot.childPrim = false;
2023 newroot._parent = null;
2024 newroot.MakeBody();
2025 }
2026 }
2027 if (reMakeBody)
2028 MakeBody();
2029 return;
2030 }
2031 else
2032 {
2033 lock (childrenPrim)
2034 {
2035 childrenPrim.Remove(odePrim);
2036 odePrim.childPrim = false;
2037 odePrim._parent = null;
2038 if (reMakeBody)
2039 odePrim.MakeBody();
2040 }
2041 }
2042 MakeBody();
2043 }
2044
2045 #region changes
2046
2047 private void changeadd()
2048 {
2049 CreateGeom();
2050
2051 if (prim_geom != IntPtr.Zero)
2052 {
2053 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2054 d.Quaternion myrot = new d.Quaternion();
2055 myrot.X = _orientation.X;
2056 myrot.Y = _orientation.Y;
2057 myrot.Z = _orientation.Z;
2058 myrot.W = _orientation.W;
2059 d.GeomSetQuaternion(prim_geom, ref myrot);
2060 // _parent_scene.actor_name_map[prim_geom] = (PhysicsActor)this;
2061 if (!m_isphysical)
2062 SetInStaticSpace(this);
2063 }
2064
2065 m_building = false; // REMOVE THIS LATER
2066
2067
2068 if (m_isphysical && Body == IntPtr.Zero)
2069 {
2070/*
2071 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
2072 {
2073 changeShape(_pbs);
2074 }
2075 else
2076 {
2077 */
2078 MakeBody();
2079// }
2080 }
2081 }
2082
2083 private void changeAngularLock(Vector3 newLock)
2084 {
2085 // do we have a Physical object?
2086 if (Body != IntPtr.Zero)
2087 {
2088 //Check that we have a Parent
2089 //If we have a parent then we're not authorative here
2090 if (_parent == null)
2091 {
2092 if (!newLock.ApproxEquals(Vector3.One, 0f))
2093 {
2094 createAMotor(newLock);
2095 }
2096 else
2097 {
2098 if (Amotor != IntPtr.Zero)
2099 {
2100 d.JointDestroy(Amotor);
2101 Amotor = IntPtr.Zero;
2102 }
2103 }
2104 }
2105 }
2106 // Store this for later in case we get turned into a separate body
2107 m_angularlock = newLock;
2108 }
2109
2110 private void changeLink(OdePrim NewParent)
2111 {
2112 if (_parent == null && NewParent != null)
2113 {
2114 NewParent.ParentPrim(this);
2115 }
2116 else if (_parent != null)
2117 {
2118 if (_parent is OdePrim)
2119 {
2120 if (NewParent != _parent)
2121 {
2122 (_parent as OdePrim).ChildDelink(this,false); // for now...
2123 childPrim = false;
2124
2125 if (NewParent != null)
2126 {
2127 NewParent.ParentPrim(this);
2128 }
2129 }
2130 }
2131 }
2132 _parent = NewParent;
2133 }
2134
2135
2136 private void Stop()
2137 {
2138 if(!childPrim)
2139 {
2140 m_force = Vector3.Zero;
2141 m_forceacc = Vector3.Zero;
2142 m_angularForceacc = Vector3.Zero;
2143 _torque = Vector3.Zero;
2144 _velocity = Vector3.Zero;
2145 _acceleration = Vector3.Zero;
2146 m_rotationalVelocity = Vector3.Zero;
2147 _target_velocity = Vector3.Zero;
2148 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
2149 m_vehicle.Stop();
2150 }
2151
2152 if (Body != IntPtr.Zero)
2153 {
2154 d.BodySetForce(Body, 0f, 0f, 0f);
2155 d.BodySetTorque(Body, 0f, 0f, 0f);
2156 d.BodySetLinearVel(Body, 0f, 0f, 0f);
2157 d.BodySetAngularVel(Body, 0f, 0f, 0f);
2158
2159 }
2160 }
2161
2162 private void changeSelectedStatus(bool newval)
2163 {
2164 m_isSelected = newval;
2165 Stop();
2166
2167 if (newval)
2168 {
2169 m_collisionCategories = CollisionCategories.Selected;
2170 m_collisionFlags = (CollisionCategories.Sensor | CollisionCategories.Space);
2171
2172 if (prim_geom != IntPtr.Zero)
2173 {
2174 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
2175 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
2176 }
2177
2178 disableBodySoft();
2179 }
2180 else
2181 {
2182 m_collisionCategories = CollisionCategories.Geom;
2183
2184 if (m_isphysical)
2185 m_collisionCategories |= CollisionCategories.Body;
2186
2187 m_collisionFlags = m_default_collisionFlags;
2188
2189 if (m_collidesLand)
2190 m_collisionFlags |= CollisionCategories.Land;
2191 if (m_collidesWater)
2192 m_collisionFlags |= CollisionCategories.Water;
2193
2194 if (prim_geom != IntPtr.Zero)
2195 {
2196 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
2197 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
2198 }
2199
2200 enableBodySoft();
2201 }
2202
2203 resetCollisionAccounting();
2204 }
2205
2206 private void changePosition(Vector3 newPos)
2207 {
2208 if (m_isphysical)
2209 {
2210 if (childPrim) // inertia is messed, must rebuild
2211 {
2212 if (m_building)
2213 {
2214 _position = newPos;
2215 }
2216 }
2217 else
2218 {
2219 if (_position != newPos)
2220 {
2221 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2222 _position = newPos;
2223 }
2224 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2225 d.BodyEnable(Body);
2226 }
2227 }
2228 else
2229 {
2230 if (prim_geom != IntPtr.Zero)
2231 {
2232 if (newPos != _position)
2233 {
2234 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2235 _position = newPos;
2236
2237 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, _position, m_targetSpace);
2238 }
2239 }
2240 }
2241 givefakepos--;
2242 if (givefakepos < 0)
2243 givefakepos = 0;
2244// changeSelectedStatus();
2245 resetCollisionAccounting();
2246 }
2247
2248 private void changeOrientation(Quaternion newOri)
2249 {
2250 if (m_isphysical)
2251 {
2252 if (childPrim) // inertia is messed, must rebuild
2253 {
2254 if (m_building)
2255 {
2256 _orientation = newOri;
2257 }
2258 }
2259 else
2260 {
2261 if (newOri != _orientation)
2262 {
2263 d.Quaternion myrot = new d.Quaternion();
2264 myrot.X = newOri.X;
2265 myrot.Y = newOri.Y;
2266 myrot.Z = newOri.Z;
2267 myrot.W = newOri.W;
2268 d.GeomSetQuaternion(prim_geom, ref myrot);
2269 _orientation = newOri;
2270 if (Body != IntPtr.Zero && !m_angularlock.ApproxEquals(Vector3.One, 0f))
2271 createAMotor(m_angularlock);
2272 }
2273 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2274 d.BodyEnable(Body);
2275 }
2276 }
2277 else
2278 {
2279 if (prim_geom != IntPtr.Zero)
2280 {
2281 if (newOri != _orientation)
2282 {
2283 d.Quaternion myrot = new d.Quaternion();
2284 myrot.X = newOri.X;
2285 myrot.Y = newOri.Y;
2286 myrot.Z = newOri.Z;
2287 myrot.W = newOri.W;
2288 d.GeomSetQuaternion(prim_geom, ref myrot);
2289 _orientation = newOri;
2290 }
2291 }
2292 }
2293 givefakeori--;
2294 if (givefakeori < 0)
2295 givefakeori = 0;
2296 resetCollisionAccounting();
2297 }
2298
2299 private void changePositionAndOrientation(Vector3 newPos, Quaternion newOri)
2300 {
2301 if (m_isphysical)
2302 {
2303 if (childPrim && m_building) // inertia is messed, must rebuild
2304 {
2305 _position = newPos;
2306 _orientation = newOri;
2307 }
2308 else
2309 {
2310 if (newOri != _orientation)
2311 {
2312 d.Quaternion myrot = new d.Quaternion();
2313 myrot.X = newOri.X;
2314 myrot.Y = newOri.Y;
2315 myrot.Z = newOri.Z;
2316 myrot.W = newOri.W;
2317 d.GeomSetQuaternion(prim_geom, ref myrot);
2318 _orientation = newOri;
2319 if (Body != IntPtr.Zero && !m_angularlock.ApproxEquals(Vector3.One, 0f))
2320 createAMotor(m_angularlock);
2321 }
2322 if (_position != newPos)
2323 {
2324 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2325 _position = newPos;
2326 }
2327 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2328 d.BodyEnable(Body);
2329 }
2330 }
2331 else
2332 {
2333 // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
2334 // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
2335
2336 if (prim_geom != IntPtr.Zero)
2337 {
2338 if (newOri != _orientation)
2339 {
2340 d.Quaternion myrot = new d.Quaternion();
2341 myrot.X = newOri.X;
2342 myrot.Y = newOri.Y;
2343 myrot.Z = newOri.Z;
2344 myrot.W = newOri.W;
2345 d.GeomSetQuaternion(prim_geom, ref myrot);
2346 _orientation = newOri;
2347 }
2348
2349 if (newPos != _position)
2350 {
2351 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2352 _position = newPos;
2353
2354 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, _position, m_targetSpace);
2355 }
2356 }
2357 }
2358 givefakepos--;
2359 if (givefakepos < 0)
2360 givefakepos = 0;
2361 givefakeori--;
2362 if (givefakeori < 0)
2363 givefakeori = 0;
2364
2365 resetCollisionAccounting();
2366 }
2367
2368
2369 private void changeDisable(bool disable)
2370 {
2371 if (disable)
2372 {
2373 if (!m_disabled)
2374 disableBodySoft();
2375 }
2376 else
2377 {
2378 if (m_disabled)
2379 enableBodySoft();
2380 }
2381 }
2382
2383 private void changePhysicsStatus(bool NewStatus)
2384 {
2385 m_isphysical = NewStatus;
2386
2387 if (!childPrim)
2388 {
2389 if (NewStatus)
2390 {
2391 if (Body == IntPtr.Zero)
2392 {
2393/*
2394 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
2395 {
2396 changeShape(_pbs);
2397 }
2398 else
2399 */
2400 {
2401 MakeBody();
2402 }
2403 }
2404 }
2405 else
2406 {
2407 if (Body != IntPtr.Zero)
2408 {
2409 // UpdateChildsfromgeom();
2410/* if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
2411 {
2412 changeShape(_pbs);
2413 }
2414 else
2415 */
2416 DestroyBody();
2417 }
2418 }
2419 }
2420
2421 resetCollisionAccounting();
2422 }
2423
2424 private void changeprimsizeshape()
2425 {
2426 OdePrim parent = (OdePrim)_parent;
2427
2428 bool chp = childPrim;
2429
2430 if (chp)
2431 {
2432 if (parent != null)
2433 {
2434 parent.DestroyBody();
2435 }
2436 }
2437 else
2438 {
2439 DestroyBody();
2440 }
2441
2442 RemoveGeom();
2443
2444 // we don't need to do space calculation because the client sends a position update also.
2445 if (_size.X <= 0)
2446 _size.X = 0.01f;
2447 if (_size.Y <= 0)
2448 _size.Y = 0.01f;
2449 if (_size.Z <= 0)
2450 _size.Z = 0.01f;
2451 // Construction of new prim
2452
2453 CreateGeom();
2454
2455 if (prim_geom != IntPtr.Zero)
2456 {
2457 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2458 d.Quaternion myrot = new d.Quaternion();
2459 myrot.X = _orientation.X;
2460 myrot.Y = _orientation.Y;
2461 myrot.Z = _orientation.Z;
2462 myrot.W = _orientation.W;
2463 d.GeomSetQuaternion(prim_geom, ref myrot);
2464 }
2465
2466 if (chp)
2467 {
2468 if (parent != null)
2469 {
2470 parent.MakeBody();
2471 }
2472 }
2473 else
2474 MakeBody();
2475
2476 resetCollisionAccounting();
2477 }
2478
2479 private void changeSize(Vector3 newSize)
2480 {
2481 _size = newSize;
2482 changeprimsizeshape();
2483 }
2484
2485 private void changeShape(PrimitiveBaseShape newShape)
2486 {
2487 _pbs = newShape;
2488 changeprimsizeshape();
2489 }
2490
2491 private void changeFloatOnWater(bool newval)
2492 {
2493 m_collidesWater = newval;
2494
2495 if (prim_geom != IntPtr.Zero)
2496 {
2497 if (m_collidesWater)
2498 {
2499 m_collisionFlags |= CollisionCategories.Water;
2500 }
2501 else
2502 {
2503 m_collisionFlags &= ~CollisionCategories.Water;
2504 }
2505 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
2506 }
2507 }
2508
2509 private void changeSetTorque(Vector3 newtorque)
2510 {
2511 if (!m_isSelected)
2512 {
2513 if (m_isphysical && Body != IntPtr.Zero)
2514 {
2515 if (m_disabled)
2516 enableBodySoft();
2517 else if (!d.BodyIsEnabled(Body))
2518 d.BodyEnable(Body);
2519
2520 }
2521 _torque = newtorque;
2522 }
2523 }
2524
2525 private void changeForce(Vector3 force)
2526 {
2527 m_force = force;
2528 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2529 d.BodyEnable(Body);
2530 }
2531
2532 private void changeAddForce(Vector3 force)
2533 {
2534 m_forceacc += force;
2535 if (!m_isSelected)
2536 {
2537 lock (this)
2538 {
2539 //m_log.Info("[PHYSICS]: dequeing forcelist");
2540 if (m_isphysical && Body != IntPtr.Zero)
2541 {
2542 if (m_disabled)
2543 enableBodySoft();
2544 else if (!d.BodyIsEnabled(Body))
2545 d.BodyEnable(Body);
2546 }
2547 }
2548
2549 m_collisionscore = 0;
2550 m_interpenetrationcount = 0;
2551 }
2552 }
2553
2554 private void changeAddAngularForce(Vector3 aforce)
2555 {
2556 m_angularForceacc += aforce;
2557 if (!m_isSelected)
2558 {
2559 lock (this)
2560 {
2561 if (m_isphysical && Body != IntPtr.Zero)
2562 {
2563 if (m_disabled)
2564 enableBodySoft();
2565 else if (!d.BodyIsEnabled(Body))
2566 d.BodyEnable(Body);
2567 }
2568 }
2569 m_collisionscore = 0;
2570 m_interpenetrationcount = 0;
2571 }
2572 }
2573
2574 private void changevelocity(Vector3 newVel)
2575 {
2576 if (!m_isSelected)
2577 {
2578 if (Body != IntPtr.Zero)
2579 {
2580 if (m_disabled)
2581 enableBodySoft();
2582 else if (!d.BodyIsEnabled(Body))
2583 d.BodyEnable(Body);
2584
2585 d.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z);
2586 }
2587 //resetCollisionAccounting();
2588 }
2589 _velocity = newVel;
2590 }
2591
2592 private void changeVolumedetetion(bool newVolDtc)
2593 {
2594 m_isVolumeDetect = newVolDtc;
2595 }
2596
2597 protected void changeBuilding(bool newbuilding)
2598 {
2599 if ((bool)newbuilding)
2600 {
2601 m_building = true;
2602 DestroyBody();
2603 }
2604 else
2605 {
2606 m_building = false;
2607 if (!childPrim)
2608 MakeBody();
2609 }
2610 if (!childPrim && childrenPrim.Count > 0)
2611 {
2612 foreach (OdePrim prm in childrenPrim)
2613 prm.changeBuilding(m_building); // call directly
2614 }
2615 }
2616
2617 #endregion
2618
2619 public void Move()
2620 {
2621 if (!childPrim && m_isphysical && Body != IntPtr.Zero &&
2622 !m_disabled && !m_isSelected && d.BodyIsEnabled(Body) && !m_building) // KF: Only move root prims.
2623 {
2624// if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body); // KF add 161009
2625
2626 float timestep = _parent_scene.ODE_STEPSIZE;
2627
2628 float fx = 0;
2629 float fy = 0;
2630 float fz = 0;
2631
2632 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
2633 {
2634 // 'VEHICLES' are dealt with in ODEDynamics.cs
2635 m_vehicle.Step();
2636 }
2637 else
2638 {
2639 float m_mass = _mass;
2640
2641 // fz = 0f;
2642 //m_log.Info(m_collisionFlags.ToString());
2643 if (m_usePID)
2644 {
2645
2646 // If the PID Controller isn't active then we set our force
2647 // calculating base velocity to the current position
2648
2649 if ((m_PIDTau < 1) && (m_PIDTau != 0))
2650 {
2651 //PID_G = PID_G / m_PIDTau;
2652 m_PIDTau = 1;
2653 }
2654
2655 if ((PID_G - m_PIDTau) <= 0)
2656 {
2657 PID_G = m_PIDTau + 1;
2658 }
2659
2660 d.Vector3 vel = d.BodyGetLinearVel(Body);
2661 d.Vector3 pos = d.BodyGetPosition(Body);
2662 _target_velocity =
2663 new Vector3(
2664 (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep),
2665 (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep),
2666 (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep)
2667 );
2668
2669 // if velocity is zero, use position control; otherwise, velocity control
2670
2671 if (_target_velocity.ApproxEquals(Vector3.Zero, 0.1f))
2672 {
2673 // keep track of where we stopped. No more slippin' & slidin'
2674
2675 // We only want to deactivate the PID Controller if we think we want to have our surrogate
2676 // react to the physics scene by moving it's position.
2677 // Avatar to Avatar collisions
2678 // Prim to avatar collisions
2679
2680 //fx = (_target_velocity.X - vel.X) * (PID_D) + (_zeroPosition.X - pos.X) * (PID_P * 2);
2681 //fy = (_target_velocity.Y - vel.Y) * (PID_D) + (_zeroPosition.Y - pos.Y) * (PID_P * 2);
2682 //fz = fz + (_target_velocity.Z - vel.Z) * (PID_D) + (_zeroPosition.Z - pos.Z) * PID_P;
2683 d.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z);
2684 d.BodySetLinearVel(Body, 0, 0, 0);
2685 d.BodyAddForce(Body, 0, 0, fz);
2686 return;
2687 }
2688 else
2689 {
2690 _zeroFlag = false;
2691
2692 // We're flying and colliding with something
2693 fx = ((_target_velocity.X) - vel.X) * (PID_D);
2694 fy = ((_target_velocity.Y) - vel.Y) * (PID_D);
2695
2696 // vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P;
2697
2698 fz = ((_target_velocity.Z - vel.Z) * (PID_D));
2699 }
2700 } // end if (m_usePID)
2701
2702 // Hover PID Controller needs to be mutually exlusive to MoveTo PID controller
2703 else if (m_useHoverPID)
2704 {
2705 //Console.WriteLine("Hover " + Name);
2706
2707 // If we're using the PID controller, then we have no gravity
2708
2709 // no lock; for now it's only called from within Simulate()
2710
2711 // If the PID Controller isn't active then we set our force
2712 // calculating base velocity to the current position
2713
2714 if ((m_PIDTau < 1))
2715 {
2716 PID_G = PID_G / m_PIDTau;
2717 }
2718
2719 if ((PID_G - m_PIDTau) <= 0)
2720 {
2721 PID_G = m_PIDTau + 1;
2722 }
2723
2724 // Where are we, and where are we headed?
2725 d.Vector3 pos = d.BodyGetPosition(Body);
2726 d.Vector3 vel = d.BodyGetLinearVel(Body);
2727
2728 // Non-Vehicles have a limited set of Hover options.
2729 // determine what our target height really is based on HoverType
2730 switch (m_PIDHoverType)
2731 {
2732 case PIDHoverType.Ground:
2733 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y);
2734 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
2735 break;
2736 case PIDHoverType.GroundAndWater:
2737 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y);
2738 m_waterHeight = _parent_scene.GetWaterLevel();
2739 if (m_groundHeight > m_waterHeight)
2740 {
2741 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
2742 }
2743 else
2744 {
2745 m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight;
2746 }
2747 break;
2748
2749 } // end switch (m_PIDHoverType)
2750
2751
2752 _target_velocity =
2753 new Vector3(0.0f, 0.0f,
2754 (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep)
2755 );
2756
2757 // if velocity is zero, use position control; otherwise, velocity control
2758
2759 if (_target_velocity.ApproxEquals(Vector3.Zero, 0.1f))
2760 {
2761 // keep track of where we stopped. No more slippin' & slidin'
2762
2763 // We only want to deactivate the PID Controller if we think we want to have our surrogate
2764 // react to the physics scene by moving it's position.
2765 // Avatar to Avatar collisions
2766 // Prim to avatar collisions
2767
2768 d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight);
2769 d.BodySetLinearVel(Body, vel.X, vel.Y, 0);
2770 // ? d.BodyAddForce(Body, 0, 0, fz);
2771 return;
2772 }
2773 else
2774 {
2775 _zeroFlag = false;
2776
2777 // We're flying and colliding with something
2778 fz = ((_target_velocity.Z - vel.Z) * (PID_D));
2779 }
2780 }
2781 else
2782 {
2783 float b = (1.0f - m_buoyancy);
2784 fx = _parent_scene.gravityx * b;
2785 fy = _parent_scene.gravityy * b;
2786 fz = _parent_scene.gravityz * b;
2787 }
2788
2789 fx *= m_mass;
2790 fy *= m_mass;
2791 fz *= m_mass;
2792
2793 // constant force
2794 fx += m_force.X;
2795 fy += m_force.Y;
2796 fz += m_force.Z;
2797
2798 fx += m_forceacc.X;
2799 fy += m_forceacc.Y;
2800 fz += m_forceacc.Z;
2801
2802 m_forceacc = Vector3.Zero;
2803
2804 //m_log.Info("[OBJPID]: X:" + fx.ToString() + " Y:" + fy.ToString() + " Z:" + fz.ToString());
2805 if (fx != 0 || fy != 0 || fz != 0)
2806 {
2807 d.BodyAddForce(Body, fx, fy, fz);
2808 //Console.WriteLine("AddForce " + fx + "," + fy + "," + fz);
2809 }
2810
2811 Vector3 trq;
2812
2813 trq = _torque;
2814 trq += m_angularForceacc;
2815 m_angularForceacc = Vector3.Zero;
2816 if (trq.X != 0 || trq.Y != 0 || trq.Z != 0)
2817 {
2818 d.BodyAddTorque(Body, trq.X, trq.Y, trq.Z);
2819 }
2820
2821 }
2822 }
2823 else
2824 { // is not physical, or is not a body or is selected
2825 // _zeroPosition = d.BodyGetPosition(Body);
2826 return;
2827 //Console.WriteLine("Nothing " + Name);
2828
2829 }
2830 }
2831
2832
2833 public void UpdatePositionAndVelocity(float simulatedtime)
2834 {
2835 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
2836 if (_parent == null && !m_disabled && !m_building)
2837 {
2838 if (Body != IntPtr.Zero)
2839 {
2840 if (m_crossingfailures != 0 && m_crossingfailures < 5)
2841 {
2842 _position.X = Util.Clip(_position.X, 0.4f, _parent_scene.WorldExtents.X - 0.4f);
2843 _position.Y = Util.Clip(_position.Y, 0.4f, _parent_scene.WorldExtents.Y - 0.4f);
2844 _position.Z = Util.Clip(_position.Z + 0.2f, -100f, 50000f);
2845
2846 float tmp = _parent_scene.GetTerrainHeightAtXY(_position.X, _position.Y);
2847 if (_position.Z < tmp)
2848 _position.Z = tmp + 0.2f;
2849
2850 m_lastposition = _position;
2851 m_lastorientation = _orientation;
2852 _velocity.X = 0;
2853 _velocity.Y = 0;
2854 _velocity.Z = 0;
2855
2856 m_lastVelocity = _velocity;
2857 m_rotationalVelocity = _velocity;
2858 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
2859 m_vehicle.Stop();
2860
2861 m_crossingfailures = 0; // do this only once
2862 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
2863 d.BodySetAngularVel(Body, 0, 0, 0);
2864 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2865 enableBodySoft();
2866 base.RequestPhysicsterseUpdate();
2867 return;
2868 }
2869
2870 else if (m_crossingfailures != 0)
2871 {
2872 return;
2873 }
2874
2875 Vector3 pv = Vector3.Zero;
2876 bool lastZeroFlag = _zeroFlag;
2877
2878 d.Vector3 lpos;
2879 d.GeomCopyPosition(prim_geom,out lpos); // root position that is seem by rest of simulator
2880
2881 // we need to use root position since that's all the rest of scene uses
2882 if ( lpos.X < 0f || lpos.X > _parent_scene.WorldExtents.X
2883 || lpos.Y < 0f || lpos.Y > _parent_scene.WorldExtents.Y
2884 )
2885 {
2886 // we are outside current region
2887 // we can't let it keeping moving and having colisions
2888 // since it can be stucked between something like terrain and edge
2889 // so lets stop and disable it until something else kicks it
2890 if (m_crossingfailures == 0)
2891 {
2892
2893 _position.X = Util.Clip(lpos.X, -0.5f, _parent_scene.WorldExtents.X + 0.5f);
2894 _position.Y = Util.Clip(lpos.Y, -0.5f, _parent_scene.WorldExtents.Y + 0.5f);
2895 _position.Z = Util.Clip(lpos.Z, -100f, 50000f);
2896
2897 m_lastposition = _position;
2898 m_lastorientation = _orientation;
2899
2900 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
2901 d.BodySetAngularVel(Body, 0, 0, 0);
2902 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2903 disableBodySoft(); // stop collisions
2904 m_crossingfailures++; // do this only once
2905 base.RequestPhysicsterseUpdate();
2906 return;
2907 }
2908 }
2909
2910 if (lpos.Z < -100 || lpos.Z > 100000f)
2911 {
2912 lpos.Z = Util.Clip(lpos.Z, -100f, 50000f);
2913
2914 _acceleration.X = 0;
2915 _acceleration.Y = 0;
2916 _acceleration.Z = 0;
2917
2918 _velocity.X = 0;
2919 _velocity.Y = 0;
2920 _velocity.Z = 0;
2921 m_rotationalVelocity.X = 0;
2922 m_rotationalVelocity.Y = 0;
2923 m_rotationalVelocity.Z = 0;
2924
2925 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
2926 d.BodySetAngularVel(Body, 0, 0, 0); // stop it
2927 d.BodySetPosition(Body, lpos.X, lpos.Y, lpos.Z); // put it somewhere
2928 m_lastposition = _position;
2929 m_lastorientation = _orientation;
2930
2931 base.RequestPhysicsterseUpdate();
2932
2933 m_throttleUpdates = false;
2934 throttleCounter = 0;
2935 _zeroFlag = true;
2936
2937 disableBodySoft(); // disable it and colisions
2938 base.RaiseOutOfBounds(_position);
2939
2940 return;
2941 }
2942
2943 d.Quaternion ori;
2944 d.GeomCopyQuaternion(prim_geom, out ori);
2945 d.Vector3 vel = d.BodyGetLinearVel(Body);
2946 d.Vector3 rotvel = d.BodyGetAngularVel(Body);
2947
2948 if ((Math.Abs(m_lastposition.X - lpos.X) < 0.01)
2949 && (Math.Abs(m_lastposition.Y - lpos.Y) < 0.01)
2950 && (Math.Abs(m_lastposition.Z - lpos.Z) < 0.01)
2951 && (Math.Abs(m_lastorientation.X - ori.X) < 0.0001)
2952 && (Math.Abs(m_lastorientation.Y - ori.Y) < 0.0001)
2953 && (Math.Abs(m_lastorientation.Z - ori.Z) < 0.0001)
2954 )
2955 {
2956 _zeroFlag = true;
2957 //Console.WriteLine("ZFT 2");
2958 m_throttleUpdates = false;
2959 }
2960 else
2961 {
2962 //m_log.Debug(Math.Abs(m_lastposition.X - l_position.X).ToString());
2963 _zeroFlag = false;
2964 m_lastUpdateSent = false;
2965 //m_throttleUpdates = false;
2966 }
2967
2968 if (_zeroFlag)
2969 {
2970 m_lastposition = _position;
2971 m_lastorientation = _orientation;
2972
2973 _velocity.X = 0.0f;
2974 _velocity.Y = 0.0f;
2975 _velocity.Z = 0.0f;
2976
2977 _acceleration.X = 0;
2978 _acceleration.Y = 0;
2979 _acceleration.Z = 0;
2980
2981 m_rotationalVelocity.X = 0;
2982 m_rotationalVelocity.Y = 0;
2983 m_rotationalVelocity.Z = 0;
2984 if (!m_lastUpdateSent)
2985 {
2986 m_throttleUpdates = false;
2987 throttleCounter = 0;
2988 m_rotationalVelocity = pv;
2989
2990 base.RequestPhysicsterseUpdate();
2991
2992 m_lastUpdateSent = true;
2993 }
2994 }
2995 else
2996 {
2997 if (lastZeroFlag != _zeroFlag)
2998 {
2999 base.RequestPhysicsterseUpdate();
3000 }
3001
3002 m_lastVelocity = _velocity;
3003
3004 _position.X = lpos.X;
3005 _position.Y = lpos.Y;
3006 _position.Z = lpos.Z;
3007
3008 _velocity.X = vel.X;
3009 _velocity.Y = vel.Y;
3010 _velocity.Z = vel.Z;
3011
3012 _orientation.X = ori.X;
3013 _orientation.Y = ori.Y;
3014 _orientation.Z = ori.Z;
3015 _orientation.W = ori.W;
3016
3017 _acceleration = ((_velocity - m_lastVelocity) / simulatedtime);
3018
3019 if (m_rotationalVelocity.ApproxEquals(pv, 0.0001f))
3020 {
3021 m_rotationalVelocity = pv;
3022 }
3023 else
3024 {
3025 m_rotationalVelocity.X = rotvel.X;
3026 m_rotationalVelocity.Y = rotvel.Y;
3027 m_rotationalVelocity.Z = rotvel.Z;
3028 }
3029
3030 m_lastUpdateSent = false;
3031 if (!m_throttleUpdates || throttleCounter > _parent_scene.geomUpdatesPerThrottledUpdate)
3032 {
3033 m_lastposition = _position;
3034 m_lastorientation = _orientation;
3035 base.RequestPhysicsterseUpdate();
3036 }
3037 else
3038 {
3039 throttleCounter++;
3040 }
3041 }
3042 }
3043 else if (!m_lastUpdateSent || !_zeroFlag)
3044 {
3045 // Not a body.. so Make sure the client isn't interpolating
3046 _velocity.X = 0;
3047 _velocity.Y = 0;
3048 _velocity.Z = 0;
3049
3050 _acceleration.X = 0;
3051 _acceleration.Y = 0;
3052 _acceleration.Z = 0;
3053
3054 m_rotationalVelocity.X = 0;
3055 m_rotationalVelocity.Y = 0;
3056 m_rotationalVelocity.Z = 0;
3057 _zeroFlag = true;
3058
3059 if (!m_lastUpdateSent)
3060 {
3061 m_throttleUpdates = false;
3062 throttleCounter = 0;
3063
3064 base.RequestPhysicsterseUpdate();
3065
3066 m_lastUpdateSent = true;
3067 }
3068 }
3069 }
3070 }
3071
3072 internal static bool QuaternionIsFinite(Quaternion q)
3073 {
3074 if (Single.IsNaN(q.X) || Single.IsInfinity(q.X))
3075 return false;
3076 if (Single.IsNaN(q.Y) || Single.IsInfinity(q.Y))
3077 return false;
3078 if (Single.IsNaN(q.Z) || Single.IsInfinity(q.Z))
3079 return false;
3080 if (Single.IsNaN(q.W) || Single.IsInfinity(q.W))
3081 return false;
3082 return true;
3083 }
3084
3085 internal static void DMassCopy(ref d.Mass src, ref d.Mass dst)
3086 {
3087 dst.c.W = src.c.W;
3088 dst.c.X = src.c.X;
3089 dst.c.Y = src.c.Y;
3090 dst.c.Z = src.c.Z;
3091 dst.mass = src.mass;
3092 dst.I.M00 = src.I.M00;
3093 dst.I.M01 = src.I.M01;
3094 dst.I.M02 = src.I.M02;
3095 dst.I.M10 = src.I.M10;
3096 dst.I.M11 = src.I.M11;
3097 dst.I.M12 = src.I.M12;
3098 dst.I.M20 = src.I.M20;
3099 dst.I.M21 = src.I.M21;
3100 dst.I.M22 = src.I.M22;
3101 }
3102
3103 private static void DMassDup(ref d.Mass src, out d.Mass dst)
3104 {
3105 dst = new d.Mass { };
3106
3107 dst.c.W = src.c.W;
3108 dst.c.X = src.c.X;
3109 dst.c.Y = src.c.Y;
3110 dst.c.Z = src.c.Z;
3111 dst.mass = src.mass;
3112 dst.I.M00 = src.I.M00;
3113 dst.I.M01 = src.I.M01;
3114 dst.I.M02 = src.I.M02;
3115 dst.I.M10 = src.I.M10;
3116 dst.I.M11 = src.I.M11;
3117 dst.I.M12 = src.I.M12;
3118 dst.I.M20 = src.I.M20;
3119 dst.I.M21 = src.I.M21;
3120 dst.I.M22 = src.I.M22;
3121 }
3122 private void donullchange()
3123 {
3124 }
3125
3126 public bool DoAChange(changes what, object arg)
3127 {
3128 if (prim_geom == IntPtr.Zero && what != changes.Add && what != changes.Remove)
3129 {
3130 return false;
3131 }
3132
3133 // nasty switch
3134 switch (what)
3135 {
3136 case changes.Add:
3137 changeadd();
3138 break;
3139 case changes.Remove:
3140 //If its being removed, we don't want to rebuild the physical rep at all, so ignore this stuff...
3141 //When we return true, it destroys all of the prims in the linkset anyway
3142 if (_parent != null)
3143 {
3144 OdePrim parent = (OdePrim)_parent;
3145 parent.ChildRemove(this,false);
3146 }
3147 else
3148 ChildRemove(this,false);
3149
3150 RemoveGeom();
3151 m_targetSpace = IntPtr.Zero;
3152 if (m_eventsubscription > 0)
3153 UnSubscribeEvents();
3154 return true;
3155
3156 case changes.Link:
3157 OdePrim tmp = (OdePrim)arg;
3158 changeLink(tmp);
3159 break;
3160
3161 case changes.DeLink:
3162 changeLink(null);
3163 break;
3164
3165 case changes.Position:
3166 changePosition((Vector3)arg);
3167 break;
3168
3169 case changes.Orientation:
3170 changeOrientation((Quaternion)arg);
3171 break;
3172
3173 case changes.PosOffset:
3174 donullchange();
3175 break;
3176
3177 case changes.OriOffset:
3178 donullchange();
3179 break;
3180
3181 case changes.Velocity:
3182 changevelocity((Vector3)arg);
3183 break;
3184
3185// case changes.Acceleration:
3186// changeacceleration((Vector3)arg);
3187// break;
3188// case changes.AngVelocity:
3189// changeangvelocity((Vector3)arg);
3190// break;
3191
3192 case changes.Force:
3193 changeForce((Vector3)arg);
3194 break;
3195
3196 case changes.Torque:
3197 changeSetTorque((Vector3)arg);
3198 break;
3199
3200 case changes.AddForce:
3201 changeAddForce((Vector3)arg);
3202 break;
3203
3204 case changes.AddAngForce:
3205 changeAddAngularForce((Vector3)arg);
3206 break;
3207
3208 case changes.AngLock:
3209 changeAngularLock((Vector3)arg);
3210 break;
3211
3212 case changes.Size:
3213 changeSize((Vector3)arg);
3214 break;
3215
3216 case changes.Shape:
3217 changeShape((PrimitiveBaseShape) arg);
3218 break;
3219
3220 case changes.CollidesWater:
3221 changeFloatOnWater((bool)arg);
3222 break;
3223
3224 case changes.VolumeDtc:
3225 changeVolumedetetion((bool)arg);
3226 break;
3227
3228 case changes.Physical:
3229 changePhysicsStatus((bool)arg);
3230 break;
3231
3232 case changes.Selected:
3233 changeSelectedStatus((bool)arg);
3234 break;
3235
3236 case changes.disabled:
3237 changeDisable((bool) arg);
3238 break;
3239
3240 case changes.building:
3241 changeBuilding((bool)arg);
3242 break;
3243
3244 case changes.Null:
3245 donullchange();
3246 break;
3247
3248 default:
3249 donullchange();
3250 break;
3251 }
3252 return false;
3253 }
3254
3255 public void AddChange(changes what, object arg)
3256 {
3257 _parent_scene.AddChange(this, what, arg);
3258 }
3259 }
3260}
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs
new file mode 100644
index 0000000..4b3f83b
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs
@@ -0,0 +1,443 @@
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 System.Text;
33using OpenMetaverse;
34using OpenSim.Region.Physics.Manager;
35using OdeAPI;
36using log4net;
37
38namespace OpenSim.Region.Physics.OdePlugin
39{
40 /// <summary>
41 /// Processes raycast requests as ODE is in a state to be able to do them.
42 /// This ensures that it's thread safe and there will be no conflicts.
43 /// Requests get returned by a different thread then they were requested by.
44 /// </summary>
45 public class ODERayCastRequestManager
46 {
47 /// <summary>
48 /// Pending ray requests
49 /// </summary>
50 protected OpenSim.Framework.LocklessQueue<ODERayRequest> m_PendingRequests = new OpenSim.Framework.LocklessQueue<ODERayRequest>();
51
52 /// <summary>
53 /// Scene that created this object.
54 /// </summary>
55 private OdeScene m_scene;
56
57 IntPtr ray;
58
59 private const int ColisionContactGeomsPerTest = 5;
60
61 /// <summary>
62 /// ODE near callback delegate
63 /// </summary>
64 private d.NearCallback nearCallback;
65 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
66 private List<ContactResult> m_contactResults = new List<ContactResult>();
67
68 public ODERayCastRequestManager(OdeScene pScene)
69 {
70 m_scene = pScene;
71 nearCallback = near;
72 ray = d.CreateRay(IntPtr.Zero, 1.0f);
73 }
74
75 /// <summary>
76 /// Queues a raycast
77 /// </summary>
78 /// <param name="position">Origin of Ray</param>
79 /// <param name="direction">Ray normal</param>
80 /// <param name="length">Ray length</param>
81 /// <param name="retMethod">Return method to send the results</param>
82 public void QueueRequest(Vector3 position, Vector3 direction, float length, RayCallback retMethod)
83 {
84 ODERayRequest req = new ODERayRequest();
85 req.geom = IntPtr.Zero;
86 req.callbackMethod = retMethod;
87 req.Count = 0;
88 req.length = length;
89 req.Normal = direction;
90 req.Origin = position;
91
92 m_PendingRequests.Enqueue(req);
93 }
94
95 public void QueueRequest(IntPtr geom, Vector3 position, Vector3 direction, float length, RayCallback retMethod)
96 {
97 ODERayRequest req = new ODERayRequest();
98 req.geom = geom;
99 req.callbackMethod = retMethod;
100 req.length = length;
101 req.Normal = direction;
102 req.Origin = position;
103 req.Count = 0;
104
105 m_PendingRequests.Enqueue(req);
106 }
107
108 public void QueueRequest(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
109 {
110 ODERayRequest req = new ODERayRequest();
111 req.geom = IntPtr.Zero;
112 req.callbackMethod = retMethod;
113 req.Count = 0;
114 req.length = length;
115 req.Normal = direction;
116 req.Origin = position;
117
118 m_PendingRequests.Enqueue(req);
119 }
120
121 public void QueueRequest(IntPtr geom, Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
122 {
123 ODERayRequest req = new ODERayRequest();
124 req.geom = geom;
125 req.callbackMethod = retMethod;
126 req.length = length;
127 req.Normal = direction;
128 req.Origin = position;
129 req.Count = 0;
130
131 m_PendingRequests.Enqueue(req);
132 }
133
134 /// <summary>
135 /// Queues a raycast
136 /// </summary>
137 /// <param name="position">Origin of Ray</param>
138 /// <param name="direction">Ray normal</param>
139 /// <param name="length">Ray length</param>
140 /// <param name="count"></param>
141 /// <param name="retMethod">Return method to send the results</param>
142 public void QueueRequest(Vector3 position, Vector3 direction, float length, int count, RayCallback retMethod)
143 {
144 ODERayRequest req = new ODERayRequest();
145 req.geom = IntPtr.Zero;
146 req.callbackMethod = retMethod;
147 req.length = length;
148 req.Normal = direction;
149 req.Origin = position;
150 req.Count = count;
151
152 m_PendingRequests.Enqueue(req);
153 }
154
155 public void QueueRequest(IntPtr geom, Vector3 position, Vector3 direction, float length, int count, RayCallback retMethod)
156 {
157 ODERayRequest req = new ODERayRequest();
158 req.geom = geom;
159 req.callbackMethod = retMethod;
160 req.length = length;
161 req.Normal = direction;
162 req.Origin = position;
163 req.Count = count;
164
165 m_PendingRequests.Enqueue(req);
166 }
167
168 public void QueueRequest(Vector3 position, Vector3 direction, float length, int count, RaycastCallback retMethod)
169 {
170 ODERayRequest req = new ODERayRequest();
171 req.geom = IntPtr.Zero;
172 req.callbackMethod = retMethod;
173 req.length = length;
174 req.Normal = direction;
175 req.Origin = position;
176 req.Count = count;
177
178 m_PendingRequests.Enqueue(req);
179 }
180
181 public void QueueRequest(IntPtr geom, Vector3 position, Vector3 direction, float length, int count, RaycastCallback retMethod)
182 {
183 ODERayRequest req = new ODERayRequest();
184 req.geom = geom;
185 req.callbackMethod = retMethod;
186 req.length = length;
187 req.Normal = direction;
188 req.Origin = position;
189 req.Count = count;
190
191 m_PendingRequests.Enqueue(req);
192 }
193
194 /// <summary>
195 /// Process all queued raycast requests
196 /// </summary>
197 /// <returns>Time in MS the raycasts took to process.</returns>
198 public int ProcessQueuedRequests()
199 {
200 int time = System.Environment.TickCount;
201
202 if (m_PendingRequests.Count <= 0)
203 return 0;
204
205 if (m_scene.ContactgeomsArray == IntPtr.Zero) // oops something got wrong or scene isn't ready still
206 {
207 m_PendingRequests.Clear();
208 return 0;
209 }
210
211 ODERayRequest req;
212
213 int i = 50; // arbitary limit of processed tests per frame
214
215 while(m_PendingRequests.Dequeue(out req))
216 {
217 if (req.geom == IntPtr.Zero)
218 doSpaceRay(req);
219 else
220 doGeomRay(req);
221 if(--i < 0)
222 break;
223 }
224
225 lock (m_contactResults)
226 m_contactResults.Clear();
227
228 return System.Environment.TickCount - time;
229 }
230 /// <summary>
231 /// Method that actually initiates the raycast with full top space
232 /// </summary>
233 /// <param name="req"></param>
234 private void doSpaceRay(ODERayRequest req)
235 {
236 // Create the ray
237// IntPtr ray = d.CreateRay(m_scene.TopSpace, req.length);
238 d.GeomRaySetLength(ray, req.length);
239 d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
240
241 // Collide test
242 d.SpaceCollide2(m_scene.TopSpace, ray, IntPtr.Zero, nearCallback);
243
244 // Remove Ray
245// d.GeomDestroy(ray);
246
247 if (req.callbackMethod == null)
248 return;
249
250 if (req.callbackMethod is RaycastCallback)
251 {
252 // Define default results
253 bool hitYN = false;
254 uint hitConsumerID = 0;
255 float distance = 999999999999f;
256 Vector3 closestcontact = new Vector3(99999f, 99999f, 99999f);
257 Vector3 snormal = Vector3.Zero;
258
259 // Find closest contact and object.
260 lock (m_contactResults)
261 {
262 foreach (ContactResult cResult in m_contactResults)
263 {
264 if (Vector3.Distance(req.Origin, cResult.Pos) < Vector3.Distance(req.Origin, closestcontact))
265 {
266 closestcontact = cResult.Pos;
267 hitConsumerID = cResult.ConsumerID;
268 distance = cResult.Depth;
269 hitYN = true;
270 snormal = cResult.Normal;
271 }
272 }
273 m_contactResults.Clear();
274 }
275
276 ((RaycastCallback)req.callbackMethod)(hitYN, closestcontact, hitConsumerID, distance, snormal);
277 }
278 else
279 {
280 ((RayCallback)req.callbackMethod)(m_contactResults);
281 lock (m_PendingRequests)
282 m_contactResults.Clear();
283 }
284 }
285
286 /// <summary>
287 /// Method that actually initiates the raycast with a geom
288 /// </summary>
289 /// <param name="req"></param>
290 private void doGeomRay(ODERayRequest req)
291 {
292 // Create the ray
293// IntPtr ray = d.CreateRay(m_scene.TopSpace, req.length);
294 d.GeomRaySetLength(ray, req.length);
295 d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
296
297 // Collide test
298 d.SpaceCollide2(req.geom, ray, IntPtr.Zero, nearCallback); // still do this to have full AABB pre test
299
300 // Remove Ray
301// d.GeomDestroy(ray);
302
303 if (req.callbackMethod == null)
304 return;
305
306 if (req.callbackMethod is RaycastCallback)
307 {
308 // Define default results
309 bool hitYN = false;
310 uint hitConsumerID = 0;
311 float distance = 999999999999f;
312 Vector3 closestcontact = new Vector3(99999f, 99999f, 99999f);
313 Vector3 snormal = Vector3.Zero;
314
315 // Find closest contact and object.
316 lock (m_contactResults)
317 {
318 foreach (ContactResult cResult in m_contactResults)
319 {
320 if (Vector3.Distance(req.Origin, cResult.Pos) < Vector3.Distance(req.Origin, closestcontact))
321 {
322 closestcontact = cResult.Pos;
323 hitConsumerID = cResult.ConsumerID;
324 distance = cResult.Depth;
325 hitYN = true;
326 snormal = cResult.Normal;
327 }
328 }
329 m_contactResults.Clear();
330 }
331
332 ((RaycastCallback)req.callbackMethod)(hitYN, closestcontact, hitConsumerID, distance, snormal);
333 }
334 else
335 {
336 ((RayCallback)req.callbackMethod)(m_contactResults);
337 lock (m_PendingRequests)
338 m_contactResults.Clear();
339 }
340 }
341
342 private bool GetCurContactGeom(int index, ref d.ContactGeom newcontactgeom)
343 {
344 IntPtr ContactgeomsArray = m_scene.ContactgeomsArray;
345 if (ContactgeomsArray == IntPtr.Zero || index >= ColisionContactGeomsPerTest)
346 return false;
347
348 IntPtr contactptr = new IntPtr(ContactgeomsArray.ToInt64() + (Int64)(index * d.ContactGeom.unmanagedSizeOf));
349 newcontactgeom = (d.ContactGeom)Marshal.PtrToStructure(contactptr, typeof(d.ContactGeom));
350 return true;
351 }
352
353 // This is the standard Near. g2 is the ray
354 private void near(IntPtr space, IntPtr g1, IntPtr g2)
355 {
356 //Don't test against heightfield Geom, or you'll be sorry!
357 // Exclude heightfield geom
358
359 if (g1 == IntPtr.Zero || g1 == g2)
360 return;
361
362 if (d.GeomGetClass(g1) == d.GeomClassID.HeightfieldClass)
363 return;
364
365 // Raytest against AABBs of spaces first, then dig into the spaces it hits for actual geoms.
366 if (d.GeomIsSpace(g1))
367 {
368 try
369 {
370 d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback);
371 }
372 catch (Exception e)
373 {
374 m_log.WarnFormat("[PHYSICS Ray]: Unable to Space collide test an object: {0}", e.Message);
375 }
376 return;
377 }
378
379 int count = 0;
380 try
381 {
382 count = d.CollidePtr(g1, g2, ColisionContactGeomsPerTest, m_scene.ContactgeomsArray, d.ContactGeom.unmanagedSizeOf);
383 }
384 catch (SEHException)
385 {
386 m_log.Error("[PHYSICS Ray]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim.");
387 }
388 catch (Exception e)
389 {
390 m_log.WarnFormat("[PHYSICS Ray]: Unable to collide test an object: {0}", e.Message);
391 return;
392 }
393
394 if (count == 0)
395 return;
396
397 PhysicsActor p1 = null;
398
399 if (g1 != IntPtr.Zero)
400 m_scene.actor_name_map.TryGetValue(g1, out p1);
401
402 d.ContactGeom curcontact = new d.ContactGeom();
403 // Loop over contacts, build results.
404 for (int i = 0; i < count; i++)
405 {
406 if (!GetCurContactGeom(i, ref curcontact))
407 break;
408 if (p1 != null) {
409 if (p1 is OdePrim)
410 {
411 ContactResult collisionresult = new ContactResult();
412
413 collisionresult.ConsumerID = ((OdePrim)p1).m_localID;
414 collisionresult.Pos = new Vector3(curcontact.pos.X, curcontact.pos.Y, curcontact.pos.Z);
415 collisionresult.Depth = curcontact.depth;
416 collisionresult.Normal = new Vector3(curcontact.normal.X, curcontact.normal.Y,
417 curcontact.normal.Z);
418 lock (m_contactResults)
419 m_contactResults.Add(collisionresult);
420 }
421 }
422 }
423 }
424
425 /// <summary>
426 /// Dereference the creator scene so that it can be garbage collected if needed.
427 /// </summary>
428 internal void Dispose()
429 {
430 m_scene = null;
431 }
432 }
433
434 public struct ODERayRequest
435 {
436 public IntPtr geom;
437 public Vector3 Origin;
438 public Vector3 Normal;
439 public int Count;
440 public float length;
441 public object callbackMethod;
442 }
443} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs
new file mode 100644
index 0000000..c0c7ff3
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs
@@ -0,0 +1,1903 @@
1/*
2 * based on:
3 * Ode.NET - .NET bindings for ODE
4 * Jason Perkins (starkos@industriousone.com)
5 * Licensed under the New BSD
6 * Part of the OpenDynamicsEngine
7Open Dynamics Engine
8Copyright (c) 2001-2007, Russell L. Smith.
9All rights reserved.
10
11Redistribution and use in source and binary forms, with or without
12modification, are permitted provided that the following conditions
13are met:
14
15Redistributions of source code must retain the above copyright notice,
16this list of conditions and the following disclaimer.
17
18Redistributions in binary form must reproduce the above copyright notice,
19this list of conditions and the following disclaimer in the documentation
20and/or other materials provided with the distribution.
21
22Neither the names of ODE's copyright owner nor the names of its
23contributors may be used to endorse or promote products derived from
24this software without specific prior written permission.
25
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 * changes by opensim team;
39 * changes by Aurora team http://www.aurora-sim.org/
40
41 * Revision/fixs by Ubit Umarov
42 */
43
44using System;
45using System.Runtime.InteropServices;
46using System.Security;
47
48namespace OdeAPI
49{
50//#if dDOUBLE
51// don't see much use in double precision with time steps of 20ms and 10 iterations used on opensim
52// at least we save same memory and memory access time, FPU performance on intel usually is similar
53// using dReal = System.Double;
54//#else
55 using dReal = System.Single;
56//#endif
57
58 public static class d
59 {
60 public static dReal Infinity = dReal.MaxValue;
61 public static int NTotalBodies = 0;
62
63 #region Flags and Enumerations
64
65 [Flags]
66 public enum AllocateODEDataFlags : uint
67 {
68 BasicData = 0,
69 CollisionData = 0x00000001,
70 All = ~0u
71 }
72
73 [Flags]
74 public enum IniteODEFlags : uint
75 {
76 dInitFlagManualThreadCleanup = 0x00000001
77 }
78
79 [Flags]
80 public enum ContactFlags : int
81 {
82 Mu2 = 0x001,
83 FDir1 = 0x002,
84 Bounce = 0x004,
85 SoftERP = 0x008,
86 SoftCFM = 0x010,
87 Motion1 = 0x020,
88 Motion2 = 0x040,
89 MotionN = 0x080,
90 Slip1 = 0x100,
91 Slip2 = 0x200,
92 Approx0 = 0x0000,
93 Approx1_1 = 0x1000,
94 Approx1_2 = 0x2000,
95 Approx1 = 0x3000
96 }
97
98 public enum GeomClassID : int
99 {
100 SphereClass,
101 BoxClass,
102 CapsuleClass,
103 CylinderClass,
104 PlaneClass,
105 RayClass,
106 ConvexClass,
107 GeomTransformClass,
108 TriMeshClass,
109 HeightfieldClass,
110 FirstSpaceClass,
111 SimpleSpaceClass = FirstSpaceClass,
112 HashSpaceClass,
113 QuadTreeSpaceClass,
114 LastSpaceClass = QuadTreeSpaceClass,
115 FirstUserClass,
116 LastUserClass = FirstUserClass + MaxUserClasses - 1,
117 NumClasses,
118 MaxUserClasses = 4
119 }
120
121 public enum JointType : int
122 {
123 None,
124 Ball,
125 Hinge,
126 Slider,
127 Contact,
128 Universal,
129 Hinge2,
130 Fixed,
131 Null,
132 AMotor,
133 LMotor,
134 Plane2D
135 }
136
137 public enum JointParam : int
138 {
139 LoStop,
140 HiStop,
141 Vel,
142 FMax,
143 FudgeFactor,
144 Bounce,
145 CFM,
146 StopERP,
147 StopCFM,
148 SuspensionERP,
149 SuspensionCFM,
150 LoStop2 = 256,
151 HiStop2,
152 Vel2,
153 FMax2,
154 FudgeFactor2,
155 Bounce2,
156 CFM2,
157 StopERP2,
158 StopCFM2,
159 SuspensionERP2,
160 SuspensionCFM2,
161 LoStop3 = 512,
162 HiStop3,
163 Vel3,
164 FMax3,
165 FudgeFactor3,
166 Bounce3,
167 CFM3,
168 StopERP3,
169 StopCFM3,
170 SuspensionERP3,
171 SuspensionCFM3
172 }
173
174 public enum dSweepAndPruneAxis : int
175 {
176 XYZ = ((0)|(1<<2)|(2<<4)),
177 XZY = ((0)|(2<<2)|(1<<4)),
178 YXZ = ((1)|(0<<2)|(2<<4)),
179 YZX = ((1)|(2<<2)|(0<<4)),
180 ZXY = ((2)|(0<<2)|(1<<4)),
181 ZYX = ((2)|(1<<2)|(0<<4))
182 }
183
184 #endregion
185
186 #region Callbacks
187
188 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
189 public delegate int AABBTestFn(IntPtr o1, IntPtr o2, ref AABB aabb);
190
191 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
192 public delegate int ColliderFn(IntPtr o1, IntPtr o2, int flags, out ContactGeom contact, int skip);
193
194 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
195 public delegate void GetAABBFn(IntPtr geom, out AABB aabb);
196
197 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
198 public delegate ColliderFn GetColliderFnFn(int num);
199
200 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
201 public delegate void GeomDtorFn(IntPtr o);
202
203 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
204 public delegate dReal HeightfieldGetHeight(IntPtr p_user_data, int x, int z);
205
206 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
207 public delegate void NearCallback(IntPtr data, IntPtr geom1, IntPtr geom2);
208
209 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
210 public delegate int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex);
211
212 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
213 public delegate int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount);
214
215 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
216 public delegate int TriRayCallback(IntPtr trimesh, IntPtr ray, int triangleIndex, dReal u, dReal v);
217
218 #endregion
219
220 #region Structs
221
222 [StructLayout(LayoutKind.Sequential)]
223 public struct AABB
224 {
225 public dReal MinX, MaxX;
226 public dReal MinY, MaxY;
227 public dReal MinZ, MaxZ;
228 }
229
230
231 [StructLayout(LayoutKind.Sequential)]
232 public struct Contact
233 {
234 public SurfaceParameters surface;
235 public ContactGeom geom;
236 public Vector3 fdir1;
237 public static readonly int unmanagedSizeOf = Marshal.SizeOf(typeof(Contact));
238 }
239
240
241 [StructLayout(LayoutKind.Sequential)]
242 public struct ContactGeom
243 {
244
245 public Vector3 pos;
246 public Vector3 normal;
247 public dReal depth;
248 public IntPtr g1;
249 public IntPtr g2;
250 public int side1;
251 public int side2;
252 public static readonly int unmanagedSizeOf = Marshal.SizeOf(typeof(ContactGeom));
253 }
254
255 [StructLayout(LayoutKind.Sequential)]
256 public struct GeomClass
257 {
258 public int bytes;
259 public GetColliderFnFn collider;
260 public GetAABBFn aabb;
261 public AABBTestFn aabb_test;
262 public GeomDtorFn dtor;
263 }
264
265
266 [StructLayout(LayoutKind.Sequential)]
267 public struct JointFeedback
268 {
269 public Vector3 f1;
270 public Vector3 t1;
271 public Vector3 f2;
272 public Vector3 t2;
273 }
274
275
276 [StructLayout(LayoutKind.Sequential)]
277 public struct Mass
278 {
279 public dReal mass;
280 public Vector4 c;
281 public Matrix3 I;
282 }
283
284
285 [StructLayout(LayoutKind.Sequential)]
286 public struct Matrix3
287 {
288 public Matrix3(dReal m00, dReal m10, dReal m20, dReal m01, dReal m11, dReal m21, dReal m02, dReal m12, dReal m22)
289 {
290 M00 = m00; M10 = m10; M20 = m20; _m30 = 0.0f;
291 M01 = m01; M11 = m11; M21 = m21; _m31 = 0.0f;
292 M02 = m02; M12 = m12; M22 = m22; _m32 = 0.0f;
293 }
294 public dReal M00, M10, M20;
295 private dReal _m30;
296 public dReal M01, M11, M21;
297 private dReal _m31;
298 public dReal M02, M12, M22;
299 private dReal _m32;
300 }
301
302 [StructLayout(LayoutKind.Sequential)]
303 public struct Matrix4
304 {
305 public Matrix4(dReal m00, dReal m10, dReal m20, dReal m30,
306 dReal m01, dReal m11, dReal m21, dReal m31,
307 dReal m02, dReal m12, dReal m22, dReal m32,
308 dReal m03, dReal m13, dReal m23, dReal m33)
309 {
310 M00 = m00; M10 = m10; M20 = m20; M30 = m30;
311 M01 = m01; M11 = m11; M21 = m21; M31 = m31;
312 M02 = m02; M12 = m12; M22 = m22; M32 = m32;
313 M03 = m03; M13 = m13; M23 = m23; M33 = m33;
314 }
315 public dReal M00, M10, M20, M30;
316 public dReal M01, M11, M21, M31;
317 public dReal M02, M12, M22, M32;
318 public dReal M03, M13, M23, M33;
319 }
320
321 [StructLayout(LayoutKind.Sequential)]
322 public struct Quaternion
323 {
324 public dReal W, X, Y, Z;
325 }
326
327
328 [StructLayout(LayoutKind.Sequential)]
329 public struct SurfaceParameters
330 {
331 public ContactFlags mode;
332 public dReal mu;
333 public dReal mu2;
334 public dReal bounce;
335 public dReal bounce_vel;
336 public dReal soft_erp;
337 public dReal soft_cfm;
338 public dReal motion1;
339 public dReal motion2;
340 public dReal motionN;
341 public dReal slip1;
342 public dReal slip2;
343 }
344
345
346 [StructLayout(LayoutKind.Sequential)]
347 public struct Vector3
348 {
349 public Vector3(dReal x, dReal y, dReal z)
350 {
351 X = x; Y = y; Z = z; _w = 0.0f;
352 }
353 public dReal X, Y, Z;
354 private dReal _w;
355 }
356
357
358 [StructLayout(LayoutKind.Sequential)]
359 public struct Vector4
360 {
361 public Vector4(dReal x, dReal y, dReal z, dReal w)
362 {
363 X = x; Y = y; Z = z; W = w;
364 }
365 public dReal X, Y, Z, W;
366 }
367
368 #endregion
369
370 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dAllocateODEDataForThread"), SuppressUnmanagedCodeSecurity]
371 public static extern int AllocateODEDataForThread(uint ODEInitFlags);
372
373 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dAreConnected"), SuppressUnmanagedCodeSecurity]
374 public static extern bool AreConnected(IntPtr b1, IntPtr b2);
375
376 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dAreConnectedExcluding"), SuppressUnmanagedCodeSecurity]
377 public static extern bool AreConnectedExcluding(IntPtr b1, IntPtr b2, JointType joint_type);
378
379 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddForce"), SuppressUnmanagedCodeSecurity]
380 public static extern void BodyAddForce(IntPtr body, dReal fx, dReal fy, dReal fz);
381
382 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddForceAtPos"), SuppressUnmanagedCodeSecurity]
383 public static extern void BodyAddForceAtPos(IntPtr body, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
384
385 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddForceAtRelPos"), SuppressUnmanagedCodeSecurity]
386 public static extern void BodyAddForceAtRelPos(IntPtr body, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
387
388 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddRelForce"), SuppressUnmanagedCodeSecurity]
389 public static extern void BodyAddRelForce(IntPtr body, dReal fx, dReal fy, dReal fz);
390
391 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddRelForceAtPos"), SuppressUnmanagedCodeSecurity]
392 public static extern void BodyAddRelForceAtPos(IntPtr body, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
393
394 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddRelForceAtRelPos"), SuppressUnmanagedCodeSecurity]
395 public static extern void BodyAddRelForceAtRelPos(IntPtr body, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
396
397 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddRelTorque"), SuppressUnmanagedCodeSecurity]
398 public static extern void BodyAddRelTorque(IntPtr body, dReal fx, dReal fy, dReal fz);
399
400 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddTorque"), SuppressUnmanagedCodeSecurity]
401 public static extern void BodyAddTorque(IntPtr body, dReal fx, dReal fy, dReal fz);
402
403 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyPosition"), SuppressUnmanagedCodeSecurity]
404 public static extern void BodyCopyPosition(IntPtr body, out Vector3 pos);
405
406 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyPosition"), SuppressUnmanagedCodeSecurity]
407 public static extern void BodyCopyPosition(IntPtr body, out dReal X);
408
409 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyQuaternion"), SuppressUnmanagedCodeSecurity]
410 public static extern void BodyCopyQuaternion(IntPtr body, out Quaternion quat);
411
412 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyQuaternion"), SuppressUnmanagedCodeSecurity]
413 public static extern void BodyCopyQuaternion(IntPtr body, out dReal X);
414
415 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyRotation"), SuppressUnmanagedCodeSecurity]
416 public static extern void BodyCopyRotation(IntPtr body, out Matrix3 R);
417
418 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyRotation"), SuppressUnmanagedCodeSecurity]
419 public static extern void BodyCopyRotation(IntPtr body, out dReal M00);
420
421 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCreate"), SuppressUnmanagedCodeSecurity]
422 public static extern IntPtr BodyiCreate(IntPtr world);
423 public static IntPtr BodyCreate(IntPtr world)
424 {
425 NTotalBodies++;
426 return BodyiCreate(world);
427 }
428
429 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyDestroy"), SuppressUnmanagedCodeSecurity]
430 public static extern void BodyiDestroy(IntPtr body);
431 public static void BodyDestroy(IntPtr body)
432 {
433 NTotalBodies--;
434 BodyiDestroy(body);
435 }
436
437 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyDisable"), SuppressUnmanagedCodeSecurity]
438 public static extern void BodyDisable(IntPtr body);
439
440 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyEnable"), SuppressUnmanagedCodeSecurity]
441 public static extern void BodyEnable(IntPtr body);
442
443 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableAngularThreshold"), SuppressUnmanagedCodeSecurity]
444 public static extern dReal BodyGetAutoDisableAngularThreshold(IntPtr body);
445
446 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableFlag"), SuppressUnmanagedCodeSecurity]
447 public static extern bool BodyGetAutoDisableFlag(IntPtr body);
448
449 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableDefaults"), SuppressUnmanagedCodeSecurity]
450 public static extern void BodyGetAutoDisableDefaults(IntPtr body);
451
452 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableLinearThreshold"), SuppressUnmanagedCodeSecurity]
453 public static extern dReal BodyGetAutoDisableLinearThreshold(IntPtr body);
454
455 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableSteps"), SuppressUnmanagedCodeSecurity]
456 public static extern int BodyGetAutoDisableSteps(IntPtr body);
457
458 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableTime"), SuppressUnmanagedCodeSecurity]
459 public static extern dReal BodyGetAutoDisableTime(IntPtr body);
460
461 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAngularVel"), SuppressUnmanagedCodeSecurity]
462 public extern unsafe static Vector3* BodyGetAngularVelUnsafe(IntPtr body);
463 public static Vector3 BodyGetAngularVel(IntPtr body)
464 {
465 unsafe { return *(BodyGetAngularVelUnsafe(body)); }
466 }
467
468 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetData"), SuppressUnmanagedCodeSecurity]
469 public static extern IntPtr BodyGetData(IntPtr body);
470
471 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetFiniteRotationMode"), SuppressUnmanagedCodeSecurity]
472 public static extern int BodyGetFiniteRotationMode(IntPtr body);
473
474 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetFiniteRotationAxis"), SuppressUnmanagedCodeSecurity]
475 public static extern void BodyGetFiniteRotationAxis(IntPtr body, out Vector3 result);
476
477 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetForce"), SuppressUnmanagedCodeSecurity]
478 public extern unsafe static Vector3* BodyGetForceUnsafe(IntPtr body);
479 public static Vector3 BodyGetForce(IntPtr body)
480 {
481 unsafe { return *(BodyGetForceUnsafe(body)); }
482 }
483
484 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetGravityMode"), SuppressUnmanagedCodeSecurity]
485 public static extern bool BodyGetGravityMode(IntPtr body);
486
487 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetGyroscopicMode"), SuppressUnmanagedCodeSecurity]
488 public static extern int BodyGetGyroscopicMode(IntPtr body);
489
490 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetJoint"), SuppressUnmanagedCodeSecurity]
491 public static extern IntPtr BodyGetJoint(IntPtr body, int index);
492
493 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetLinearVel"), SuppressUnmanagedCodeSecurity]
494 public extern unsafe static Vector3* BodyGetLinearVelUnsafe(IntPtr body);
495 public static Vector3 BodyGetLinearVel(IntPtr body)
496 {
497 unsafe { return *(BodyGetLinearVelUnsafe(body)); }
498 }
499
500 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetMass"), SuppressUnmanagedCodeSecurity]
501 public static extern void BodyGetMass(IntPtr body, out Mass mass);
502
503 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetNumJoints"), SuppressUnmanagedCodeSecurity]
504 public static extern int BodyGetNumJoints(IntPtr body);
505
506 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetPointVel"), SuppressUnmanagedCodeSecurity]
507 public static extern void BodyGetPointVel(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
508
509 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetPosition"), SuppressUnmanagedCodeSecurity]
510 public extern unsafe static Vector3* BodyGetPositionUnsafe(IntPtr body);
511 public static Vector3 BodyGetPosition(IntPtr body)
512 {
513 unsafe { return *(BodyGetPositionUnsafe(body)); }
514 }
515
516 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetPosRelPoint"), SuppressUnmanagedCodeSecurity]
517 public static extern void BodyGetPosRelPoint(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
518
519 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetQuaternion"), SuppressUnmanagedCodeSecurity]
520 public extern unsafe static Quaternion* BodyGetQuaternionUnsafe(IntPtr body);
521 public static Quaternion BodyGetQuaternion(IntPtr body)
522 {
523 unsafe { return *(BodyGetQuaternionUnsafe(body)); }
524 }
525
526 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetRelPointPos"), SuppressUnmanagedCodeSecurity]
527 public static extern void BodyGetRelPointPos(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
528
529 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetRelPointVel"), SuppressUnmanagedCodeSecurity]
530 public static extern void BodyGetRelPointVel(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
531
532 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetRotation"), SuppressUnmanagedCodeSecurity]
533 public extern unsafe static Matrix3* BodyGetRotationUnsafe(IntPtr body);
534 public static Matrix3 BodyGetRotation(IntPtr body)
535 {
536 unsafe { return *(BodyGetRotationUnsafe(body)); }
537 }
538
539 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetTorque"), SuppressUnmanagedCodeSecurity]
540 public extern unsafe static Vector3* BodyGetTorqueUnsafe(IntPtr body);
541 public static Vector3 BodyGetTorque(IntPtr body)
542 {
543 unsafe { return *(BodyGetTorqueUnsafe(body)); }
544 }
545
546 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetWorld"), SuppressUnmanagedCodeSecurity]
547 public static extern IntPtr BodyGetWorld(IntPtr body);
548
549 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetFirstGeom"), SuppressUnmanagedCodeSecurity]
550 public static extern IntPtr BodyGetFirstGeom(IntPtr body);
551
552 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetNextGeom"), SuppressUnmanagedCodeSecurity]
553 public static extern IntPtr dBodyGetNextGeom(IntPtr Geom);
554
555
556 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyIsEnabled"), SuppressUnmanagedCodeSecurity]
557 public static extern bool BodyIsEnabled(IntPtr body);
558
559 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAngularVel"), SuppressUnmanagedCodeSecurity]
560 public static extern void BodySetAngularVel(IntPtr body, dReal x, dReal y, dReal z);
561
562 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableAngularThreshold"), SuppressUnmanagedCodeSecurity]
563 public static extern void BodySetAutoDisableAngularThreshold(IntPtr body, dReal angular_threshold);
564
565 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableDefaults"), SuppressUnmanagedCodeSecurity]
566 public static extern void BodySetAutoDisableDefaults(IntPtr body);
567
568 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableFlag"), SuppressUnmanagedCodeSecurity]
569 public static extern void BodySetAutoDisableFlag(IntPtr body, bool do_auto_disable);
570
571 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableLinearThreshold"), SuppressUnmanagedCodeSecurity]
572 public static extern void BodySetAutoDisableLinearThreshold(IntPtr body, dReal linear_threshold);
573
574 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableSteps"), SuppressUnmanagedCodeSecurity]
575 public static extern void BodySetAutoDisableSteps(IntPtr body, int steps);
576
577 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableTime"), SuppressUnmanagedCodeSecurity]
578 public static extern void BodySetAutoDisableTime(IntPtr body, dReal time);
579
580 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetData"), SuppressUnmanagedCodeSecurity]
581 public static extern void BodySetData(IntPtr body, IntPtr data);
582
583 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetFiniteRotationMode"), SuppressUnmanagedCodeSecurity]
584 public static extern void BodySetFiniteRotationMode(IntPtr body, int mode);
585
586 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetFiniteRotationAxis"), SuppressUnmanagedCodeSecurity]
587 public static extern void BodySetFiniteRotationAxis(IntPtr body, dReal x, dReal y, dReal z);
588
589 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetLinearDamping"), SuppressUnmanagedCodeSecurity]
590 public static extern void BodySetLinearDamping(IntPtr body, dReal scale);
591
592 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAngularDamping"), SuppressUnmanagedCodeSecurity]
593 public static extern void BodySetAngularDamping(IntPtr body, dReal scale);
594
595 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetLinearDamping"), SuppressUnmanagedCodeSecurity]
596 public static extern dReal BodyGetLinearDamping(IntPtr body);
597
598 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAngularDamping"), SuppressUnmanagedCodeSecurity]
599 public static extern dReal BodyGetAngularDamping(IntPtr body);
600
601 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAngularDamping"), SuppressUnmanagedCodeSecurity]
602 public static extern void BodySetDamping(IntPtr body, dReal linear_scale, dReal angular_scale);
603
604 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAngularDampingThreshold"), SuppressUnmanagedCodeSecurity]
605 public static extern void BodySetAngularDampingThreshold(IntPtr body, dReal threshold);
606
607 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetLinearDampingThreshold"), SuppressUnmanagedCodeSecurity]
608 public static extern void BodySetLinearDampingThreshold(IntPtr body, dReal threshold);
609
610 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetLinearDampingThreshold"), SuppressUnmanagedCodeSecurity]
611 public static extern dReal BodyGetLinearDampingThreshold(IntPtr body);
612
613 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAngularDampingThreshold"), SuppressUnmanagedCodeSecurity]
614 public static extern dReal BodyGetAngularDampingThreshold(IntPtr body);
615
616 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetForce"), SuppressUnmanagedCodeSecurity]
617 public static extern void BodySetForce(IntPtr body, dReal x, dReal y, dReal z);
618
619 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetGravityMode"), SuppressUnmanagedCodeSecurity]
620 public static extern void BodySetGravityMode(IntPtr body, bool mode);
621
622 /// <summary>
623 /// Sets the Gyroscopic term status on the body specified.
624 /// </summary>
625 /// <param name="body">Pointer to body</param>
626 /// <param name="enabled">NonZero enabled, Zero disabled</param>
627 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetGyroscopicMode"), SuppressUnmanagedCodeSecurity]
628 public static extern void dBodySetGyroscopicMode(IntPtr body, int enabled);
629
630 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetLinearVel"), SuppressUnmanagedCodeSecurity]
631 public static extern void BodySetLinearVel(IntPtr body, dReal x, dReal y, dReal z);
632
633 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetMass"), SuppressUnmanagedCodeSecurity]
634 public static extern void BodySetMass(IntPtr body, ref Mass mass);
635
636 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetPosition"), SuppressUnmanagedCodeSecurity]
637 public static extern void BodySetPosition(IntPtr body, dReal x, dReal y, dReal z);
638
639 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetQuaternion"), SuppressUnmanagedCodeSecurity]
640 public static extern void BodySetQuaternion(IntPtr body, ref Quaternion q);
641
642 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetQuaternion"), SuppressUnmanagedCodeSecurity]
643 public static extern void BodySetQuaternion(IntPtr body, ref dReal w);
644
645 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetRotation"), SuppressUnmanagedCodeSecurity]
646 public static extern void BodySetRotation(IntPtr body, ref Matrix3 R);
647
648 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetRotation"), SuppressUnmanagedCodeSecurity]
649 public static extern void BodySetRotation(IntPtr body, ref dReal M00);
650
651 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetTorque"), SuppressUnmanagedCodeSecurity]
652 public static extern void BodySetTorque(IntPtr body, dReal x, dReal y, dReal z);
653
654 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyVectorFromWorld"), SuppressUnmanagedCodeSecurity]
655 public static extern void BodyVectorFromWorld(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
656
657 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyVectorToWorld"), SuppressUnmanagedCodeSecurity]
658 public static extern void BodyVectorToWorld(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
659
660 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBoxBox"), SuppressUnmanagedCodeSecurity]
661 public static extern void BoxBox(ref Vector3 p1, ref Matrix3 R1,
662 ref Vector3 side1, ref Vector3 p2,
663 ref Matrix3 R2, ref Vector3 side2,
664 ref Vector3 normal, out dReal depth, out int return_code,
665 int maxc, out ContactGeom contact, int skip);
666
667 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBoxTouchesBox"), SuppressUnmanagedCodeSecurity]
668 public static extern void BoxTouchesBox(ref Vector3 _p1, ref Matrix3 R1,
669 ref Vector3 side1, ref Vector3 _p2,
670 ref Matrix3 R2, ref Vector3 side2);
671
672 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCleanupODEAllDataForThread"), SuppressUnmanagedCodeSecurity]
673 public static extern void CleanupODEAllDataForThread();
674
675 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dClosestLineSegmentPoints"), SuppressUnmanagedCodeSecurity]
676 public static extern void ClosestLineSegmentPoints(ref Vector3 a1, ref Vector3 a2,
677 ref Vector3 b1, ref Vector3 b2,
678 ref Vector3 cp1, ref Vector3 cp2);
679
680 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCloseODE"), SuppressUnmanagedCodeSecurity]
681 public static extern void CloseODE();
682
683 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCollide"), SuppressUnmanagedCodeSecurity]
684 public static extern int Collide(IntPtr o1, IntPtr o2, int flags, [In, Out] ContactGeom[] contact, int skip);
685 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCollide"), SuppressUnmanagedCodeSecurity]
686 public static extern int CollidePtr(IntPtr o1, IntPtr o2, int flags, IntPtr contactgeomarray, int skip);
687
688 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dConnectingJoint"), SuppressUnmanagedCodeSecurity]
689 public static extern IntPtr ConnectingJoint(IntPtr j1, IntPtr j2);
690
691 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateBox"), SuppressUnmanagedCodeSecurity]
692 public static extern IntPtr CreateBox(IntPtr space, dReal lx, dReal ly, dReal lz);
693
694 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateCapsule"), SuppressUnmanagedCodeSecurity]
695 public static extern IntPtr CreateCapsule(IntPtr space, dReal radius, dReal length);
696
697 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateConvex"), SuppressUnmanagedCodeSecurity]
698 public static extern IntPtr CreateConvex(IntPtr space, dReal[] planes, int planeCount, dReal[] points, int pointCount, int[] polygons);
699
700 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateCylinder"), SuppressUnmanagedCodeSecurity]
701 public static extern IntPtr CreateCylinder(IntPtr space, dReal radius, dReal length);
702
703 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateHeightfield"), SuppressUnmanagedCodeSecurity]
704 public static extern IntPtr CreateHeightfield(IntPtr space, IntPtr data, int bPlaceable);
705
706 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeom"), SuppressUnmanagedCodeSecurity]
707 public static extern IntPtr CreateGeom(int classnum);
708
709 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeomClass"), SuppressUnmanagedCodeSecurity]
710 public static extern int CreateGeomClass(ref GeomClass classptr);
711
712 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeomTransform"), SuppressUnmanagedCodeSecurity]
713 public static extern IntPtr CreateGeomTransform(IntPtr space);
714
715 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreatePlane"), SuppressUnmanagedCodeSecurity]
716 public static extern IntPtr CreatePlane(IntPtr space, dReal a, dReal b, dReal c, dReal d);
717
718 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateRay"), SuppressUnmanagedCodeSecurity]
719 public static extern IntPtr CreateRay(IntPtr space, dReal length);
720
721 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateSphere"), SuppressUnmanagedCodeSecurity]
722 public static extern IntPtr CreateSphere(IntPtr space, dReal radius);
723
724 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateTriMesh"), SuppressUnmanagedCodeSecurity]
725 public static extern IntPtr CreateTriMesh(IntPtr space, IntPtr data,
726 TriCallback callback, TriArrayCallback arrayCallback, TriRayCallback rayCallback);
727
728 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dDot"), SuppressUnmanagedCodeSecurity]
729 public static extern dReal Dot(ref dReal X0, ref dReal X1, int n);
730
731 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dDQfromW"), SuppressUnmanagedCodeSecurity]
732 public static extern void DQfromW(dReal[] dq, ref Vector3 w, ref Quaternion q);
733
734 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dFactorCholesky"), SuppressUnmanagedCodeSecurity]
735 public static extern int FactorCholesky(ref dReal A00, int n);
736
737 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dFactorLDLT"), SuppressUnmanagedCodeSecurity]
738 public static extern void FactorLDLT(ref dReal A, out dReal d, int n, int nskip);
739
740 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomBoxGetLengths"), SuppressUnmanagedCodeSecurity]
741 public static extern void GeomBoxGetLengths(IntPtr geom, out Vector3 len);
742
743 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomBoxGetLengths"), SuppressUnmanagedCodeSecurity]
744 public static extern void GeomBoxGetLengths(IntPtr geom, out dReal x);
745
746 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomBoxPointDepth"), SuppressUnmanagedCodeSecurity]
747 public static extern dReal GeomBoxPointDepth(IntPtr geom, dReal x, dReal y, dReal z);
748
749 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomBoxSetLengths"), SuppressUnmanagedCodeSecurity]
750 public static extern void GeomBoxSetLengths(IntPtr geom, dReal x, dReal y, dReal z);
751
752 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCapsuleGetParams"), SuppressUnmanagedCodeSecurity]
753 public static extern void GeomCapsuleGetParams(IntPtr geom, out dReal radius, out dReal length);
754
755 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCapsulePointDepth"), SuppressUnmanagedCodeSecurity]
756 public static extern dReal GeomCapsulePointDepth(IntPtr geom, dReal x, dReal y, dReal z);
757
758 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCapsuleSetParams"), SuppressUnmanagedCodeSecurity]
759 public static extern void GeomCapsuleSetParams(IntPtr geom, dReal radius, dReal length);
760
761 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomClearOffset"), SuppressUnmanagedCodeSecurity]
762 public static extern void GeomClearOffset(IntPtr geom);
763
764 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyOffsetPosition"), SuppressUnmanagedCodeSecurity]
765 public static extern IntPtr GeomCopyOffsetPosition(IntPtr geom, ref Vector3 pos);
766
767 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyOffsetPosition"), SuppressUnmanagedCodeSecurity]
768 public static extern IntPtr GeomCopyOffsetPosition(IntPtr geom, ref dReal X);
769
770 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetOffsetQuaternion"), SuppressUnmanagedCodeSecurity]
771 public static extern void GeomCopyOffsetQuaternion(IntPtr geom, ref Quaternion Q);
772
773 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetOffsetQuaternion"), SuppressUnmanagedCodeSecurity]
774 public static extern void GeomCopyOffsetQuaternion(IntPtr geom, ref dReal X);
775
776 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyOffsetRotation"), SuppressUnmanagedCodeSecurity]
777 public static extern IntPtr GeomCopyOffsetRotation(IntPtr geom, ref Matrix3 R);
778
779 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyOffsetRotation"), SuppressUnmanagedCodeSecurity]
780 public static extern IntPtr GeomCopyOffsetRotation(IntPtr geom, ref dReal M00);
781
782 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyPosition"), SuppressUnmanagedCodeSecurity]
783 public static extern void GeomCopyPosition(IntPtr geom, out Vector3 pos);
784
785 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyPosition"), SuppressUnmanagedCodeSecurity]
786 public static extern void GeomCopyPosition(IntPtr geom, out dReal X);
787
788 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyRotation"), SuppressUnmanagedCodeSecurity]
789 public static extern void GeomCopyRotation(IntPtr geom, out Matrix3 R);
790
791 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyRotation"), SuppressUnmanagedCodeSecurity]
792 public static extern void GeomCopyRotation(IntPtr geom, out dReal M00);
793
794 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCylinderGetParams"), SuppressUnmanagedCodeSecurity]
795 public static extern void GeomCylinderGetParams(IntPtr geom, out dReal radius, out dReal length);
796
797 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCylinderSetParams"), SuppressUnmanagedCodeSecurity]
798 public static extern void GeomCylinderSetParams(IntPtr geom, dReal radius, dReal length);
799
800 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomDestroy"), SuppressUnmanagedCodeSecurity]
801 public static extern void GeomDestroy(IntPtr geom);
802
803 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomDisable"), SuppressUnmanagedCodeSecurity]
804 public static extern void GeomDisable(IntPtr geom);
805
806 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomEnable"), SuppressUnmanagedCodeSecurity]
807 public static extern void GeomEnable(IntPtr geom);
808
809 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetAABB"), SuppressUnmanagedCodeSecurity]
810 public static extern void GeomGetAABB(IntPtr geom, out AABB aabb);
811
812 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetAABB"), SuppressUnmanagedCodeSecurity]
813 public static extern void GeomGetAABB(IntPtr geom, out dReal minX);
814
815 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetBody"), SuppressUnmanagedCodeSecurity]
816 public static extern IntPtr GeomGetBody(IntPtr geom);
817
818 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetCategoryBits"), SuppressUnmanagedCodeSecurity]
819 public static extern int GeomGetCategoryBits(IntPtr geom);
820
821 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetClassData"), SuppressUnmanagedCodeSecurity]
822 public static extern IntPtr GeomGetClassData(IntPtr geom);
823
824 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetCollideBits"), SuppressUnmanagedCodeSecurity]
825 public static extern int GeomGetCollideBits(IntPtr geom);
826
827 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetClass"), SuppressUnmanagedCodeSecurity]
828 public static extern GeomClassID GeomGetClass(IntPtr geom);
829
830 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetData"), SuppressUnmanagedCodeSecurity]
831 public static extern IntPtr GeomGetData(IntPtr geom);
832
833 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetOffsetPosition"), SuppressUnmanagedCodeSecurity]
834 public extern unsafe static Vector3* GeomGetOffsetPositionUnsafe(IntPtr geom);
835 public static Vector3 GeomGetOffsetPosition(IntPtr geom)
836 {
837 unsafe { return *(GeomGetOffsetPositionUnsafe(geom)); }
838 }
839
840 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetOffsetRotation"), SuppressUnmanagedCodeSecurity]
841 public extern unsafe static Matrix3* GeomGetOffsetRotationUnsafe(IntPtr geom);
842 public static Matrix3 GeomGetOffsetRotation(IntPtr geom)
843 {
844 unsafe { return *(GeomGetOffsetRotationUnsafe(geom)); }
845 }
846
847 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetPosition"), SuppressUnmanagedCodeSecurity]
848 public extern unsafe static Vector3* GeomGetPositionUnsafe(IntPtr geom);
849 public static Vector3 GeomGetPosition(IntPtr geom)
850 {
851 unsafe { return *(GeomGetPositionUnsafe(geom)); }
852 }
853
854 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetQuaternion"), SuppressUnmanagedCodeSecurity]
855 public static extern void GeomCopyQuaternion(IntPtr geom, out Quaternion q);
856
857 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetQuaternion"), SuppressUnmanagedCodeSecurity]
858 public static extern void GeomCopyQuaternion(IntPtr geom, out dReal X);
859
860 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetRotation"), SuppressUnmanagedCodeSecurity]
861 public extern unsafe static Matrix3* GeomGetRotationUnsafe(IntPtr geom);
862 public static Matrix3 GeomGetRotation(IntPtr geom)
863 {
864 unsafe { return *(GeomGetRotationUnsafe(geom)); }
865 }
866
867 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetSpace"), SuppressUnmanagedCodeSecurity]
868 public static extern IntPtr GeomGetSpace(IntPtr geom);
869
870 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildByte"), SuppressUnmanagedCodeSecurity]
871 public static extern void GeomHeightfieldDataBuildByte(IntPtr d, byte[] pHeightData, int bCopyHeightData,
872 dReal width, dReal depth, int widthSamples, int depthSamples,
873 dReal scale, dReal offset, dReal thickness, int bWrap);
874
875 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildByte"), SuppressUnmanagedCodeSecurity]
876 public static extern void GeomHeightfieldDataBuildByte(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
877 dReal width, dReal depth, int widthSamples, int depthSamples,
878 dReal scale, dReal offset, dReal thickness, int bWrap);
879
880 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildCallback"), SuppressUnmanagedCodeSecurity]
881 public static extern void GeomHeightfieldDataBuildCallback(IntPtr d, IntPtr pUserData, HeightfieldGetHeight pCallback,
882 dReal width, dReal depth, int widthSamples, int depthSamples,
883 dReal scale, dReal offset, dReal thickness, int bWrap);
884
885 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildShort"), SuppressUnmanagedCodeSecurity]
886 public static extern void GeomHeightfieldDataBuildShort(IntPtr d, ushort[] pHeightData, int bCopyHeightData,
887 dReal width, dReal depth, int widthSamples, int depthSamples,
888 dReal scale, dReal offset, dReal thickness, int bWrap);
889
890 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildShort"), SuppressUnmanagedCodeSecurity]
891 public static extern void GeomHeightfieldDataBuildShort(IntPtr d, short[] pHeightData, int bCopyHeightData,
892 dReal width, dReal depth, int widthSamples, int depthSamples,
893 dReal scale, dReal offset, dReal thickness, int bWrap);
894
895 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildShort"), SuppressUnmanagedCodeSecurity]
896 public static extern void GeomHeightfieldDataBuildShort(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
897 dReal width, dReal depth, int widthSamples, int depthSamples,
898 dReal scale, dReal offset, dReal thickness, int bWrap);
899
900 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildSingle"), SuppressUnmanagedCodeSecurity]
901 public static extern void GeomHeightfieldDataBuildSingle(IntPtr d, float[] pHeightData, int bCopyHeightData,
902 dReal width, dReal depth, int widthSamples, int depthSamples,
903 dReal scale, dReal offset, dReal thickness, int bWrap);
904
905 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildSingle"), SuppressUnmanagedCodeSecurity]
906 public static extern void GeomHeightfieldDataBuildSingle(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
907 dReal width, dReal depth, int widthSamples, int depthSamples,
908 dReal scale, dReal offset, dReal thickness, int bWrap);
909
910 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildDouble"), SuppressUnmanagedCodeSecurity]
911 public static extern void GeomHeightfieldDataBuildDouble(IntPtr d, double[] pHeightData, int bCopyHeightData,
912 dReal width, dReal depth, int widthSamples, int depthSamples,
913 dReal scale, dReal offset, dReal thickness, int bWrap);
914
915 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildDouble"), SuppressUnmanagedCodeSecurity]
916 public static extern void GeomHeightfieldDataBuildDouble(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
917 dReal width, dReal depth, int widthSamples, int depthSamples,
918 dReal scale, dReal offset, dReal thickness, int bWrap);
919
920 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataCreate"), SuppressUnmanagedCodeSecurity]
921 public static extern IntPtr GeomHeightfieldDataCreate();
922
923 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataDestroy"), SuppressUnmanagedCodeSecurity]
924 public static extern void GeomHeightfieldDataDestroy(IntPtr d);
925
926 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataSetBounds"), SuppressUnmanagedCodeSecurity]
927 public static extern void GeomHeightfieldDataSetBounds(IntPtr d, dReal minHeight, dReal maxHeight);
928
929 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldGetHeightfieldData"), SuppressUnmanagedCodeSecurity]
930 public static extern IntPtr GeomHeightfieldGetHeightfieldData(IntPtr g);
931
932 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldSetHeightfieldData"), SuppressUnmanagedCodeSecurity]
933 public static extern void GeomHeightfieldSetHeightfieldData(IntPtr g, IntPtr d);
934
935 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomIsEnabled"), SuppressUnmanagedCodeSecurity]
936 public static extern bool GeomIsEnabled(IntPtr geom);
937
938 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomIsOffset"), SuppressUnmanagedCodeSecurity]
939 public static extern bool GeomIsOffset(IntPtr geom);
940
941 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomIsSpace"), SuppressUnmanagedCodeSecurity]
942 public static extern bool GeomIsSpace(IntPtr geom);
943
944 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomPlaneGetParams"), SuppressUnmanagedCodeSecurity]
945 public static extern void GeomPlaneGetParams(IntPtr geom, ref Vector4 result);
946
947 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomPlaneGetParams"), SuppressUnmanagedCodeSecurity]
948 public static extern void GeomPlaneGetParams(IntPtr geom, ref dReal A);
949
950 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomPlanePointDepth"), SuppressUnmanagedCodeSecurity]
951 public static extern dReal GeomPlanePointDepth(IntPtr geom, dReal x, dReal y, dReal z);
952
953 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomPlaneSetParams"), SuppressUnmanagedCodeSecurity]
954 public static extern void GeomPlaneSetParams(IntPtr plane, dReal a, dReal b, dReal c, dReal d);
955
956 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGet"), SuppressUnmanagedCodeSecurity]
957 public static extern void GeomRayGet(IntPtr ray, ref Vector3 start, ref Vector3 dir);
958
959 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGet"), SuppressUnmanagedCodeSecurity]
960 public static extern void GeomRayGet(IntPtr ray, ref dReal startX, ref dReal dirX);
961
962 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGetClosestHit"), SuppressUnmanagedCodeSecurity]
963 public static extern int GeomRayGetClosestHit(IntPtr ray);
964
965 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGetLength"), SuppressUnmanagedCodeSecurity]
966 public static extern dReal GeomRayGetLength(IntPtr ray);
967
968 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGetParams"), SuppressUnmanagedCodeSecurity]
969 public static extern dReal GeomRayGetParams(IntPtr g, out int firstContact, out int backfaceCull);
970
971 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRaySet"), SuppressUnmanagedCodeSecurity]
972 public static extern void GeomRaySet(IntPtr ray, dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz);
973
974 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRaySetClosestHit"), SuppressUnmanagedCodeSecurity]
975 public static extern void GeomRaySetClosestHit(IntPtr ray, int closestHit);
976
977 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRaySetLength"), SuppressUnmanagedCodeSecurity]
978 public static extern void GeomRaySetLength(IntPtr ray, dReal length);
979
980 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRaySetParams"), SuppressUnmanagedCodeSecurity]
981 public static extern void GeomRaySetParams(IntPtr ray, int firstContact, int backfaceCull);
982
983 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetBody"), SuppressUnmanagedCodeSecurity]
984 public static extern void GeomSetBody(IntPtr geom, IntPtr body);
985
986 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetCategoryBits"), SuppressUnmanagedCodeSecurity]
987 public static extern void GeomSetCategoryBits(IntPtr geom, int bits);
988
989 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetCollideBits"), SuppressUnmanagedCodeSecurity]
990 public static extern void GeomSetCollideBits(IntPtr geom, int bits);
991
992 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetConvex"), SuppressUnmanagedCodeSecurity]
993 public static extern IntPtr GeomSetConvex(IntPtr geom, dReal[] planes, int planeCount, dReal[] points, int pointCount, int[] polygons);
994
995 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetData"), SuppressUnmanagedCodeSecurity]
996 public static extern void GeomSetData(IntPtr geom, IntPtr data);
997
998 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetPosition"), SuppressUnmanagedCodeSecurity]
999 public static extern void GeomSetOffsetPosition(IntPtr geom, dReal x, dReal y, dReal z);
1000
1001 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetQuaternion"), SuppressUnmanagedCodeSecurity]
1002 public static extern void GeomSetOffsetQuaternion(IntPtr geom, ref Quaternion Q);
1003
1004 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetQuaternion"), SuppressUnmanagedCodeSecurity]
1005 public static extern void GeomSetOffsetQuaternion(IntPtr geom, ref dReal X);
1006
1007 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetRotation"), SuppressUnmanagedCodeSecurity]
1008 public static extern void GeomSetOffsetRotation(IntPtr geom, ref Matrix3 R);
1009
1010 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetRotation"), SuppressUnmanagedCodeSecurity]
1011 public static extern void GeomSetOffsetRotation(IntPtr geom, ref dReal M00);
1012
1013 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldPosition"), SuppressUnmanagedCodeSecurity]
1014 public static extern void GeomSetOffsetWorldPosition(IntPtr geom, dReal x, dReal y, dReal z);
1015
1016 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldQuaternion"), SuppressUnmanagedCodeSecurity]
1017 public static extern void GeomSetOffsetWorldQuaternion(IntPtr geom, ref Quaternion Q);
1018
1019 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldQuaternion"), SuppressUnmanagedCodeSecurity]
1020 public static extern void GeomSetOffsetWorldQuaternion(IntPtr geom, ref dReal X);
1021
1022 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldRotation"), SuppressUnmanagedCodeSecurity]
1023 public static extern void GeomSetOffsetWorldRotation(IntPtr geom, ref Matrix3 R);
1024
1025 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldRotation"), SuppressUnmanagedCodeSecurity]
1026 public static extern void GeomSetOffsetWorldRotation(IntPtr geom, ref dReal M00);
1027
1028 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetPosition"), SuppressUnmanagedCodeSecurity]
1029 public static extern void GeomSetPosition(IntPtr geom, dReal x, dReal y, dReal z);
1030
1031 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetQuaternion"), SuppressUnmanagedCodeSecurity]
1032 public static extern void GeomSetQuaternion(IntPtr geom, ref Quaternion quat);
1033
1034 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetQuaternion"), SuppressUnmanagedCodeSecurity]
1035 public static extern void GeomSetQuaternion(IntPtr geom, ref dReal w);
1036
1037 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetRotation"), SuppressUnmanagedCodeSecurity]
1038 public static extern void GeomSetRotation(IntPtr geom, ref Matrix3 R);
1039
1040 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetRotation"), SuppressUnmanagedCodeSecurity]
1041 public static extern void GeomSetRotation(IntPtr geom, ref dReal M00);
1042
1043 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSphereGetRadius"), SuppressUnmanagedCodeSecurity]
1044 public static extern dReal GeomSphereGetRadius(IntPtr geom);
1045
1046 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSpherePointDepth"), SuppressUnmanagedCodeSecurity]
1047 public static extern dReal GeomSpherePointDepth(IntPtr geom, dReal x, dReal y, dReal z);
1048
1049 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSphereSetRadius"), SuppressUnmanagedCodeSecurity]
1050 public static extern void GeomSphereSetRadius(IntPtr geom, dReal radius);
1051
1052 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformGetCleanup"), SuppressUnmanagedCodeSecurity]
1053 public static extern int GeomTransformGetCleanup(IntPtr geom);
1054
1055 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformGetGeom"), SuppressUnmanagedCodeSecurity]
1056 public static extern IntPtr GeomTransformGetGeom(IntPtr geom);
1057
1058 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformGetInfo"), SuppressUnmanagedCodeSecurity]
1059 public static extern int GeomTransformGetInfo(IntPtr geom);
1060
1061 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformSetCleanup"), SuppressUnmanagedCodeSecurity]
1062 public static extern void GeomTransformSetCleanup(IntPtr geom, int mode);
1063
1064 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformSetGeom"), SuppressUnmanagedCodeSecurity]
1065 public static extern void GeomTransformSetGeom(IntPtr geom, IntPtr obj);
1066
1067 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformSetInfo"), SuppressUnmanagedCodeSecurity]
1068 public static extern void GeomTransformSetInfo(IntPtr geom, int info);
1069
1070 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildDouble"), SuppressUnmanagedCodeSecurity]
1071 public static extern void GeomTriMeshDataBuildDouble(IntPtr d,
1072 double[] vertices, int vertexStride, int vertexCount,
1073 int[] indices, int indexCount, int triStride);
1074
1075 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildDouble"), SuppressUnmanagedCodeSecurity]
1076 public static extern void GeomTriMeshDataBuildDouble(IntPtr d,
1077 IntPtr vertices, int vertexStride, int vertexCount,
1078 IntPtr indices, int indexCount, int triStride);
1079
1080 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildDouble1"), SuppressUnmanagedCodeSecurity]
1081 public static extern void GeomTriMeshDataBuildDouble1(IntPtr d,
1082 double[] vertices, int vertexStride, int vertexCount,
1083 int[] indices, int indexCount, int triStride,
1084 double[] normals);
1085
1086 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildDouble1"), SuppressUnmanagedCodeSecurity]
1087 public static extern void GeomTriMeshDataBuildDouble(IntPtr d,
1088 IntPtr vertices, int vertexStride, int vertexCount,
1089 IntPtr indices, int indexCount, int triStride,
1090 IntPtr normals);
1091
1092 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSimple"), SuppressUnmanagedCodeSecurity]
1093 public static extern void GeomTriMeshDataBuildSingle(IntPtr d,
1094 dReal[] vertices, int vertexStride, int vertexCount,
1095 int[] indices, int indexCount, int triStride);
1096
1097 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSimple"), SuppressUnmanagedCodeSecurity]
1098 public static extern void GeomTriMeshDataBuildSingle(IntPtr d,
1099 IntPtr vertices, int vertexStride, int vertexCount,
1100 IntPtr indices, int indexCount, int triStride);
1101
1102 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSimple1"), SuppressUnmanagedCodeSecurity]
1103 public static extern void GeomTriMeshDataBuildSingle1(IntPtr d,
1104 dReal[] vertices, int vertexStride, int vertexCount,
1105 int[] indices, int indexCount, int triStride,
1106 dReal[] normals);
1107
1108 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSimple1"), SuppressUnmanagedCodeSecurity]
1109 public static extern void GeomTriMeshDataBuildSingle1(IntPtr d,
1110 IntPtr vertices, int vertexStride, int vertexCount,
1111 IntPtr indices, int indexCount, int triStride,
1112 IntPtr normals);
1113
1114 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSingle"), SuppressUnmanagedCodeSecurity]
1115 public static extern void GeomTriMeshDataBuildSimple(IntPtr d,
1116 float[] vertices, int vertexStride, int vertexCount,
1117 int[] indices, int indexCount, int triStride);
1118
1119 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSingle"), SuppressUnmanagedCodeSecurity]
1120 public static extern void GeomTriMeshDataBuildSimple(IntPtr d,
1121 IntPtr vertices, int vertexStride, int vertexCount,
1122 IntPtr indices, int indexCount, int triStride);
1123
1124 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSingle1"), SuppressUnmanagedCodeSecurity]
1125 public static extern void GeomTriMeshDataBuildSimple1(IntPtr d,
1126 float[] vertices, int vertexStride, int vertexCount,
1127 int[] indices, int indexCount, int triStride,
1128 float[] normals);
1129
1130 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSingle1"), SuppressUnmanagedCodeSecurity]
1131 public static extern void GeomTriMeshDataBuildSimple1(IntPtr d,
1132 IntPtr vertices, int vertexStride, int vertexCount,
1133 IntPtr indices, int indexCount, int triStride,
1134 IntPtr normals);
1135
1136 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshClearTCCache"), SuppressUnmanagedCodeSecurity]
1137 public static extern void GeomTriMeshClearTCCache(IntPtr g);
1138
1139 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataCreate"), SuppressUnmanagedCodeSecurity]
1140 public static extern IntPtr GeomTriMeshDataCreate();
1141
1142 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataDestroy"), SuppressUnmanagedCodeSecurity]
1143 public static extern void GeomTriMeshDataDestroy(IntPtr d);
1144
1145 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataGet"), SuppressUnmanagedCodeSecurity]
1146 public static extern IntPtr GeomTriMeshDataGet(IntPtr d, int data_id);
1147
1148 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataPreprocess"), SuppressUnmanagedCodeSecurity]
1149 public static extern void GeomTriMeshDataPreprocess(IntPtr d);
1150
1151 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataSet"), SuppressUnmanagedCodeSecurity]
1152 public static extern void GeomTriMeshDataSet(IntPtr d, int data_id, IntPtr in_data);
1153
1154 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataUpdate"), SuppressUnmanagedCodeSecurity]
1155 public static extern void GeomTriMeshDataUpdate(IntPtr d);
1156
1157 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshEnableTC"), SuppressUnmanagedCodeSecurity]
1158 public static extern void GeomTriMeshEnableTC(IntPtr g, int geomClass, bool enable);
1159
1160 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetArrayCallback"), SuppressUnmanagedCodeSecurity]
1161 public static extern TriArrayCallback GeomTriMeshGetArrayCallback(IntPtr g);
1162
1163 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetCallback"), SuppressUnmanagedCodeSecurity]
1164 public static extern TriCallback GeomTriMeshGetCallback(IntPtr g);
1165
1166 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetData"), SuppressUnmanagedCodeSecurity]
1167 public static extern IntPtr GeomTriMeshGetData(IntPtr g);
1168
1169 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetLastTransform"), SuppressUnmanagedCodeSecurity]
1170 public extern unsafe static Matrix4* GeomTriMeshGetLastTransformUnsafe(IntPtr geom);
1171 public static Matrix4 GeomTriMeshGetLastTransform(IntPtr geom)
1172 {
1173 unsafe { return *(GeomTriMeshGetLastTransformUnsafe(geom)); }
1174 }
1175
1176 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetPoint"), SuppressUnmanagedCodeSecurity]
1177 public extern static void GeomTriMeshGetPoint(IntPtr g, int index, dReal u, dReal v, ref Vector3 outVec);
1178
1179 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetRayCallback"), SuppressUnmanagedCodeSecurity]
1180 public static extern TriRayCallback GeomTriMeshGetRayCallback(IntPtr g);
1181
1182 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetTriangle"), SuppressUnmanagedCodeSecurity]
1183 public extern static void GeomTriMeshGetTriangle(IntPtr g, int index, ref Vector3 v0, ref Vector3 v1, ref Vector3 v2);
1184
1185 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetTriangleCount"), SuppressUnmanagedCodeSecurity]
1186 public extern static int GeomTriMeshGetTriangleCount(IntPtr g);
1187
1188 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetTriMeshDataID"), SuppressUnmanagedCodeSecurity]
1189 public static extern IntPtr GeomTriMeshGetTriMeshDataID(IntPtr g);
1190
1191 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshIsTCEnabled"), SuppressUnmanagedCodeSecurity]
1192 public static extern bool GeomTriMeshIsTCEnabled(IntPtr g, int geomClass);
1193
1194 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetArrayCallback"), SuppressUnmanagedCodeSecurity]
1195 public static extern void GeomTriMeshSetArrayCallback(IntPtr g, TriArrayCallback arrayCallback);
1196
1197 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetCallback"), SuppressUnmanagedCodeSecurity]
1198 public static extern void GeomTriMeshSetCallback(IntPtr g, TriCallback callback);
1199
1200 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetData"), SuppressUnmanagedCodeSecurity]
1201 public static extern void GeomTriMeshSetData(IntPtr g, IntPtr data);
1202
1203 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetLastTransform"), SuppressUnmanagedCodeSecurity]
1204 public static extern void GeomTriMeshSetLastTransform(IntPtr g, ref Matrix4 last_trans);
1205
1206 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetLastTransform"), SuppressUnmanagedCodeSecurity]
1207 public static extern void GeomTriMeshSetLastTransform(IntPtr g, ref dReal M00);
1208
1209 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetRayCallback"), SuppressUnmanagedCodeSecurity]
1210 public static extern void GeomTriMeshSetRayCallback(IntPtr g, TriRayCallback callback);
1211
1212 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGetConfiguration"), SuppressUnmanagedCodeSecurity]
1213 public static extern string GetConfiguration(string str);
1214
1215 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dHashSpaceCreate"), SuppressUnmanagedCodeSecurity]
1216 public static extern IntPtr HashSpaceCreate(IntPtr space);
1217
1218 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dHashSpaceGetLevels"), SuppressUnmanagedCodeSecurity]
1219 public static extern void HashSpaceGetLevels(IntPtr space, out int minlevel, out int maxlevel);
1220
1221 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dHashSpaceSetLevels"), SuppressUnmanagedCodeSecurity]
1222 public static extern void HashSpaceSetLevels(IntPtr space, int minlevel, int maxlevel);
1223
1224 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dInfiniteAABB"), SuppressUnmanagedCodeSecurity]
1225 public static extern void InfiniteAABB(IntPtr geom, out AABB aabb);
1226
1227 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dInitODE"), SuppressUnmanagedCodeSecurity]
1228 public static extern void InitODE();
1229
1230 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dInitODE2"), SuppressUnmanagedCodeSecurity]
1231 public static extern int InitODE2(uint ODEInitFlags);
1232
1233 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dIsPositiveDefinite"), SuppressUnmanagedCodeSecurity]
1234 public static extern int IsPositiveDefinite(ref dReal A, int n);
1235
1236 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dInvertPDMatrix"), SuppressUnmanagedCodeSecurity]
1237 public static extern int InvertPDMatrix(ref dReal A, out dReal Ainv, int n);
1238
1239 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddAMotorTorques"), SuppressUnmanagedCodeSecurity]
1240 public static extern void JointAddAMotorTorques(IntPtr joint, dReal torque1, dReal torque2, dReal torque3);
1241
1242 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddHingeTorque"), SuppressUnmanagedCodeSecurity]
1243 public static extern void JointAddHingeTorque(IntPtr joint, dReal torque);
1244
1245 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddHinge2Torque"), SuppressUnmanagedCodeSecurity]
1246 public static extern void JointAddHinge2Torques(IntPtr joint, dReal torque1, dReal torque2);
1247
1248 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddPRTorque"), SuppressUnmanagedCodeSecurity]
1249 public static extern void JointAddPRTorque(IntPtr joint, dReal torque);
1250
1251 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddUniversalTorque"), SuppressUnmanagedCodeSecurity]
1252 public static extern void JointAddUniversalTorques(IntPtr joint, dReal torque1, dReal torque2);
1253
1254 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddSliderForce"), SuppressUnmanagedCodeSecurity]
1255 public static extern void JointAddSliderForce(IntPtr joint, dReal force);
1256
1257 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAttach"), SuppressUnmanagedCodeSecurity]
1258 public static extern void JointAttach(IntPtr joint, IntPtr body1, IntPtr body2);
1259
1260 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateAMotor"), SuppressUnmanagedCodeSecurity]
1261 public static extern IntPtr JointCreateAMotor(IntPtr world, IntPtr group);
1262
1263 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateBall"), SuppressUnmanagedCodeSecurity]
1264 public static extern IntPtr JointCreateBall(IntPtr world, IntPtr group);
1265
1266 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateContact"), SuppressUnmanagedCodeSecurity]
1267 public static extern IntPtr JointCreateContact(IntPtr world, IntPtr group, ref Contact contact);
1268 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateContact"), SuppressUnmanagedCodeSecurity]
1269 public static extern IntPtr JointCreateContactPtr(IntPtr world, IntPtr group, IntPtr contact);
1270
1271 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateFixed"), SuppressUnmanagedCodeSecurity]
1272 public static extern IntPtr JointCreateFixed(IntPtr world, IntPtr group);
1273
1274 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateHinge"), SuppressUnmanagedCodeSecurity]
1275 public static extern IntPtr JointCreateHinge(IntPtr world, IntPtr group);
1276
1277 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateHinge2"), SuppressUnmanagedCodeSecurity]
1278 public static extern IntPtr JointCreateHinge2(IntPtr world, IntPtr group);
1279
1280 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateLMotor"), SuppressUnmanagedCodeSecurity]
1281 public static extern IntPtr JointCreateLMotor(IntPtr world, IntPtr group);
1282
1283 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateNull"), SuppressUnmanagedCodeSecurity]
1284 public static extern IntPtr JointCreateNull(IntPtr world, IntPtr group);
1285
1286 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreatePR"), SuppressUnmanagedCodeSecurity]
1287 public static extern IntPtr JointCreatePR(IntPtr world, IntPtr group);
1288
1289 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreatePlane2D"), SuppressUnmanagedCodeSecurity]
1290 public static extern IntPtr JointCreatePlane2D(IntPtr world, IntPtr group);
1291
1292 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateSlider"), SuppressUnmanagedCodeSecurity]
1293 public static extern IntPtr JointCreateSlider(IntPtr world, IntPtr group);
1294
1295 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateUniversal"), SuppressUnmanagedCodeSecurity]
1296 public static extern IntPtr JointCreateUniversal(IntPtr world, IntPtr group);
1297
1298 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointDestroy"), SuppressUnmanagedCodeSecurity]
1299 public static extern void JointDestroy(IntPtr j);
1300
1301 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorAngle"), SuppressUnmanagedCodeSecurity]
1302 public static extern dReal JointGetAMotorAngle(IntPtr j, int anum);
1303
1304 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorAngleRate"), SuppressUnmanagedCodeSecurity]
1305 public static extern dReal JointGetAMotorAngleRate(IntPtr j, int anum);
1306
1307 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorAxis"), SuppressUnmanagedCodeSecurity]
1308 public static extern void JointGetAMotorAxis(IntPtr j, int anum, out Vector3 result);
1309
1310 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorAxisRel"), SuppressUnmanagedCodeSecurity]
1311 public static extern int JointGetAMotorAxisRel(IntPtr j, int anum);
1312
1313 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorMode"), SuppressUnmanagedCodeSecurity]
1314 public static extern int JointGetAMotorMode(IntPtr j);
1315
1316 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorNumAxes"), SuppressUnmanagedCodeSecurity]
1317 public static extern int JointGetAMotorNumAxes(IntPtr j);
1318
1319 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorParam"), SuppressUnmanagedCodeSecurity]
1320 public static extern dReal JointGetAMotorParam(IntPtr j, int parameter);
1321
1322 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetBallAnchor"), SuppressUnmanagedCodeSecurity]
1323 public static extern void JointGetBallAnchor(IntPtr j, out Vector3 result);
1324
1325 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetBallAnchor2"), SuppressUnmanagedCodeSecurity]
1326 public static extern void JointGetBallAnchor2(IntPtr j, out Vector3 result);
1327
1328 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetBody"), SuppressUnmanagedCodeSecurity]
1329 public static extern IntPtr JointGetBody(IntPtr j);
1330
1331 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetData"), SuppressUnmanagedCodeSecurity]
1332 public static extern IntPtr JointGetData(IntPtr j);
1333
1334 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetFeedback"), SuppressUnmanagedCodeSecurity]
1335 public extern unsafe static JointFeedback* JointGetFeedbackUnsafe(IntPtr j);
1336 public static JointFeedback JointGetFeedback(IntPtr j)
1337 {
1338 unsafe { return *(JointGetFeedbackUnsafe(j)); }
1339 }
1340
1341 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAnchor"), SuppressUnmanagedCodeSecurity]
1342 public static extern void JointGetHingeAnchor(IntPtr j, out Vector3 result);
1343
1344 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAngle"), SuppressUnmanagedCodeSecurity]
1345 public static extern dReal JointGetHingeAngle(IntPtr j);
1346
1347 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAngleRate"), SuppressUnmanagedCodeSecurity]
1348 public static extern dReal JointGetHingeAngleRate(IntPtr j);
1349
1350 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAxis"), SuppressUnmanagedCodeSecurity]
1351 public static extern void JointGetHingeAxis(IntPtr j, out Vector3 result);
1352
1353 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeParam"), SuppressUnmanagedCodeSecurity]
1354 public static extern dReal JointGetHingeParam(IntPtr j, int parameter);
1355
1356 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Angle1"), SuppressUnmanagedCodeSecurity]
1357 public static extern dReal JointGetHinge2Angle1(IntPtr j);
1358
1359 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Angle1Rate"), SuppressUnmanagedCodeSecurity]
1360 public static extern dReal JointGetHinge2Angle1Rate(IntPtr j);
1361
1362 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Angle2Rate"), SuppressUnmanagedCodeSecurity]
1363 public static extern dReal JointGetHinge2Angle2Rate(IntPtr j);
1364
1365 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAnchor2"), SuppressUnmanagedCodeSecurity]
1366 public static extern void JointGetHingeAnchor2(IntPtr j, out Vector3 result);
1367
1368 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Anchor"), SuppressUnmanagedCodeSecurity]
1369 public static extern void JointGetHinge2Anchor(IntPtr j, out Vector3 result);
1370
1371 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Anchor2"), SuppressUnmanagedCodeSecurity]
1372 public static extern void JointGetHinge2Anchor2(IntPtr j, out Vector3 result);
1373
1374 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Axis1"), SuppressUnmanagedCodeSecurity]
1375 public static extern void JointGetHinge2Axis1(IntPtr j, out Vector3 result);
1376
1377 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Axis2"), SuppressUnmanagedCodeSecurity]
1378 public static extern void JointGetHinge2Axis2(IntPtr j, out Vector3 result);
1379
1380 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Param"), SuppressUnmanagedCodeSecurity]
1381 public static extern dReal JointGetHinge2Param(IntPtr j, int parameter);
1382
1383 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetLMotorAxis"), SuppressUnmanagedCodeSecurity]
1384 public static extern void JointGetLMotorAxis(IntPtr j, int anum, out Vector3 result);
1385
1386 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetLMotorNumAxes"), SuppressUnmanagedCodeSecurity]
1387 public static extern int JointGetLMotorNumAxes(IntPtr j);
1388
1389 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetLMotorParam"), SuppressUnmanagedCodeSecurity]
1390 public static extern dReal JointGetLMotorParam(IntPtr j, int parameter);
1391
1392 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRAnchor"), SuppressUnmanagedCodeSecurity]
1393 public static extern void JointGetPRAnchor(IntPtr j, out Vector3 result);
1394
1395 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRAxis1"), SuppressUnmanagedCodeSecurity]
1396 public static extern void JointGetPRAxis1(IntPtr j, out Vector3 result);
1397
1398 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRAxis2"), SuppressUnmanagedCodeSecurity]
1399 public static extern void JointGetPRAxis2(IntPtr j, out Vector3 result);
1400
1401 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRParam"), SuppressUnmanagedCodeSecurity]
1402 public static extern dReal JointGetPRParam(IntPtr j, int parameter);
1403
1404 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRPosition"), SuppressUnmanagedCodeSecurity]
1405 public static extern dReal JointGetPRPosition(IntPtr j);
1406
1407 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRPositionRate"), SuppressUnmanagedCodeSecurity]
1408 public static extern dReal JointGetPRPositionRate(IntPtr j);
1409
1410 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetSliderAxis"), SuppressUnmanagedCodeSecurity]
1411 public static extern void JointGetSliderAxis(IntPtr j, out Vector3 result);
1412
1413 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetSliderParam"), SuppressUnmanagedCodeSecurity]
1414 public static extern dReal JointGetSliderParam(IntPtr j, int parameter);
1415
1416 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetSliderPosition"), SuppressUnmanagedCodeSecurity]
1417 public static extern dReal JointGetSliderPosition(IntPtr j);
1418
1419 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetSliderPositionRate"), SuppressUnmanagedCodeSecurity]
1420 public static extern dReal JointGetSliderPositionRate(IntPtr j);
1421
1422 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetType"), SuppressUnmanagedCodeSecurity]
1423 public static extern JointType JointGetType(IntPtr j);
1424
1425 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAnchor"), SuppressUnmanagedCodeSecurity]
1426 public static extern void JointGetUniversalAnchor(IntPtr j, out Vector3 result);
1427
1428 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAnchor2"), SuppressUnmanagedCodeSecurity]
1429 public static extern void JointGetUniversalAnchor2(IntPtr j, out Vector3 result);
1430
1431 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngle1"), SuppressUnmanagedCodeSecurity]
1432 public static extern dReal JointGetUniversalAngle1(IntPtr j);
1433
1434 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngle1Rate"), SuppressUnmanagedCodeSecurity]
1435 public static extern dReal JointGetUniversalAngle1Rate(IntPtr j);
1436
1437 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngle2"), SuppressUnmanagedCodeSecurity]
1438 public static extern dReal JointGetUniversalAngle2(IntPtr j);
1439
1440 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngle2Rate"), SuppressUnmanagedCodeSecurity]
1441 public static extern dReal JointGetUniversalAngle2Rate(IntPtr j);
1442
1443 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngles"), SuppressUnmanagedCodeSecurity]
1444 public static extern void JointGetUniversalAngles(IntPtr j, out dReal angle1, out dReal angle2);
1445
1446 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAxis1"), SuppressUnmanagedCodeSecurity]
1447 public static extern void JointGetUniversalAxis1(IntPtr j, out Vector3 result);
1448
1449 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAxis2"), SuppressUnmanagedCodeSecurity]
1450 public static extern void JointGetUniversalAxis2(IntPtr j, out Vector3 result);
1451
1452 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalParam"), SuppressUnmanagedCodeSecurity]
1453 public static extern dReal JointGetUniversalParam(IntPtr j, int parameter);
1454
1455 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGroupCreate"), SuppressUnmanagedCodeSecurity]
1456 public static extern IntPtr JointGroupCreate(int max_size);
1457
1458 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGroupDestroy"), SuppressUnmanagedCodeSecurity]
1459 public static extern void JointGroupDestroy(IntPtr group);
1460
1461 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGroupEmpty"), SuppressUnmanagedCodeSecurity]
1462 public static extern void JointGroupEmpty(IntPtr group);
1463
1464 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorAngle"), SuppressUnmanagedCodeSecurity]
1465 public static extern void JointSetAMotorAngle(IntPtr j, int anum, dReal angle);
1466
1467 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorAxis"), SuppressUnmanagedCodeSecurity]
1468 public static extern void JointSetAMotorAxis(IntPtr j, int anum, int rel, dReal x, dReal y, dReal z);
1469
1470 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorMode"), SuppressUnmanagedCodeSecurity]
1471 public static extern void JointSetAMotorMode(IntPtr j, int mode);
1472
1473 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorNumAxes"), SuppressUnmanagedCodeSecurity]
1474 public static extern void JointSetAMotorNumAxes(IntPtr group, int num);
1475
1476 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorParam"), SuppressUnmanagedCodeSecurity]
1477 public static extern void JointSetAMotorParam(IntPtr group, int parameter, dReal value);
1478
1479 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetBallAnchor"), SuppressUnmanagedCodeSecurity]
1480 public static extern void JointSetBallAnchor(IntPtr j, dReal x, dReal y, dReal z);
1481
1482 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetBallAnchor2"), SuppressUnmanagedCodeSecurity]
1483 public static extern void JointSetBallAnchor2(IntPtr j, dReal x, dReal y, dReal z);
1484
1485 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetData"), SuppressUnmanagedCodeSecurity]
1486 public static extern void JointSetData(IntPtr j, IntPtr data);
1487
1488 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetFeedback"), SuppressUnmanagedCodeSecurity]
1489 public static extern void JointSetFeedback(IntPtr j, out JointFeedback feedback);
1490
1491 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetFixed"), SuppressUnmanagedCodeSecurity]
1492 public static extern void JointSetFixed(IntPtr j);
1493
1494 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHingeAnchor"), SuppressUnmanagedCodeSecurity]
1495 public static extern void JointSetHingeAnchor(IntPtr j, dReal x, dReal y, dReal z);
1496
1497 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHingeAnchorDelta"), SuppressUnmanagedCodeSecurity]
1498 public static extern void JointSetHingeAnchorDelta(IntPtr j, dReal x, dReal y, dReal z, dReal ax, dReal ay, dReal az);
1499
1500 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHingeAxis"), SuppressUnmanagedCodeSecurity]
1501 public static extern void JointSetHingeAxis(IntPtr j, dReal x, dReal y, dReal z);
1502
1503 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHingeParam"), SuppressUnmanagedCodeSecurity]
1504 public static extern void JointSetHingeParam(IntPtr j, int parameter, dReal value);
1505
1506 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHinge2Anchor"), SuppressUnmanagedCodeSecurity]
1507 public static extern void JointSetHinge2Anchor(IntPtr j, dReal x, dReal y, dReal z);
1508
1509 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHinge2Axis1"), SuppressUnmanagedCodeSecurity]
1510 public static extern void JointSetHinge2Axis1(IntPtr j, dReal x, dReal y, dReal z);
1511
1512 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHinge2Axis2"), SuppressUnmanagedCodeSecurity]
1513 public static extern void JointSetHinge2Axis2(IntPtr j, dReal x, dReal y, dReal z);
1514
1515 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHinge2Param"), SuppressUnmanagedCodeSecurity]
1516 public static extern void JointSetHinge2Param(IntPtr j, int parameter, dReal value);
1517
1518 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetLMotorAxis"), SuppressUnmanagedCodeSecurity]
1519 public static extern void JointSetLMotorAxis(IntPtr j, int anum, int rel, dReal x, dReal y, dReal z);
1520
1521 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetLMotorNumAxes"), SuppressUnmanagedCodeSecurity]
1522 public static extern void JointSetLMotorNumAxes(IntPtr j, int num);
1523
1524 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetLMotorParam"), SuppressUnmanagedCodeSecurity]
1525 public static extern void JointSetLMotorParam(IntPtr j, int parameter, dReal value);
1526
1527 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPlane2DAngleParam"), SuppressUnmanagedCodeSecurity]
1528 public static extern void JointSetPlane2DAngleParam(IntPtr j, int parameter, dReal value);
1529
1530 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPlane2DXParam"), SuppressUnmanagedCodeSecurity]
1531 public static extern void JointSetPlane2DXParam(IntPtr j, int parameter, dReal value);
1532
1533 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPlane2DYParam"), SuppressUnmanagedCodeSecurity]
1534 public static extern void JointSetPlane2DYParam(IntPtr j, int parameter, dReal value);
1535
1536 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPRAnchor"), SuppressUnmanagedCodeSecurity]
1537 public static extern void JointSetPRAnchor(IntPtr j, dReal x, dReal y, dReal z);
1538
1539 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPRAxis1"), SuppressUnmanagedCodeSecurity]
1540 public static extern void JointSetPRAxis1(IntPtr j, dReal x, dReal y, dReal z);
1541
1542 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPRAxis2"), SuppressUnmanagedCodeSecurity]
1543 public static extern void JointSetPRAxis2(IntPtr j, dReal x, dReal y, dReal z);
1544
1545 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPRParam"), SuppressUnmanagedCodeSecurity]
1546 public static extern void JointSetPRParam(IntPtr j, int parameter, dReal value);
1547
1548 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetSliderAxis"), SuppressUnmanagedCodeSecurity]
1549 public static extern void JointSetSliderAxis(IntPtr j, dReal x, dReal y, dReal z);
1550
1551 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetSliderAxisDelta"), SuppressUnmanagedCodeSecurity]
1552 public static extern void JointSetSliderAxisDelta(IntPtr j, dReal x, dReal y, dReal z, dReal ax, dReal ay, dReal az);
1553
1554 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetSliderParam"), SuppressUnmanagedCodeSecurity]
1555 public static extern void JointSetSliderParam(IntPtr j, int parameter, dReal value);
1556
1557 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetUniversalAnchor"), SuppressUnmanagedCodeSecurity]
1558 public static extern void JointSetUniversalAnchor(IntPtr j, dReal x, dReal y, dReal z);
1559
1560 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetUniversalAxis1"), SuppressUnmanagedCodeSecurity]
1561 public static extern void JointSetUniversalAxis1(IntPtr j, dReal x, dReal y, dReal z);
1562
1563 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetUniversalAxis2"), SuppressUnmanagedCodeSecurity]
1564 public static extern void JointSetUniversalAxis2(IntPtr j, dReal x, dReal y, dReal z);
1565
1566 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetUniversalParam"), SuppressUnmanagedCodeSecurity]
1567 public static extern void JointSetUniversalParam(IntPtr j, int parameter, dReal value);
1568
1569 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dLDLTAddTL"), SuppressUnmanagedCodeSecurity]
1570 public static extern void LDLTAddTL(ref dReal L, ref dReal d, ref dReal a, int n, int nskip);
1571
1572 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassAdd"), SuppressUnmanagedCodeSecurity]
1573 public static extern void MassAdd(ref Mass a, ref Mass b);
1574
1575 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassAdjust"), SuppressUnmanagedCodeSecurity]
1576 public static extern void MassAdjust(ref Mass m, dReal newmass);
1577
1578 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassCheck"), SuppressUnmanagedCodeSecurity]
1579 public static extern bool MassCheck(ref Mass m);
1580
1581 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassRotate"), SuppressUnmanagedCodeSecurity]
1582 public static extern void MassRotate(ref Mass mass, ref Matrix3 R);
1583
1584 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassRotate"), SuppressUnmanagedCodeSecurity]
1585 public static extern void MassRotate(ref Mass mass, ref dReal M00);
1586
1587 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetBox"), SuppressUnmanagedCodeSecurity]
1588 public static extern void MassSetBox(out Mass mass, dReal density, dReal lx, dReal ly, dReal lz);
1589
1590 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetBoxTotal"), SuppressUnmanagedCodeSecurity]
1591 public static extern void MassSetBoxTotal(out Mass mass, dReal total_mass, dReal lx, dReal ly, dReal lz);
1592
1593 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetCapsule"), SuppressUnmanagedCodeSecurity]
1594 public static extern void MassSetCapsule(out Mass mass, dReal density, int direction, dReal radius, dReal length);
1595
1596 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetCapsuleTotal"), SuppressUnmanagedCodeSecurity]
1597 public static extern void MassSetCapsuleTotal(out Mass mass, dReal total_mass, int direction, dReal radius, dReal length);
1598
1599 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetCylinder"), SuppressUnmanagedCodeSecurity]
1600 public static extern void MassSetCylinder(out Mass mass, dReal density, int direction, dReal radius, dReal length);
1601
1602 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetCylinderTotal"), SuppressUnmanagedCodeSecurity]
1603 public static extern void MassSetCylinderTotal(out Mass mass, dReal total_mass, int direction, dReal radius, dReal length);
1604
1605 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetParameters"), SuppressUnmanagedCodeSecurity]
1606 public static extern void MassSetParameters(out Mass mass, dReal themass,
1607 dReal cgx, dReal cgy, dReal cgz,
1608 dReal i11, dReal i22, dReal i33,
1609 dReal i12, dReal i13, dReal i23);
1610
1611 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetSphere"), SuppressUnmanagedCodeSecurity]
1612 public static extern void MassSetSphere(out Mass mass, dReal density, dReal radius);
1613
1614 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetSphereTotal"), SuppressUnmanagedCodeSecurity]
1615 public static extern void dMassSetSphereTotal(out Mass mass, dReal total_mass, dReal radius);
1616
1617 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetTrimesh"), SuppressUnmanagedCodeSecurity]
1618 public static extern void MassSetTrimesh(out Mass mass, dReal density, IntPtr g);
1619
1620 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetZero"), SuppressUnmanagedCodeSecurity]
1621 public static extern void MassSetZero(out Mass mass);
1622
1623 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassTranslate"), SuppressUnmanagedCodeSecurity]
1624 public static extern void MassTranslate(ref Mass mass, dReal x, dReal y, dReal z);
1625
1626 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMultiply0"), SuppressUnmanagedCodeSecurity]
1627 public static extern void Multiply0(out dReal A00, ref dReal B00, ref dReal C00, int p, int q, int r);
1628
1629 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMultiply0"), SuppressUnmanagedCodeSecurity]
1630 private static extern void MultiplyiM3V3(out Vector3 vout, ref Matrix3 matrix, ref Vector3 vect,int p, int q, int r);
1631 public static void MultiplyM3V3(out Vector3 outvector, ref Matrix3 matrix, ref Vector3 invector)
1632 {
1633 MultiplyiM3V3(out outvector, ref matrix, ref invector, 3, 3, 1);
1634 }
1635
1636 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMultiply1"), SuppressUnmanagedCodeSecurity]
1637 public static extern void Multiply1(out dReal A00, ref dReal B00, ref dReal C00, int p, int q, int r);
1638
1639 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMultiply2"), SuppressUnmanagedCodeSecurity]
1640 public static extern void Multiply2(out dReal A00, ref dReal B00, ref dReal C00, int p, int q, int r);
1641
1642 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQFromAxisAndAngle"), SuppressUnmanagedCodeSecurity]
1643 public static extern void QFromAxisAndAngle(out Quaternion q, dReal ax, dReal ay, dReal az, dReal angle);
1644
1645 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQfromR"), SuppressUnmanagedCodeSecurity]
1646 public static extern void QfromR(out Quaternion q, ref Matrix3 R);
1647
1648 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQMultiply0"), SuppressUnmanagedCodeSecurity]
1649 public static extern void QMultiply0(out Quaternion qa, ref Quaternion qb, ref Quaternion qc);
1650
1651 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQMultiply1"), SuppressUnmanagedCodeSecurity]
1652 public static extern void QMultiply1(out Quaternion qa, ref Quaternion qb, ref Quaternion qc);
1653
1654 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQMultiply2"), SuppressUnmanagedCodeSecurity]
1655 public static extern void QMultiply2(out Quaternion qa, ref Quaternion qb, ref Quaternion qc);
1656
1657 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQMultiply3"), SuppressUnmanagedCodeSecurity]
1658 public static extern void QMultiply3(out Quaternion qa, ref Quaternion qb, ref Quaternion qc);
1659
1660 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQSetIdentity"), SuppressUnmanagedCodeSecurity]
1661 public static extern void QSetIdentity(out Quaternion q);
1662
1663 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQuadTreeSpaceCreate"), SuppressUnmanagedCodeSecurity]
1664 public static extern IntPtr QuadTreeSpaceCreate(IntPtr space, ref Vector3 center, ref Vector3 extents, int depth);
1665
1666 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQuadTreeSpaceCreate"), SuppressUnmanagedCodeSecurity]
1667 public static extern IntPtr QuadTreeSpaceCreate(IntPtr space, ref dReal centerX, ref dReal extentsX, int depth);
1668
1669 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRandReal"), SuppressUnmanagedCodeSecurity]
1670 public static extern dReal RandReal();
1671
1672 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRFrom2Axes"), SuppressUnmanagedCodeSecurity]
1673 public static extern void RFrom2Axes(out Matrix3 R, dReal ax, dReal ay, dReal az, dReal bx, dReal by, dReal bz);
1674
1675 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRFromAxisAndAngle"), SuppressUnmanagedCodeSecurity]
1676 public static extern void RFromAxisAndAngle(out Matrix3 R, dReal x, dReal y, dReal z, dReal angle);
1677
1678 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRFromEulerAngles"), SuppressUnmanagedCodeSecurity]
1679 public static extern void RFromEulerAngles(out Matrix3 R, dReal phi, dReal theta, dReal psi);
1680
1681 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRfromQ"), SuppressUnmanagedCodeSecurity]
1682 public static extern void RfromQ(out Matrix3 R, ref Quaternion q);
1683
1684 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRFromZAxis"), SuppressUnmanagedCodeSecurity]
1685 public static extern void RFromZAxis(out Matrix3 R, dReal ax, dReal ay, dReal az);
1686
1687 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRSetIdentity"), SuppressUnmanagedCodeSecurity]
1688 public static extern void RSetIdentity(out Matrix3 R);
1689
1690 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSetValue"), SuppressUnmanagedCodeSecurity]
1691 public static extern void SetValue(out dReal a, int n);
1692
1693 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSetZero"), SuppressUnmanagedCodeSecurity]
1694 public static extern void SetZero(out dReal a, int n);
1695
1696 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSimpleSpaceCreate"), SuppressUnmanagedCodeSecurity]
1697 public static extern IntPtr SimpleSpaceCreate(IntPtr space);
1698
1699 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSolveCholesky"), SuppressUnmanagedCodeSecurity]
1700 public static extern void SolveCholesky(ref dReal L, out dReal b, int n);
1701
1702 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSolveL1"), SuppressUnmanagedCodeSecurity]
1703 public static extern void SolveL1(ref dReal L, out dReal b, int n, int nskip);
1704
1705 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSolveL1T"), SuppressUnmanagedCodeSecurity]
1706 public static extern void SolveL1T(ref dReal L, out dReal b, int n, int nskip);
1707
1708 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSolveLDLT"), SuppressUnmanagedCodeSecurity]
1709 public static extern void SolveLDLT(ref dReal L, ref dReal d, out dReal b, int n, int nskip);
1710
1711 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceAdd"), SuppressUnmanagedCodeSecurity]
1712 public static extern void SpaceAdd(IntPtr space, IntPtr geom);
1713
1714 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceLockQuery"), SuppressUnmanagedCodeSecurity]
1715 public static extern bool SpaceLockQuery(IntPtr space);
1716
1717 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceClean"), SuppressUnmanagedCodeSecurity]
1718 public static extern void SpaceClean(IntPtr space);
1719
1720 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceCollide"), SuppressUnmanagedCodeSecurity]
1721 public static extern void SpaceCollide(IntPtr space, IntPtr data, NearCallback callback);
1722
1723 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceCollide2"), SuppressUnmanagedCodeSecurity]
1724 public static extern void SpaceCollide2(IntPtr space1, IntPtr space2, IntPtr data, NearCallback callback);
1725
1726 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceDestroy"), SuppressUnmanagedCodeSecurity]
1727 public static extern void SpaceDestroy(IntPtr space);
1728
1729 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceGetCleanup"), SuppressUnmanagedCodeSecurity]
1730 public static extern bool SpaceGetCleanup(IntPtr space);
1731
1732 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceGetNumGeoms"), SuppressUnmanagedCodeSecurity]
1733 public static extern int SpaceGetNumGeoms(IntPtr space);
1734
1735 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceGetGeom"), SuppressUnmanagedCodeSecurity]
1736 public static extern IntPtr SpaceGetGeom(IntPtr space, int i);
1737
1738 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceGetSublevel"), SuppressUnmanagedCodeSecurity]
1739 public static extern int SpaceGetSublevel(IntPtr space);
1740
1741 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceQuery"), SuppressUnmanagedCodeSecurity]
1742 public static extern bool SpaceQuery(IntPtr space, IntPtr geom);
1743
1744 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceRemove"), SuppressUnmanagedCodeSecurity]
1745 public static extern void SpaceRemove(IntPtr space, IntPtr geom);
1746
1747 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceSetCleanup"), SuppressUnmanagedCodeSecurity]
1748 public static extern void SpaceSetCleanup(IntPtr space, bool mode);
1749
1750 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceSetSublevel"), SuppressUnmanagedCodeSecurity]
1751 public static extern void SpaceSetSublevel(IntPtr space, int sublevel);
1752
1753 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSweepAndPruneSpaceCreate"), SuppressUnmanagedCodeSecurity]
1754 public static extern IntPtr SweepAndPruneSpaceCreate(IntPtr space, int AxisOrder);
1755
1756 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dVectorScale"), SuppressUnmanagedCodeSecurity]
1757 public static extern void VectorScale(out dReal a, ref dReal d, int n);
1758
1759 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldCreate"), SuppressUnmanagedCodeSecurity]
1760 public static extern IntPtr WorldCreate();
1761
1762 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldDestroy"), SuppressUnmanagedCodeSecurity]
1763 public static extern void WorldDestroy(IntPtr world);
1764
1765 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableAverageSamplesCount"), SuppressUnmanagedCodeSecurity]
1766 public static extern int WorldGetAutoDisableAverageSamplesCount(IntPtr world);
1767
1768 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableAngularThreshold"), SuppressUnmanagedCodeSecurity]
1769 public static extern dReal WorldGetAutoDisableAngularThreshold(IntPtr world);
1770
1771 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableFlag"), SuppressUnmanagedCodeSecurity]
1772 public static extern bool WorldGetAutoDisableFlag(IntPtr world);
1773
1774 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableLinearThreshold"), SuppressUnmanagedCodeSecurity]
1775 public static extern dReal WorldGetAutoDisableLinearThreshold(IntPtr world);
1776
1777 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableSteps"), SuppressUnmanagedCodeSecurity]
1778 public static extern int WorldGetAutoDisableSteps(IntPtr world);
1779
1780 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableTime"), SuppressUnmanagedCodeSecurity]
1781 public static extern dReal WorldGetAutoDisableTime(IntPtr world);
1782
1783 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoEnableDepthSF1"), SuppressUnmanagedCodeSecurity]
1784 public static extern int WorldGetAutoEnableDepthSF1(IntPtr world);
1785
1786 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetCFM"), SuppressUnmanagedCodeSecurity]
1787 public static extern dReal WorldGetCFM(IntPtr world);
1788
1789 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetERP"), SuppressUnmanagedCodeSecurity]
1790 public static extern dReal WorldGetERP(IntPtr world);
1791
1792 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetGravity"), SuppressUnmanagedCodeSecurity]
1793 public static extern void WorldGetGravity(IntPtr world, out Vector3 gravity);
1794
1795 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetGravity"), SuppressUnmanagedCodeSecurity]
1796 public static extern void WorldGetGravity(IntPtr world, out dReal X);
1797
1798 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetContactMaxCorrectingVel"), SuppressUnmanagedCodeSecurity]
1799 public static extern dReal WorldGetContactMaxCorrectingVel(IntPtr world);
1800
1801 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetContactSurfaceLayer"), SuppressUnmanagedCodeSecurity]
1802 public static extern dReal WorldGetContactSurfaceLayer(IntPtr world);
1803
1804 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAngularDamping"), SuppressUnmanagedCodeSecurity]
1805 public static extern dReal WorldGetAngularDamping(IntPtr world);
1806
1807 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAngularDampingThreshold"), SuppressUnmanagedCodeSecurity]
1808 public static extern dReal WorldGetAngularDampingThreshold(IntPtr world);
1809
1810 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetLinearDamping"), SuppressUnmanagedCodeSecurity]
1811 public static extern dReal WorldGetLinearDamping(IntPtr world);
1812
1813 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetLinearDampingThreshold"), SuppressUnmanagedCodeSecurity]
1814 public static extern dReal WorldGetLinearDampingThreshold(IntPtr world);
1815
1816 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetQuickStepNumIterations"), SuppressUnmanagedCodeSecurity]
1817 public static extern int WorldGetQuickStepNumIterations(IntPtr world);
1818
1819 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetQuickStepW"), SuppressUnmanagedCodeSecurity]
1820 public static extern dReal WorldGetQuickStepW(IntPtr world);
1821
1822 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetMaxAngularSpeed"), SuppressUnmanagedCodeSecurity]
1823 public static extern dReal WorldGetMaxAngularSpeed(IntPtr world);
1824
1825 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldImpulseToForce"), SuppressUnmanagedCodeSecurity]
1826 public static extern void WorldImpulseToForce(IntPtr world, dReal stepsize, dReal ix, dReal iy, dReal iz, out Vector3 force);
1827
1828 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldImpulseToForce"), SuppressUnmanagedCodeSecurity]
1829 public static extern void WorldImpulseToForce(IntPtr world, dReal stepsize, dReal ix, dReal iy, dReal iz, out dReal forceX);
1830
1831 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldQuickStep"), SuppressUnmanagedCodeSecurity]
1832 public static extern void WorldQuickStep(IntPtr world, dReal stepsize);
1833
1834 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAngularDamping"), SuppressUnmanagedCodeSecurity]
1835 public static extern void WorldSetAngularDamping(IntPtr world, dReal scale);
1836
1837 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAngularDampingThreshold"), SuppressUnmanagedCodeSecurity]
1838 public static extern void WorldSetAngularDampingThreshold(IntPtr world, dReal threshold);
1839
1840 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableAngularThreshold"), SuppressUnmanagedCodeSecurity]
1841 public static extern void WorldSetAutoDisableAngularThreshold(IntPtr world, dReal angular_threshold);
1842
1843 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableAverageSamplesCount"), SuppressUnmanagedCodeSecurity]
1844 public static extern void WorldSetAutoDisableAverageSamplesCount(IntPtr world, int average_samples_count);
1845
1846 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableFlag"), SuppressUnmanagedCodeSecurity]
1847 public static extern void WorldSetAutoDisableFlag(IntPtr world, bool do_auto_disable);
1848
1849 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableLinearThreshold"), SuppressUnmanagedCodeSecurity]
1850 public static extern void WorldSetAutoDisableLinearThreshold(IntPtr world, dReal linear_threshold);
1851
1852 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableSteps"), SuppressUnmanagedCodeSecurity]
1853 public static extern void WorldSetAutoDisableSteps(IntPtr world, int steps);
1854
1855 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableTime"), SuppressUnmanagedCodeSecurity]
1856 public static extern void WorldSetAutoDisableTime(IntPtr world, dReal time);
1857
1858 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoEnableDepthSF1"), SuppressUnmanagedCodeSecurity]
1859 public static extern void WorldSetAutoEnableDepthSF1(IntPtr world, int autoEnableDepth);
1860
1861 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetCFM"), SuppressUnmanagedCodeSecurity]
1862 public static extern void WorldSetCFM(IntPtr world, dReal cfm);
1863
1864 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetContactMaxCorrectingVel"), SuppressUnmanagedCodeSecurity]
1865 public static extern void WorldSetContactMaxCorrectingVel(IntPtr world, dReal vel);
1866
1867 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetContactSurfaceLayer"), SuppressUnmanagedCodeSecurity]
1868 public static extern void WorldSetContactSurfaceLayer(IntPtr world, dReal depth);
1869
1870 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetDamping"), SuppressUnmanagedCodeSecurity]
1871 public static extern void WorldSetDamping(IntPtr world, dReal linear_scale, dReal angular_scale);
1872
1873 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetERP"), SuppressUnmanagedCodeSecurity]
1874 public static extern void WorldSetERP(IntPtr world, dReal erp);
1875
1876 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetGravity"), SuppressUnmanagedCodeSecurity]
1877 public static extern void WorldSetGravity(IntPtr world, dReal x, dReal y, dReal z);
1878
1879 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetLinearDamping"), SuppressUnmanagedCodeSecurity]
1880 public static extern void WorldSetLinearDamping(IntPtr world, dReal scale);
1881
1882 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetLinearDampingThreshold"), SuppressUnmanagedCodeSecurity]
1883 public static extern void WorldSetLinearDampingThreshold(IntPtr world, dReal threshold);
1884
1885 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetQuickStepNumIterations"), SuppressUnmanagedCodeSecurity]
1886 public static extern void WorldSetQuickStepNumIterations(IntPtr world, int num);
1887
1888 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetQuickStepW"), SuppressUnmanagedCodeSecurity]
1889 public static extern void WorldSetQuickStepW(IntPtr world, dReal over_relaxation);
1890
1891 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetMaxAngularSpeed"), SuppressUnmanagedCodeSecurity]
1892 public static extern void WorldSetMaxAngularSpeed(IntPtr world, dReal max_speed);
1893
1894 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldStep"), SuppressUnmanagedCodeSecurity]
1895 public static extern void WorldStep(IntPtr world, dReal stepsize);
1896
1897 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldStepFast1"), SuppressUnmanagedCodeSecurity]
1898 public static extern void WorldStepFast1(IntPtr world, dReal stepsize, int maxiterations);
1899
1900 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldExportDIF"), SuppressUnmanagedCodeSecurity]
1901 public static extern void WorldExportDIF(IntPtr world, string filename, bool append, string prefix);
1902 }
1903}
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdePlugin.cs
new file mode 100644
index 0000000..215d47a
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdePlugin.cs
@@ -0,0 +1,86 @@
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 System.Threading;
33using System.IO;
34using System.Diagnostics;
35using log4net;
36using Nini.Config;
37using OdeAPI;
38using OpenSim.Framework;
39using OpenSim.Region.Physics.Manager;
40using OpenMetaverse;
41
42namespace OpenSim.Region.Physics.OdePlugin
43{
44 /// <summary>
45 /// ODE plugin
46 /// </summary>
47 public class OdePlugin : IPhysicsPlugin
48 {
49 //private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
50
51 private OdeScene m_scene;
52
53 public bool Init()
54 {
55 if (d.InitODE2(0) != 0)
56 {
57 if (d.AllocateODEDataForThread(~0U) == 0)
58 {
59 d.CloseODE();
60 return false;
61 }
62 return true;
63 }
64 return false;
65 }
66
67 public PhysicsScene GetScene(String sceneIdentifier)
68 {
69 if (m_scene == null)
70 {
71 m_scene = new OdeScene(sceneIdentifier);
72 }
73 return (m_scene);
74 }
75
76 public string GetName()
77 {
78 return ("UbitODE");
79 }
80
81 public void Dispose()
82 {
83 d.CloseODE();
84 }
85 }
86} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
new file mode 100644
index 0000000..74de2ee
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
@@ -0,0 +1,2741 @@
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
28//#define USE_DRAWSTUFF
29//#define SPAM
30
31using System;
32using System.Collections.Generic;
33using System.Reflection;
34using System.Runtime.InteropServices;
35using System.Threading;
36using System.IO;
37using System.Diagnostics;
38using log4net;
39using Nini.Config;
40using OdeAPI;
41#if USE_DRAWSTUFF
42using ODEDrawstuff;
43#endif
44using OpenSim.Framework;
45using OpenSim.Region.Physics.Manager;
46using OpenMetaverse;
47
48namespace OpenSim.Region.Physics.OdePlugin
49{
50 public enum StatusIndicators : int
51 {
52 Generic = 0,
53 Start = 1,
54 End = 2
55 }
56
57 public struct sCollisionData
58 {
59 public uint ColliderLocalId;
60 public uint CollidedWithLocalId;
61 public int NumberOfCollisions;
62 public int CollisionType;
63 public int StatusIndicator;
64 public int lastframe;
65 }
66
67 [Flags]
68 public enum CollisionCategories : int
69 {
70 Disabled = 0,
71 Geom = 0x00000001,
72 Body = 0x00000002,
73 Space = 0x00000004,
74 Character = 0x00000008,
75 Land = 0x00000010,
76 Water = 0x00000020,
77 Wind = 0x00000040,
78 Sensor = 0x00000080,
79 Selected = 0x00000100
80 }
81
82 /// <summary>
83 /// Material type for a primitive
84 /// </summary>
85 public enum Material : int
86 {
87 /// <summary></summary>
88 Stone = 0,
89 /// <summary></summary>
90 Metal = 1,
91 /// <summary></summary>
92 Glass = 2,
93 /// <summary></summary>
94 Wood = 3,
95 /// <summary></summary>
96 Flesh = 4,
97 /// <summary></summary>
98 Plastic = 5,
99 /// <summary></summary>
100 Rubber = 6,
101
102 light = 7 // compatibility with old viewers
103 }
104
105 public enum changes : int
106 {
107 Add = 0, // arg null. finishs the prim creation. should be used internally only ( to remove later ?)
108 Remove,
109 Link, // arg AuroraODEPrim new parent prim or null to delink. Makes the prim part of a object with prim parent as root
110 // or removes from a object if arg is null
111 DeLink,
112 Position, // arg Vector3 new position in world coords. Changes prim position. Prim must know if it is root or child
113 Orientation, // arg Quaternion new orientation in world coords. Changes prim position. Prim must know it it is root or child
114 PosOffset, // not in use
115 // arg Vector3 new position in local coords. Changes prim position in object
116 OriOffset, // not in use
117 // arg Vector3 new position in local coords. Changes prim position in object
118 Velocity,
119 AngVelocity,
120 Acceleration,
121 Force,
122 Torque,
123
124 AddForce,
125 AddAngForce,
126 AngLock,
127
128 Size,
129 Shape,
130
131 CollidesWater,
132 VolumeDtc,
133
134 Physical,
135 Selected,
136 disabled,
137 building,
138
139 Null //keep this last used do dim the methods array. does nothing but pulsing the prim
140 }
141
142 public struct ODEchangeitem
143 {
144 public OdePrim prim;
145 public OdeCharacter character;
146 public changes what;
147 public Object arg;
148 }
149
150 public class OdeScene : PhysicsScene
151 {
152 private readonly ILog m_log;
153 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>();
154
155 private int threadid = 0;
156 private Random fluidRandomizer = new Random(Environment.TickCount);
157
158 const d.ContactFlags comumContactFlags = d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM |d.ContactFlags.Approx1 | d.ContactFlags.Bounce;
159 const float comumContactERP = 0.6f;
160 const float comumSoftContactERP = 0.1f;
161 const float comumContactCFM = 0.0001f;
162
163 float frictionScale = 1.0f;
164
165 float frictionMovementMult = 0.3f;
166
167 float TerrainBounce = 0.3f;
168 float TerrainFriction = 0.3f;
169
170 public float AvatarBounce = 0.3f;
171 public float AvatarFriction = 0;// 0.9f * 0.5f;
172
173 private const uint m_regionWidth = Constants.RegionSize;
174 private const uint m_regionHeight = Constants.RegionSize;
175
176 public float ODE_STEPSIZE = 0.020f;
177 private float metersInSpace = 25.6f;
178 private float m_timeDilation = 1.0f;
179
180 public float gravityx = 0f;
181 public float gravityy = 0f;
182 public float gravityz = -9.8f;
183
184
185 private float waterlevel = 0f;
186 private int framecount = 0;
187
188 internal IntPtr WaterGeom;
189
190 public float avPIDD = 3200f; // make it visible
191 public float avPIDP = 1400f; // make it visible
192 private float avCapRadius = 0.37f;
193 private float avDensity = 3f;
194 private float avMovementDivisorWalk = 1.3f;
195 private float avMovementDivisorRun = 0.8f;
196 private float minimumGroundFlightOffset = 3f;
197 public float maximumMassObject = 10000.01f;
198
199 public bool meshSculptedPrim = true;
200 public bool forceSimplePrimMeshing = false;
201
202 public float meshSculptLOD = 32;
203 public float MeshSculptphysicalLOD = 16;
204
205 public float geomDefaultDensity = 10.000006836f;
206
207 public int geomContactPointsStartthrottle = 3;
208 public int geomUpdatesPerThrottledUpdate = 15;
209
210 public float bodyPIDD = 35f;
211 public float bodyPIDG = 25;
212
213 public int geomCrossingFailuresBeforeOutofbounds = 6;
214
215 public int bodyFramesAutoDisable = 20;
216
217 private float[] _watermap;
218 private bool m_filterCollisions = true;
219
220 private d.NearCallback nearCallback;
221
222 private readonly HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>();
223 private readonly HashSet<OdePrim> _prims = new HashSet<OdePrim>();
224 private readonly HashSet<OdePrim> _activeprims = new HashSet<OdePrim>();
225
226 private readonly Object _taintedCharacterLock = new Object();
227 private readonly HashSet<OdeCharacter> _taintedCharacterH = new HashSet<OdeCharacter>(); // faster verification of repeated character taints
228 private readonly Queue<OdeCharacter> _taintedCharacterQ = new Queue<OdeCharacter>(); // character taints
229
230 public OpenSim.Framework.LocklessQueue<ODEchangeitem> ChangesQueue = new OpenSim.Framework.LocklessQueue<ODEchangeitem>();
231
232 /// <summary>
233 /// A list of actors that should receive collision events.
234 /// </summary>
235 private readonly List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>();
236
237 private readonly HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>();
238 public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>();
239 public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>();
240
241 private float contactsurfacelayer = 0.002f;
242
243 private int contactsPerCollision = 80;
244 internal IntPtr ContactgeomsArray = IntPtr.Zero;
245 private IntPtr GlobalContactsArray = IntPtr.Zero;
246
247 const int maxContactsbeforedeath = 4000;
248 private volatile int m_global_contactcount = 0;
249
250
251 private readonly IntPtr contactgroup;
252
253 public ContactData[] m_materialContactsData = new ContactData[8];
254
255 private readonly DoubleDictionary<Vector3, IntPtr, IntPtr> RegionTerrain = new DoubleDictionary<Vector3, IntPtr, IntPtr>();
256 private readonly Dictionary<IntPtr, float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>();
257 private readonly Dictionary<IntPtr, GCHandle> TerrainHeightFieldHeightsHandlers = new Dictionary<IntPtr, GCHandle>();
258
259 private int m_physicsiterations = 10;
260 private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag
261 private readonly PhysicsActor PANull = new NullPhysicsActor();
262 private float step_time = 0.0f;
263
264 public IntPtr world;
265
266 private uint obj2LocalID = 0;
267 private OdeCharacter cc1;
268 private OdePrim cp1;
269 private OdeCharacter cc2;
270 private OdePrim cp2;
271
272 // split the spaces acording to contents type
273 // ActiveSpace contains characters and active prims
274 // StaticSpace contains land and other that is mostly static in enviroment
275 // this can contain subspaces, like the grid in staticspace
276 // as now space only contains this 2 top spaces
277
278 public IntPtr TopSpace; // the global space
279 public IntPtr ActiveSpace; // space for active prims
280 public IntPtr StaticSpace; // space for the static things around
281
282 // some speedup variables
283 private int spaceGridMaxX;
284 private int spaceGridMaxY;
285 private float spacesPerMeter;
286
287 // split static geometry collision into a grid as before
288 private IntPtr[,] staticPrimspace;
289
290 private Object OdeLock;
291 private static Object SimulationLock;
292
293 public IMesher mesher;
294
295 private IConfigSource m_config;
296
297 public bool physics_logging = false;
298 public int physics_logging_interval = 0;
299 public bool physics_logging_append_existing_logfile = false;
300
301 private Vector3 m_worldOffset = Vector3.Zero;
302 public Vector2 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize);
303 private PhysicsScene m_parentScene = null;
304
305 private ODERayCastRequestManager m_rayCastManager;
306
307
308/* maybe needed if ode uses tls
309 private void checkThread()
310 {
311
312 int th = Thread.CurrentThread.ManagedThreadId;
313 if(th != threadid)
314 {
315 threadid = th;
316 d.AllocateODEDataForThread(~0U);
317 }
318 }
319 */
320 /// <summary>
321 /// Initiailizes the scene
322 /// Sets many properties that ODE requires to be stable
323 /// These settings need to be tweaked 'exactly' right or weird stuff happens.
324 /// </summary>
325 public OdeScene(string sceneIdentifier)
326 {
327 m_log
328 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "." + sceneIdentifier);
329
330// checkThread();
331 Name = sceneIdentifier;
332
333 OdeLock = new Object();
334 SimulationLock = new Object();
335
336 nearCallback = near;
337
338 m_rayCastManager = new ODERayCastRequestManager(this);
339 lock (OdeLock)
340 {
341 // Create the world and the first space
342 try
343 {
344 world = d.WorldCreate();
345 TopSpace = d.HashSpaceCreate(IntPtr.Zero);
346
347 // now the major subspaces
348 ActiveSpace = d.HashSpaceCreate(TopSpace);
349 StaticSpace = d.HashSpaceCreate(TopSpace);
350 }
351 catch
352 {
353 // i must RtC#FM
354 }
355
356 d.HashSpaceSetLevels(TopSpace, -2, 8); // cell sizes from .25 to 256 ?? need check what this really does
357 d.HashSpaceSetLevels(ActiveSpace, -2, 8);
358 d.HashSpaceSetLevels(StaticSpace, -2, 8);
359
360 // demote to second level
361 d.SpaceSetSublevel(ActiveSpace, 1);
362 d.SpaceSetSublevel(StaticSpace, 1);
363
364 contactgroup = d.JointGroupCreate(0);
365 //contactgroup
366
367 d.WorldSetAutoDisableFlag(world, false);
368 #if USE_DRAWSTUFF
369
370 Thread viewthread = new Thread(new ParameterizedThreadStart(startvisualization));
371 viewthread.Start();
372 #endif
373 }
374
375 _watermap = new float[258 * 258];
376 }
377
378#if USE_DRAWSTUFF
379 public void startvisualization(object o)
380 {
381 ds.Functions fn;
382 fn.version = ds.VERSION;
383 fn.start = new ds.CallbackFunction(start);
384 fn.step = new ds.CallbackFunction(step);
385 fn.command = new ds.CallbackFunction(command);
386 fn.stop = null;
387 fn.path_to_textures = "./textures";
388 string[] args = new string[0];
389 ds.SimulationLoop(args.Length, args, 352, 288, ref fn);
390 }
391#endif
392
393 // Initialize the mesh plugin
394// public override void Initialise(IMesher meshmerizer, IConfigSource config, RegionInfo region )
395 public override void Initialise(IMesher meshmerizer, IConfigSource config)
396 {
397// checkThread();
398 mesher = meshmerizer;
399 m_config = config;
400
401// m_log.WarnFormat("ODE configuration: {0}", d.GetConfiguration("ODE"));
402 /*
403 if (region != null)
404 {
405 WorldExtents.X = region.RegionSizeX;
406 WorldExtents.Y = region.RegionSizeY;
407 }
408 */
409
410 // Defaults
411
412 avPIDD = 2200.0f;
413 avPIDP = 900.0f;
414
415 int contactsPerCollision = 80;
416
417 if (m_config != null)
418 {
419 IConfig physicsconfig = m_config.Configs["ODEPhysicsSettings"];
420 if (physicsconfig != null)
421 {
422 gravityx = physicsconfig.GetFloat("world_gravityx", 0f);
423 gravityy = physicsconfig.GetFloat("world_gravityy", 0f);
424 gravityz = physicsconfig.GetFloat("world_gravityz", -9.8f);
425
426 metersInSpace = physicsconfig.GetFloat("meters_in_small_space", 29.9f);
427
428 contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", contactsurfacelayer);
429
430 ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", 0.020f);
431 m_physicsiterations = physicsconfig.GetInt("world_internal_steps_without_collisions", 10);
432
433 avDensity = physicsconfig.GetFloat("av_density", avDensity);
434 avMovementDivisorWalk = physicsconfig.GetFloat("av_movement_divisor_walk", 1.3f);
435 avMovementDivisorRun = physicsconfig.GetFloat("av_movement_divisor_run", 0.8f);
436 avCapRadius = physicsconfig.GetFloat("av_capsule_radius", 0.37f);
437
438 contactsPerCollision = physicsconfig.GetInt("contacts_per_collision", 80);
439
440 geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 3);
441 geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15);
442 geomCrossingFailuresBeforeOutofbounds = physicsconfig.GetInt("geom_crossing_failures_before_outofbounds", 5);
443
444 geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", 10.000006836f);
445 bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", 20);
446
447 bodyPIDD = physicsconfig.GetFloat("body_pid_derivative", 35f);
448 bodyPIDG = physicsconfig.GetFloat("body_pid_gain", 25f);
449
450 forceSimplePrimMeshing = physicsconfig.GetBoolean("force_simple_prim_meshing", forceSimplePrimMeshing);
451 meshSculptedPrim = physicsconfig.GetBoolean("mesh_sculpted_prim", true);
452 meshSculptLOD = physicsconfig.GetFloat("mesh_lod", 32f);
453 MeshSculptphysicalLOD = physicsconfig.GetFloat("mesh_physical_lod", 16f);
454 m_filterCollisions = physicsconfig.GetBoolean("filter_collisions", false);
455
456 if (Environment.OSVersion.Platform == PlatformID.Unix)
457 {
458 avPIDD = physicsconfig.GetFloat("av_pid_derivative_linux", 2200.0f);
459 avPIDP = physicsconfig.GetFloat("av_pid_proportional_linux", 900.0f);
460 }
461 else
462 {
463 avPIDD = physicsconfig.GetFloat("av_pid_derivative_win", 2200.0f);
464 avPIDP = physicsconfig.GetFloat("av_pid_proportional_win", 900.0f);
465 }
466
467 physics_logging = physicsconfig.GetBoolean("physics_logging", false);
468 physics_logging_interval = physicsconfig.GetInt("physics_logging_interval", 0);
469 physics_logging_append_existing_logfile = physicsconfig.GetBoolean("physics_logging_append_existing_logfile", false);
470
471 minimumGroundFlightOffset = physicsconfig.GetFloat("minimum_ground_flight_offset", 3f);
472 maximumMassObject = physicsconfig.GetFloat("maximum_mass_object", 10000.01f);
473 }
474 }
475
476 ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf);
477 GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf);
478
479 m_materialContactsData[(int)Material.Stone].mu = frictionScale * 0.8f;
480 m_materialContactsData[(int)Material.Stone].bounce = 0.4f;
481
482 m_materialContactsData[(int)Material.Metal].mu = frictionScale * 0.3f;
483 m_materialContactsData[(int)Material.Metal].bounce = 0.4f;
484
485 m_materialContactsData[(int)Material.Glass].mu = frictionScale * 0.2f;
486 m_materialContactsData[(int)Material.Glass].bounce = 0.7f;
487
488 m_materialContactsData[(int)Material.Wood].mu = frictionScale * 0.6f;
489 m_materialContactsData[(int)Material.Wood].bounce = 0.5f;
490
491 m_materialContactsData[(int)Material.Flesh].mu = frictionScale * 0.9f;
492 m_materialContactsData[(int)Material.Flesh].bounce = 0.3f;
493
494 m_materialContactsData[(int)Material.Plastic].mu = frictionScale * 0.4f;
495 m_materialContactsData[(int)Material.Plastic].bounce = 0.7f;
496
497 m_materialContactsData[(int)Material.Rubber].mu = frictionScale * 0.9f;
498 m_materialContactsData[(int)Material.Rubber].bounce = 0.95f;
499
500 m_materialContactsData[(int)Material.light].mu = 0.0f;
501 m_materialContactsData[(int)Material.light].bounce = 0.0f;
502
503 TerrainFriction *= frictionScale;
504// AvatarFriction *= frictionScale;
505
506 // Set the gravity,, don't disable things automatically (we set it explicitly on some things)
507
508 d.WorldSetGravity(world, gravityx, gravityy, gravityz);
509 d.WorldSetContactSurfaceLayer(world, contactsurfacelayer);
510
511 d.WorldSetLinearDamping(world, 0.001f);
512 d.WorldSetAngularDamping(world, 0.001f);
513 d.WorldSetAngularDampingThreshold(world, 0f);
514 d.WorldSetLinearDampingThreshold(world, 0f);
515 d.WorldSetMaxAngularSpeed(world, 256f);
516
517 d.WorldSetCFM(world,1e-6f); // a bit harder than default
518 //d.WorldSetCFM(world, 1e-4f); // a bit harder than default
519 d.WorldSetERP(world, 0.6f); // higher than original
520
521 // Set how many steps we go without running collision testing
522 // This is in addition to the step size.
523 // Essentially Steps * m_physicsiterations
524 d.WorldSetQuickStepNumIterations(world, m_physicsiterations);
525 d.WorldSetContactMaxCorrectingVel(world, 100.0f);
526
527 spacesPerMeter = 1 / metersInSpace;
528 spaceGridMaxX = (int)(WorldExtents.X * spacesPerMeter);
529 spaceGridMaxY = (int)(WorldExtents.Y * spacesPerMeter);
530
531 staticPrimspace = new IntPtr[spaceGridMaxX, spaceGridMaxY];
532
533 // create all spaces now
534 int i, j;
535 IntPtr newspace;
536 for (i = 0; i < spaceGridMaxX; i++)
537 for (j = 0; j < spaceGridMaxY; j++)
538 {
539 newspace = d.HashSpaceCreate(StaticSpace);
540 d.GeomSetCategoryBits(newspace, (int)CollisionCategories.Space);
541 waitForSpaceUnlock(newspace);
542 d.SpaceSetSublevel(newspace, 2);
543 d.HashSpaceSetLevels(newspace, -2, 8);
544 staticPrimspace[i, j] = newspace;
545 }
546 // let this now be real maximum values
547 spaceGridMaxX--;
548 spaceGridMaxY--;
549 }
550
551 internal void waitForSpaceUnlock(IntPtr space)
552 {
553 //if (space != IntPtr.Zero)
554 //while (d.SpaceLockQuery(space)) { } // Wait and do nothing
555 }
556
557 #region Collision Detection
558
559 // sets a global contact for a joint for contactgeom , and base contact description)
560
561 private IntPtr CreateContacJoint(ref d.ContactGeom contactGeom, float mu, float bounce, bool softerp)
562 {
563 if (GlobalContactsArray == IntPtr.Zero || m_global_contactcount >= maxContactsbeforedeath)
564 return IntPtr.Zero;
565
566 d.Contact newcontact = new d.Contact();
567 newcontact.geom.depth = contactGeom.depth;
568 newcontact.geom.g1 = contactGeom.g1;
569 newcontact.geom.g2 = contactGeom.g2;
570 newcontact.geom.pos = contactGeom.pos;
571 newcontact.geom.normal = contactGeom.normal;
572 newcontact.geom.side1 = contactGeom.side1;
573 newcontact.geom.side2 = contactGeom.side2;
574
575 // this needs bounce also
576 newcontact.surface.mode = comumContactFlags;
577 newcontact.surface.mu = mu;
578 newcontact.surface.bounce = bounce;
579 newcontact.surface.soft_cfm = comumContactCFM;
580 if (softerp)
581 newcontact.surface.soft_erp = comumSoftContactERP;
582 else
583 newcontact.surface.soft_erp = comumContactERP;
584
585 IntPtr contact = new IntPtr(GlobalContactsArray.ToInt64() + (Int64)(m_global_contactcount * d.Contact.unmanagedSizeOf));
586 Marshal.StructureToPtr(newcontact, contact, true);
587 return d.JointCreateContactPtr(world, contactgroup, contact);
588 }
589
590
591 /// <summary>
592 /// This is our near callback. A geometry is near a body
593 /// </summary>
594 /// <param name="space">The space that contains the geoms. Remember, spaces are also geoms</param>
595 /// <param name="g1">a geometry or space</param>
596 /// <param name="g2">another geometry or space</param>
597 ///
598
599 private bool GetCurContactGeom(int index, ref d.ContactGeom newcontactgeom)
600 {
601 if (ContactgeomsArray == IntPtr.Zero || index >= contactsPerCollision)
602 return false;
603
604 IntPtr contactptr = new IntPtr(ContactgeomsArray.ToInt64() + (Int64)(index * d.ContactGeom.unmanagedSizeOf));
605 newcontactgeom = (d.ContactGeom)Marshal.PtrToStructure(contactptr, typeof(d.ContactGeom));
606 return true;
607 }
608
609
610
611 private void near(IntPtr space, IntPtr g1, IntPtr g2)
612 {
613 // no lock here! It's invoked from within Simulate(), which is thread-locked
614
615 if (m_global_contactcount >= maxContactsbeforedeath)
616 return;
617
618 // Test if we're colliding a geom with a space.
619 // If so we have to drill down into the space recursively
620
621 if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
622 return;
623
624 if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2))
625 {
626 // We'll be calling near recursivly if one
627 // of them is a space to find all of the
628 // contact points in the space
629 try
630 {
631 d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback);
632 }
633 catch (AccessViolationException)
634 {
635 m_log.Warn("[PHYSICS]: Unable to collide test a space");
636 return;
637 }
638 //here one should check collisions of geoms inside a space
639 // but on each space we only should have geoms that not colide amoung each other
640 // so we don't dig inside spaces
641 return;
642 }
643
644 // get geom bodies to check if we already a joint contact
645 // guess this shouldn't happen now
646 IntPtr b1 = d.GeomGetBody(g1);
647 IntPtr b2 = d.GeomGetBody(g2);
648
649 // d.GeomClassID id = d.GeomGetClass(g1);
650
651 // Figure out how many contact points we have
652 int count = 0;
653 try
654 {
655 // Colliding Geom To Geom
656 // This portion of the function 'was' blatantly ripped off from BoxStack.cs
657
658 if (g1 == g2)
659 return; // Can't collide with yourself
660
661 if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
662 return;
663
664 count = d.CollidePtr(g1, g2, (contactsPerCollision & 0xffff), ContactgeomsArray, d.ContactGeom.unmanagedSizeOf);
665 }
666 catch (SEHException)
667 {
668 m_log.Error("[PHYSICS]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim.");
669// ode.drelease(world);
670 base.TriggerPhysicsBasedRestart();
671 }
672 catch (Exception e)
673 {
674 m_log.WarnFormat("[PHYSICS]: Unable to collide test an object: {0}", e.Message);
675 return;
676 }
677
678 // id contacts done
679 if (count == 0)
680 return;
681
682 // try get physical actors
683 PhysicsActor p1;
684 PhysicsActor p2;
685
686 if (!actor_name_map.TryGetValue(g1, out p1))
687 {
688 p1 = PANull;
689 }
690
691 if (!actor_name_map.TryGetValue(g2, out p2))
692 {
693 p2 = PANull;
694 }
695
696 // update actors collision score
697 if (p1.CollisionScore >= float.MaxValue - count)
698 p1.CollisionScore = 0;
699 p1.CollisionScore += count;
700
701 if (p2.CollisionScore >= float.MaxValue - count)
702 p2.CollisionScore = 0;
703 p2.CollisionScore += count;
704
705
706 // get first contact
707 d.ContactGeom curContact = new d.ContactGeom();
708 if (!GetCurContactGeom(0, ref curContact))
709 return;
710 // for now it's the one with max depth
711 ContactPoint maxDepthContact = new ContactPoint(
712 new Vector3(curContact.pos.X, curContact.pos.Y, curContact.pos.Z),
713 new Vector3(curContact.normal.X, curContact.normal.Y, curContact.normal.Z),
714 curContact.depth
715 );
716 // do volume detection case
717 if (
718 (p1 is OdePrim) && (((OdePrim)p1).m_isVolumeDetect) ||
719 (p2 is OdePrim) && (((OdePrim)p2).m_isVolumeDetect))
720 {
721 collision_accounting_events(p1, p2, maxDepthContact);
722 return;
723 }
724
725 // big messy collision analises
726 float mu = 0;
727 float bounce = 0;
728 ContactData contactdata1;
729 ContactData contactdata2;
730 bool erpSoft = false;
731
732 String name = null;
733 bool dop1foot = false;
734 bool dop2foot = false;
735 bool ignore = false;
736
737 switch (p1.PhysicsActorType)
738 {
739 case (int)ActorTypes.Agent:
740 switch (p2.PhysicsActorType)
741 {
742 case (int)ActorTypes.Agent:
743 contactdata1 = p1.ContactData;
744 contactdata2 = p2.ContactData;
745 bounce = contactdata1.bounce * contactdata2.bounce;
746
747 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
748
749 if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f))
750 mu *= frictionMovementMult;
751
752 p1.CollidingObj = true;
753 p2.CollidingObj = true;
754 break;
755 case (int)ActorTypes.Prim:
756 contactdata1 = p1.ContactData;
757 contactdata2 = p2.ContactData;
758 bounce = contactdata1.bounce * contactdata2.bounce;
759
760 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
761
762 if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f))
763 mu *= frictionMovementMult;
764 if (p2.Velocity.LengthSquared() > 0.0f)
765 p2.CollidingObj = true;
766 dop1foot = true;
767 break;
768 default:
769 ignore=true; // avatar to terrain and water ignored
770 break;
771 }
772 break;
773
774 case (int)ActorTypes.Prim:
775 switch (p2.PhysicsActorType)
776 {
777 case (int)ActorTypes.Agent:
778 contactdata1 = p1.ContactData;
779 contactdata2 = p2.ContactData;
780 bounce = contactdata1.bounce * contactdata2.bounce;
781
782 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
783
784 if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f))
785 mu *= frictionMovementMult;
786
787 dop2foot = true;
788 if (p1.Velocity.LengthSquared() > 0.0f)
789 p1.CollidingObj = true;
790 break;
791 case (int)ActorTypes.Prim:
792 if ((p1.Velocity - p2.Velocity).LengthSquared() > 0.0f)
793 {
794 p1.CollidingObj = true;
795 p2.CollidingObj = true;
796 }
797 contactdata1 = p1.ContactData;
798 contactdata2 = p2.ContactData;
799 bounce = contactdata1.bounce * contactdata2.bounce;
800 erpSoft = true;
801 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
802
803 if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f))
804 mu *= frictionMovementMult;
805
806 break;
807 default:
808 if (geom_name_map.TryGetValue(g2, out name))
809 {
810 if (name == "Terrain")
811 {
812 erpSoft = true;
813 contactdata1 = p1.ContactData;
814 bounce = contactdata1.bounce * TerrainBounce;
815 mu = (float)Math.Sqrt(contactdata1.mu * TerrainFriction);
816 if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f)
817 mu *= frictionMovementMult;
818 p1.CollidingGround = true;
819 }
820 else if (name == "Water")
821 {
822 erpSoft = true;
823 }
824 }
825 else
826 ignore=true;
827 break;
828 }
829 break;
830
831 default:
832 if (geom_name_map.TryGetValue(g1, out name))
833 {
834 if (name == "Terrain")
835 {
836 if (p2.PhysicsActorType == (int)ActorTypes.Prim)
837 {
838 erpSoft = true;
839 p2.CollidingGround = true;
840 contactdata2 = p2.ContactData;
841 bounce = contactdata2.bounce * TerrainBounce;
842 mu = (float)Math.Sqrt(contactdata2.mu * TerrainFriction);
843
844 if (Math.Abs(p2.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y) > 0.1f)
845 mu *= frictionMovementMult;
846 }
847 else
848 ignore = true;
849
850 }
851 else if (name == "Water" &&
852 (p2.PhysicsActorType == (int)ActorTypes.Prim || p2.PhysicsActorType == (int)ActorTypes.Agent))
853 {
854 erpSoft = true;
855 }
856 }
857 else
858 ignore = true;
859 break;
860 }
861
862 if (ignore)
863 return;
864
865 IntPtr Joint;
866
867 int i = 0;
868 while(true)
869 {
870 if (dop1foot && (p1.Position.Z - curContact.pos.Z) > (p1.Size.Z - avCapRadius) * 0.5f)
871 p1.IsColliding = true;
872 if (dop2foot && (p2.Position.Z - curContact.pos.Z) > (p2.Size.Z - avCapRadius) * 0.5f)
873 p2.IsColliding = true;
874
875 Joint = CreateContacJoint(ref curContact, mu, bounce, erpSoft);
876 d.JointAttach(Joint, b1, b2);
877
878 if (++m_global_contactcount >= maxContactsbeforedeath)
879 break;
880
881 if(++i >= count)
882 break;
883
884 if (!GetCurContactGeom(i, ref curContact))
885 break;
886
887 if (curContact.depth > maxDepthContact.PenetrationDepth)
888 {
889 maxDepthContact.Position.X = curContact.pos.X;
890 maxDepthContact.Position.Y = curContact.pos.Y;
891 maxDepthContact.Position.Z = curContact.pos.Z;
892 maxDepthContact.SurfaceNormal.X = curContact.normal.X;
893 maxDepthContact.SurfaceNormal.Y = curContact.normal.Y;
894 maxDepthContact.SurfaceNormal.Z = curContact.normal.Z;
895 maxDepthContact.PenetrationDepth = curContact.depth;
896 }
897 }
898
899 collision_accounting_events(p1, p2, maxDepthContact);
900
901/*
902 if (notskipedcount > geomContactPointsStartthrottle)
903 {
904 // If there are more then 3 contact points, it's likely
905 // that we've got a pile of objects, so ...
906 // We don't want to send out hundreds of terse updates over and over again
907 // so lets throttle them and send them again after it's somewhat sorted out.
908 this needs checking so out for now
909 if (b1 != IntPtr.Zero)
910 p1.ThrottleUpdates = true;
911 if (b2 != IntPtr.Zero)
912 p2.ThrottleUpdates = true;
913
914 }
915 */
916 }
917
918 private void collision_accounting_events(PhysicsActor p1, PhysicsActor p2, ContactPoint contact)
919 {
920 // obj1LocalID = 0;
921 //returncollisions = false;
922 obj2LocalID = 0;
923 //ctype = 0;
924 //cStartStop = 0;
925 if (!(p2.SubscribedEvents() || p1.SubscribedEvents()))
926 return;
927
928 switch ((ActorTypes)p1.PhysicsActorType)
929 {
930 case ActorTypes.Agent:
931 cc1 = (OdeCharacter)p1;
932 switch ((ActorTypes)p2.PhysicsActorType)
933 {
934 case ActorTypes.Agent:
935 cc2 = (OdeCharacter)p2;
936 obj2LocalID = cc2.m_localID;
937 if (p2.SubscribedEvents())
938 cc2.AddCollisionEvent(cc1.m_localID, contact);
939 break;
940
941 case ActorTypes.Prim:
942 if (p2 is OdePrim)
943 {
944 cp2 = (OdePrim)p2;
945 obj2LocalID = cp2.m_localID;
946 if (p2.SubscribedEvents())
947 cp2.AddCollisionEvent(cc1.m_localID, contact);
948 }
949 break;
950
951 case ActorTypes.Ground:
952 case ActorTypes.Unknown:
953 default:
954 obj2LocalID = 0;
955 break;
956 }
957 if (p1.SubscribedEvents())
958 {
959 contact.SurfaceNormal = -contact.SurfaceNormal;
960 cc1.AddCollisionEvent(obj2LocalID, contact);
961 }
962 break;
963
964 case ActorTypes.Prim:
965
966 if (p1 is OdePrim)
967 {
968 cp1 = (OdePrim)p1;
969
970 // obj1LocalID = cp2.m_localID;
971 switch ((ActorTypes)p2.PhysicsActorType)
972 {
973 case ActorTypes.Agent:
974 if (p2 is OdeCharacter)
975 {
976 cc2 = (OdeCharacter)p2;
977 obj2LocalID = cc2.m_localID;
978 if (p2.SubscribedEvents())
979 cc2.AddCollisionEvent(cp1.m_localID, contact);
980 }
981 break;
982 case ActorTypes.Prim:
983
984 if (p2 is OdePrim)
985 {
986 cp2 = (OdePrim)p2;
987 obj2LocalID = cp2.m_localID;
988 if (p2.SubscribedEvents())
989 cp2.AddCollisionEvent(cp1.m_localID, contact);
990 }
991 break;
992
993 case ActorTypes.Ground:
994 case ActorTypes.Unknown:
995 default:
996 obj2LocalID = 0;
997 break;
998 }
999 if (p1.SubscribedEvents())
1000 {
1001 contact.SurfaceNormal = -contact.SurfaceNormal;
1002 cp1.AddCollisionEvent(obj2LocalID, contact);
1003 }
1004 }
1005 break;
1006 }
1007 }
1008
1009 /// <summary>
1010 /// This is our collision testing routine in ODE
1011 /// </summary>
1012 /// <param name="timeStep"></param>
1013 private void collision_optimized()
1014 {
1015// _perloopContact.Clear();
1016// clear characts IsColliding until we do it some other way
1017
1018 lock (_characters)
1019 {
1020 foreach (OdeCharacter chr in _characters)
1021 {
1022 // this are odd checks if they are needed something is wrong elsewhere
1023 // keep for now
1024 if (chr == null)
1025 continue;
1026
1027 if (chr.Shell == IntPtr.Zero || chr.Body == IntPtr.Zero)
1028 continue;
1029
1030 chr.IsColliding = false;
1031 // chr.CollidingGround = false; not done here
1032 chr.CollidingObj = false;
1033 }
1034 }
1035
1036 // now let ode do its job
1037 // colide active things amoung them
1038
1039 int st = Util.EnvironmentTickCount();
1040 int ta;
1041 int ts;
1042 try
1043 {
1044 d.SpaceCollide(ActiveSpace, IntPtr.Zero, nearCallback);
1045 }
1046 catch (AccessViolationException)
1047 {
1048 m_log.Warn("[PHYSICS]: Unable to Active space collide");
1049 }
1050 ta = Util.EnvironmentTickCountSubtract(st);
1051 // then active things with static enviroment
1052 try
1053 {
1054 d.SpaceCollide2(ActiveSpace,StaticSpace, IntPtr.Zero, nearCallback);
1055 }
1056 catch (AccessViolationException)
1057 {
1058 m_log.Warn("[PHYSICS]: Unable to Active to static space collide");
1059 }
1060 ts = Util.EnvironmentTickCountSubtract(st);
1061// _perloopContact.Clear();
1062 }
1063
1064 #endregion
1065
1066
1067 public float GetTerrainHeightAtXY(float x, float y)
1068 {
1069 // assumes 1m size grid and constante size square regions
1070 // region offset in mega position
1071
1072 int offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1073 int offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1074
1075 IntPtr heightFieldGeom = IntPtr.Zero;
1076
1077 // get region map
1078 if (!RegionTerrain.TryGetValue(new Vector3(offsetX, offsetY, 0), out heightFieldGeom))
1079 return 0f;
1080
1081 if (heightFieldGeom == IntPtr.Zero)
1082 return 0f;
1083
1084 if (!TerrainHeightFieldHeights.ContainsKey(heightFieldGeom))
1085 return 0f;
1086
1087 // TerrainHeightField for ODE as offset 1m
1088 x += 1f - offsetX;
1089 y += 1f - offsetY;
1090
1091 // make position fit into array
1092 if (x < 0)
1093 x = 0;
1094 if (y < 0)
1095 y = 0;
1096
1097 // integer indexs
1098 int ix;
1099 int iy;
1100 // interpolators offset
1101 float dx;
1102 float dy;
1103
1104 int regsize = (int)Constants.RegionSize + 2; // map size see setterrain
1105
1106 // we still have square fixed size regions
1107 // also flip x and y because of how map is done for ODE fliped axis
1108 // so ix,iy,dx and dy are inter exchanged
1109 if (x < regsize - 1)
1110 {
1111 iy = (int)x;
1112 dy = x - (float)iy;
1113 }
1114 else // out world use external height
1115 {
1116 iy = regsize - 1;
1117 dy = 0;
1118 }
1119 if (y < regsize - 1)
1120 {
1121 ix = (int)y;
1122 dx = y - (float)ix;
1123 }
1124 else
1125 {
1126 ix = regsize - 1;
1127 dx = 0;
1128 }
1129
1130 float h0;
1131 float h1;
1132 float h2;
1133
1134 iy *= regsize;
1135 iy += ix; // all indexes have iy + ix
1136
1137 float[] heights = TerrainHeightFieldHeights[heightFieldGeom];
1138
1139 if ((dx + dy) <= 1.0f)
1140 {
1141 h0 = ((float)heights[iy]); // 0,0 vertice
1142 h1 = (((float)heights[iy + 1]) - h0) * dx; // 1,0 vertice minus 0,0
1143 h2 = (((float)heights[iy + regsize]) - h0) * dy; // 0,1 vertice minus 0,0
1144 }
1145 else
1146 {
1147 h0 = ((float)heights[iy + regsize + 1]); // 1,1 vertice
1148 h1 = (((float)heights[iy + 1]) - h0) * (1 - dy); // 1,1 vertice minus 1,0
1149 h2 = (((float)heights[iy + regsize]) - h0) * (1 - dx); // 1,1 vertice minus 0,1
1150 }
1151
1152 return h0 + h1 + h2;
1153 }
1154
1155 /// <summary>
1156 /// Add actor to the list that should receive collision events in the simulate loop.
1157 /// </summary>
1158 /// <param name="obj"></param>
1159 public void AddCollisionEventReporting(PhysicsActor obj)
1160 {
1161 lock (_collisionEventPrim)
1162 {
1163 if (!_collisionEventPrim.Contains(obj))
1164 _collisionEventPrim.Add(obj);
1165 }
1166 }
1167
1168 /// <summary>
1169 /// Remove actor from the list that should receive collision events in the simulate loop.
1170 /// </summary>
1171 /// <param name="obj"></param>
1172 public void RemoveCollisionEventReporting(PhysicsActor obj)
1173 {
1174 lock (_collisionEventPrim)
1175 {
1176 if (_collisionEventPrim.Contains(obj))
1177 _collisionEventPrim.Remove(obj);
1178 }
1179 }
1180
1181 #region Add/Remove Entities
1182
1183 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
1184 {
1185 Vector3 pos;
1186 pos.X = position.X;
1187 pos.Y = position.Y;
1188 pos.Z = position.Z;
1189 OdeCharacter newAv = new OdeCharacter(avName, this, pos, size, avPIDD, avPIDP, avCapRadius, avDensity, avMovementDivisorWalk, avMovementDivisorRun);
1190 newAv.Flying = isFlying;
1191 newAv.MinimumGroundFlightOffset = minimumGroundFlightOffset;
1192
1193 return newAv;
1194 }
1195
1196 public void AddCharacter(OdeCharacter chr)
1197 {
1198 lock (_characters)
1199 {
1200 if (!_characters.Contains(chr))
1201 {
1202 _characters.Add(chr);
1203 if (chr.bad)
1204 m_log.DebugFormat("[PHYSICS] Added BAD actor {0} to characters list", chr.m_uuid);
1205 }
1206 }
1207 }
1208
1209 public void RemoveCharacter(OdeCharacter chr)
1210 {
1211 lock (_characters)
1212 {
1213 if (_characters.Contains(chr))
1214 {
1215 _characters.Remove(chr);
1216 }
1217 }
1218 }
1219
1220 public void BadCharacter(OdeCharacter chr)
1221 {
1222 lock (_badCharacter)
1223 {
1224 if (!_badCharacter.Contains(chr))
1225 _badCharacter.Add(chr);
1226 }
1227 }
1228
1229 public override void RemoveAvatar(PhysicsActor actor)
1230 {
1231 //m_log.Debug("[PHYSICS]:ODELOCK");
1232 ((OdeCharacter) actor).Destroy();
1233 }
1234
1235 private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation,
1236 PrimitiveBaseShape pbs, bool isphysical, uint localID)
1237 {
1238 Vector3 pos = position;
1239 Vector3 siz = size;
1240 Quaternion rot = rotation;
1241
1242 OdePrim newPrim;
1243 lock (OdeLock)
1244 {
1245 newPrim = new OdePrim(name, this, pos, siz, rot, pbs, isphysical);
1246
1247 lock (_prims)
1248 _prims.Add(newPrim);
1249 }
1250 newPrim.LocalID = localID;
1251 return newPrim;
1252 }
1253
1254 public void addActivePrim(OdePrim activatePrim)
1255 {
1256 // adds active prim.. (ones that should be iterated over in collisions_optimized
1257 lock (_activeprims)
1258 {
1259 if (!_activeprims.Contains(activatePrim))
1260 _activeprims.Add(activatePrim);
1261 //else
1262 // m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent");
1263 }
1264 }
1265
1266 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1267 Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
1268 {
1269#if SPAM
1270 m_log.DebugFormat("[PHYSICS]: Adding physics actor to {0}", primName);
1271#endif
1272
1273 return AddPrim(primName, position, size, rotation, pbs, isPhysical, localid);
1274 }
1275
1276 public override float TimeDilation
1277 {
1278 get { return m_timeDilation; }
1279 }
1280
1281 public override bool SupportsNINJAJoints
1282 {
1283 get { return false; }
1284 }
1285
1286
1287 public void remActivePrim(OdePrim deactivatePrim)
1288 {
1289 lock (_activeprims)
1290 {
1291 _activeprims.Remove(deactivatePrim);
1292 }
1293 }
1294
1295 public override void RemovePrim(PhysicsActor prim)
1296 {
1297 // As with all ODE physics operations, we don't remove the prim immediately but signal that it should be
1298 // removed in the next physics simulate pass.
1299 if (prim is OdePrim)
1300 {
1301// lock (OdeLock)
1302 {
1303 OdePrim p = (OdePrim)prim;
1304 p.setPrimForRemoval();
1305 }
1306 }
1307 }
1308 /// <summary>
1309 /// This is called from within simulate but outside the locked portion
1310 /// We need to do our own locking here
1311 /// (Note: As of 20110801 this no longer appears to be true - this is being called within lock (odeLock) in
1312 /// Simulate() -- justincc).
1313 ///
1314 /// Essentially, we need to remove the prim from our space segment, whatever segment it's in.
1315 ///
1316 /// If there are no more prim in the segment, we need to empty (spacedestroy)the segment and reclaim memory
1317 /// that the space was using.
1318 /// </summary>
1319 /// <param name="prim"></param>
1320 public void RemovePrimThreadLocked(OdePrim prim)
1321 {
1322 //Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName);
1323 lock (prim)
1324 {
1325 RemoveCollisionEventReporting(prim);
1326 lock (_prims)
1327 _prims.Remove(prim);
1328 }
1329
1330 }
1331 #endregion
1332
1333 #region Space Separation Calculation
1334
1335 /// <summary>
1336 /// Called when a static prim moves or becomes static
1337 /// Places the prim in a space one the static sub-spaces grid
1338 /// </summary>
1339 /// <param name="geom">the pointer to the geom that moved</param>
1340 /// <param name="pos">the position that the geom moved to</param>
1341 /// <param name="currentspace">a pointer to the space it was in before it was moved.</param>
1342 /// <returns>a pointer to the new space it's in</returns>
1343 public IntPtr MoveGeomToStaticSpace(IntPtr geom, Vector3 pos, IntPtr currentspace)
1344 {
1345 // moves a prim into another static sub-space or from another space into a static sub-space
1346
1347 // Called ODEPrim so
1348 // it's already in locked space.
1349
1350 if (geom == IntPtr.Zero) // shouldn't happen
1351 return IntPtr.Zero;
1352
1353 // get the static sub-space for current position
1354 IntPtr newspace = calculateSpaceForGeom(pos);
1355
1356 if (newspace == currentspace) // if we are there all done
1357 return newspace;
1358
1359 // else remove it from its current space
1360 if (currentspace != IntPtr.Zero && d.SpaceQuery(currentspace, geom))
1361 {
1362 if (d.GeomIsSpace(currentspace))
1363 {
1364 waitForSpaceUnlock(currentspace);
1365 d.SpaceRemove(currentspace, geom);
1366 }
1367 else
1368 {
1369 m_log.Info("[Physics]: Invalid or empty Space passed to 'MoveGeomToStaticSpace':" + currentspace +
1370 " Geom:" + geom);
1371 }
1372 }
1373 else // odd currentspace is null or doesn't contain the geom? lets try the geom ideia of current space
1374 {
1375 currentspace = d.GeomGetSpace(geom);
1376 if (currentspace != IntPtr.Zero)
1377 {
1378 if (d.GeomIsSpace(currentspace))
1379 {
1380 waitForSpaceUnlock(currentspace);
1381 d.SpaceRemove(currentspace, geom);
1382 }
1383 }
1384 }
1385
1386 // put the geom in the newspace
1387 waitForSpaceUnlock(newspace);
1388 d.SpaceAdd(newspace, geom);
1389
1390 // let caller know this newspace
1391 return newspace;
1392 }
1393
1394 /// <summary>
1395 /// Calculates the space the prim should be in by its position
1396 /// </summary>
1397 /// <param name="pos"></param>
1398 /// <returns>a pointer to the space. This could be a new space or reused space.</returns>
1399 public IntPtr calculateSpaceForGeom(Vector3 pos)
1400 {
1401 int x, y;
1402 x = (int)(pos.X * spacesPerMeter);
1403 if (x < 0)
1404 x = 0;
1405 else if (x > spaceGridMaxX)
1406 x = spaceGridMaxX;
1407
1408 y = (int)(pos.Y * spacesPerMeter);
1409 if (y < 0)
1410 y = 0;
1411 else if (y >spaceGridMaxY)
1412 y = spaceGridMaxY;
1413
1414 IntPtr tmpSpace = staticPrimspace[x, y];
1415 return tmpSpace;
1416 }
1417
1418 #endregion
1419
1420 /// <summary>
1421 /// Routine to figure out if we need to mesh this prim with our mesher
1422 /// </summary>
1423 /// <param name="pbs"></param>
1424 /// <returns></returns>
1425 public bool needsMeshing(PrimitiveBaseShape pbs)
1426 {
1427 // most of this is redundant now as the mesher will return null if it cant mesh a prim
1428 // but we still need to check for sculptie meshing being enabled so this is the most
1429 // convenient place to do it for now...
1430
1431 // //if (pbs.PathCurve == (byte)Primitive.PathCurve.Circle && pbs.ProfileCurve == (byte)Primitive.ProfileCurve.Circle && pbs.PathScaleY <= 0.75f)
1432 // //m_log.Debug("needsMeshing: " + " pathCurve: " + pbs.PathCurve.ToString() + " profileCurve: " + pbs.ProfileCurve.ToString() + " pathScaleY: " + Primitive.UnpackPathScale(pbs.PathScaleY).ToString());
1433 int iPropertiesNotSupportedDefault = 0;
1434
1435 if (pbs.SculptEntry)
1436 {
1437 if(!meshSculptedPrim)
1438 return false;
1439 }
1440
1441 // if it's a standard box or sphere with no cuts, hollows, twist or top shear, return false since ODE can use an internal representation for the prim
1442 if (!forceSimplePrimMeshing && !pbs.SculptEntry)
1443 {
1444 if ((pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight)
1445 || (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1
1446 && pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z))
1447 {
1448
1449 if (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0
1450 && pbs.ProfileHollow == 0
1451 && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0
1452 && pbs.PathBegin == 0 && pbs.PathEnd == 0
1453 && pbs.PathTaperX == 0 && pbs.PathTaperY == 0
1454 && pbs.PathScaleX == 100 && pbs.PathScaleY == 100
1455 && pbs.PathShearX == 0 && pbs.PathShearY == 0)
1456 {
1457#if SPAM
1458 m_log.Warn("NonMesh");
1459#endif
1460 return false;
1461 }
1462 }
1463 }
1464
1465 // following code doesn't give meshs to boxes and spheres ever
1466 // and it's odd.. so for now just return true if asked to force meshs
1467 // hopefully mesher will fail if doesn't suport so things still get basic boxes
1468
1469 if (forceSimplePrimMeshing)
1470 return true;
1471
1472 if (pbs.ProfileHollow != 0)
1473 iPropertiesNotSupportedDefault++;
1474
1475 if ((pbs.PathBegin != 0) || pbs.PathEnd != 0)
1476 iPropertiesNotSupportedDefault++;
1477
1478 if ((pbs.PathTwistBegin != 0) || (pbs.PathTwist != 0))
1479 iPropertiesNotSupportedDefault++;
1480
1481 if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0)
1482 iPropertiesNotSupportedDefault++;
1483
1484 if ((pbs.PathScaleX != 100) || (pbs.PathScaleY != 100))
1485 iPropertiesNotSupportedDefault++;
1486
1487 if ((pbs.PathShearX != 0) || (pbs.PathShearY != 0))
1488 iPropertiesNotSupportedDefault++;
1489
1490 if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight)
1491 iPropertiesNotSupportedDefault++;
1492
1493 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1 && (pbs.Scale.X != pbs.Scale.Y || pbs.Scale.Y != pbs.Scale.Z || pbs.Scale.Z != pbs.Scale.X))
1494 iPropertiesNotSupportedDefault++;
1495
1496 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte) Extrusion.Curve1)
1497 iPropertiesNotSupportedDefault++;
1498
1499 // test for torus
1500 if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Square)
1501 {
1502 if (pbs.PathCurve == (byte)Extrusion.Curve1)
1503 {
1504 iPropertiesNotSupportedDefault++;
1505 }
1506 }
1507 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Circle)
1508 {
1509 if (pbs.PathCurve == (byte)Extrusion.Straight)
1510 {
1511 iPropertiesNotSupportedDefault++;
1512 }
1513
1514 // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits
1515 else if (pbs.PathCurve == (byte)Extrusion.Curve1)
1516 {
1517 iPropertiesNotSupportedDefault++;
1518 }
1519 }
1520 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle)
1521 {
1522 if (pbs.PathCurve == (byte)Extrusion.Curve1 || pbs.PathCurve == (byte)Extrusion.Curve2)
1523 {
1524 iPropertiesNotSupportedDefault++;
1525 }
1526 }
1527 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle)
1528 {
1529 if (pbs.PathCurve == (byte)Extrusion.Straight)
1530 {
1531 iPropertiesNotSupportedDefault++;
1532 }
1533 else if (pbs.PathCurve == (byte)Extrusion.Curve1)
1534 {
1535 iPropertiesNotSupportedDefault++;
1536 }
1537 }
1538
1539 if (pbs.SculptEntry && meshSculptedPrim)
1540 iPropertiesNotSupportedDefault++;
1541
1542 if (iPropertiesNotSupportedDefault == 0)
1543 {
1544#if SPAM
1545 m_log.Warn("NonMesh");
1546#endif
1547 return false;
1548 }
1549#if SPAM
1550 m_log.Debug("Mesh");
1551#endif
1552 return true;
1553 }
1554
1555 public void AddChange(OdePrim prim, changes what, Object arg)
1556 {
1557 ODEchangeitem item = new ODEchangeitem();
1558 item.prim = prim;
1559 item.what = what;
1560 item.arg = arg;
1561 ChangesQueue.Enqueue(item);
1562 }
1563
1564 /// <summary>
1565 /// Called to queue a change to a prim
1566 /// to use in place of old taint mechanism so changes do have a time sequence
1567 /// </summary>
1568 public void AddChange(OdeCharacter character, changes what, Object arg)
1569 {
1570 ODEchangeitem item = new ODEchangeitem();
1571 item.character = character;
1572 item.what = what;
1573 item.arg = arg;
1574 ChangesQueue.Enqueue(item);
1575 }
1576
1577 /// <summary>
1578 /// Called after our prim properties are set Scale, position etc.
1579 /// We use this event queue like method to keep changes to the physical scene occuring in the threadlocked mutex
1580 /// This assures us that we have no race conditions
1581 /// </summary>
1582 /// <param name="prim"></param>
1583 public override void AddPhysicsActorTaint(PhysicsActor prim)
1584 {
1585 if (prim is OdePrim)
1586 {
1587/* OdePrim taintedprim = ((OdePrim) prim);
1588 lock (_taintedPrimLock)
1589 {
1590 if (!(_taintedPrimH.Contains(taintedprim)))
1591 {
1592 _taintedPrimH.Add(taintedprim); // HashSet for searching
1593 _taintedPrimQ.Enqueue(taintedprim); // List for ordered readout
1594 }
1595 }
1596 */
1597 return;
1598 }
1599 else if (prim is OdeCharacter)
1600 {
1601 OdeCharacter taintedchar = ((OdeCharacter)prim);
1602 lock (_taintedCharacterLock)
1603 {
1604 if (!(_taintedCharacterH.Contains(taintedchar)))
1605 {
1606 _taintedCharacterH.Add(taintedchar);
1607 _taintedCharacterQ.Enqueue(taintedchar);
1608 if (taintedchar.bad)
1609 m_log.DebugFormat("[PHYSICS]: Added BAD actor {0} to tainted actors", taintedchar.m_uuid);
1610 }
1611 }
1612 }
1613 }
1614
1615 /// <summary>
1616 /// This is our main simulate loop
1617 /// It's thread locked by a Mutex in the scene.
1618 /// It holds Collisions, it instructs ODE to step through the physical reactions
1619 /// It moves the objects around in memory
1620 /// It calls the methods that report back to the object owners.. (scenepresence, SceneObjectGroup)
1621 /// </summary>
1622 /// <param name="timeStep"></param>
1623 /// <returns></returns>
1624 public override float Simulate(float timeStep)
1625 {
1626 int statstart;
1627 int statchanges = 0;
1628 int statchmove = 0;
1629 int statactmove = 0;
1630 int statray = 0;
1631 int statcol = 0;
1632 int statstep = 0;
1633 int statmovchar = 0;
1634 int statmovprim;
1635 int totjcontact = 0;
1636
1637 // acumulate time so we can reduce error
1638 step_time += timeStep;
1639
1640 if (step_time < ODE_STEPSIZE)
1641 return 0;
1642
1643 if (framecount >= int.MaxValue)
1644 framecount = 0;
1645
1646 framecount++;
1647
1648 int curphysiteractions = m_physicsiterations;
1649
1650 if (step_time >= m_SkipFramesAtms)
1651 {
1652 // if in trouble reduce step resolution
1653 curphysiteractions /= 2;
1654 }
1655
1656 int nodeframes = 0;
1657
1658// checkThread();
1659
1660 lock (SimulationLock)
1661 {
1662 // adjust number of iterations per step
1663 try
1664 {
1665 d.WorldSetQuickStepNumIterations(world, curphysiteractions);
1666 }
1667 catch (StackOverflowException)
1668 {
1669 m_log.Error("[PHYSICS]: The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim.");
1670// ode.drelease(world);
1671 base.TriggerPhysicsBasedRestart();
1672 }
1673
1674
1675 while (step_time >= ODE_STEPSIZE && nodeframes < 10) //limit number of steps so we don't say here for ever
1676 {
1677 try
1678 {
1679 statstart = Util.EnvironmentTickCount();
1680
1681 // clear pointer/counter to contacts to pass into joints
1682 m_global_contactcount = 0;
1683
1684 // do characters requested changes
1685
1686 OdeCharacter character;
1687 int numtaints;
1688 lock (_taintedCharacterLock)
1689 {
1690 numtaints = _taintedCharacterQ.Count;
1691 // if (numtaints > 50)
1692 // numtaints = 50;
1693 while (numtaints > 0)
1694 {
1695 character = _taintedCharacterQ.Dequeue();
1696 character.ProcessTaints(ODE_STEPSIZE);
1697 _taintedCharacterH.Remove(character);
1698 numtaints--;
1699 }
1700 }
1701 // do other objects requested changes
1702
1703 ODEchangeitem item;
1704
1705 if(ChangesQueue.Count >0)
1706 {
1707 int ttmpstart = Util.EnvironmentTickCount();
1708 int ttmp;
1709 int ttmp2;
1710
1711 while(ChangesQueue.Dequeue(out item))
1712 {
1713 if (item.prim != null)
1714 {
1715 try
1716 {
1717 if (item.prim.DoAChange(item.what, item.arg))
1718 RemovePrimThreadLocked(item.prim);
1719 }
1720 catch { };
1721 }
1722 ttmp = Util.EnvironmentTickCountSubtract(ttmpstart);
1723 if (ttmp > 20)
1724 break;
1725 }
1726
1727 ttmp2 = Util.EnvironmentTickCountSubtract(ttmpstart);
1728 if (ttmp2 > 50)
1729 ttmp2 = 0;
1730
1731 }
1732
1733 statchanges += Util.EnvironmentTickCountSubtract(statstart);
1734
1735 // Move characters
1736 lock (_characters)
1737 {
1738 List<OdeCharacter> defects = new List<OdeCharacter>();
1739 foreach (OdeCharacter actor in _characters)
1740 {
1741 if (actor != null)
1742 actor.Move(ODE_STEPSIZE, defects);
1743 }
1744 if (defects.Count != 0)
1745 {
1746 foreach (OdeCharacter defect in defects)
1747 {
1748 RemoveCharacter(defect);
1749 }
1750 }
1751 }
1752 statchmove += Util.EnvironmentTickCountSubtract(statstart);
1753
1754 // Move other active objects
1755 lock (_activeprims)
1756 {
1757 foreach (OdePrim aprim in _activeprims)
1758 {
1759 aprim.CollisionScore = 0;
1760 aprim.IsColliding = false;
1761 aprim.Move();
1762 }
1763 }
1764
1765 statactmove += Util.EnvironmentTickCountSubtract(statstart);
1766 //if ((framecount % m_randomizeWater) == 0)
1767 // randomizeWater(waterlevel);
1768
1769 m_rayCastManager.ProcessQueuedRequests();
1770
1771 statray += Util.EnvironmentTickCountSubtract(statstart);
1772 collision_optimized();
1773 statcol += Util.EnvironmentTickCountSubtract(statstart);
1774
1775 lock (_collisionEventPrim)
1776 {
1777 foreach (PhysicsActor obj in _collisionEventPrim)
1778 {
1779 if (obj == null)
1780 continue;
1781
1782 switch ((ActorTypes)obj.PhysicsActorType)
1783 {
1784 case ActorTypes.Agent:
1785 OdeCharacter cobj = (OdeCharacter)obj;
1786 cobj.AddCollisionFrameTime((int)(ODE_STEPSIZE*1000.0f));
1787 cobj.SendCollisions();
1788 break;
1789
1790 case ActorTypes.Prim:
1791 OdePrim pobj = (OdePrim)obj;
1792 pobj.SendCollisions();
1793 break;
1794 }
1795 }
1796 }
1797
1798 d.WorldQuickStep(world, ODE_STEPSIZE);
1799 statstep += Util.EnvironmentTickCountSubtract(statstart);
1800 d.JointGroupEmpty(contactgroup);
1801 totjcontact += m_global_contactcount;
1802 //ode.dunlock(world);
1803 }
1804 catch (Exception e)
1805 {
1806 m_log.ErrorFormat("[PHYSICS]: {0}, {1}, {2}", e.Message, e.TargetSite, e);
1807// ode.dunlock(world);
1808 }
1809
1810 step_time -= ODE_STEPSIZE;
1811 nodeframes++;
1812 }
1813
1814 statstart = Util.EnvironmentTickCount();
1815
1816 lock (_characters)
1817 {
1818 foreach (OdeCharacter actor in _characters)
1819 {
1820 if (actor != null)
1821 {
1822 if (actor.bad)
1823 m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid);
1824
1825 actor.UpdatePositionAndVelocity();
1826 }
1827 }
1828 }
1829
1830 lock (_badCharacter)
1831 {
1832 if (_badCharacter.Count > 0)
1833 {
1834 foreach (OdeCharacter chr in _badCharacter)
1835 {
1836 RemoveCharacter(chr);
1837 }
1838
1839 _badCharacter.Clear();
1840 }
1841 }
1842 statmovchar = Util.EnvironmentTickCountSubtract(statstart);
1843
1844 lock (_activeprims)
1845 {
1846 {
1847 foreach (OdePrim actor in _activeprims)
1848 {
1849 if (actor.IsPhysical)
1850 {
1851 actor.UpdatePositionAndVelocity((float)nodeframes * ODE_STEPSIZE);
1852 }
1853 }
1854 }
1855 }
1856
1857 statmovprim = Util.EnvironmentTickCountSubtract(statstart);
1858
1859 int nactivegeoms = d.SpaceGetNumGeoms(ActiveSpace);
1860 int nstaticgeoms = d.SpaceGetNumGeoms(StaticSpace);
1861 int ntopgeoms = d.SpaceGetNumGeoms(TopSpace);
1862 int nbodies = d.NTotalBodies;
1863
1864 // Finished with all sim stepping. If requested, dump world state to file for debugging.
1865 // TODO: This call to the export function is already inside lock (OdeLock) - but is an extra lock needed?
1866 // TODO: This overwrites all dump files in-place. Should this be a growing logfile, or separate snapshots?
1867 if (physics_logging && (physics_logging_interval > 0) && (framecount % physics_logging_interval == 0))
1868 {
1869 string fname = "state-" + world.ToString() + ".DIF"; // give each physics world a separate filename
1870 string prefix = "world" + world.ToString(); // prefix for variable names in exported .DIF file
1871
1872 if (physics_logging_append_existing_logfile)
1873 {
1874 string header = "-------------- START OF PHYSICS FRAME " + framecount.ToString() + " --------------";
1875 TextWriter fwriter = File.AppendText(fname);
1876 fwriter.WriteLine(header);
1877 fwriter.Close();
1878 }
1879
1880 d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix);
1881 }
1882
1883 // think time dilation is not a physics issue alone.. but ok let's fake something
1884 if (step_time < ODE_STEPSIZE) // we did the required loops
1885 m_timeDilation = 1.0f;
1886 else
1887 { // we didn't forget the lost ones and let user know something
1888 m_timeDilation = 1 - step_time / timeStep;
1889 if (m_timeDilation < 0)
1890 m_timeDilation = 0;
1891 step_time = 0;
1892 }
1893 }
1894
1895// return nodeframes * ODE_STEPSIZE; // return real simulated time
1896 return 1000 * nodeframes; // return steps for now * 1000 to keep core happy
1897 }
1898
1899 /// <summary>
1900 public override void GetResults()
1901 {
1902 }
1903
1904 public override bool IsThreaded
1905 {
1906 // for now we won't be multithreaded
1907 get { return (false); }
1908 }
1909
1910 #region ODE Specific Terrain Fixes
1911 public float[] ResizeTerrain512NearestNeighbour(float[] heightMap)
1912 {
1913 float[] returnarr = new float[262144];
1914 float[,] resultarr = new float[(int)WorldExtents.X, (int)WorldExtents.Y];
1915
1916 // Filling out the array into its multi-dimensional components
1917 for (int y = 0; y < WorldExtents.Y; y++)
1918 {
1919 for (int x = 0; x < WorldExtents.X; x++)
1920 {
1921 resultarr[y, x] = heightMap[y * (int)WorldExtents.Y + x];
1922 }
1923 }
1924
1925 // Resize using Nearest Neighbour
1926
1927 // This particular way is quick but it only works on a multiple of the original
1928
1929 // The idea behind this method can be described with the following diagrams
1930 // second pass and third pass happen in the same loop really.. just separated
1931 // them to show what this does.
1932
1933 // First Pass
1934 // ResultArr:
1935 // 1,1,1,1,1,1
1936 // 1,1,1,1,1,1
1937 // 1,1,1,1,1,1
1938 // 1,1,1,1,1,1
1939 // 1,1,1,1,1,1
1940 // 1,1,1,1,1,1
1941
1942 // Second Pass
1943 // ResultArr2:
1944 // 1,,1,,1,,1,,1,,1,
1945 // ,,,,,,,,,,
1946 // 1,,1,,1,,1,,1,,1,
1947 // ,,,,,,,,,,
1948 // 1,,1,,1,,1,,1,,1,
1949 // ,,,,,,,,,,
1950 // 1,,1,,1,,1,,1,,1,
1951 // ,,,,,,,,,,
1952 // 1,,1,,1,,1,,1,,1,
1953 // ,,,,,,,,,,
1954 // 1,,1,,1,,1,,1,,1,
1955
1956 // Third pass fills in the blanks
1957 // ResultArr2:
1958 // 1,1,1,1,1,1,1,1,1,1,1,1
1959 // 1,1,1,1,1,1,1,1,1,1,1,1
1960 // 1,1,1,1,1,1,1,1,1,1,1,1
1961 // 1,1,1,1,1,1,1,1,1,1,1,1
1962 // 1,1,1,1,1,1,1,1,1,1,1,1
1963 // 1,1,1,1,1,1,1,1,1,1,1,1
1964 // 1,1,1,1,1,1,1,1,1,1,1,1
1965 // 1,1,1,1,1,1,1,1,1,1,1,1
1966 // 1,1,1,1,1,1,1,1,1,1,1,1
1967 // 1,1,1,1,1,1,1,1,1,1,1,1
1968 // 1,1,1,1,1,1,1,1,1,1,1,1
1969
1970 // X,Y = .
1971 // X+1,y = ^
1972 // X,Y+1 = *
1973 // X+1,Y+1 = #
1974
1975 // Filling in like this;
1976 // .*
1977 // ^#
1978 // 1st .
1979 // 2nd *
1980 // 3rd ^
1981 // 4th #
1982 // on single loop.
1983
1984 float[,] resultarr2 = new float[512, 512];
1985 for (int y = 0; y < WorldExtents.Y; y++)
1986 {
1987 for (int x = 0; x < WorldExtents.X; x++)
1988 {
1989 resultarr2[y * 2, x * 2] = resultarr[y, x];
1990
1991 if (y < WorldExtents.Y)
1992 {
1993 resultarr2[(y * 2) + 1, x * 2] = resultarr[y, x];
1994 }
1995 if (x < WorldExtents.X)
1996 {
1997 resultarr2[y * 2, (x * 2) + 1] = resultarr[y, x];
1998 }
1999 if (x < WorldExtents.X && y < WorldExtents.Y)
2000 {
2001 resultarr2[(y * 2) + 1, (x * 2) + 1] = resultarr[y, x];
2002 }
2003 }
2004 }
2005
2006 //Flatten out the array
2007 int i = 0;
2008 for (int y = 0; y < 512; y++)
2009 {
2010 for (int x = 0; x < 512; x++)
2011 {
2012 if (resultarr2[y, x] <= 0)
2013 returnarr[i] = 0.0000001f;
2014 else
2015 returnarr[i] = resultarr2[y, x];
2016
2017 i++;
2018 }
2019 }
2020
2021 return returnarr;
2022 }
2023
2024 public float[] ResizeTerrain512Interpolation(float[] heightMap)
2025 {
2026 float[] returnarr = new float[262144];
2027 float[,] resultarr = new float[512,512];
2028
2029 // Filling out the array into its multi-dimensional components
2030 for (int y = 0; y < 256; y++)
2031 {
2032 for (int x = 0; x < 256; x++)
2033 {
2034 resultarr[y, x] = heightMap[y * 256 + x];
2035 }
2036 }
2037
2038 // Resize using interpolation
2039
2040 // This particular way is quick but it only works on a multiple of the original
2041
2042 // The idea behind this method can be described with the following diagrams
2043 // second pass and third pass happen in the same loop really.. just separated
2044 // them to show what this does.
2045
2046 // First Pass
2047 // ResultArr:
2048 // 1,1,1,1,1,1
2049 // 1,1,1,1,1,1
2050 // 1,1,1,1,1,1
2051 // 1,1,1,1,1,1
2052 // 1,1,1,1,1,1
2053 // 1,1,1,1,1,1
2054
2055 // Second Pass
2056 // ResultArr2:
2057 // 1,,1,,1,,1,,1,,1,
2058 // ,,,,,,,,,,
2059 // 1,,1,,1,,1,,1,,1,
2060 // ,,,,,,,,,,
2061 // 1,,1,,1,,1,,1,,1,
2062 // ,,,,,,,,,,
2063 // 1,,1,,1,,1,,1,,1,
2064 // ,,,,,,,,,,
2065 // 1,,1,,1,,1,,1,,1,
2066 // ,,,,,,,,,,
2067 // 1,,1,,1,,1,,1,,1,
2068
2069 // Third pass fills in the blanks
2070 // ResultArr2:
2071 // 1,1,1,1,1,1,1,1,1,1,1,1
2072 // 1,1,1,1,1,1,1,1,1,1,1,1
2073 // 1,1,1,1,1,1,1,1,1,1,1,1
2074 // 1,1,1,1,1,1,1,1,1,1,1,1
2075 // 1,1,1,1,1,1,1,1,1,1,1,1
2076 // 1,1,1,1,1,1,1,1,1,1,1,1
2077 // 1,1,1,1,1,1,1,1,1,1,1,1
2078 // 1,1,1,1,1,1,1,1,1,1,1,1
2079 // 1,1,1,1,1,1,1,1,1,1,1,1
2080 // 1,1,1,1,1,1,1,1,1,1,1,1
2081 // 1,1,1,1,1,1,1,1,1,1,1,1
2082
2083 // X,Y = .
2084 // X+1,y = ^
2085 // X,Y+1 = *
2086 // X+1,Y+1 = #
2087
2088 // Filling in like this;
2089 // .*
2090 // ^#
2091 // 1st .
2092 // 2nd *
2093 // 3rd ^
2094 // 4th #
2095 // on single loop.
2096
2097 float[,] resultarr2 = new float[512,512];
2098 for (int y = 0; y < (int)Constants.RegionSize; y++)
2099 {
2100 for (int x = 0; x < (int)Constants.RegionSize; x++)
2101 {
2102 resultarr2[y*2, x*2] = resultarr[y, x];
2103
2104 if (y < (int)Constants.RegionSize)
2105 {
2106 if (y + 1 < (int)Constants.RegionSize)
2107 {
2108 if (x + 1 < (int)Constants.RegionSize)
2109 {
2110 resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x] +
2111 resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4);
2112 }
2113 else
2114 {
2115 resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x])/2);
2116 }
2117 }
2118 else
2119 {
2120 resultarr2[(y*2) + 1, x*2] = resultarr[y, x];
2121 }
2122 }
2123 if (x < (int)Constants.RegionSize)
2124 {
2125 if (x + 1 < (int)Constants.RegionSize)
2126 {
2127 if (y + 1 < (int)Constants.RegionSize)
2128 {
2129 resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] +
2130 resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4);
2131 }
2132 else
2133 {
2134 resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y, x + 1])/2);
2135 }
2136 }
2137 else
2138 {
2139 resultarr2[y*2, (x*2) + 1] = resultarr[y, x];
2140 }
2141 }
2142 if (x < (int)Constants.RegionSize && y < (int)Constants.RegionSize)
2143 {
2144 if ((x + 1 < (int)Constants.RegionSize) && (y + 1 < (int)Constants.RegionSize))
2145 {
2146 resultarr2[(y*2) + 1, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] +
2147 resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4);
2148 }
2149 else
2150 {
2151 resultarr2[(y*2) + 1, (x*2) + 1] = resultarr[y, x];
2152 }
2153 }
2154 }
2155 }
2156 //Flatten out the array
2157 int i = 0;
2158 for (int y = 0; y < 512; y++)
2159 {
2160 for (int x = 0; x < 512; x++)
2161 {
2162 if (Single.IsNaN(resultarr2[y, x]) || Single.IsInfinity(resultarr2[y, x]))
2163 {
2164 m_log.Warn("[PHYSICS]: Non finite heightfield element detected. Setting it to 0");
2165 resultarr2[y, x] = 0;
2166 }
2167 returnarr[i] = resultarr2[y, x];
2168 i++;
2169 }
2170 }
2171
2172 return returnarr;
2173 }
2174
2175 #endregion
2176
2177 public override void SetTerrain(float[] heightMap)
2178 {
2179 if (m_worldOffset != Vector3.Zero && m_parentScene != null)
2180 {
2181 if (m_parentScene is OdeScene)
2182 {
2183 ((OdeScene)m_parentScene).SetTerrain(heightMap, m_worldOffset);
2184 }
2185 }
2186 else
2187 {
2188 SetTerrain(heightMap, m_worldOffset);
2189 }
2190 }
2191
2192 public override void CombineTerrain(float[] heightMap, Vector3 pOffset)
2193 {
2194 SetTerrain(heightMap, pOffset);
2195 }
2196
2197 public void SetTerrain(float[] heightMap, Vector3 pOffset)
2198 {
2199
2200 float[] _heightmap;
2201 _heightmap = new float[(((int)Constants.RegionSize + 2) * ((int)Constants.RegionSize + 2))];
2202
2203 uint heightmapWidth = Constants.RegionSize + 2;
2204 uint heightmapHeight = Constants.RegionSize + 2;
2205
2206 uint heightmapWidthSamples;
2207
2208 uint heightmapHeightSamples;
2209
2210 heightmapWidthSamples = (uint)Constants.RegionSize + 2;
2211 heightmapHeightSamples = (uint)Constants.RegionSize + 2;
2212
2213 const float scale = 1.0f;
2214 const float offset = 0.0f;
2215 const float thickness = 10f;
2216 const int wrap = 0;
2217
2218 int regionsize = (int) Constants.RegionSize + 2;
2219
2220 float hfmin = float.MaxValue;
2221 float hfmax = float.MinValue;
2222 float val;
2223 int xx;
2224 int yy;
2225
2226 int maxXXYY = regionsize - 3;
2227 // flipping map adding one margin all around so things don't fall in edges
2228
2229 int xt = 0;
2230 xx = 0;
2231
2232 for (int x = 0; x < heightmapWidthSamples; x++)
2233 {
2234 if (x > 1 && xx < maxXXYY)
2235 xx++;
2236 yy = 0;
2237 for (int y = 0; y < heightmapHeightSamples; y++)
2238 {
2239 if (y > 1 && y < maxXXYY)
2240 yy += (int)Constants.RegionSize;
2241
2242 val = heightMap[yy + xx];
2243 _heightmap[xt + y] = val;
2244
2245 if (hfmin > val)
2246 hfmin = val;
2247 if (hfmax < val)
2248 hfmax = val;
2249
2250 }
2251
2252 xt += regionsize;
2253 }
2254 lock (OdeLock)
2255 {
2256 IntPtr GroundGeom = IntPtr.Zero;
2257 if (RegionTerrain.TryGetValue(pOffset, out GroundGeom))
2258 {
2259 RegionTerrain.Remove(pOffset);
2260 if (GroundGeom != IntPtr.Zero)
2261 {
2262 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
2263 {
2264 TerrainHeightFieldHeightsHandlers[GroundGeom].Free();
2265 TerrainHeightFieldHeightsHandlers.Remove(GroundGeom);
2266 TerrainHeightFieldHeights.Remove(GroundGeom);
2267 }
2268 d.SpaceRemove(StaticSpace, GroundGeom);
2269 d.GeomDestroy(GroundGeom);
2270 }
2271 }
2272 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
2273
2274 GCHandle _heightmaphandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned);
2275
2276 d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmaphandler.AddrOfPinnedObject(), 0, heightmapWidth , heightmapHeight,
2277 (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale,
2278 offset, thickness, wrap);
2279
2280 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
2281 GroundGeom = d.CreateHeightfield(StaticSpace, HeightmapData, 1);
2282 if (GroundGeom != IntPtr.Zero)
2283 {
2284 d.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land));
2285 d.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space));
2286
2287 }
2288 geom_name_map[GroundGeom] = "Terrain";
2289
2290 d.Matrix3 R = new d.Matrix3();
2291
2292 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
2293 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
2294
2295
2296 q1 = q1 * q2;
2297
2298 Vector3 v3;
2299 float angle;
2300 q1.GetAxisAngle(out v3, out angle);
2301
2302 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
2303 d.GeomSetRotation(GroundGeom, ref R);
2304 d.GeomSetPosition(GroundGeom, pOffset.X + (float)Constants.RegionSize * 0.5f - 0.5f, pOffset.Y + (float)Constants.RegionSize * 0.5f - 0.5f, 0);
2305 IntPtr testGround = IntPtr.Zero;
2306 if (RegionTerrain.TryGetValue(pOffset, out testGround))
2307 {
2308 RegionTerrain.Remove(pOffset);
2309 }
2310 RegionTerrain.Add(pOffset, GroundGeom, GroundGeom);
2311// TerrainHeightFieldHeights.Add(GroundGeom, ODElandMap);
2312 TerrainHeightFieldHeights.Add(GroundGeom, _heightmap);
2313 TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler);
2314
2315 }
2316 }
2317
2318 public override void DeleteTerrain()
2319 {
2320 }
2321
2322 public float GetWaterLevel()
2323 {
2324 return waterlevel;
2325 }
2326
2327 public override bool SupportsCombining()
2328 {
2329 return true;
2330 }
2331/*
2332 public override void UnCombine(PhysicsScene pScene)
2333 {
2334 IntPtr localGround = IntPtr.Zero;
2335// float[] localHeightfield;
2336 bool proceed = false;
2337 List<IntPtr> geomDestroyList = new List<IntPtr>();
2338
2339 lock (OdeLock)
2340 {
2341 if (RegionTerrain.TryGetValue(Vector3.Zero, out localGround))
2342 {
2343 foreach (IntPtr geom in TerrainHeightFieldHeights.Keys)
2344 {
2345 if (geom == localGround)
2346 {
2347// localHeightfield = TerrainHeightFieldHeights[geom];
2348 proceed = true;
2349 }
2350 else
2351 {
2352 geomDestroyList.Add(geom);
2353 }
2354 }
2355
2356 if (proceed)
2357 {
2358 m_worldOffset = Vector3.Zero;
2359 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize);
2360 m_parentScene = null;
2361
2362 foreach (IntPtr g in geomDestroyList)
2363 {
2364 // removingHeightField needs to be done or the garbage collector will
2365 // collect the terrain data before we tell ODE to destroy it causing
2366 // memory corruption
2367 if (TerrainHeightFieldHeights.ContainsKey(g))
2368 {
2369// float[] removingHeightField = TerrainHeightFieldHeights[g];
2370 TerrainHeightFieldHeights.Remove(g);
2371
2372 if (RegionTerrain.ContainsKey(g))
2373 {
2374 RegionTerrain.Remove(g);
2375 }
2376
2377 d.GeomDestroy(g);
2378 //removingHeightField = new float[0];
2379 }
2380 }
2381
2382 }
2383 else
2384 {
2385 m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data.");
2386 }
2387 }
2388 }
2389 }
2390*/
2391 public override void SetWaterLevel(float baseheight)
2392 {
2393 waterlevel = baseheight;
2394 randomizeWater(waterlevel);
2395 }
2396
2397 public void randomizeWater(float baseheight)
2398 {
2399 const uint heightmapWidth = m_regionWidth + 2;
2400 const uint heightmapHeight = m_regionHeight + 2;
2401 const uint heightmapWidthSamples = m_regionWidth + 2;
2402 const uint heightmapHeightSamples = m_regionHeight + 2;
2403 const float scale = 1.0f;
2404 const float offset = 0.0f;
2405 const float thickness = 2.9f;
2406 const int wrap = 0;
2407
2408 for (int i = 0; i < (258 * 258); i++)
2409 {
2410 _watermap[i] = (baseheight-0.1f) + ((float)fluidRandomizer.Next(1,9) / 10f);
2411 // m_log.Info((baseheight - 0.1f) + ((float)fluidRandomizer.Next(1, 9) / 10f));
2412 }
2413
2414 lock (OdeLock)
2415 {
2416 if (WaterGeom != IntPtr.Zero)
2417 {
2418 d.SpaceRemove(StaticSpace, WaterGeom);
2419 }
2420 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
2421 d.GeomHeightfieldDataBuildSingle(HeightmapData, _watermap, 0, heightmapWidth, heightmapHeight,
2422 (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale,
2423 offset, thickness, wrap);
2424 d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight);
2425 WaterGeom = d.CreateHeightfield(StaticSpace, HeightmapData, 1);
2426 if (WaterGeom != IntPtr.Zero)
2427 {
2428 d.GeomSetCategoryBits(WaterGeom, (int)(CollisionCategories.Water));
2429 d.GeomSetCollideBits(WaterGeom, (int)(CollisionCategories.Space));
2430
2431 }
2432 geom_name_map[WaterGeom] = "Water";
2433
2434 d.Matrix3 R = new d.Matrix3();
2435
2436 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
2437 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
2438
2439 q1 = q1 * q2;
2440 Vector3 v3;
2441 float angle;
2442 q1.GetAxisAngle(out v3, out angle);
2443
2444 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
2445 d.GeomSetRotation(WaterGeom, ref R);
2446 d.GeomSetPosition(WaterGeom, 128, 128, 0);
2447
2448 }
2449
2450 }
2451
2452 public override void Dispose()
2453 {
2454 m_rayCastManager.Dispose();
2455 m_rayCastManager = null;
2456
2457 lock (OdeLock)
2458 {
2459 lock (_prims)
2460 {
2461 foreach (OdePrim prm in _prims)
2462 {
2463 RemovePrim(prm);
2464 }
2465 }
2466
2467 if (ContactgeomsArray != IntPtr.Zero)
2468 Marshal.FreeHGlobal(ContactgeomsArray);
2469 if (GlobalContactsArray != IntPtr.Zero)
2470 Marshal.FreeHGlobal(GlobalContactsArray);
2471
2472 d.WorldDestroy(world);
2473 //d.CloseODE();
2474 }
2475 }
2476
2477 public override Dictionary<uint, float> GetTopColliders()
2478 {
2479 Dictionary<uint, float> returncolliders = new Dictionary<uint, float>();
2480 int cnt = 0;
2481 lock (_prims)
2482 {
2483 foreach (OdePrim prm in _prims)
2484 {
2485 if (prm.CollisionScore > 0)
2486 {
2487 returncolliders.Add(prm.m_localID, prm.CollisionScore);
2488 cnt++;
2489 prm.CollisionScore = 0f;
2490 if (cnt > 25)
2491 {
2492 break;
2493 }
2494 }
2495 }
2496 }
2497 return returncolliders;
2498 }
2499
2500 public override bool SupportsRayCast()
2501 {
2502 return true;
2503 }
2504
2505 public override void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
2506 {
2507 if (retMethod != null)
2508 {
2509 m_rayCastManager.QueueRequest(position, direction, length, retMethod);
2510 }
2511 }
2512
2513 public override void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod)
2514 {
2515 if (retMethod != null)
2516 {
2517 m_rayCastManager.QueueRequest(position, direction, length, Count, retMethod);
2518 }
2519 }
2520
2521 // don't like this
2522 public override List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count)
2523 {
2524 ContactResult[] ourResults = null;
2525 RayCallback retMethod = delegate(List<ContactResult> results)
2526 {
2527 ourResults = new ContactResult[results.Count];
2528 results.CopyTo(ourResults, 0);
2529 };
2530 int waitTime = 0;
2531 m_rayCastManager.QueueRequest(position, direction, length, Count, retMethod);
2532 while (ourResults == null && waitTime < 1000)
2533 {
2534 Thread.Sleep(1);
2535 waitTime++;
2536 }
2537 if (ourResults == null)
2538 return new List<ContactResult>();
2539 return new List<ContactResult>(ourResults);
2540 }
2541
2542 public override void RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
2543 {
2544 if (retMethod != null && actor !=null)
2545 {
2546 IntPtr geom;
2547 if (actor is OdePrim)
2548 geom = ((OdePrim)actor).prim_geom;
2549 else if (actor is OdeCharacter)
2550 geom = ((OdePrim)actor).prim_geom;
2551 else
2552 return;
2553 if (geom == IntPtr.Zero)
2554 return;
2555 m_rayCastManager.QueueRequest(geom, position, direction, length, retMethod);
2556 }
2557 }
2558
2559 public override void RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod)
2560 {
2561 if (retMethod != null && actor != null)
2562 {
2563 IntPtr geom;
2564 if (actor is OdePrim)
2565 geom = ((OdePrim)actor).prim_geom;
2566 else if (actor is OdeCharacter)
2567 geom = ((OdePrim)actor).prim_geom;
2568 else
2569 return;
2570 if (geom == IntPtr.Zero)
2571 return;
2572
2573 m_rayCastManager.QueueRequest(geom,position, direction, length, Count, retMethod);
2574 }
2575 }
2576
2577 // don't like this
2578 public override List<ContactResult> RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, int Count)
2579 {
2580 if (actor != null)
2581 {
2582 IntPtr geom;
2583 if (actor is OdePrim)
2584 geom = ((OdePrim)actor).prim_geom;
2585 else if (actor is OdeCharacter)
2586 geom = ((OdePrim)actor).prim_geom;
2587 else
2588 return new List<ContactResult>();
2589 if (geom == IntPtr.Zero)
2590 return new List<ContactResult>();
2591
2592 ContactResult[] ourResults = null;
2593 RayCallback retMethod = delegate(List<ContactResult> results)
2594 {
2595 ourResults = new ContactResult[results.Count];
2596 results.CopyTo(ourResults, 0);
2597 };
2598 int waitTime = 0;
2599 m_rayCastManager.QueueRequest(geom,position, direction, length, Count, retMethod);
2600 while (ourResults == null && waitTime < 1000)
2601 {
2602 Thread.Sleep(1);
2603 waitTime++;
2604 }
2605 if (ourResults == null)
2606 return new List<ContactResult>();
2607 return new List<ContactResult>(ourResults);
2608 }
2609 return new List<ContactResult>();
2610 }
2611
2612#if USE_DRAWSTUFF
2613 // Keyboard callback
2614 public void command(int cmd)
2615 {
2616 IntPtr geom;
2617 d.Mass mass;
2618 d.Vector3 sides = new d.Vector3(d.RandReal() * 0.5f + 0.1f, d.RandReal() * 0.5f + 0.1f, d.RandReal() * 0.5f + 0.1f);
2619
2620
2621
2622 Char ch = Char.ToLower((Char)cmd);
2623 switch ((Char)ch)
2624 {
2625 case 'w':
2626 try
2627 {
2628 Vector3 rotate = (new Vector3(1, 0, 0) * Quaternion.CreateFromEulers(hpr.Z * Utils.DEG_TO_RAD, hpr.Y * Utils.DEG_TO_RAD, hpr.X * Utils.DEG_TO_RAD));
2629
2630 xyz.X += rotate.X; xyz.Y += rotate.Y; xyz.Z += rotate.Z;
2631 ds.SetViewpoint(ref xyz, ref hpr);
2632 }
2633 catch (ArgumentException)
2634 { hpr.X = 0; }
2635 break;
2636
2637 case 'a':
2638 hpr.X++;
2639 ds.SetViewpoint(ref xyz, ref hpr);
2640 break;
2641
2642 case 's':
2643 try
2644 {
2645 Vector3 rotate2 = (new Vector3(-1, 0, 0) * Quaternion.CreateFromEulers(hpr.Z * Utils.DEG_TO_RAD, hpr.Y * Utils.DEG_TO_RAD, hpr.X * Utils.DEG_TO_RAD));
2646
2647 xyz.X += rotate2.X; xyz.Y += rotate2.Y; xyz.Z += rotate2.Z;
2648 ds.SetViewpoint(ref xyz, ref hpr);
2649 }
2650 catch (ArgumentException)
2651 { hpr.X = 0; }
2652 break;
2653 case 'd':
2654 hpr.X--;
2655 ds.SetViewpoint(ref xyz, ref hpr);
2656 break;
2657 case 'r':
2658 xyz.Z++;
2659 ds.SetViewpoint(ref xyz, ref hpr);
2660 break;
2661 case 'f':
2662 xyz.Z--;
2663 ds.SetViewpoint(ref xyz, ref hpr);
2664 break;
2665 case 'e':
2666 xyz.Y++;
2667 ds.SetViewpoint(ref xyz, ref hpr);
2668 break;
2669 case 'q':
2670 xyz.Y--;
2671 ds.SetViewpoint(ref xyz, ref hpr);
2672 break;
2673 }
2674 }
2675
2676 public void step(int pause)
2677 {
2678
2679 ds.SetColor(1.0f, 1.0f, 0.0f);
2680 ds.SetTexture(ds.Texture.Wood);
2681 lock (_prims)
2682 {
2683 foreach (OdePrim prm in _prims)
2684 {
2685 //IntPtr body = d.GeomGetBody(prm.prim_geom);
2686 if (prm.prim_geom != IntPtr.Zero)
2687 {
2688 d.Vector3 pos;
2689 d.GeomCopyPosition(prm.prim_geom, out pos);
2690 //d.BodyCopyPosition(body, out pos);
2691
2692 d.Matrix3 R;
2693 d.GeomCopyRotation(prm.prim_geom, out R);
2694 //d.BodyCopyRotation(body, out R);
2695
2696
2697 d.Vector3 sides = new d.Vector3();
2698 sides.X = prm.Size.X;
2699 sides.Y = prm.Size.Y;
2700 sides.Z = prm.Size.Z;
2701
2702 ds.DrawBox(ref pos, ref R, ref sides);
2703 }
2704 }
2705 }
2706 ds.SetColor(1.0f, 0.0f, 0.0f);
2707 lock (_characters)
2708 {
2709 foreach (OdeCharacter chr in _characters)
2710 {
2711 if (chr.Shell != IntPtr.Zero)
2712 {
2713 IntPtr body = d.GeomGetBody(chr.Shell);
2714
2715 d.Vector3 pos;
2716 d.GeomCopyPosition(chr.Shell, out pos);
2717 //d.BodyCopyPosition(body, out pos);
2718
2719 d.Matrix3 R;
2720 d.GeomCopyRotation(chr.Shell, out R);
2721 //d.BodyCopyRotation(body, out R);
2722
2723 ds.DrawCapsule(ref pos, ref R, chr.Size.Z, 0.35f);
2724 d.Vector3 sides = new d.Vector3();
2725 sides.X = 0.5f;
2726 sides.Y = 0.5f;
2727 sides.Z = 0.5f;
2728
2729 ds.DrawBox(ref pos, ref R, ref sides);
2730 }
2731 }
2732 }
2733 }
2734
2735 public void start(int unused)
2736 {
2737 ds.SetViewpoint(ref xyz, ref hpr);
2738 }
2739#endif
2740 }
2741}
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/drawstuff.cs b/OpenSim/Region/Physics/UbitOdePlugin/drawstuff.cs
new file mode 100644
index 0000000..aefad3a
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/drawstuff.cs
@@ -0,0 +1,99 @@
1/*
2 * Copyright ODE
3 * Ode.NET - .NET bindings for ODE
4 * Jason Perkins (starkos@industriousone.com)
5 * Licensed under the New BSD
6 * Part of the OpenDynamicsEngine
7Open Dynamics Engine
8Copyright (c) 2001-2007, Russell L. Smith.
9All rights reserved.
10
11Redistribution and use in source and binary forms, with or without
12modification, are permitted provided that the following conditions
13are met:
14
15Redistributions of source code must retain the above copyright notice,
16this list of conditions and the following disclaimer.
17
18Redistributions in binary form must reproduce the above copyright notice,
19this list of conditions and the following disclaimer in the documentation
20and/or other materials provided with the distribution.
21
22Neither the names of ODE's copyright owner nor the names of its
23contributors may be used to endorse or promote products derived from
24this software without specific prior written permission.
25
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 *
39 */
40
41using System;
42using System.Runtime.InteropServices;
43using OdeAPI;
44
45namespace ODEDrawstuff
46{
47/*#if dDOUBLE
48 using dReal = System.Double;
49#else
50 */
51 using dReal = System.Single;
52//#endif
53
54 public static class ds
55 {
56 public const int VERSION = 2;
57
58 public enum Texture
59 {
60 None,
61 Wood
62 }
63
64 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
65 public delegate void CallbackFunction(int arg);
66
67 [StructLayout(LayoutKind.Sequential)]
68 public struct Functions
69 {
70 public int version;
71 public CallbackFunction start;
72 public CallbackFunction step;
73 public CallbackFunction command;
74 public CallbackFunction stop;
75 public string path_to_textures;
76 }
77
78 [DllImport("drawstuff", EntryPoint = "dsDrawBox")]
79 public static extern void DrawBox(ref d.Vector3 pos, ref d.Matrix3 R, ref d.Vector3 sides);
80
81 [DllImport("drawstuff", EntryPoint = "dsDrawCapsule")]
82 public static extern void DrawCapsule(ref d.Vector3 pos, ref d.Matrix3 R, dReal length, dReal radius);
83
84 [DllImport("drawstuff", EntryPoint = "dsDrawConvex")]
85 public static extern void DrawConvex(ref d.Vector3 pos, ref d.Matrix3 R, dReal[] planes, int planeCount, dReal[] points, int pointCount, int[] polygons);
86
87 [DllImport("drawstuff", EntryPoint = "dsSetColor")]
88 public static extern void SetColor(float red, float green, float blue);
89
90 [DllImport("drawstuff", EntryPoint = "dsSetTexture")]
91 public static extern void SetTexture(Texture texture);
92
93 [DllImport("drawstuff", EntryPoint = "dsSetViewpoint")]
94 public static extern void SetViewpoint(ref d.Vector3 xyz, ref d.Vector3 hpr);
95
96 [DllImport("drawstuff", EntryPoint = "dsSimulationLoop")]
97 public static extern void SimulationLoop(int argc, string[] argv, int window_width, int window_height, ref Functions fn);
98 }
99}