aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs47
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs24
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsActor.cs19
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsScene.cs10
-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.cs883
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs3256
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs443
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs1960
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdePlugin.cs86
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs2742
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/drawstuff.cs99
-rw-r--r--bin/Physics/OpenSim.Region.Physics.UbitOdePlugin.dll.config7
-rw-r--r--bin/Physics/libode-x86_64.sobin0 -> 5546089 bytes
-rw-r--r--bin/Physics/libode.sobin0 -> 3051566 bytes
-rw-r--r--prebuild.xml40
-rwxr-xr-xrunprebuild.bat2
-rwxr-xr-xrunprebuild2010.bat2
22 files changed, 11591 insertions, 22 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
index 5ca2ce4..c5cec59 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
@@ -417,7 +417,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
417 so.AttachedAvatar = UUID.Zero; 417 so.AttachedAvatar = UUID.Zero;
418 rootPart.SetParentLocalId(0); 418 rootPart.SetParentLocalId(0);
419 so.ClearPartAttachmentData(); 419 so.ClearPartAttachmentData();
420 rootPart.ApplyPhysics(rootPart.GetEffectiveObjectFlags(), rootPart.VolumeDetectActive); 420 rootPart.ApplyPhysics(rootPart.GetEffectiveObjectFlags(), rootPart.VolumeDetectActive,false);
421 so.HasGroupChanged = true; 421 so.HasGroupChanged = true;
422 rootPart.Rezzed = DateTime.Now; 422 rootPart.Rezzed = DateTime.Now;
423 rootPart.RemFlag(PrimFlags.TemporaryOnRez); 423 rootPart.RemFlag(PrimFlags.TemporaryOnRez);
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index ec5cf32..456e86b 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -4766,7 +4766,7 @@ Environment.Exit(1);
4766 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0); 4766 bool wasUsingPhysics = ((jointProxyObject.Flags & PrimFlags.Physics) != 0);
4767 if (wasUsingPhysics) 4767 if (wasUsingPhysics)
4768 { 4768 {
4769 jointProxyObject.UpdatePrimFlags(false, false, true, false); // FIXME: possible deadlock here; check to make sure all the scene alterations set into motion here won't deadlock 4769 jointProxyObject.UpdatePrimFlags(false, false, true, false,false); // FIXME: possible deadlock here; check to make sure all the scene alterations set into motion here won't deadlock
4770 } 4770 }
4771 } 4771 }
4772 4772
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index 683aafc..9961438 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -1281,7 +1281,8 @@ namespace OpenSim.Region.Framework.Scenes
1281 1281
1282 m_rootPart.SetParentLocalId(0); 1282 m_rootPart.SetParentLocalId(0);
1283 AttachmentPoint = (byte)0; 1283 AttachmentPoint = (byte)0;
1284 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive); 1284 // must check if buildind should be true or false here
1285 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive,false);
1285 HasGroupChanged = true; 1286 HasGroupChanged = true;
1286 RootPart.Rezzed = DateTime.Now; 1287 RootPart.Rezzed = DateTime.Now;
1287 RootPart.RemFlag(PrimFlags.TemporaryOnRez); 1288 RootPart.RemFlag(PrimFlags.TemporaryOnRez);
@@ -1581,21 +1582,33 @@ namespace OpenSim.Region.Framework.Scenes
1581 public void ApplyPhysics() 1582 public void ApplyPhysics()
1582 { 1583 {
1583 // Apply physics to the root prim 1584 // Apply physics to the root prim
1584 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive); 1585 // m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive);
1585 1586
1586 // Apply physics to child prims 1587 // Apply physics to child prims
1587 SceneObjectPart[] parts = m_parts.GetArray(); 1588 SceneObjectPart[] parts = m_parts.GetArray();
1588 if (parts.Length > 1) 1589 if (parts.Length > 1)
1589 { 1590 {
1591 ResetChildPrimPhysicsPositions();
1592
1593 // Apply physics to the root prim
1594 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, true);
1590 for (int i = 0; i < parts.Length; i++) 1595 for (int i = 0; i < parts.Length; i++)
1591 { 1596 {
1592 SceneObjectPart part = parts[i]; 1597 SceneObjectPart part = parts[i];
1593 if (part.LocalId != m_rootPart.LocalId) 1598 if (part.LocalId != m_rootPart.LocalId)
1594 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive); 1599// part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive);
1595 } 1600 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, true);
1596 1601
1602 }
1597 // Hack to get the physics scene geometries in the right spot 1603 // Hack to get the physics scene geometries in the right spot
1598 ResetChildPrimPhysicsPositions(); 1604// ResetChildPrimPhysicsPositions();
1605 if (m_rootPart.PhysActor != null)
1606 m_rootPart.PhysActor.Building = false;
1607 }
1608 else
1609 {
1610 // Apply physics to the root prim
1611 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, false);
1599 } 1612 }
1600 } 1613 }
1601 1614
@@ -1829,13 +1842,16 @@ namespace OpenSim.Region.Framework.Scenes
1829 pbs, 1842 pbs,
1830 newPart.AbsolutePosition, 1843 newPart.AbsolutePosition,
1831 newPart.Scale, 1844 newPart.Scale,
1832 newPart.RotationOffset, 1845 //newPart.RotationOffset,
1846 newPart.GetWorldRotation(),
1833 part.PhysActor.IsPhysical, 1847 part.PhysActor.IsPhysical,
1834 newPart.LocalId); 1848 newPart.LocalId);
1835 1849
1836 newPart.DoPhysicsPropertyUpdate(part.PhysActor.IsPhysical, true); 1850 newPart.DoPhysicsPropertyUpdate(part.PhysActor.IsPhysical, true);
1837 } 1851 }
1838 } 1852 }
1853 if (dupe.m_rootPart.PhysActor != null && userExposed)
1854 dupe.m_rootPart.PhysActor.Building = false; // tell physics to finish building
1839 1855
1840 if (userExposed) 1856 if (userExposed)
1841 { 1857 {
@@ -2853,12 +2869,31 @@ namespace OpenSim.Region.Framework.Scenes
2853 } 2869 }
2854 } 2870 }
2855 2871
2872/*
2856 RootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect); 2873 RootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect);
2857 for (int i = 0; i < parts.Length; i++) 2874 for (int i = 0; i < parts.Length; i++)
2858 { 2875 {
2859 if (parts[i] != RootPart) 2876 if (parts[i] != RootPart)
2860 parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect); 2877 parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect);
2861 } 2878 }
2879*/
2880 if (parts.Length > 1)
2881 {
2882 m_rootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, true);
2883
2884 for (int i = 0; i < parts.Length; i++)
2885 {
2886
2887 if (parts[i].UUID != m_rootPart.UUID)
2888 parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, true);
2889 }
2890
2891 if (m_rootPart.PhysActor != null)
2892 m_rootPart.PhysActor.Building = false;
2893 }
2894 else
2895 m_rootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, false);
2896
2862 } 2897 }
2863 } 2898 }
2864 2899
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index ac39b6b..577c0d3 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -1503,7 +1503,8 @@ namespace OpenSim.Region.Framework.Scenes
1503 /// </summary> 1503 /// </summary>
1504 /// <param name="rootObjectFlags"></param> 1504 /// <param name="rootObjectFlags"></param>
1505 /// <param name="VolumeDetectActive"></param> 1505 /// <param name="VolumeDetectActive"></param>
1506 public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive) 1506// public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive)
1507 public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive, bool building)
1507 { 1508 {
1508 if (!ParentGroup.Scene.CollidablePrims) 1509 if (!ParentGroup.Scene.CollidablePrims)
1509 return; 1510 return;
@@ -1539,7 +1540,8 @@ namespace OpenSim.Region.Framework.Scenes
1539 Shape, 1540 Shape,
1540 AbsolutePosition, 1541 AbsolutePosition,
1541 Scale, 1542 Scale,
1542 RotationOffset, 1543// RotationOffset,
1544 GetWorldRotation(), // physics wants world rotation
1543 RigidBody, 1545 RigidBody,
1544 m_localId); 1546 m_localId);
1545 } 1547 }
@@ -1556,6 +1558,8 @@ namespace OpenSim.Region.Framework.Scenes
1556 PhysActor.SetMaterial(Material); 1558 PhysActor.SetMaterial(Material);
1557 DoPhysicsPropertyUpdate(RigidBody, true); 1559 DoPhysicsPropertyUpdate(RigidBody, true);
1558 PhysActor.SetVolumeDetect(VolumeDetectActive ? 1 : 0); 1560 PhysActor.SetVolumeDetect(VolumeDetectActive ? 1 : 0);
1561 if (!building)
1562 PhysActor.Building = false;
1559 } 1563 }
1560 } 1564 }
1561 } 1565 }
@@ -1791,6 +1795,10 @@ namespace OpenSim.Region.Framework.Scenes
1791 if (!isNew) 1795 if (!isNew)
1792 ParentGroup.Scene.RemovePhysicalPrim(1); 1796 ParentGroup.Scene.RemovePhysicalPrim(1);
1793 1797
1798 Velocity = new Vector3(0, 0, 0);
1799 Acceleration = new Vector3(0, 0, 0);
1800 AngularVelocity = new Vector3(0, 0, 0);
1801
1794 PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate; 1802 PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
1795 PhysActor.OnOutOfBounds -= PhysicsOutOfBounds; 1803 PhysActor.OnOutOfBounds -= PhysicsOutOfBounds;
1796 PhysActor.delink(); 1804 PhysActor.delink();
@@ -4267,7 +4275,8 @@ namespace OpenSim.Region.Framework.Scenes
4267 /// <param name="SetTemporary"></param> 4275 /// <param name="SetTemporary"></param>
4268 /// <param name="SetPhantom"></param> 4276 /// <param name="SetPhantom"></param>
4269 /// <param name="SetVD"></param> 4277 /// <param name="SetVD"></param>
4270 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD) 4278// public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD)
4279 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD, bool building)
4271 { 4280 {
4272 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0); 4281 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0);
4273 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0); 4282 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0);
@@ -4285,6 +4294,9 @@ namespace OpenSim.Region.Framework.Scenes
4285 // that... 4294 // that...
4286 // ... if VD is changed, all others are not. 4295 // ... if VD is changed, all others are not.
4287 // ... if one of the others is changed, VD is not. 4296 // ... if one of the others is changed, VD is not.
4297 // do this first
4298 if (building && PhysActor != null && PhysActor.Building != building)
4299 PhysActor.Building = building;
4288 if (SetVD) // VD is active, special logic applies 4300 if (SetVD) // VD is active, special logic applies
4289 { 4301 {
4290 // State machine logic for VolumeDetect 4302 // State machine logic for VolumeDetect
@@ -4366,7 +4378,8 @@ namespace OpenSim.Region.Framework.Scenes
4366 Shape, 4378 Shape,
4367 AbsolutePosition, 4379 AbsolutePosition,
4368 Scale, 4380 Scale,
4369 RotationOffset, 4381// RotationOffset,
4382 GetWorldRotation(), //physics wants world rotation like all other functions send
4370 UsePhysics, 4383 UsePhysics,
4371 m_localId); 4384 m_localId);
4372 4385
@@ -4446,6 +4459,9 @@ namespace OpenSim.Region.Framework.Scenes
4446 } 4459 }
4447 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString()); 4460 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
4448 4461
4462 // and last in case we have a new actor and not building
4463 if (PhysActor != null && PhysActor.Building != building)
4464 PhysActor.Building = building;
4449 if (ParentGroup != null) 4465 if (ParentGroup != null)
4450 { 4466 {
4451 ParentGroup.HasGroupChanged = true; 4467 ParentGroup.HasGroupChanged = true;
diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs
index 0587054..e1a68be 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs
@@ -68,6 +68,17 @@ namespace OpenSim.Region.Physics.Manager
68 } 68 }
69 } 69 }
70 70
71 public struct ContactData
72 {
73 public float mu;
74 public float bounce;
75
76 public ContactData(float _mu, float _bounce)
77 {
78 mu = _mu;
79 bounce = _bounce;
80 }
81 }
71 /// <summary> 82 /// <summary>
72 /// Used to pass collision information to OnCollisionUpdate listeners. 83 /// Used to pass collision information to OnCollisionUpdate listeners.
73 /// </summary> 84 /// </summary>
@@ -143,6 +154,14 @@ namespace OpenSim.Region.Physics.Manager
143 get { return new NullPhysicsActor(); } 154 get { return new NullPhysicsActor(); }
144 } 155 }
145 156
157
158 public virtual bool Building { get; set; }
159
160 public virtual ContactData ContactData
161 {
162 get { return new ContactData(0, 0); }
163 }
164
146 public abstract bool Stopped { get; } 165 public abstract bool Stopped { get; }
147 166
148 public abstract Vector3 Size { get; set; } 167 public abstract Vector3 Size { get; set; }
diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
index 514d9ad..3db71e5 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
@@ -225,7 +225,7 @@ namespace OpenSim.Region.Physics.Manager
225 } 225 }
226 226
227 public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {} 227 public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {}
228 228 public virtual void CombineTerrain(float[] heightMap, Vector3 pOffset) {}
229 public virtual void UnCombine(PhysicsScene pScene) {} 229 public virtual void UnCombine(PhysicsScene pScene) {}
230 230
231 /// <summary> 231 /// <summary>
@@ -263,5 +263,13 @@ namespace OpenSim.Region.Physics.Manager
263 { 263 {
264 return new List<ContactResult>(); 264 return new List<ContactResult>();
265 } 265 }
266
267 public virtual void RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, RaycastCallback retMethod){}
268 public virtual void RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod) { }
269 public virtual List<ContactResult> RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, int Count)
270 {
271 return new List<ContactResult>();
272 }
273
266 } 274 }
267} 275}
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..6b323fb
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs
@@ -0,0 +1,883 @@
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();
633
634 // linear motor
635 if (m_lmEfect > 0.01 && m_linearMotorTimescale < 1000)
636 {
637 tmpV = m_linearMotorDirection - curLocalVel; // velocity error
638 tmpV *= m_lmEfect / m_linearMotorTimescale; // error to correct in this timestep
639 tmpV *= rotq; // to world
640
641 if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0)
642 tmpV.Z = 0;
643
644 if (m_linearMotorOffset.X != 0 || m_linearMotorOffset.Y != 0 || m_linearMotorOffset.Z != 0)
645 {
646 // have offset, do it now
647 tmpV *= rootPrim.Mass;
648 d.BodyAddForceAtRelPos(Body, tmpV.X, tmpV.Y, tmpV.Z, m_linearMotorOffset.X, m_linearMotorOffset.Y, m_linearMotorOffset.Z);
649 }
650 else
651 {
652 force.X += tmpV.X;
653 force.Y += tmpV.Y;
654 force.Z += tmpV.Z;
655 }
656 m_lmEfect *= (1.0f - 1.0f / m_linearMotorDecayTimescale);
657 }
658 else
659 m_lmEfect = 0;
660
661 // friction
662 if (curLocalVel.X != 0 || curLocalVel.Y != 0 || curLocalVel.Z != 0)
663 {
664 tmpV.X = -curLocalVel.X / m_linearFrictionTimescale.X;
665 tmpV.Y = -curLocalVel.Y / m_linearFrictionTimescale.Y;
666 tmpV.Z = -curLocalVel.Z / m_linearFrictionTimescale.Z;
667 tmpV *= rotq; // to world
668 force.X += tmpV.X;
669 force.Y += tmpV.Y;
670 force.Z += tmpV.Z;
671 }
672
673 // hover
674 if (m_VhoverTimescale < 300)
675 {
676 d.Vector3 pos = d.BodyGetPosition(Body);
677
678 // default to global
679 float perr = m_VhoverHeight - pos.Z;;
680
681 if ((m_flags & VehicleFlag.HOVER_TERRAIN_ONLY) != 0)
682 {
683 perr += _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y);
684 }
685 else if ((m_flags & VehicleFlag.HOVER_WATER_ONLY) != 0)
686 {
687 perr += _pParentScene.GetWaterLevel();
688 }
689 else if ((m_flags & VehicleFlag.HOVER_GLOBAL_HEIGHT) == 0)
690 {
691 float t = _pParentScene.GetTerrainHeightAtXY(pos.X, pos.Y);
692 float w = _pParentScene.GetWaterLevel();
693 if (t > w)
694 perr += t;
695 else
696 perr += w;
697 }
698
699 if ((m_flags & VehicleFlag.HOVER_UP_ONLY) == 0 || perr > 0)
700 {
701 force.Z += (perr / m_VhoverTimescale / m_VhoverTimescale - curVel.Z * m_VhoverEfficiency) / _pParentScene.ODE_STEPSIZE;
702 force.Z += _pParentScene.gravityz * (1f - m_VehicleBuoyancy);
703 }
704 else // no buoyancy
705 force.Z += _pParentScene.gravityz;
706 }
707 else
708 {
709 // default gravity and buoancy
710 force.Z += _pParentScene.gravityz * (1f - m_VehicleBuoyancy);
711 }
712
713 // linear deflection
714 if (m_linearDeflectionEfficiency > 0)
715 {
716 float len = curVel.Length();
717 Vector3 atAxis;
718 atAxis = Xrot(rotq); // where are we pointing to
719 atAxis *= len; // make it same size as world velocity vector
720 tmpV = -atAxis; // oposite direction
721 atAxis -= curVel; // error to one direction
722 len = atAxis.LengthSquared();
723 tmpV -= curVel; // error to oposite
724 float lens = tmpV.LengthSquared();
725 if (len > 0.01 || lens > 0.01) // do nothing if close enougth
726 {
727 if (len < lens)
728 tmpV = atAxis;
729
730 tmpV *= (m_linearDeflectionEfficiency / m_linearDeflectionTimescale); // error to correct in this timestep
731 force.X += tmpV.X;
732 force.Y += tmpV.Y;
733 if ((m_flags & VehicleFlag.NO_DEFLECTION_UP) == 0)
734 force.Z += tmpV.Z;
735 }
736 }
737
738 // angular motor
739 if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000)
740 {
741 tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error
742 tmpV *= m_amEfect / m_angularMotorTimescale; // error to correct in this timestep
743 torque.X += tmpV.X;
744 torque.Y += tmpV.Y;
745 torque.Z += tmpV.Z;
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 torque.X -= curLocalAngVel.X / m_angularFrictionTimescale.X;
755 torque.Y -= curLocalAngVel.Y / m_angularFrictionTimescale.Y;
756 torque.Z -= curLocalAngVel.Z / m_angularFrictionTimescale.Z;
757 }
758
759 // angular deflection
760 if (m_angularDeflectionEfficiency > 0)
761 {
762 Vector3 dirv;
763
764 if (curLocalVel.X > 0.01f)
765 dirv = curLocalVel;
766 else if (curLocalVel.X < -0.01f)
767 // use oposite
768 dirv = -curLocalVel;
769 else
770 {
771 // make it fall into small positive x case
772 dirv.X = 0.01f;
773 dirv.Y = curLocalVel.Y;
774 dirv.Z = curLocalVel.Z;
775 }
776
777 float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale;
778
779 if (Math.Abs(dirv.Z) > 0.01)
780 {
781 torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp;
782 }
783
784 if (Math.Abs(dirv.Y) > 0.01)
785 {
786 torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp;
787 }
788 }
789
790 // vertical atractor
791 if (m_verticalAttractionTimescale < 300)
792 {
793 float roll;
794 float pitch;
795
796 GetRollPitch(rotq, out roll, out pitch);
797
798 float ftmp = 1.0f / m_verticalAttractionTimescale / m_verticalAttractionTimescale / _pParentScene.ODE_STEPSIZE;
799 float ftmp2 = m_verticalAttractionEfficiency / _pParentScene.ODE_STEPSIZE;
800
801 if (Math.Abs(roll) > 0.01) // roll
802 {
803 torque.X -= roll * ftmp + curLocalAngVel.X * ftmp2;
804 }
805
806 if (Math.Abs(pitch) > 0.01 && ((m_flags & VehicleFlag.LIMIT_ROLL_ONLY) == 0)) // pitch
807 {
808 torque.Y -= pitch * ftmp + curLocalAngVel.Y * ftmp2;
809 }
810
811 if (m_bankingEfficiency != 0 && Math.Abs(roll) < 0.01)
812 {
813 float broll = -roll * m_bankingEfficiency; ;
814 if (m_bankingMix != 0)
815 {
816 float vfact = m_bankingMix * Math.Abs(curLocalVel.X) / 10.0f;
817 if (vfact < m_bankingMix)
818 broll *= ((1 - m_bankingMix) + vfact);
819 }
820
821 torque.Z += (broll - curLocalAngVel.Z) / m_bankingTimescale;
822 }
823 }
824
825 d.Mass dmass;
826 d.BodyGetMass(Body,out dmass);
827
828 if (force.X != 0 || force.Y != 0 || force.Z != 0)
829 {
830 force *= dmass.mass;
831 d.BodySetForce(Body, force.X, force.Y, force.Z);
832 }
833
834 if (torque.X != 0 || torque.Y != 0 || torque.Z != 0)
835 {
836 torque *= m_referenceFrame; // to object frame
837 dtorque.X = torque.X;
838 dtorque.Y = torque.Y;
839 dtorque.Z = torque.Z;
840
841 d.MultiplyM3V3(out dvtmp, ref dmass.I, ref dtorque);
842 d.BodyAddRelTorque(Body, dvtmp.X, dvtmp.Y, dvtmp.Z); // add torque in object frame
843 }
844
845 //end MoveAngular
846
847 // limit rotations
848/*
849 bool changed = false;
850
851 if (m_RollreferenceFrame != Quaternion.Identity)
852 {
853 if (rotq.X >= m_RollreferenceFrame.X)
854 {
855 rot.X = rotq.X - (m_RollreferenceFrame.X / 2);
856 }
857 if (rotq.Y >= m_RollreferenceFrame.Y)
858 {
859 rot.Y = rotq.Y - (m_RollreferenceFrame.Y / 2);
860 }
861 if (rotq.X <= -m_RollreferenceFrame.X)
862 {
863 rot.X = rotq.X + (m_RollreferenceFrame.X / 2);
864 }
865 if (rotq.Y <= -m_RollreferenceFrame.Y)
866 {
867 rot.Y = rotq.Y + (m_RollreferenceFrame.Y / 2);
868 }
869 changed = true;
870 }
871
872 if ((m_flags & VehicleFlag.LOCK_ROTATION) != 0)
873 {
874 rot.X = 0;
875 rot.Y = 0;
876 changed = true;
877 }
878 if (changed)
879 d.BodySetQuaternion(Body, ref rot);
880*/
881 }
882 }
883}
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
new file mode 100644
index 0000000..7718a29
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
@@ -0,0 +1,3256 @@
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 if (m_targetSpace != _parent_scene.ActiveSpace)
1227 {
1228 m_targetSpace = _parent_scene.ActiveSpace;
1229
1230 foreach (OdePrim prm in childrenPrim)
1231 {
1232 if (prm.prim_geom != IntPtr.Zero)
1233 {
1234 d.SpaceAdd(m_targetSpace, prm.prim_geom);
1235 prm.m_targetSpace = m_targetSpace;
1236 }
1237 }
1238 d.SpaceAdd(m_targetSpace, prim_geom);
1239 }
1240 d.GeomEnable(prim_geom);
1241 foreach (OdePrim prm in childrenPrim)
1242 d.GeomEnable(prm.prim_geom);
1243
1244 d.BodyEnable(Body);
1245 }
1246 }
1247 resetCollisionAccounting(); // this sets m_disable to false
1248 }
1249
1250 private void disableBodySoft()
1251 {
1252 m_disabled = true;
1253 if (!childPrim)
1254 {
1255 if (m_isphysical && Body != IntPtr.Zero && prim_geom != IntPtr.Zero)
1256 {
1257 if (m_targetSpace == _parent_scene.ActiveSpace)
1258 {
1259 foreach (OdePrim prm in childrenPrim)
1260 {
1261 if (prm.m_targetSpace != IntPtr.Zero && prm.prim_geom != IntPtr.Zero)
1262 {
1263 d.SpaceRemove(prm.m_targetSpace, prm.prim_geom);
1264 prm.m_targetSpace = IntPtr.Zero;
1265 }
1266 }
1267 d.SpaceRemove(m_targetSpace, prim_geom);
1268 m_targetSpace = IntPtr.Zero;
1269 }
1270 d.GeomDisable(prim_geom);
1271 foreach (OdePrim prm in childrenPrim)
1272 d.GeomDisable(prm.prim_geom);
1273 d.BodyDisable(Body);
1274 }
1275 }
1276 }
1277
1278 private void MakeBody()
1279 {
1280 if (!m_isphysical) // only physical get bodies
1281 return;
1282
1283 if (childPrim) // child prims don't get bodies;
1284 return;
1285
1286 if (m_building)
1287 return;
1288
1289 if (prim_geom == IntPtr.Zero)
1290 {
1291 m_log.Warn("[PHYSICS]: Unable to link the linkset. Root has no geom yet");
1292 return;
1293 }
1294
1295 if (Body != IntPtr.Zero)
1296 {
1297 d.BodyDestroy(Body);
1298 Body = IntPtr.Zero;
1299 m_log.Warn("[PHYSICS]: MakeBody called having a body");
1300 }
1301
1302
1303 if (d.GeomGetBody(prim_geom) != IntPtr.Zero)
1304 {
1305 d.GeomSetBody(prim_geom, IntPtr.Zero);
1306 m_log.Warn("[PHYSICS]: MakeBody root geom already had a body");
1307 }
1308
1309 d.Matrix3 mymat = new d.Matrix3();
1310 d.Quaternion myrot = new d.Quaternion();
1311 d.Mass objdmass = new d.Mass { };
1312
1313 Body = d.BodyCreate(_parent_scene.world);
1314
1315 DMassDup(ref primdMass, out objdmass);
1316
1317 // rotate inertia
1318 myrot.X = _orientation.X;
1319 myrot.Y = _orientation.Y;
1320 myrot.Z = _orientation.Z;
1321 myrot.W = _orientation.W;
1322
1323 d.RfromQ(out mymat, ref myrot);
1324 d.MassRotate(ref objdmass, ref mymat);
1325
1326 // set the body rotation and position
1327 d.BodySetRotation(Body, ref mymat);
1328
1329 // recompute full object inertia if needed
1330 if (childrenPrim.Count > 0)
1331 {
1332 d.Matrix3 mat = new d.Matrix3();
1333 d.Quaternion quat = new d.Quaternion();
1334 d.Mass tmpdmass = new d.Mass { };
1335 Vector3 rcm;
1336
1337 rcm.X = _position.X + objdmass.c.X;
1338 rcm.Y = _position.Y + objdmass.c.Y;
1339 rcm.Z = _position.Z + objdmass.c.Z;
1340
1341 lock (childrenPrim)
1342 {
1343 foreach (OdePrim prm in childrenPrim)
1344 {
1345 if (prm.prim_geom == IntPtr.Zero)
1346 {
1347 m_log.Warn("[PHYSICS]: Unable to link one of the linkset elements, skipping it. No geom yet");
1348 continue;
1349 }
1350
1351
1352
1353 DMassCopy(ref prm.primdMass, ref tmpdmass);
1354
1355 // apply prim current rotation to inertia
1356 quat.X = prm._orientation.X;
1357 quat.Y = prm._orientation.Y;
1358 quat.Z = prm._orientation.Z;
1359 quat.W = prm._orientation.W;
1360 d.RfromQ(out mat, ref quat);
1361 d.MassRotate(ref tmpdmass, ref mat);
1362
1363 Vector3 ppos = prm._position;
1364 ppos.X += tmpdmass.c.X - rcm.X;
1365 ppos.Y += tmpdmass.c.Y - rcm.Y;
1366 ppos.Z += tmpdmass.c.Z - rcm.Z;
1367
1368 // refer inertia to root prim center of mass position
1369 d.MassTranslate(ref tmpdmass,
1370 ppos.X,
1371 ppos.Y,
1372 ppos.Z);
1373
1374 d.MassAdd(ref objdmass, ref tmpdmass); // add to total object inertia
1375 // fix prim colision cats
1376
1377 if (d.GeomGetBody(prm.prim_geom) != IntPtr.Zero)
1378 {
1379 d.GeomSetBody(prm.prim_geom, IntPtr.Zero);
1380 m_log.Warn("[PHYSICS]: MakeBody child geom already had a body");
1381 }
1382
1383 d.GeomClearOffset(prm.prim_geom);
1384 d.GeomSetBody(prm.prim_geom, Body);
1385 prm.Body = Body;
1386 d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat); // set relative rotation
1387 }
1388 }
1389 }
1390
1391 d.GeomClearOffset(prim_geom); // make sure we don't have a hidden offset
1392 // associate root geom with body
1393 d.GeomSetBody(prim_geom, Body);
1394
1395 d.BodySetPosition(Body, _position.X + objdmass.c.X, _position.Y + objdmass.c.Y, _position.Z + objdmass.c.Z);
1396 d.GeomSetOffsetWorldPosition(prim_geom, _position.X, _position.Y, _position.Z);
1397
1398 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
1399 myrot.W = -myrot.W;
1400 d.RfromQ(out mymat, ref myrot);
1401 d.MassRotate(ref objdmass, ref mymat);
1402 d.BodySetMass(Body, ref objdmass);
1403 _mass = objdmass.mass;
1404
1405 m_collisionCategories |= CollisionCategories.Body;
1406 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1407
1408 // disconnect from world gravity so we can apply buoyancy
1409 d.BodySetGravityMode(Body, false);
1410
1411 d.BodySetAutoDisableFlag(Body, true);
1412 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1413 // d.BodySetLinearDampingThreshold(Body, 0.01f);
1414 // d.BodySetAngularDampingThreshold(Body, 0.001f);
1415 d.BodySetDamping(Body, .001f, .0002f);
1416
1417 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1418 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1419
1420 m_interpenetrationcount = 0;
1421 m_collisionscore = 0;
1422
1423 m_disabled = false;
1424
1425 if (m_targetSpace != _parent_scene.ActiveSpace)
1426 {
1427 if (m_targetSpace != IntPtr.Zero)
1428 {
1429 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1430 if (d.SpaceQuery(m_targetSpace, prim_geom))
1431 d.SpaceRemove(m_targetSpace, prim_geom);
1432 }
1433
1434 m_targetSpace = _parent_scene.ActiveSpace;
1435 d.SpaceAdd(m_targetSpace, prim_geom);
1436 }
1437
1438 lock (childrenPrim)
1439 {
1440 foreach (OdePrim prm in childrenPrim)
1441 {
1442 if (prm.prim_geom == IntPtr.Zero)
1443 continue;
1444
1445 Vector3 ppos = prm._position;
1446 d.GeomSetOffsetWorldPosition(prm.prim_geom, ppos.X, ppos.Y, ppos.Z); // set relative position
1447
1448 prm.m_collisionCategories |= CollisionCategories.Body;
1449 prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1450 d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories);
1451 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
1452
1453 if (prm.m_targetSpace != _parent_scene.ActiveSpace)
1454 {
1455 if (prm.m_targetSpace != IntPtr.Zero)
1456 {
1457 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1458 if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom))
1459 d.SpaceRemove(prm.m_targetSpace, prm.prim_geom);
1460 }
1461 prm.m_targetSpace = _parent_scene.ActiveSpace;
1462 d.SpaceAdd(m_targetSpace, prm.prim_geom);
1463 }
1464 d.GeomEnable(prm.prim_geom);
1465 prm.m_disabled = false;
1466 prm.m_interpenetrationcount = 0;
1467 prm.m_collisionscore = 0;
1468 _parent_scene.addActivePrim(prm);
1469 }
1470 }
1471
1472 // The body doesn't already have a finite rotation mode set here
1473 if ((!m_angularlock.ApproxEquals(Vector3.One, 0.0f)) && _parent == null)
1474 {
1475 createAMotor(m_angularlock);
1476 }
1477
1478 d.GeomEnable(prim_geom);
1479 m_disabled = false;
1480 _parent_scene.addActivePrim(this);
1481 }
1482
1483 private void DestroyBody()
1484 {
1485 if (Body != IntPtr.Zero)
1486 {
1487 _parent_scene.remActivePrim(this);
1488 m_collisionCategories &= ~CollisionCategories.Body;
1489 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
1490 if (prim_geom != IntPtr.Zero)
1491 {
1492 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1493 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1494 UpdateDataFromGeom();
1495 d.GeomSetBody(prim_geom, IntPtr.Zero);
1496 SetInStaticSpace(this);
1497 }
1498
1499 if (!childPrim)
1500 {
1501 lock (childrenPrim)
1502 {
1503 foreach (OdePrim prm in childrenPrim)
1504 {
1505 _parent_scene.remActivePrim(prm);
1506 prm.m_collisionCategories &= ~CollisionCategories.Body;
1507 prm.m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
1508 if (prm.prim_geom != IntPtr.Zero)
1509 {
1510 d.GeomSetCategoryBits(prm.prim_geom, (int)m_collisionCategories);
1511 d.GeomSetCollideBits(prm.prim_geom, (int)m_collisionFlags);
1512 prm.UpdateDataFromGeom();
1513 SetInStaticSpace(prm);
1514 }
1515 prm.Body = IntPtr.Zero;
1516 prm._mass = prm.primMass;
1517 prm.m_collisionscore = 0;
1518 }
1519 }
1520 d.BodyDestroy(Body);
1521 }
1522 Body = IntPtr.Zero;
1523 }
1524 _mass = primMass;
1525 m_disabled = true;
1526 m_collisionscore = 0;
1527 }
1528
1529 #region Mass Calculation
1530
1531 private float CalculatePrimVolume()
1532 {
1533 float volume = _size.X * _size.Y * _size.Z; // default
1534 float tmp;
1535
1536 float hollowAmount = (float)_pbs.ProfileHollow * 2.0e-5f;
1537 float hollowVolume = hollowAmount * hollowAmount;
1538
1539 switch (_pbs.ProfileShape)
1540 {
1541 case ProfileShape.Square:
1542 // default box
1543
1544 if (_pbs.PathCurve == (byte)Extrusion.Straight)
1545 {
1546 if (hollowAmount > 0.0)
1547 {
1548 switch (_pbs.HollowShape)
1549 {
1550 case HollowShape.Square:
1551 case HollowShape.Same:
1552 break;
1553
1554 case HollowShape.Circle:
1555
1556 hollowVolume *= 0.78539816339f;
1557 break;
1558
1559 case HollowShape.Triangle:
1560
1561 hollowVolume *= (0.5f * .5f);
1562 break;
1563
1564 default:
1565 hollowVolume = 0;
1566 break;
1567 }
1568 volume *= (1.0f - hollowVolume);
1569 }
1570 }
1571
1572 else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1573 {
1574 //a tube
1575
1576 volume *= 0.78539816339e-2f * (float)(200 - _pbs.PathScaleX);
1577 tmp = 1.0f - 2.0e-2f * (float)(200 - _pbs.PathScaleY);
1578 volume -= volume * tmp * tmp;
1579
1580 if (hollowAmount > 0.0)
1581 {
1582 hollowVolume *= hollowAmount;
1583
1584 switch (_pbs.HollowShape)
1585 {
1586 case HollowShape.Square:
1587 case HollowShape.Same:
1588 break;
1589
1590 case HollowShape.Circle:
1591 hollowVolume *= 0.78539816339f;
1592 break;
1593
1594 case HollowShape.Triangle:
1595 hollowVolume *= 0.5f * 0.5f;
1596 break;
1597 default:
1598 hollowVolume = 0;
1599 break;
1600 }
1601 volume *= (1.0f - hollowVolume);
1602 }
1603 }
1604
1605 break;
1606
1607 case ProfileShape.Circle:
1608
1609 if (_pbs.PathCurve == (byte)Extrusion.Straight)
1610 {
1611 volume *= 0.78539816339f; // elipse base
1612
1613 if (hollowAmount > 0.0)
1614 {
1615 switch (_pbs.HollowShape)
1616 {
1617 case HollowShape.Same:
1618 case HollowShape.Circle:
1619 break;
1620
1621 case HollowShape.Square:
1622 hollowVolume *= 0.5f * 2.5984480504799f;
1623 break;
1624
1625 case HollowShape.Triangle:
1626 hollowVolume *= .5f * 1.27323954473516f;
1627 break;
1628
1629 default:
1630 hollowVolume = 0;
1631 break;
1632 }
1633 volume *= (1.0f - hollowVolume);
1634 }
1635 }
1636
1637 else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1638 {
1639 volume *= 0.61685027506808491367715568749226e-2f * (float)(200 - _pbs.PathScaleX);
1640 tmp = 1.0f - .02f * (float)(200 - _pbs.PathScaleY);
1641 volume *= (1.0f - tmp * tmp);
1642
1643 if (hollowAmount > 0.0)
1644 {
1645
1646 // calculate the hollow volume by it's shape compared to the prim shape
1647 hollowVolume *= hollowAmount;
1648
1649 switch (_pbs.HollowShape)
1650 {
1651 case HollowShape.Same:
1652 case HollowShape.Circle:
1653 break;
1654
1655 case HollowShape.Square:
1656 hollowVolume *= 0.5f * 2.5984480504799f;
1657 break;
1658
1659 case HollowShape.Triangle:
1660 hollowVolume *= .5f * 1.27323954473516f;
1661 break;
1662
1663 default:
1664 hollowVolume = 0;
1665 break;
1666 }
1667 volume *= (1.0f - hollowVolume);
1668 }
1669 }
1670 break;
1671
1672 case ProfileShape.HalfCircle:
1673 if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1674 {
1675 volume *= 0.52359877559829887307710723054658f;
1676 }
1677 break;
1678
1679 case ProfileShape.EquilateralTriangle:
1680
1681 if (_pbs.PathCurve == (byte)Extrusion.Straight)
1682 {
1683 volume *= 0.32475953f;
1684
1685 if (hollowAmount > 0.0)
1686 {
1687
1688 // calculate the hollow volume by it's shape compared to the prim shape
1689 switch (_pbs.HollowShape)
1690 {
1691 case HollowShape.Same:
1692 case HollowShape.Triangle:
1693 hollowVolume *= .25f;
1694 break;
1695
1696 case HollowShape.Square:
1697 hollowVolume *= 0.499849f * 3.07920140172638f;
1698 break;
1699
1700 case HollowShape.Circle:
1701 // Hollow shape is a perfect cyllinder in respect to the cube's scale
1702 // Cyllinder hollow volume calculation
1703
1704 hollowVolume *= 0.1963495f * 3.07920140172638f;
1705 break;
1706
1707 default:
1708 hollowVolume = 0;
1709 break;
1710 }
1711 volume *= (1.0f - hollowVolume);
1712 }
1713 }
1714 else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1715 {
1716 volume *= 0.32475953f;
1717 volume *= 0.01f * (float)(200 - _pbs.PathScaleX);
1718 tmp = 1.0f - .02f * (float)(200 - _pbs.PathScaleY);
1719 volume *= (1.0f - tmp * tmp);
1720
1721 if (hollowAmount > 0.0)
1722 {
1723
1724 hollowVolume *= hollowAmount;
1725
1726 switch (_pbs.HollowShape)
1727 {
1728 case HollowShape.Same:
1729 case HollowShape.Triangle:
1730 hollowVolume *= .25f;
1731 break;
1732
1733 case HollowShape.Square:
1734 hollowVolume *= 0.499849f * 3.07920140172638f;
1735 break;
1736
1737 case HollowShape.Circle:
1738
1739 hollowVolume *= 0.1963495f * 3.07920140172638f;
1740 break;
1741
1742 default:
1743 hollowVolume = 0;
1744 break;
1745 }
1746 volume *= (1.0f - hollowVolume);
1747 }
1748 }
1749 break;
1750
1751 default:
1752 break;
1753 }
1754
1755 float taperX1;
1756 float taperY1;
1757 float taperX;
1758 float taperY;
1759 float pathBegin;
1760 float pathEnd;
1761 float profileBegin;
1762 float profileEnd;
1763
1764 if (_pbs.PathCurve == (byte)Extrusion.Straight || _pbs.PathCurve == (byte)Extrusion.Flexible)
1765 {
1766 taperX1 = _pbs.PathScaleX * 0.01f;
1767 if (taperX1 > 1.0f)
1768 taperX1 = 2.0f - taperX1;
1769 taperX = 1.0f - taperX1;
1770
1771 taperY1 = _pbs.PathScaleY * 0.01f;
1772 if (taperY1 > 1.0f)
1773 taperY1 = 2.0f - taperY1;
1774 taperY = 1.0f - taperY1;
1775 }
1776 else
1777 {
1778 taperX = _pbs.PathTaperX * 0.01f;
1779 if (taperX < 0.0f)
1780 taperX = -taperX;
1781 taperX1 = 1.0f - taperX;
1782
1783 taperY = _pbs.PathTaperY * 0.01f;
1784 if (taperY < 0.0f)
1785 taperY = -taperY;
1786 taperY1 = 1.0f - taperY;
1787 }
1788
1789 volume *= (taperX1 * taperY1 + 0.5f * (taperX1 * taperY + taperX * taperY1) + 0.3333333333f * taperX * taperY);
1790
1791 pathBegin = (float)_pbs.PathBegin * 2.0e-5f;
1792 pathEnd = 1.0f - (float)_pbs.PathEnd * 2.0e-5f;
1793 volume *= (pathEnd - pathBegin);
1794
1795 // this is crude aproximation
1796 profileBegin = (float)_pbs.ProfileBegin * 2.0e-5f;
1797 profileEnd = 1.0f - (float)_pbs.ProfileEnd * 2.0e-5f;
1798 volume *= (profileEnd - profileBegin);
1799
1800 return volume;
1801 }
1802
1803
1804 private void CalcPrimBodyData()
1805 {
1806 float volume;
1807
1808 if (prim_geom == IntPtr.Zero)
1809 {
1810 // Ubit let's have a initial basic OOB
1811 primOOBsize.X = _size.X;
1812 primOOBsize.Y = _size.Y;
1813 primOOBsize.Z = _size.Z;
1814 primOOBoffset = Vector3.Zero;
1815 }
1816 else
1817 {
1818 d.AABB AABB;
1819 d.GeomGetAABB(prim_geom, out AABB); // get the AABB from engine geom
1820
1821 primOOBsize.X = (AABB.MaxX - AABB.MinX);
1822 primOOBsize.Y = (AABB.MaxY - AABB.MinY);
1823 primOOBsize.Z = (AABB.MaxZ - AABB.MinZ);
1824 if (!hasOOBoffsetFromMesh)
1825 {
1826 primOOBoffset.X = (AABB.MaxX + AABB.MinX) * 0.5f;
1827 primOOBoffset.Y = (AABB.MaxY + AABB.MinY) * 0.5f;
1828 primOOBoffset.Z = (AABB.MaxZ + AABB.MinZ) * 0.5f;
1829 }
1830 }
1831
1832 // also its own inertia and mass
1833 // keep using basic shape mass for now
1834 volume = CalculatePrimVolume();
1835
1836 primMass = m_density * volume;
1837
1838 if (primMass <= 0)
1839 primMass = 0.0001f;//ckrinke: Mass must be greater then zero.
1840 if (primMass > _parent_scene.maximumMassObject)
1841 primMass = _parent_scene.maximumMassObject;
1842
1843 _mass = primMass; // just in case
1844
1845 d.MassSetBoxTotal(out primdMass, primMass, primOOBsize.X, primOOBsize.Y, primOOBsize.Z);
1846
1847 d.MassTranslate(ref primdMass,
1848 primOOBoffset.X,
1849 primOOBoffset.Y,
1850 primOOBoffset.Z);
1851
1852 primOOBsize *= 0.5f; // let obb size be a corner coords
1853 primOOBradiusSQ = primOOBsize.LengthSquared();
1854 }
1855
1856
1857 #endregion
1858
1859
1860 /// <summary>
1861 /// Add a child prim to this parent prim.
1862 /// </summary>
1863 /// <param name="prim">Child prim</param>
1864 // I'm the parent
1865 // prim is the child
1866 public void ParentPrim(OdePrim prim)
1867 {
1868 //Console.WriteLine("ParentPrim " + m_primName);
1869 if (this.m_localID != prim.m_localID)
1870 {
1871 DestroyBody(); // for now we need to rebuil entire object on link change
1872
1873 lock (childrenPrim)
1874 {
1875 // adopt the prim
1876 if (!childrenPrim.Contains(prim))
1877 childrenPrim.Add(prim);
1878
1879 // see if this prim has kids and adopt them also
1880 // should not happen for now
1881 foreach (OdePrim prm in prim.childrenPrim)
1882 {
1883 if (!childrenPrim.Contains(prm))
1884 {
1885 if (prm.Body != IntPtr.Zero)
1886 {
1887 if (prm.prim_geom != IntPtr.Zero)
1888 d.GeomSetBody(prm.prim_geom, IntPtr.Zero);
1889 if(prm.Body != prim.Body)
1890 prm.DestroyBody(); // don't loose bodies around
1891 prm.Body = IntPtr.Zero;
1892 }
1893
1894 childrenPrim.Add(prm);
1895 prm._parent = this;
1896 }
1897 }
1898 }
1899 //Remove old children from the prim
1900 prim.childrenPrim.Clear();
1901
1902 if (prim.Body != IntPtr.Zero)
1903 {
1904 if (prim.prim_geom != IntPtr.Zero)
1905 d.GeomSetBody(prim.prim_geom, IntPtr.Zero);
1906 prim.DestroyBody(); // don't loose bodies around
1907 prim.Body = IntPtr.Zero;
1908 }
1909
1910 prim.childPrim = true;
1911 prim._parent = this;
1912
1913 MakeBody(); // full nasty reconstruction
1914 }
1915 }
1916
1917 private void UpdateChildsfromgeom()
1918 {
1919 if (childrenPrim.Count > 0)
1920 {
1921 foreach (OdePrim prm in childrenPrim)
1922 prm.UpdateDataFromGeom();
1923 }
1924 }
1925
1926 private void UpdateDataFromGeom()
1927 {
1928 if (prim_geom != IntPtr.Zero)
1929 {
1930 d.Vector3 lpos;
1931 d.GeomCopyPosition(prim_geom, out lpos);
1932 _position.X = lpos.X;
1933 _position.Y = lpos.Y;
1934 _position.Z = lpos.Z;
1935 d.Quaternion qtmp = new d.Quaternion { };
1936 d.GeomCopyQuaternion(prim_geom, out qtmp);
1937 _orientation.W = qtmp.W;
1938 _orientation.X = qtmp.X;
1939 _orientation.Y = qtmp.Y;
1940 _orientation.Z = qtmp.Z;
1941 }
1942 }
1943
1944 private void ChildDelink(OdePrim odePrim, bool remakebodies)
1945 {
1946 // Okay, we have a delinked child.. destroy all body and remake
1947 if (odePrim != this && !childrenPrim.Contains(odePrim))
1948 return;
1949
1950 DestroyBody();
1951
1952 if (odePrim == this) // delinking the root prim
1953 {
1954 OdePrim newroot = null;
1955 lock (childrenPrim)
1956 {
1957 if (childrenPrim.Count > 0)
1958 {
1959 newroot = childrenPrim[0];
1960 childrenPrim.RemoveAt(0);
1961 foreach (OdePrim prm in childrenPrim)
1962 {
1963 newroot.childrenPrim.Add(prm);
1964 }
1965 childrenPrim.Clear();
1966 }
1967 if (newroot != null)
1968 {
1969 newroot.childPrim = false;
1970 newroot._parent = null;
1971 if (remakebodies)
1972 newroot.MakeBody();
1973 }
1974 }
1975 }
1976
1977 else
1978 {
1979 lock (childrenPrim)
1980 {
1981 childrenPrim.Remove(odePrim);
1982 odePrim.childPrim = false;
1983 odePrim._parent = null;
1984 // odePrim.UpdateDataFromGeom();
1985 if (remakebodies)
1986 odePrim.MakeBody();
1987 }
1988 }
1989 if (remakebodies)
1990 MakeBody();
1991 }
1992
1993 protected void ChildRemove(OdePrim odePrim, bool reMakeBody)
1994 {
1995 // Okay, we have a delinked child.. destroy all body and remake
1996 if (odePrim != this && !childrenPrim.Contains(odePrim))
1997 return;
1998
1999 DestroyBody();
2000
2001 if (odePrim == this)
2002 {
2003 OdePrim newroot = null;
2004 lock (childrenPrim)
2005 {
2006 if (childrenPrim.Count > 0)
2007 {
2008 newroot = childrenPrim[0];
2009 childrenPrim.RemoveAt(0);
2010 foreach (OdePrim prm in childrenPrim)
2011 {
2012 newroot.childrenPrim.Add(prm);
2013 }
2014 childrenPrim.Clear();
2015 }
2016 if (newroot != null)
2017 {
2018 newroot.childPrim = false;
2019 newroot._parent = null;
2020 newroot.MakeBody();
2021 }
2022 }
2023 if (reMakeBody)
2024 MakeBody();
2025 return;
2026 }
2027 else
2028 {
2029 lock (childrenPrim)
2030 {
2031 childrenPrim.Remove(odePrim);
2032 odePrim.childPrim = false;
2033 odePrim._parent = null;
2034 if (reMakeBody)
2035 odePrim.MakeBody();
2036 }
2037 }
2038 MakeBody();
2039 }
2040
2041 #region changes
2042
2043 private void changeadd()
2044 {
2045 CreateGeom();
2046
2047 if (prim_geom != IntPtr.Zero)
2048 {
2049 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2050 d.Quaternion myrot = new d.Quaternion();
2051 myrot.X = _orientation.X;
2052 myrot.Y = _orientation.Y;
2053 myrot.Z = _orientation.Z;
2054 myrot.W = _orientation.W;
2055 d.GeomSetQuaternion(prim_geom, ref myrot);
2056 // _parent_scene.actor_name_map[prim_geom] = (PhysicsActor)this;
2057 if (!m_isphysical)
2058 SetInStaticSpace(this);
2059 }
2060
2061// m_building = false; // REMOVE THIS LATER
2062
2063
2064 if (m_isphysical && Body == IntPtr.Zero)
2065 {
2066/*
2067 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
2068 {
2069 changeShape(_pbs);
2070 }
2071 else
2072 {
2073 */
2074 MakeBody();
2075// }
2076 }
2077 }
2078
2079 private void changeAngularLock(Vector3 newLock)
2080 {
2081 // do we have a Physical object?
2082 if (Body != IntPtr.Zero)
2083 {
2084 //Check that we have a Parent
2085 //If we have a parent then we're not authorative here
2086 if (_parent == null)
2087 {
2088 if (!newLock.ApproxEquals(Vector3.One, 0f))
2089 {
2090 createAMotor(newLock);
2091 }
2092 else
2093 {
2094 if (Amotor != IntPtr.Zero)
2095 {
2096 d.JointDestroy(Amotor);
2097 Amotor = IntPtr.Zero;
2098 }
2099 }
2100 }
2101 }
2102 // Store this for later in case we get turned into a separate body
2103 m_angularlock = newLock;
2104 }
2105
2106 private void changeLink(OdePrim NewParent)
2107 {
2108 if (_parent == null && NewParent != null)
2109 {
2110 NewParent.ParentPrim(this);
2111 }
2112 else if (_parent != null)
2113 {
2114 if (_parent is OdePrim)
2115 {
2116 if (NewParent != _parent)
2117 {
2118 (_parent as OdePrim).ChildDelink(this,false); // for now...
2119 childPrim = false;
2120
2121 if (NewParent != null)
2122 {
2123 NewParent.ParentPrim(this);
2124 }
2125 }
2126 }
2127 }
2128 _parent = NewParent;
2129 }
2130
2131
2132 private void Stop()
2133 {
2134 if(!childPrim)
2135 {
2136 m_force = Vector3.Zero;
2137 m_forceacc = Vector3.Zero;
2138 m_angularForceacc = Vector3.Zero;
2139 _torque = Vector3.Zero;
2140 _velocity = Vector3.Zero;
2141 _acceleration = Vector3.Zero;
2142 m_rotationalVelocity = Vector3.Zero;
2143 _target_velocity = Vector3.Zero;
2144 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
2145 m_vehicle.Stop();
2146 }
2147
2148 if (Body != IntPtr.Zero)
2149 {
2150 d.BodySetForce(Body, 0f, 0f, 0f);
2151 d.BodySetTorque(Body, 0f, 0f, 0f);
2152 d.BodySetLinearVel(Body, 0f, 0f, 0f);
2153 d.BodySetAngularVel(Body, 0f, 0f, 0f);
2154
2155 }
2156 }
2157
2158 private void changeSelectedStatus(bool newval)
2159 {
2160 m_isSelected = newval;
2161 Stop();
2162
2163 if (newval)
2164 {
2165 m_collisionCategories = CollisionCategories.Selected;
2166 m_collisionFlags = (CollisionCategories.Sensor | CollisionCategories.Space);
2167
2168 if (prim_geom != IntPtr.Zero)
2169 {
2170 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
2171 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
2172 }
2173
2174 disableBodySoft();
2175 }
2176 else
2177 {
2178 m_collisionCategories = CollisionCategories.Geom;
2179
2180 if (m_isphysical)
2181 m_collisionCategories |= CollisionCategories.Body;
2182
2183 m_collisionFlags = m_default_collisionFlags;
2184
2185 if (m_collidesLand)
2186 m_collisionFlags |= CollisionCategories.Land;
2187 if (m_collidesWater)
2188 m_collisionFlags |= CollisionCategories.Water;
2189
2190 if (prim_geom != IntPtr.Zero)
2191 {
2192 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
2193 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
2194 }
2195
2196 enableBodySoft();
2197 }
2198
2199 resetCollisionAccounting();
2200 }
2201
2202 private void changePosition(Vector3 newPos)
2203 {
2204 if (m_isphysical)
2205 {
2206 if (childPrim) // inertia is messed, must rebuild
2207 {
2208 if (m_building)
2209 {
2210 _position = newPos;
2211 }
2212 }
2213 else
2214 {
2215 if (_position != newPos)
2216 {
2217 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2218 _position = newPos;
2219 }
2220 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2221 d.BodyEnable(Body);
2222 }
2223 }
2224 else
2225 {
2226 if (prim_geom != IntPtr.Zero)
2227 {
2228 if (newPos != _position)
2229 {
2230 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2231 _position = newPos;
2232
2233 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, _position, m_targetSpace);
2234 }
2235 }
2236 }
2237 givefakepos--;
2238 if (givefakepos < 0)
2239 givefakepos = 0;
2240// changeSelectedStatus();
2241 resetCollisionAccounting();
2242 }
2243
2244 private void changeOrientation(Quaternion newOri)
2245 {
2246 if (m_isphysical)
2247 {
2248 if (childPrim) // inertia is messed, must rebuild
2249 {
2250 if (m_building)
2251 {
2252 _orientation = newOri;
2253 }
2254 }
2255 else
2256 {
2257 if (newOri != _orientation)
2258 {
2259 d.Quaternion myrot = new d.Quaternion();
2260 myrot.X = newOri.X;
2261 myrot.Y = newOri.Y;
2262 myrot.Z = newOri.Z;
2263 myrot.W = newOri.W;
2264 d.GeomSetQuaternion(prim_geom, ref myrot);
2265 _orientation = newOri;
2266 if (Body != IntPtr.Zero && !m_angularlock.ApproxEquals(Vector3.One, 0f))
2267 createAMotor(m_angularlock);
2268 }
2269 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2270 d.BodyEnable(Body);
2271 }
2272 }
2273 else
2274 {
2275 if (prim_geom != IntPtr.Zero)
2276 {
2277 if (newOri != _orientation)
2278 {
2279 d.Quaternion myrot = new d.Quaternion();
2280 myrot.X = newOri.X;
2281 myrot.Y = newOri.Y;
2282 myrot.Z = newOri.Z;
2283 myrot.W = newOri.W;
2284 d.GeomSetQuaternion(prim_geom, ref myrot);
2285 _orientation = newOri;
2286 }
2287 }
2288 }
2289 givefakeori--;
2290 if (givefakeori < 0)
2291 givefakeori = 0;
2292 resetCollisionAccounting();
2293 }
2294
2295 private void changePositionAndOrientation(Vector3 newPos, Quaternion newOri)
2296 {
2297 if (m_isphysical)
2298 {
2299 if (childPrim && m_building) // inertia is messed, must rebuild
2300 {
2301 _position = newPos;
2302 _orientation = newOri;
2303 }
2304 else
2305 {
2306 if (newOri != _orientation)
2307 {
2308 d.Quaternion myrot = new d.Quaternion();
2309 myrot.X = newOri.X;
2310 myrot.Y = newOri.Y;
2311 myrot.Z = newOri.Z;
2312 myrot.W = newOri.W;
2313 d.GeomSetQuaternion(prim_geom, ref myrot);
2314 _orientation = newOri;
2315 if (Body != IntPtr.Zero && !m_angularlock.ApproxEquals(Vector3.One, 0f))
2316 createAMotor(m_angularlock);
2317 }
2318 if (_position != newPos)
2319 {
2320 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2321 _position = newPos;
2322 }
2323 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2324 d.BodyEnable(Body);
2325 }
2326 }
2327 else
2328 {
2329 // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
2330 // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
2331
2332 if (prim_geom != IntPtr.Zero)
2333 {
2334 if (newOri != _orientation)
2335 {
2336 d.Quaternion myrot = new d.Quaternion();
2337 myrot.X = newOri.X;
2338 myrot.Y = newOri.Y;
2339 myrot.Z = newOri.Z;
2340 myrot.W = newOri.W;
2341 d.GeomSetQuaternion(prim_geom, ref myrot);
2342 _orientation = newOri;
2343 }
2344
2345 if (newPos != _position)
2346 {
2347 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2348 _position = newPos;
2349
2350 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, _position, m_targetSpace);
2351 }
2352 }
2353 }
2354 givefakepos--;
2355 if (givefakepos < 0)
2356 givefakepos = 0;
2357 givefakeori--;
2358 if (givefakeori < 0)
2359 givefakeori = 0;
2360
2361 resetCollisionAccounting();
2362 }
2363
2364
2365 private void changeDisable(bool disable)
2366 {
2367 if (disable)
2368 {
2369 if (!m_disabled)
2370 disableBodySoft();
2371 }
2372 else
2373 {
2374 if (m_disabled)
2375 enableBodySoft();
2376 }
2377 }
2378
2379 private void changePhysicsStatus(bool NewStatus)
2380 {
2381 m_isphysical = NewStatus;
2382
2383 if (!childPrim)
2384 {
2385 if (NewStatus)
2386 {
2387 if (Body == IntPtr.Zero)
2388 {
2389/*
2390 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
2391 {
2392 changeShape(_pbs);
2393 }
2394 else
2395 */
2396 {
2397 MakeBody();
2398 }
2399 }
2400 }
2401 else
2402 {
2403 if (Body != IntPtr.Zero)
2404 {
2405 // UpdateChildsfromgeom();
2406/* if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
2407 {
2408 changeShape(_pbs);
2409 }
2410 else
2411 */
2412 DestroyBody();
2413 }
2414 }
2415 }
2416
2417 resetCollisionAccounting();
2418 }
2419
2420 private void changeprimsizeshape()
2421 {
2422 OdePrim parent = (OdePrim)_parent;
2423
2424 bool chp = childPrim;
2425
2426 if (chp)
2427 {
2428 if (parent != null)
2429 {
2430 parent.DestroyBody();
2431 }
2432 }
2433 else
2434 {
2435 DestroyBody();
2436 }
2437
2438 RemoveGeom();
2439
2440 // we don't need to do space calculation because the client sends a position update also.
2441 if (_size.X <= 0)
2442 _size.X = 0.01f;
2443 if (_size.Y <= 0)
2444 _size.Y = 0.01f;
2445 if (_size.Z <= 0)
2446 _size.Z = 0.01f;
2447 // Construction of new prim
2448
2449 CreateGeom();
2450
2451 if (prim_geom != IntPtr.Zero)
2452 {
2453 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2454 d.Quaternion myrot = new d.Quaternion();
2455 myrot.X = _orientation.X;
2456 myrot.Y = _orientation.Y;
2457 myrot.Z = _orientation.Z;
2458 myrot.W = _orientation.W;
2459 d.GeomSetQuaternion(prim_geom, ref myrot);
2460 }
2461
2462 if (chp)
2463 {
2464 if (parent != null)
2465 {
2466 parent.MakeBody();
2467 }
2468 }
2469 else
2470 MakeBody();
2471
2472 resetCollisionAccounting();
2473 }
2474
2475 private void changeSize(Vector3 newSize)
2476 {
2477 _size = newSize;
2478 changeprimsizeshape();
2479 }
2480
2481 private void changeShape(PrimitiveBaseShape newShape)
2482 {
2483 _pbs = newShape;
2484 changeprimsizeshape();
2485 }
2486
2487 private void changeFloatOnWater(bool newval)
2488 {
2489 m_collidesWater = newval;
2490
2491 if (prim_geom != IntPtr.Zero)
2492 {
2493 if (m_collidesWater)
2494 {
2495 m_collisionFlags |= CollisionCategories.Water;
2496 }
2497 else
2498 {
2499 m_collisionFlags &= ~CollisionCategories.Water;
2500 }
2501 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
2502 }
2503 }
2504
2505 private void changeSetTorque(Vector3 newtorque)
2506 {
2507 if (!m_isSelected)
2508 {
2509 if (m_isphysical && Body != IntPtr.Zero)
2510 {
2511 if (m_disabled)
2512 enableBodySoft();
2513 else if (!d.BodyIsEnabled(Body))
2514 d.BodyEnable(Body);
2515
2516 }
2517 _torque = newtorque;
2518 }
2519 }
2520
2521 private void changeForce(Vector3 force)
2522 {
2523 m_force = force;
2524 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2525 d.BodyEnable(Body);
2526 }
2527
2528 private void changeAddForce(Vector3 force)
2529 {
2530 m_forceacc += force;
2531 if (!m_isSelected)
2532 {
2533 lock (this)
2534 {
2535 //m_log.Info("[PHYSICS]: dequeing forcelist");
2536 if (m_isphysical && Body != IntPtr.Zero)
2537 {
2538 if (m_disabled)
2539 enableBodySoft();
2540 else if (!d.BodyIsEnabled(Body))
2541 d.BodyEnable(Body);
2542 }
2543 }
2544
2545 m_collisionscore = 0;
2546 m_interpenetrationcount = 0;
2547 }
2548 }
2549
2550 private void changeAddAngularForce(Vector3 aforce)
2551 {
2552 m_angularForceacc += aforce;
2553 if (!m_isSelected)
2554 {
2555 lock (this)
2556 {
2557 if (m_isphysical && Body != IntPtr.Zero)
2558 {
2559 if (m_disabled)
2560 enableBodySoft();
2561 else if (!d.BodyIsEnabled(Body))
2562 d.BodyEnable(Body);
2563 }
2564 }
2565 m_collisionscore = 0;
2566 m_interpenetrationcount = 0;
2567 }
2568 }
2569
2570 private void changevelocity(Vector3 newVel)
2571 {
2572 if (!m_isSelected)
2573 {
2574 if (Body != IntPtr.Zero)
2575 {
2576 if (m_disabled)
2577 enableBodySoft();
2578 else if (!d.BodyIsEnabled(Body))
2579 d.BodyEnable(Body);
2580
2581 d.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z);
2582 }
2583 //resetCollisionAccounting();
2584 }
2585 _velocity = newVel;
2586 }
2587
2588 private void changeVolumedetetion(bool newVolDtc)
2589 {
2590 m_isVolumeDetect = newVolDtc;
2591 }
2592
2593 protected void changeBuilding(bool newbuilding)
2594 {
2595 if ((bool)newbuilding)
2596 {
2597 m_building = true;
2598 DestroyBody();
2599 }
2600 else
2601 {
2602 m_building = false;
2603 if (!childPrim)
2604 MakeBody();
2605 }
2606 if (!childPrim && childrenPrim.Count > 0)
2607 {
2608 foreach (OdePrim prm in childrenPrim)
2609 prm.changeBuilding(m_building); // call directly
2610 }
2611 }
2612
2613 #endregion
2614
2615 public void Move()
2616 {
2617 if (!childPrim && m_isphysical && Body != IntPtr.Zero &&
2618 !m_disabled && !m_isSelected && d.BodyIsEnabled(Body) && !m_building) // KF: Only move root prims.
2619 {
2620// if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body); // KF add 161009
2621
2622 float timestep = _parent_scene.ODE_STEPSIZE;
2623
2624 float fx = 0;
2625 float fy = 0;
2626 float fz = 0;
2627
2628 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
2629 {
2630 // 'VEHICLES' are dealt with in ODEDynamics.cs
2631 m_vehicle.Step();
2632 }
2633 else
2634 {
2635 float m_mass = _mass;
2636
2637 // fz = 0f;
2638 //m_log.Info(m_collisionFlags.ToString());
2639 if (m_usePID)
2640 {
2641
2642 // If the PID Controller isn't active then we set our force
2643 // calculating base velocity to the current position
2644
2645 if ((m_PIDTau < 1) && (m_PIDTau != 0))
2646 {
2647 //PID_G = PID_G / m_PIDTau;
2648 m_PIDTau = 1;
2649 }
2650
2651 if ((PID_G - m_PIDTau) <= 0)
2652 {
2653 PID_G = m_PIDTau + 1;
2654 }
2655
2656 d.Vector3 vel = d.BodyGetLinearVel(Body);
2657 d.Vector3 pos = d.BodyGetPosition(Body);
2658 _target_velocity =
2659 new Vector3(
2660 (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep),
2661 (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep),
2662 (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep)
2663 );
2664
2665 // if velocity is zero, use position control; otherwise, velocity control
2666
2667 if (_target_velocity.ApproxEquals(Vector3.Zero, 0.1f))
2668 {
2669 // keep track of where we stopped. No more slippin' & slidin'
2670
2671 // We only want to deactivate the PID Controller if we think we want to have our surrogate
2672 // react to the physics scene by moving it's position.
2673 // Avatar to Avatar collisions
2674 // Prim to avatar collisions
2675
2676 //fx = (_target_velocity.X - vel.X) * (PID_D) + (_zeroPosition.X - pos.X) * (PID_P * 2);
2677 //fy = (_target_velocity.Y - vel.Y) * (PID_D) + (_zeroPosition.Y - pos.Y) * (PID_P * 2);
2678 //fz = fz + (_target_velocity.Z - vel.Z) * (PID_D) + (_zeroPosition.Z - pos.Z) * PID_P;
2679 d.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z);
2680 d.BodySetLinearVel(Body, 0, 0, 0);
2681 d.BodyAddForce(Body, 0, 0, fz);
2682 return;
2683 }
2684 else
2685 {
2686 _zeroFlag = false;
2687
2688 // We're flying and colliding with something
2689 fx = ((_target_velocity.X) - vel.X) * (PID_D);
2690 fy = ((_target_velocity.Y) - vel.Y) * (PID_D);
2691
2692 // vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P;
2693
2694 fz = ((_target_velocity.Z - vel.Z) * (PID_D));
2695 }
2696 } // end if (m_usePID)
2697
2698 // Hover PID Controller needs to be mutually exlusive to MoveTo PID controller
2699 else if (m_useHoverPID)
2700 {
2701 //Console.WriteLine("Hover " + Name);
2702
2703 // If we're using the PID controller, then we have no gravity
2704
2705 // no lock; for now it's only called from within Simulate()
2706
2707 // If the PID Controller isn't active then we set our force
2708 // calculating base velocity to the current position
2709
2710 if ((m_PIDTau < 1))
2711 {
2712 PID_G = PID_G / m_PIDTau;
2713 }
2714
2715 if ((PID_G - m_PIDTau) <= 0)
2716 {
2717 PID_G = m_PIDTau + 1;
2718 }
2719
2720 // Where are we, and where are we headed?
2721 d.Vector3 pos = d.BodyGetPosition(Body);
2722 d.Vector3 vel = d.BodyGetLinearVel(Body);
2723
2724 // Non-Vehicles have a limited set of Hover options.
2725 // determine what our target height really is based on HoverType
2726 switch (m_PIDHoverType)
2727 {
2728 case PIDHoverType.Ground:
2729 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y);
2730 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
2731 break;
2732 case PIDHoverType.GroundAndWater:
2733 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y);
2734 m_waterHeight = _parent_scene.GetWaterLevel();
2735 if (m_groundHeight > m_waterHeight)
2736 {
2737 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
2738 }
2739 else
2740 {
2741 m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight;
2742 }
2743 break;
2744
2745 } // end switch (m_PIDHoverType)
2746
2747
2748 _target_velocity =
2749 new Vector3(0.0f, 0.0f,
2750 (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep)
2751 );
2752
2753 // if velocity is zero, use position control; otherwise, velocity control
2754
2755 if (_target_velocity.ApproxEquals(Vector3.Zero, 0.1f))
2756 {
2757 // keep track of where we stopped. No more slippin' & slidin'
2758
2759 // We only want to deactivate the PID Controller if we think we want to have our surrogate
2760 // react to the physics scene by moving it's position.
2761 // Avatar to Avatar collisions
2762 // Prim to avatar collisions
2763
2764 d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight);
2765 d.BodySetLinearVel(Body, vel.X, vel.Y, 0);
2766 // ? d.BodyAddForce(Body, 0, 0, fz);
2767 return;
2768 }
2769 else
2770 {
2771 _zeroFlag = false;
2772
2773 // We're flying and colliding with something
2774 fz = ((_target_velocity.Z - vel.Z) * (PID_D));
2775 }
2776 }
2777 else
2778 {
2779 float b = (1.0f - m_buoyancy);
2780 fx = _parent_scene.gravityx * b;
2781 fy = _parent_scene.gravityy * b;
2782 fz = _parent_scene.gravityz * b;
2783 }
2784
2785 fx *= m_mass;
2786 fy *= m_mass;
2787 fz *= m_mass;
2788
2789 // constant force
2790 fx += m_force.X;
2791 fy += m_force.Y;
2792 fz += m_force.Z;
2793
2794 fx += m_forceacc.X;
2795 fy += m_forceacc.Y;
2796 fz += m_forceacc.Z;
2797
2798 m_forceacc = Vector3.Zero;
2799
2800 //m_log.Info("[OBJPID]: X:" + fx.ToString() + " Y:" + fy.ToString() + " Z:" + fz.ToString());
2801 if (fx != 0 || fy != 0 || fz != 0)
2802 {
2803 d.BodyAddForce(Body, fx, fy, fz);
2804 //Console.WriteLine("AddForce " + fx + "," + fy + "," + fz);
2805 }
2806
2807 Vector3 trq;
2808
2809 trq = _torque;
2810 trq += m_angularForceacc;
2811 m_angularForceacc = Vector3.Zero;
2812 if (trq.X != 0 || trq.Y != 0 || trq.Z != 0)
2813 {
2814 d.BodyAddTorque(Body, trq.X, trq.Y, trq.Z);
2815 }
2816
2817 }
2818 }
2819 else
2820 { // is not physical, or is not a body or is selected
2821 // _zeroPosition = d.BodyGetPosition(Body);
2822 return;
2823 //Console.WriteLine("Nothing " + Name);
2824
2825 }
2826 }
2827
2828
2829 public void UpdatePositionAndVelocity(float simulatedtime)
2830 {
2831 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
2832 if (_parent == null && !m_disabled && !m_building)
2833 {
2834 if (Body != IntPtr.Zero)
2835 {
2836 if (m_crossingfailures != 0 && m_crossingfailures < 5)
2837 {
2838 _position.X = Util.Clip(_position.X, 0.4f, _parent_scene.WorldExtents.X - 0.4f);
2839 _position.Y = Util.Clip(_position.Y, 0.4f, _parent_scene.WorldExtents.Y - 0.4f);
2840 _position.Z = Util.Clip(_position.Z + 0.2f, -100f, 50000f);
2841
2842 float tmp = _parent_scene.GetTerrainHeightAtXY(_position.X, _position.Y);
2843 if (_position.Z < tmp)
2844 _position.Z = tmp + 0.2f;
2845
2846 m_lastposition = _position;
2847 m_lastorientation = _orientation;
2848 _velocity.X = 0;
2849 _velocity.Y = 0;
2850 _velocity.Z = 0;
2851
2852 m_lastVelocity = _velocity;
2853 m_rotationalVelocity = _velocity;
2854 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
2855 m_vehicle.Stop();
2856
2857 m_crossingfailures = 0; // do this only once
2858 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
2859 d.BodySetAngularVel(Body, 0, 0, 0);
2860 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2861 enableBodySoft();
2862 base.RequestPhysicsterseUpdate();
2863 return;
2864 }
2865
2866 else if (m_crossingfailures != 0)
2867 {
2868 return;
2869 }
2870
2871 Vector3 pv = Vector3.Zero;
2872 bool lastZeroFlag = _zeroFlag;
2873
2874 d.Vector3 lpos;
2875 d.GeomCopyPosition(prim_geom,out lpos); // root position that is seem by rest of simulator
2876
2877 // we need to use root position since that's all the rest of scene uses
2878 if ( lpos.X < 0f || lpos.X > _parent_scene.WorldExtents.X
2879 || lpos.Y < 0f || lpos.Y > _parent_scene.WorldExtents.Y
2880 )
2881 {
2882 // we are outside current region
2883 // we can't let it keeping moving and having colisions
2884 // since it can be stucked between something like terrain and edge
2885 // so lets stop and disable it until something else kicks it
2886 if (m_crossingfailures == 0)
2887 {
2888
2889 _position.X = Util.Clip(lpos.X, -0.5f, _parent_scene.WorldExtents.X + 0.5f);
2890 _position.Y = Util.Clip(lpos.Y, -0.5f, _parent_scene.WorldExtents.Y + 0.5f);
2891 _position.Z = Util.Clip(lpos.Z, -100f, 50000f);
2892
2893 m_lastposition = _position;
2894 m_lastorientation = _orientation;
2895
2896 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
2897 d.BodySetAngularVel(Body, 0, 0, 0);
2898 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2899 disableBodySoft(); // stop collisions
2900 m_crossingfailures++; // do this only once
2901 base.RequestPhysicsterseUpdate();
2902 return;
2903 }
2904 }
2905
2906 if (lpos.Z < -100 || lpos.Z > 100000f)
2907 {
2908 lpos.Z = Util.Clip(lpos.Z, -100f, 50000f);
2909
2910 _acceleration.X = 0;
2911 _acceleration.Y = 0;
2912 _acceleration.Z = 0;
2913
2914 _velocity.X = 0;
2915 _velocity.Y = 0;
2916 _velocity.Z = 0;
2917 m_rotationalVelocity.X = 0;
2918 m_rotationalVelocity.Y = 0;
2919 m_rotationalVelocity.Z = 0;
2920
2921 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
2922 d.BodySetAngularVel(Body, 0, 0, 0); // stop it
2923 d.BodySetPosition(Body, lpos.X, lpos.Y, lpos.Z); // put it somewhere
2924 m_lastposition = _position;
2925 m_lastorientation = _orientation;
2926
2927 base.RequestPhysicsterseUpdate();
2928
2929 m_throttleUpdates = false;
2930 throttleCounter = 0;
2931 _zeroFlag = true;
2932
2933 disableBodySoft(); // disable it and colisions
2934 base.RaiseOutOfBounds(_position);
2935
2936 return;
2937 }
2938
2939 d.Quaternion ori;
2940 d.GeomCopyQuaternion(prim_geom, out ori);
2941 d.Vector3 vel = d.BodyGetLinearVel(Body);
2942 d.Vector3 rotvel = d.BodyGetAngularVel(Body);
2943
2944 if ((Math.Abs(m_lastposition.X - lpos.X) < 0.01)
2945 && (Math.Abs(m_lastposition.Y - lpos.Y) < 0.01)
2946 && (Math.Abs(m_lastposition.Z - lpos.Z) < 0.01)
2947 && (Math.Abs(m_lastorientation.X - ori.X) < 0.0001)
2948 && (Math.Abs(m_lastorientation.Y - ori.Y) < 0.0001)
2949 && (Math.Abs(m_lastorientation.Z - ori.Z) < 0.0001)
2950 )
2951 {
2952 _zeroFlag = true;
2953 //Console.WriteLine("ZFT 2");
2954 m_throttleUpdates = false;
2955 }
2956 else
2957 {
2958 //m_log.Debug(Math.Abs(m_lastposition.X - l_position.X).ToString());
2959 _zeroFlag = false;
2960 m_lastUpdateSent = false;
2961 //m_throttleUpdates = false;
2962 }
2963
2964 if (_zeroFlag)
2965 {
2966 m_lastposition = _position;
2967 m_lastorientation = _orientation;
2968
2969 _velocity.X = 0.0f;
2970 _velocity.Y = 0.0f;
2971 _velocity.Z = 0.0f;
2972
2973 _acceleration.X = 0;
2974 _acceleration.Y = 0;
2975 _acceleration.Z = 0;
2976
2977 m_rotationalVelocity.X = 0;
2978 m_rotationalVelocity.Y = 0;
2979 m_rotationalVelocity.Z = 0;
2980 if (!m_lastUpdateSent)
2981 {
2982 m_throttleUpdates = false;
2983 throttleCounter = 0;
2984 m_rotationalVelocity = pv;
2985
2986 base.RequestPhysicsterseUpdate();
2987
2988 m_lastUpdateSent = true;
2989 }
2990 }
2991 else
2992 {
2993 if (lastZeroFlag != _zeroFlag)
2994 {
2995 base.RequestPhysicsterseUpdate();
2996 }
2997
2998 m_lastVelocity = _velocity;
2999
3000 _position.X = lpos.X;
3001 _position.Y = lpos.Y;
3002 _position.Z = lpos.Z;
3003
3004 _velocity.X = vel.X;
3005 _velocity.Y = vel.Y;
3006 _velocity.Z = vel.Z;
3007
3008 _orientation.X = ori.X;
3009 _orientation.Y = ori.Y;
3010 _orientation.Z = ori.Z;
3011 _orientation.W = ori.W;
3012
3013 _acceleration = ((_velocity - m_lastVelocity) / simulatedtime);
3014
3015 if (m_rotationalVelocity.ApproxEquals(pv, 0.0001f))
3016 {
3017 m_rotationalVelocity = pv;
3018 }
3019 else
3020 {
3021 m_rotationalVelocity.X = rotvel.X;
3022 m_rotationalVelocity.Y = rotvel.Y;
3023 m_rotationalVelocity.Z = rotvel.Z;
3024 }
3025
3026 m_lastUpdateSent = false;
3027 if (!m_throttleUpdates || throttleCounter > _parent_scene.geomUpdatesPerThrottledUpdate)
3028 {
3029 m_lastposition = _position;
3030 m_lastorientation = _orientation;
3031 base.RequestPhysicsterseUpdate();
3032 }
3033 else
3034 {
3035 throttleCounter++;
3036 }
3037 }
3038 }
3039 else if (!m_lastUpdateSent || !_zeroFlag)
3040 {
3041 // Not a body.. so Make sure the client isn't interpolating
3042 _velocity.X = 0;
3043 _velocity.Y = 0;
3044 _velocity.Z = 0;
3045
3046 _acceleration.X = 0;
3047 _acceleration.Y = 0;
3048 _acceleration.Z = 0;
3049
3050 m_rotationalVelocity.X = 0;
3051 m_rotationalVelocity.Y = 0;
3052 m_rotationalVelocity.Z = 0;
3053 _zeroFlag = true;
3054
3055 if (!m_lastUpdateSent)
3056 {
3057 m_throttleUpdates = false;
3058 throttleCounter = 0;
3059
3060 base.RequestPhysicsterseUpdate();
3061
3062 m_lastUpdateSent = true;
3063 }
3064 }
3065 }
3066 }
3067
3068 internal static bool QuaternionIsFinite(Quaternion q)
3069 {
3070 if (Single.IsNaN(q.X) || Single.IsInfinity(q.X))
3071 return false;
3072 if (Single.IsNaN(q.Y) || Single.IsInfinity(q.Y))
3073 return false;
3074 if (Single.IsNaN(q.Z) || Single.IsInfinity(q.Z))
3075 return false;
3076 if (Single.IsNaN(q.W) || Single.IsInfinity(q.W))
3077 return false;
3078 return true;
3079 }
3080
3081 internal static void DMassCopy(ref d.Mass src, ref d.Mass dst)
3082 {
3083 dst.c.W = src.c.W;
3084 dst.c.X = src.c.X;
3085 dst.c.Y = src.c.Y;
3086 dst.c.Z = src.c.Z;
3087 dst.mass = src.mass;
3088 dst.I.M00 = src.I.M00;
3089 dst.I.M01 = src.I.M01;
3090 dst.I.M02 = src.I.M02;
3091 dst.I.M10 = src.I.M10;
3092 dst.I.M11 = src.I.M11;
3093 dst.I.M12 = src.I.M12;
3094 dst.I.M20 = src.I.M20;
3095 dst.I.M21 = src.I.M21;
3096 dst.I.M22 = src.I.M22;
3097 }
3098
3099 private static void DMassDup(ref d.Mass src, out d.Mass dst)
3100 {
3101 dst = new d.Mass { };
3102
3103 dst.c.W = src.c.W;
3104 dst.c.X = src.c.X;
3105 dst.c.Y = src.c.Y;
3106 dst.c.Z = src.c.Z;
3107 dst.mass = src.mass;
3108 dst.I.M00 = src.I.M00;
3109 dst.I.M01 = src.I.M01;
3110 dst.I.M02 = src.I.M02;
3111 dst.I.M10 = src.I.M10;
3112 dst.I.M11 = src.I.M11;
3113 dst.I.M12 = src.I.M12;
3114 dst.I.M20 = src.I.M20;
3115 dst.I.M21 = src.I.M21;
3116 dst.I.M22 = src.I.M22;
3117 }
3118 private void donullchange()
3119 {
3120 }
3121
3122 public bool DoAChange(changes what, object arg)
3123 {
3124 if (prim_geom == IntPtr.Zero && what != changes.Add && what != changes.Remove)
3125 {
3126 return false;
3127 }
3128
3129 // nasty switch
3130 switch (what)
3131 {
3132 case changes.Add:
3133 changeadd();
3134 break;
3135 case changes.Remove:
3136 //If its being removed, we don't want to rebuild the physical rep at all, so ignore this stuff...
3137 //When we return true, it destroys all of the prims in the linkset anyway
3138 if (_parent != null)
3139 {
3140 OdePrim parent = (OdePrim)_parent;
3141 parent.ChildRemove(this,false);
3142 }
3143 else
3144 ChildRemove(this,false);
3145
3146 RemoveGeom();
3147 m_targetSpace = IntPtr.Zero;
3148 if (m_eventsubscription > 0)
3149 UnSubscribeEvents();
3150 return true;
3151
3152 case changes.Link:
3153 OdePrim tmp = (OdePrim)arg;
3154 changeLink(tmp);
3155 break;
3156
3157 case changes.DeLink:
3158 changeLink(null);
3159 break;
3160
3161 case changes.Position:
3162 changePosition((Vector3)arg);
3163 break;
3164
3165 case changes.Orientation:
3166 changeOrientation((Quaternion)arg);
3167 break;
3168
3169 case changes.PosOffset:
3170 donullchange();
3171 break;
3172
3173 case changes.OriOffset:
3174 donullchange();
3175 break;
3176
3177 case changes.Velocity:
3178 changevelocity((Vector3)arg);
3179 break;
3180
3181// case changes.Acceleration:
3182// changeacceleration((Vector3)arg);
3183// break;
3184// case changes.AngVelocity:
3185// changeangvelocity((Vector3)arg);
3186// break;
3187
3188 case changes.Force:
3189 changeForce((Vector3)arg);
3190 break;
3191
3192 case changes.Torque:
3193 changeSetTorque((Vector3)arg);
3194 break;
3195
3196 case changes.AddForce:
3197 changeAddForce((Vector3)arg);
3198 break;
3199
3200 case changes.AddAngForce:
3201 changeAddAngularForce((Vector3)arg);
3202 break;
3203
3204 case changes.AngLock:
3205 changeAngularLock((Vector3)arg);
3206 break;
3207
3208 case changes.Size:
3209 changeSize((Vector3)arg);
3210 break;
3211
3212 case changes.Shape:
3213 changeShape((PrimitiveBaseShape) arg);
3214 break;
3215
3216 case changes.CollidesWater:
3217 changeFloatOnWater((bool)arg);
3218 break;
3219
3220 case changes.VolumeDtc:
3221 changeVolumedetetion((bool)arg);
3222 break;
3223
3224 case changes.Physical:
3225 changePhysicsStatus((bool)arg);
3226 break;
3227
3228 case changes.Selected:
3229 changeSelectedStatus((bool)arg);
3230 break;
3231
3232 case changes.disabled:
3233 changeDisable((bool) arg);
3234 break;
3235
3236 case changes.building:
3237 changeBuilding((bool)arg);
3238 break;
3239
3240 case changes.Null:
3241 donullchange();
3242 break;
3243
3244 default:
3245 donullchange();
3246 break;
3247 }
3248 return false;
3249 }
3250
3251 public void AddChange(changes what, object arg)
3252 {
3253 _parent_scene.AddChange(this, what, arg);
3254 }
3255 }
3256}
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..2b6bc59
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs
@@ -0,0 +1,1960 @@
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 public static int NTotalGeoms = 0;
63
64 #region Flags and Enumerations
65
66 [Flags]
67 public enum AllocateODEDataFlags : uint
68 {
69 BasicData = 0,
70 CollisionData = 0x00000001,
71 All = ~0u
72 }
73
74 [Flags]
75 public enum IniteODEFlags : uint
76 {
77 dInitFlagManualThreadCleanup = 0x00000001
78 }
79
80 [Flags]
81 public enum ContactFlags : int
82 {
83 Mu2 = 0x001,
84 FDir1 = 0x002,
85 Bounce = 0x004,
86 SoftERP = 0x008,
87 SoftCFM = 0x010,
88 Motion1 = 0x020,
89 Motion2 = 0x040,
90 MotionN = 0x080,
91 Slip1 = 0x100,
92 Slip2 = 0x200,
93 Approx0 = 0x0000,
94 Approx1_1 = 0x1000,
95 Approx1_2 = 0x2000,
96 Approx1 = 0x3000
97 }
98
99 public enum GeomClassID : int
100 {
101 SphereClass,
102 BoxClass,
103 CapsuleClass,
104 CylinderClass,
105 PlaneClass,
106 RayClass,
107 ConvexClass,
108 GeomTransformClass,
109 TriMeshClass,
110 HeightfieldClass,
111 FirstSpaceClass,
112 SimpleSpaceClass = FirstSpaceClass,
113 HashSpaceClass,
114 QuadTreeSpaceClass,
115 LastSpaceClass = QuadTreeSpaceClass,
116 FirstUserClass,
117 LastUserClass = FirstUserClass + MaxUserClasses - 1,
118 NumClasses,
119 MaxUserClasses = 4
120 }
121
122 public enum JointType : int
123 {
124 None,
125 Ball,
126 Hinge,
127 Slider,
128 Contact,
129 Universal,
130 Hinge2,
131 Fixed,
132 Null,
133 AMotor,
134 LMotor,
135 Plane2D
136 }
137
138 public enum JointParam : int
139 {
140 LoStop,
141 HiStop,
142 Vel,
143 FMax,
144 FudgeFactor,
145 Bounce,
146 CFM,
147 StopERP,
148 StopCFM,
149 SuspensionERP,
150 SuspensionCFM,
151 LoStop2 = 256,
152 HiStop2,
153 Vel2,
154 FMax2,
155 FudgeFactor2,
156 Bounce2,
157 CFM2,
158 StopERP2,
159 StopCFM2,
160 SuspensionERP2,
161 SuspensionCFM2,
162 LoStop3 = 512,
163 HiStop3,
164 Vel3,
165 FMax3,
166 FudgeFactor3,
167 Bounce3,
168 CFM3,
169 StopERP3,
170 StopCFM3,
171 SuspensionERP3,
172 SuspensionCFM3
173 }
174
175 public enum dSweepAndPruneAxis : int
176 {
177 XYZ = ((0)|(1<<2)|(2<<4)),
178 XZY = ((0)|(2<<2)|(1<<4)),
179 YXZ = ((1)|(0<<2)|(2<<4)),
180 YZX = ((1)|(2<<2)|(0<<4)),
181 ZXY = ((2)|(0<<2)|(1<<4)),
182 ZYX = ((2)|(1<<2)|(0<<4))
183 }
184
185 #endregion
186
187 #region Callbacks
188
189 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
190 public delegate int AABBTestFn(IntPtr o1, IntPtr o2, ref AABB aabb);
191
192 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
193 public delegate int ColliderFn(IntPtr o1, IntPtr o2, int flags, out ContactGeom contact, int skip);
194
195 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
196 public delegate void GetAABBFn(IntPtr geom, out AABB aabb);
197
198 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
199 public delegate ColliderFn GetColliderFnFn(int num);
200
201 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
202 public delegate void GeomDtorFn(IntPtr o);
203
204 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
205 public delegate dReal HeightfieldGetHeight(IntPtr p_user_data, int x, int z);
206
207 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
208 public delegate void NearCallback(IntPtr data, IntPtr geom1, IntPtr geom2);
209
210 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
211 public delegate int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex);
212
213 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
214 public delegate int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount);
215
216 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
217 public delegate int TriRayCallback(IntPtr trimesh, IntPtr ray, int triangleIndex, dReal u, dReal v);
218
219 #endregion
220
221 #region Structs
222
223 [StructLayout(LayoutKind.Sequential)]
224 public struct AABB
225 {
226 public dReal MinX, MaxX;
227 public dReal MinY, MaxY;
228 public dReal MinZ, MaxZ;
229 }
230
231
232 [StructLayout(LayoutKind.Sequential)]
233 public struct Contact
234 {
235 public SurfaceParameters surface;
236 public ContactGeom geom;
237 public Vector3 fdir1;
238 public static readonly int unmanagedSizeOf = Marshal.SizeOf(typeof(Contact));
239 }
240
241
242 [StructLayout(LayoutKind.Sequential)]
243 public struct ContactGeom
244 {
245
246 public Vector3 pos;
247 public Vector3 normal;
248 public dReal depth;
249 public IntPtr g1;
250 public IntPtr g2;
251 public int side1;
252 public int side2;
253 public static readonly int unmanagedSizeOf = Marshal.SizeOf(typeof(ContactGeom));
254 }
255
256 [StructLayout(LayoutKind.Sequential)]
257 public struct GeomClass
258 {
259 public int bytes;
260 public GetColliderFnFn collider;
261 public GetAABBFn aabb;
262 public AABBTestFn aabb_test;
263 public GeomDtorFn dtor;
264 }
265
266
267 [StructLayout(LayoutKind.Sequential)]
268 public struct JointFeedback
269 {
270 public Vector3 f1;
271 public Vector3 t1;
272 public Vector3 f2;
273 public Vector3 t2;
274 }
275
276
277 [StructLayout(LayoutKind.Sequential)]
278 public struct Mass
279 {
280 public dReal mass;
281 public Vector4 c;
282 public Matrix3 I;
283 }
284
285
286 [StructLayout(LayoutKind.Sequential)]
287 public struct Matrix3
288 {
289 public Matrix3(dReal m00, dReal m10, dReal m20, dReal m01, dReal m11, dReal m21, dReal m02, dReal m12, dReal m22)
290 {
291 M00 = m00; M10 = m10; M20 = m20; _m30 = 0.0f;
292 M01 = m01; M11 = m11; M21 = m21; _m31 = 0.0f;
293 M02 = m02; M12 = m12; M22 = m22; _m32 = 0.0f;
294 }
295 public dReal M00, M10, M20;
296 private dReal _m30;
297 public dReal M01, M11, M21;
298 private dReal _m31;
299 public dReal M02, M12, M22;
300 private dReal _m32;
301 }
302
303 [StructLayout(LayoutKind.Sequential)]
304 public struct Matrix4
305 {
306 public Matrix4(dReal m00, dReal m10, dReal m20, dReal m30,
307 dReal m01, dReal m11, dReal m21, dReal m31,
308 dReal m02, dReal m12, dReal m22, dReal m32,
309 dReal m03, dReal m13, dReal m23, dReal m33)
310 {
311 M00 = m00; M10 = m10; M20 = m20; M30 = m30;
312 M01 = m01; M11 = m11; M21 = m21; M31 = m31;
313 M02 = m02; M12 = m12; M22 = m22; M32 = m32;
314 M03 = m03; M13 = m13; M23 = m23; M33 = m33;
315 }
316 public dReal M00, M10, M20, M30;
317 public dReal M01, M11, M21, M31;
318 public dReal M02, M12, M22, M32;
319 public dReal M03, M13, M23, M33;
320 }
321
322 [StructLayout(LayoutKind.Sequential)]
323 public struct Quaternion
324 {
325 public dReal W, X, Y, Z;
326 }
327
328
329 [StructLayout(LayoutKind.Sequential)]
330 public struct SurfaceParameters
331 {
332 public ContactFlags mode;
333 public dReal mu;
334 public dReal mu2;
335 public dReal bounce;
336 public dReal bounce_vel;
337 public dReal soft_erp;
338 public dReal soft_cfm;
339 public dReal motion1;
340 public dReal motion2;
341 public dReal motionN;
342 public dReal slip1;
343 public dReal slip2;
344 }
345
346
347 [StructLayout(LayoutKind.Sequential)]
348 public struct Vector3
349 {
350 public Vector3(dReal x, dReal y, dReal z)
351 {
352 X = x; Y = y; Z = z; _w = 0.0f;
353 }
354 public dReal X, Y, Z;
355 private dReal _w;
356 }
357
358
359 [StructLayout(LayoutKind.Sequential)]
360 public struct Vector4
361 {
362 public Vector4(dReal x, dReal y, dReal z, dReal w)
363 {
364 X = x; Y = y; Z = z; W = w;
365 }
366 public dReal X, Y, Z, W;
367 }
368
369 #endregion
370
371 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dAllocateODEDataForThread"), SuppressUnmanagedCodeSecurity]
372 public static extern int AllocateODEDataForThread(uint ODEInitFlags);
373
374 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dAreConnected"), SuppressUnmanagedCodeSecurity]
375 public static extern bool AreConnected(IntPtr b1, IntPtr b2);
376
377 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dAreConnectedExcluding"), SuppressUnmanagedCodeSecurity]
378 public static extern bool AreConnectedExcluding(IntPtr b1, IntPtr b2, JointType joint_type);
379
380 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddForce"), SuppressUnmanagedCodeSecurity]
381 public static extern void BodyAddForce(IntPtr body, dReal fx, dReal fy, dReal fz);
382
383 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddForceAtPos"), SuppressUnmanagedCodeSecurity]
384 public static extern void BodyAddForceAtPos(IntPtr body, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
385
386 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddForceAtRelPos"), SuppressUnmanagedCodeSecurity]
387 public static extern void BodyAddForceAtRelPos(IntPtr body, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
388
389 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddRelForce"), SuppressUnmanagedCodeSecurity]
390 public static extern void BodyAddRelForce(IntPtr body, dReal fx, dReal fy, dReal fz);
391
392 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddRelForceAtPos"), SuppressUnmanagedCodeSecurity]
393 public static extern void BodyAddRelForceAtPos(IntPtr body, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
394
395 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddRelForceAtRelPos"), SuppressUnmanagedCodeSecurity]
396 public static extern void BodyAddRelForceAtRelPos(IntPtr body, dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz);
397
398 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddRelTorque"), SuppressUnmanagedCodeSecurity]
399 public static extern void BodyAddRelTorque(IntPtr body, dReal fx, dReal fy, dReal fz);
400
401 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyAddTorque"), SuppressUnmanagedCodeSecurity]
402 public static extern void BodyAddTorque(IntPtr body, dReal fx, dReal fy, dReal fz);
403
404 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyPosition"), SuppressUnmanagedCodeSecurity]
405 public static extern void BodyCopyPosition(IntPtr body, out Vector3 pos);
406
407 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyPosition"), SuppressUnmanagedCodeSecurity]
408 public static extern void BodyCopyPosition(IntPtr body, out dReal X);
409
410 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyQuaternion"), SuppressUnmanagedCodeSecurity]
411 public static extern void BodyCopyQuaternion(IntPtr body, out Quaternion quat);
412
413 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyQuaternion"), SuppressUnmanagedCodeSecurity]
414 public static extern void BodyCopyQuaternion(IntPtr body, out dReal X);
415
416 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyRotation"), SuppressUnmanagedCodeSecurity]
417 public static extern void BodyCopyRotation(IntPtr body, out Matrix3 R);
418
419 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCopyRotation"), SuppressUnmanagedCodeSecurity]
420 public static extern void BodyCopyRotation(IntPtr body, out dReal M00);
421
422 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyCreate"), SuppressUnmanagedCodeSecurity]
423 public static extern IntPtr BodyiCreate(IntPtr world);
424 public static IntPtr BodyCreate(IntPtr world)
425 {
426 NTotalBodies++;
427 return BodyiCreate(world);
428 }
429
430 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyDestroy"), SuppressUnmanagedCodeSecurity]
431 public static extern void BodyiDestroy(IntPtr body);
432 public static void BodyDestroy(IntPtr body)
433 {
434 NTotalBodies--;
435 BodyiDestroy(body);
436 }
437
438 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyDisable"), SuppressUnmanagedCodeSecurity]
439 public static extern void BodyDisable(IntPtr body);
440
441 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyEnable"), SuppressUnmanagedCodeSecurity]
442 public static extern void BodyEnable(IntPtr body);
443
444 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableAngularThreshold"), SuppressUnmanagedCodeSecurity]
445 public static extern dReal BodyGetAutoDisableAngularThreshold(IntPtr body);
446
447 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableFlag"), SuppressUnmanagedCodeSecurity]
448 public static extern bool BodyGetAutoDisableFlag(IntPtr body);
449
450 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableDefaults"), SuppressUnmanagedCodeSecurity]
451 public static extern void BodyGetAutoDisableDefaults(IntPtr body);
452
453 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableLinearThreshold"), SuppressUnmanagedCodeSecurity]
454 public static extern dReal BodyGetAutoDisableLinearThreshold(IntPtr body);
455
456 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableSteps"), SuppressUnmanagedCodeSecurity]
457 public static extern int BodyGetAutoDisableSteps(IntPtr body);
458
459 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAutoDisableTime"), SuppressUnmanagedCodeSecurity]
460 public static extern dReal BodyGetAutoDisableTime(IntPtr body);
461
462 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAngularVel"), SuppressUnmanagedCodeSecurity]
463 public extern unsafe static Vector3* BodyGetAngularVelUnsafe(IntPtr body);
464 public static Vector3 BodyGetAngularVel(IntPtr body)
465 {
466 unsafe { return *(BodyGetAngularVelUnsafe(body)); }
467 }
468
469 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetData"), SuppressUnmanagedCodeSecurity]
470 public static extern IntPtr BodyGetData(IntPtr body);
471
472 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetFiniteRotationMode"), SuppressUnmanagedCodeSecurity]
473 public static extern int BodyGetFiniteRotationMode(IntPtr body);
474
475 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetFiniteRotationAxis"), SuppressUnmanagedCodeSecurity]
476 public static extern void BodyGetFiniteRotationAxis(IntPtr body, out Vector3 result);
477
478 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetForce"), SuppressUnmanagedCodeSecurity]
479 public extern unsafe static Vector3* BodyGetForceUnsafe(IntPtr body);
480 public static Vector3 BodyGetForce(IntPtr body)
481 {
482 unsafe { return *(BodyGetForceUnsafe(body)); }
483 }
484
485 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetGravityMode"), SuppressUnmanagedCodeSecurity]
486 public static extern bool BodyGetGravityMode(IntPtr body);
487
488 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetGyroscopicMode"), SuppressUnmanagedCodeSecurity]
489 public static extern int BodyGetGyroscopicMode(IntPtr body);
490
491 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetJoint"), SuppressUnmanagedCodeSecurity]
492 public static extern IntPtr BodyGetJoint(IntPtr body, int index);
493
494 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetLinearVel"), SuppressUnmanagedCodeSecurity]
495 public extern unsafe static Vector3* BodyGetLinearVelUnsafe(IntPtr body);
496 public static Vector3 BodyGetLinearVel(IntPtr body)
497 {
498 unsafe { return *(BodyGetLinearVelUnsafe(body)); }
499 }
500
501 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetMass"), SuppressUnmanagedCodeSecurity]
502 public static extern void BodyGetMass(IntPtr body, out Mass mass);
503
504 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetNumJoints"), SuppressUnmanagedCodeSecurity]
505 public static extern int BodyGetNumJoints(IntPtr body);
506
507 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetPointVel"), SuppressUnmanagedCodeSecurity]
508 public static extern void BodyGetPointVel(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
509
510 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetPosition"), SuppressUnmanagedCodeSecurity]
511 public extern unsafe static Vector3* BodyGetPositionUnsafe(IntPtr body);
512 public static Vector3 BodyGetPosition(IntPtr body)
513 {
514 unsafe { return *(BodyGetPositionUnsafe(body)); }
515 }
516
517 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetPosRelPoint"), SuppressUnmanagedCodeSecurity]
518 public static extern void BodyGetPosRelPoint(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
519
520 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetQuaternion"), SuppressUnmanagedCodeSecurity]
521 public extern unsafe static Quaternion* BodyGetQuaternionUnsafe(IntPtr body);
522 public static Quaternion BodyGetQuaternion(IntPtr body)
523 {
524 unsafe { return *(BodyGetQuaternionUnsafe(body)); }
525 }
526
527 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetRelPointPos"), SuppressUnmanagedCodeSecurity]
528 public static extern void BodyGetRelPointPos(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
529
530 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetRelPointVel"), SuppressUnmanagedCodeSecurity]
531 public static extern void BodyGetRelPointVel(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
532
533 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetRotation"), SuppressUnmanagedCodeSecurity]
534 public extern unsafe static Matrix3* BodyGetRotationUnsafe(IntPtr body);
535 public static Matrix3 BodyGetRotation(IntPtr body)
536 {
537 unsafe { return *(BodyGetRotationUnsafe(body)); }
538 }
539
540 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetTorque"), SuppressUnmanagedCodeSecurity]
541 public extern unsafe static Vector3* BodyGetTorqueUnsafe(IntPtr body);
542 public static Vector3 BodyGetTorque(IntPtr body)
543 {
544 unsafe { return *(BodyGetTorqueUnsafe(body)); }
545 }
546
547 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetWorld"), SuppressUnmanagedCodeSecurity]
548 public static extern IntPtr BodyGetWorld(IntPtr body);
549
550 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetFirstGeom"), SuppressUnmanagedCodeSecurity]
551 public static extern IntPtr BodyGetFirstGeom(IntPtr body);
552
553 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetNextGeom"), SuppressUnmanagedCodeSecurity]
554 public static extern IntPtr dBodyGetNextGeom(IntPtr Geom);
555
556
557 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyIsEnabled"), SuppressUnmanagedCodeSecurity]
558 public static extern bool BodyIsEnabled(IntPtr body);
559
560 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAngularVel"), SuppressUnmanagedCodeSecurity]
561 public static extern void BodySetAngularVel(IntPtr body, dReal x, dReal y, dReal z);
562
563 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableAngularThreshold"), SuppressUnmanagedCodeSecurity]
564 public static extern void BodySetAutoDisableAngularThreshold(IntPtr body, dReal angular_threshold);
565
566 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableDefaults"), SuppressUnmanagedCodeSecurity]
567 public static extern void BodySetAutoDisableDefaults(IntPtr body);
568
569 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableFlag"), SuppressUnmanagedCodeSecurity]
570 public static extern void BodySetAutoDisableFlag(IntPtr body, bool do_auto_disable);
571
572 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableLinearThreshold"), SuppressUnmanagedCodeSecurity]
573 public static extern void BodySetAutoDisableLinearThreshold(IntPtr body, dReal linear_threshold);
574
575 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableSteps"), SuppressUnmanagedCodeSecurity]
576 public static extern void BodySetAutoDisableSteps(IntPtr body, int steps);
577
578 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAutoDisableTime"), SuppressUnmanagedCodeSecurity]
579 public static extern void BodySetAutoDisableTime(IntPtr body, dReal time);
580
581 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetData"), SuppressUnmanagedCodeSecurity]
582 public static extern void BodySetData(IntPtr body, IntPtr data);
583
584 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetFiniteRotationMode"), SuppressUnmanagedCodeSecurity]
585 public static extern void BodySetFiniteRotationMode(IntPtr body, int mode);
586
587 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetFiniteRotationAxis"), SuppressUnmanagedCodeSecurity]
588 public static extern void BodySetFiniteRotationAxis(IntPtr body, dReal x, dReal y, dReal z);
589
590 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetLinearDamping"), SuppressUnmanagedCodeSecurity]
591 public static extern void BodySetLinearDamping(IntPtr body, dReal scale);
592
593 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAngularDamping"), SuppressUnmanagedCodeSecurity]
594 public static extern void BodySetAngularDamping(IntPtr body, dReal scale);
595
596 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetLinearDamping"), SuppressUnmanagedCodeSecurity]
597 public static extern dReal BodyGetLinearDamping(IntPtr body);
598
599 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAngularDamping"), SuppressUnmanagedCodeSecurity]
600 public static extern dReal BodyGetAngularDamping(IntPtr body);
601
602 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAngularDamping"), SuppressUnmanagedCodeSecurity]
603 public static extern void BodySetDamping(IntPtr body, dReal linear_scale, dReal angular_scale);
604
605 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetAngularDampingThreshold"), SuppressUnmanagedCodeSecurity]
606 public static extern void BodySetAngularDampingThreshold(IntPtr body, dReal threshold);
607
608 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetLinearDampingThreshold"), SuppressUnmanagedCodeSecurity]
609 public static extern void BodySetLinearDampingThreshold(IntPtr body, dReal threshold);
610
611 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetLinearDampingThreshold"), SuppressUnmanagedCodeSecurity]
612 public static extern dReal BodyGetLinearDampingThreshold(IntPtr body);
613
614 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyGetAngularDampingThreshold"), SuppressUnmanagedCodeSecurity]
615 public static extern dReal BodyGetAngularDampingThreshold(IntPtr body);
616
617 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetForce"), SuppressUnmanagedCodeSecurity]
618 public static extern void BodySetForce(IntPtr body, dReal x, dReal y, dReal z);
619
620 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetGravityMode"), SuppressUnmanagedCodeSecurity]
621 public static extern void BodySetGravityMode(IntPtr body, bool mode);
622
623 /// <summary>
624 /// Sets the Gyroscopic term status on the body specified.
625 /// </summary>
626 /// <param name="body">Pointer to body</param>
627 /// <param name="enabled">NonZero enabled, Zero disabled</param>
628 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetGyroscopicMode"), SuppressUnmanagedCodeSecurity]
629 public static extern void dBodySetGyroscopicMode(IntPtr body, int enabled);
630
631 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetLinearVel"), SuppressUnmanagedCodeSecurity]
632 public static extern void BodySetLinearVel(IntPtr body, dReal x, dReal y, dReal z);
633
634 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetMass"), SuppressUnmanagedCodeSecurity]
635 public static extern void BodySetMass(IntPtr body, ref Mass mass);
636
637 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetPosition"), SuppressUnmanagedCodeSecurity]
638 public static extern void BodySetPosition(IntPtr body, dReal x, dReal y, dReal z);
639
640 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetQuaternion"), SuppressUnmanagedCodeSecurity]
641 public static extern void BodySetQuaternion(IntPtr body, ref Quaternion q);
642
643 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetQuaternion"), SuppressUnmanagedCodeSecurity]
644 public static extern void BodySetQuaternion(IntPtr body, ref dReal w);
645
646 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetRotation"), SuppressUnmanagedCodeSecurity]
647 public static extern void BodySetRotation(IntPtr body, ref Matrix3 R);
648
649 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetRotation"), SuppressUnmanagedCodeSecurity]
650 public static extern void BodySetRotation(IntPtr body, ref dReal M00);
651
652 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodySetTorque"), SuppressUnmanagedCodeSecurity]
653 public static extern void BodySetTorque(IntPtr body, dReal x, dReal y, dReal z);
654
655 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyVectorFromWorld"), SuppressUnmanagedCodeSecurity]
656 public static extern void BodyVectorFromWorld(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
657
658 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBodyVectorToWorld"), SuppressUnmanagedCodeSecurity]
659 public static extern void BodyVectorToWorld(IntPtr body, dReal px, dReal py, dReal pz, out Vector3 result);
660
661 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBoxBox"), SuppressUnmanagedCodeSecurity]
662 public static extern void BoxBox(ref Vector3 p1, ref Matrix3 R1,
663 ref Vector3 side1, ref Vector3 p2,
664 ref Matrix3 R2, ref Vector3 side2,
665 ref Vector3 normal, out dReal depth, out int return_code,
666 int maxc, out ContactGeom contact, int skip);
667
668 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dBoxTouchesBox"), SuppressUnmanagedCodeSecurity]
669 public static extern void BoxTouchesBox(ref Vector3 _p1, ref Matrix3 R1,
670 ref Vector3 side1, ref Vector3 _p2,
671 ref Matrix3 R2, ref Vector3 side2);
672
673 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCleanupODEAllDataForThread"), SuppressUnmanagedCodeSecurity]
674 public static extern void CleanupODEAllDataForThread();
675
676 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dClosestLineSegmentPoints"), SuppressUnmanagedCodeSecurity]
677 public static extern void ClosestLineSegmentPoints(ref Vector3 a1, ref Vector3 a2,
678 ref Vector3 b1, ref Vector3 b2,
679 ref Vector3 cp1, ref Vector3 cp2);
680
681 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCloseODE"), SuppressUnmanagedCodeSecurity]
682 public static extern void CloseODE();
683
684 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCollide"), SuppressUnmanagedCodeSecurity]
685 public static extern int Collide(IntPtr o1, IntPtr o2, int flags, [In, Out] ContactGeom[] contact, int skip);
686 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCollide"), SuppressUnmanagedCodeSecurity]
687 public static extern int CollidePtr(IntPtr o1, IntPtr o2, int flags, IntPtr contactgeomarray, int skip);
688
689 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dConnectingJoint"), SuppressUnmanagedCodeSecurity]
690 public static extern IntPtr ConnectingJoint(IntPtr j1, IntPtr j2);
691
692 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateBox"), SuppressUnmanagedCodeSecurity]
693 public static extern IntPtr CreateiBox(IntPtr space, dReal lx, dReal ly, dReal lz);
694 public static IntPtr CreateBox(IntPtr space, dReal lx, dReal ly, dReal lz)
695 {
696 NTotalGeoms++;
697 return CreateiBox(space, lx, ly, lz);
698 }
699
700 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateCapsule"), SuppressUnmanagedCodeSecurity]
701 public static extern IntPtr CreateiCapsule(IntPtr space, dReal radius, dReal length);
702 public static IntPtr CreateCapsule(IntPtr space, dReal radius, dReal length)
703 {
704 NTotalGeoms++;
705 return CreateiCapsule(space, radius, length);
706 }
707
708 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateConvex"), SuppressUnmanagedCodeSecurity]
709 public static extern IntPtr CreateiConvex(IntPtr space, dReal[] planes, int planeCount, dReal[] points, int pointCount, int[] polygons);
710 public static IntPtr CreateConvex(IntPtr space, dReal[] planes, int planeCount, dReal[] points, int pointCount, int[] polygons)
711 {
712 NTotalGeoms++;
713 return CreateiConvex(space, planes, planeCount, points, pointCount, polygons);
714 }
715
716 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateCylinder"), SuppressUnmanagedCodeSecurity]
717 public static extern IntPtr CreateiCylinder(IntPtr space, dReal radius, dReal length);
718 public static IntPtr CreateCylinder(IntPtr space, dReal radius, dReal length)
719 {
720 NTotalGeoms++;
721 return CreateiCylinder(space, radius, length);
722 }
723
724 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateHeightfield"), SuppressUnmanagedCodeSecurity]
725 public static extern IntPtr CreateiHeightfield(IntPtr space, IntPtr data, int bPlaceable);
726 public static IntPtr CreateHeightfield(IntPtr space, IntPtr data, int bPlaceable)
727 {
728 NTotalGeoms++;
729 return CreateiHeightfield(space, data, bPlaceable);
730 }
731
732 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeom"), SuppressUnmanagedCodeSecurity]
733 public static extern IntPtr CreateiGeom(int classnum);
734 public static IntPtr CreateGeom(int classnum)
735 {
736 NTotalGeoms++;
737 return CreateiGeom(classnum);
738 }
739
740 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeomClass"), SuppressUnmanagedCodeSecurity]
741 public static extern int CreateGeomClass(ref GeomClass classptr);
742
743 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeomTransform"), SuppressUnmanagedCodeSecurity]
744 public static extern IntPtr CreateGeomTransform(IntPtr space);
745
746 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreatePlane"), SuppressUnmanagedCodeSecurity]
747 public static extern IntPtr CreateiPlane(IntPtr space, dReal a, dReal b, dReal c, dReal d);
748 public static IntPtr CreatePlane(IntPtr space, dReal a, dReal b, dReal c, dReal d)
749 {
750 NTotalGeoms++;
751 return CreateiPlane(space, a, b, c, d);
752 }
753
754 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateRay"), SuppressUnmanagedCodeSecurity]
755 public static extern IntPtr CreateiRay(IntPtr space, dReal length);
756 public static IntPtr CreateRay(IntPtr space, dReal length)
757 {
758 NTotalGeoms++;
759 return CreateiRay(space, length);
760 }
761
762 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateSphere"), SuppressUnmanagedCodeSecurity]
763 public static extern IntPtr CreateiSphere(IntPtr space, dReal radius);
764 public static IntPtr CreateSphere(IntPtr space, dReal radius)
765 {
766 NTotalGeoms++;
767 return CreateiSphere(space, radius);
768 }
769
770 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateTriMesh"), SuppressUnmanagedCodeSecurity]
771 public static extern IntPtr CreateiTriMesh(IntPtr space, IntPtr data,
772 TriCallback callback, TriArrayCallback arrayCallback, TriRayCallback rayCallback);
773 public static IntPtr CreateTriMesh(IntPtr space, IntPtr data,
774 TriCallback callback, TriArrayCallback arrayCallback, TriRayCallback rayCallback)
775 {
776 NTotalGeoms++;
777 return CreateiTriMesh(space, data, callback, arrayCallback, rayCallback);
778 }
779 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dDot"), SuppressUnmanagedCodeSecurity]
780 public static extern dReal Dot(ref dReal X0, ref dReal X1, int n);
781
782 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dDQfromW"), SuppressUnmanagedCodeSecurity]
783 public static extern void DQfromW(dReal[] dq, ref Vector3 w, ref Quaternion q);
784
785 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dFactorCholesky"), SuppressUnmanagedCodeSecurity]
786 public static extern int FactorCholesky(ref dReal A00, int n);
787
788 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dFactorLDLT"), SuppressUnmanagedCodeSecurity]
789 public static extern void FactorLDLT(ref dReal A, out dReal d, int n, int nskip);
790
791 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomBoxGetLengths"), SuppressUnmanagedCodeSecurity]
792 public static extern void GeomBoxGetLengths(IntPtr geom, out Vector3 len);
793
794 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomBoxGetLengths"), SuppressUnmanagedCodeSecurity]
795 public static extern void GeomBoxGetLengths(IntPtr geom, out dReal x);
796
797 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomBoxPointDepth"), SuppressUnmanagedCodeSecurity]
798 public static extern dReal GeomBoxPointDepth(IntPtr geom, dReal x, dReal y, dReal z);
799
800 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomBoxSetLengths"), SuppressUnmanagedCodeSecurity]
801 public static extern void GeomBoxSetLengths(IntPtr geom, dReal x, dReal y, dReal z);
802
803 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCapsuleGetParams"), SuppressUnmanagedCodeSecurity]
804 public static extern void GeomCapsuleGetParams(IntPtr geom, out dReal radius, out dReal length);
805
806 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCapsulePointDepth"), SuppressUnmanagedCodeSecurity]
807 public static extern dReal GeomCapsulePointDepth(IntPtr geom, dReal x, dReal y, dReal z);
808
809 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCapsuleSetParams"), SuppressUnmanagedCodeSecurity]
810 public static extern void GeomCapsuleSetParams(IntPtr geom, dReal radius, dReal length);
811
812 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomClearOffset"), SuppressUnmanagedCodeSecurity]
813 public static extern void GeomClearOffset(IntPtr geom);
814
815 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyOffsetPosition"), SuppressUnmanagedCodeSecurity]
816 public static extern IntPtr GeomCopyOffsetPosition(IntPtr geom, ref Vector3 pos);
817
818 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyOffsetPosition"), SuppressUnmanagedCodeSecurity]
819 public static extern IntPtr GeomCopyOffsetPosition(IntPtr geom, ref dReal X);
820
821 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetOffsetQuaternion"), SuppressUnmanagedCodeSecurity]
822 public static extern void GeomCopyOffsetQuaternion(IntPtr geom, ref Quaternion Q);
823
824 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetOffsetQuaternion"), SuppressUnmanagedCodeSecurity]
825 public static extern void GeomCopyOffsetQuaternion(IntPtr geom, ref dReal X);
826
827 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyOffsetRotation"), SuppressUnmanagedCodeSecurity]
828 public static extern IntPtr GeomCopyOffsetRotation(IntPtr geom, ref Matrix3 R);
829
830 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyOffsetRotation"), SuppressUnmanagedCodeSecurity]
831 public static extern IntPtr GeomCopyOffsetRotation(IntPtr geom, ref dReal M00);
832
833 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyPosition"), SuppressUnmanagedCodeSecurity]
834 public static extern void GeomCopyPosition(IntPtr geom, out Vector3 pos);
835
836 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyPosition"), SuppressUnmanagedCodeSecurity]
837 public static extern void GeomCopyPosition(IntPtr geom, out dReal X);
838
839 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyRotation"), SuppressUnmanagedCodeSecurity]
840 public static extern void GeomCopyRotation(IntPtr geom, out Matrix3 R);
841
842 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCopyRotation"), SuppressUnmanagedCodeSecurity]
843 public static extern void GeomCopyRotation(IntPtr geom, out dReal M00);
844
845 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCylinderGetParams"), SuppressUnmanagedCodeSecurity]
846 public static extern void GeomCylinderGetParams(IntPtr geom, out dReal radius, out dReal length);
847
848 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomCylinderSetParams"), SuppressUnmanagedCodeSecurity]
849 public static extern void GeomCylinderSetParams(IntPtr geom, dReal radius, dReal length);
850
851 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomDestroy"), SuppressUnmanagedCodeSecurity]
852 public static extern void GeomiDestroy(IntPtr geom);
853 public static void GeomDestroy(IntPtr geom)
854 {
855 NTotalGeoms--;
856 GeomiDestroy(geom);
857 }
858
859
860 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomDisable"), SuppressUnmanagedCodeSecurity]
861 public static extern void GeomDisable(IntPtr geom);
862
863 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomEnable"), SuppressUnmanagedCodeSecurity]
864 public static extern void GeomEnable(IntPtr geom);
865
866 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetAABB"), SuppressUnmanagedCodeSecurity]
867 public static extern void GeomGetAABB(IntPtr geom, out AABB aabb);
868
869 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetAABB"), SuppressUnmanagedCodeSecurity]
870 public static extern void GeomGetAABB(IntPtr geom, out dReal minX);
871
872 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetBody"), SuppressUnmanagedCodeSecurity]
873 public static extern IntPtr GeomGetBody(IntPtr geom);
874
875 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetCategoryBits"), SuppressUnmanagedCodeSecurity]
876 public static extern int GeomGetCategoryBits(IntPtr geom);
877
878 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetClassData"), SuppressUnmanagedCodeSecurity]
879 public static extern IntPtr GeomGetClassData(IntPtr geom);
880
881 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetCollideBits"), SuppressUnmanagedCodeSecurity]
882 public static extern int GeomGetCollideBits(IntPtr geom);
883
884 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetClass"), SuppressUnmanagedCodeSecurity]
885 public static extern GeomClassID GeomGetClass(IntPtr geom);
886
887 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetData"), SuppressUnmanagedCodeSecurity]
888 public static extern IntPtr GeomGetData(IntPtr geom);
889
890 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetOffsetPosition"), SuppressUnmanagedCodeSecurity]
891 public extern unsafe static Vector3* GeomGetOffsetPositionUnsafe(IntPtr geom);
892 public static Vector3 GeomGetOffsetPosition(IntPtr geom)
893 {
894 unsafe { return *(GeomGetOffsetPositionUnsafe(geom)); }
895 }
896
897 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetOffsetRotation"), SuppressUnmanagedCodeSecurity]
898 public extern unsafe static Matrix3* GeomGetOffsetRotationUnsafe(IntPtr geom);
899 public static Matrix3 GeomGetOffsetRotation(IntPtr geom)
900 {
901 unsafe { return *(GeomGetOffsetRotationUnsafe(geom)); }
902 }
903
904 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetPosition"), SuppressUnmanagedCodeSecurity]
905 public extern unsafe static Vector3* GeomGetPositionUnsafe(IntPtr geom);
906 public static Vector3 GeomGetPosition(IntPtr geom)
907 {
908 unsafe { return *(GeomGetPositionUnsafe(geom)); }
909 }
910
911 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetQuaternion"), SuppressUnmanagedCodeSecurity]
912 public static extern void GeomCopyQuaternion(IntPtr geom, out Quaternion q);
913
914 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetQuaternion"), SuppressUnmanagedCodeSecurity]
915 public static extern void GeomCopyQuaternion(IntPtr geom, out dReal X);
916
917 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetRotation"), SuppressUnmanagedCodeSecurity]
918 public extern unsafe static Matrix3* GeomGetRotationUnsafe(IntPtr geom);
919 public static Matrix3 GeomGetRotation(IntPtr geom)
920 {
921 unsafe { return *(GeomGetRotationUnsafe(geom)); }
922 }
923
924 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetSpace"), SuppressUnmanagedCodeSecurity]
925 public static extern IntPtr GeomGetSpace(IntPtr geom);
926
927 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildByte"), SuppressUnmanagedCodeSecurity]
928 public static extern void GeomHeightfieldDataBuildByte(IntPtr d, byte[] pHeightData, int bCopyHeightData,
929 dReal width, dReal depth, int widthSamples, int depthSamples,
930 dReal scale, dReal offset, dReal thickness, int bWrap);
931
932 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildByte"), SuppressUnmanagedCodeSecurity]
933 public static extern void GeomHeightfieldDataBuildByte(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
934 dReal width, dReal depth, int widthSamples, int depthSamples,
935 dReal scale, dReal offset, dReal thickness, int bWrap);
936
937 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildCallback"), SuppressUnmanagedCodeSecurity]
938 public static extern void GeomHeightfieldDataBuildCallback(IntPtr d, IntPtr pUserData, HeightfieldGetHeight pCallback,
939 dReal width, dReal depth, int widthSamples, int depthSamples,
940 dReal scale, dReal offset, dReal thickness, int bWrap);
941
942 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildShort"), SuppressUnmanagedCodeSecurity]
943 public static extern void GeomHeightfieldDataBuildShort(IntPtr d, ushort[] pHeightData, int bCopyHeightData,
944 dReal width, dReal depth, int widthSamples, int depthSamples,
945 dReal scale, dReal offset, dReal thickness, int bWrap);
946
947 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildShort"), SuppressUnmanagedCodeSecurity]
948 public static extern void GeomHeightfieldDataBuildShort(IntPtr d, short[] pHeightData, int bCopyHeightData,
949 dReal width, dReal depth, int widthSamples, int depthSamples,
950 dReal scale, dReal offset, dReal thickness, int bWrap);
951
952 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildShort"), SuppressUnmanagedCodeSecurity]
953 public static extern void GeomHeightfieldDataBuildShort(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
954 dReal width, dReal depth, int widthSamples, int depthSamples,
955 dReal scale, dReal offset, dReal thickness, int bWrap);
956
957 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildSingle"), SuppressUnmanagedCodeSecurity]
958 public static extern void GeomHeightfieldDataBuildSingle(IntPtr d, float[] pHeightData, int bCopyHeightData,
959 dReal width, dReal depth, int widthSamples, int depthSamples,
960 dReal scale, dReal offset, dReal thickness, int bWrap);
961
962 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildSingle"), SuppressUnmanagedCodeSecurity]
963 public static extern void GeomHeightfieldDataBuildSingle(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
964 dReal width, dReal depth, int widthSamples, int depthSamples,
965 dReal scale, dReal offset, dReal thickness, int bWrap);
966
967 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildDouble"), SuppressUnmanagedCodeSecurity]
968 public static extern void GeomHeightfieldDataBuildDouble(IntPtr d, double[] pHeightData, int bCopyHeightData,
969 dReal width, dReal depth, int widthSamples, int depthSamples,
970 dReal scale, dReal offset, dReal thickness, int bWrap);
971
972 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildDouble"), SuppressUnmanagedCodeSecurity]
973 public static extern void GeomHeightfieldDataBuildDouble(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
974 dReal width, dReal depth, int widthSamples, int depthSamples,
975 dReal scale, dReal offset, dReal thickness, int bWrap);
976
977 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataCreate"), SuppressUnmanagedCodeSecurity]
978 public static extern IntPtr GeomHeightfieldDataCreate();
979
980 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataDestroy"), SuppressUnmanagedCodeSecurity]
981 public static extern void GeomHeightfieldDataDestroy(IntPtr d);
982
983 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataSetBounds"), SuppressUnmanagedCodeSecurity]
984 public static extern void GeomHeightfieldDataSetBounds(IntPtr d, dReal minHeight, dReal maxHeight);
985
986 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldGetHeightfieldData"), SuppressUnmanagedCodeSecurity]
987 public static extern IntPtr GeomHeightfieldGetHeightfieldData(IntPtr g);
988
989 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldSetHeightfieldData"), SuppressUnmanagedCodeSecurity]
990 public static extern void GeomHeightfieldSetHeightfieldData(IntPtr g, IntPtr d);
991
992 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomIsEnabled"), SuppressUnmanagedCodeSecurity]
993 public static extern bool GeomIsEnabled(IntPtr geom);
994
995 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomIsOffset"), SuppressUnmanagedCodeSecurity]
996 public static extern bool GeomIsOffset(IntPtr geom);
997
998 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomIsSpace"), SuppressUnmanagedCodeSecurity]
999 public static extern bool GeomIsSpace(IntPtr geom);
1000
1001 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomPlaneGetParams"), SuppressUnmanagedCodeSecurity]
1002 public static extern void GeomPlaneGetParams(IntPtr geom, ref Vector4 result);
1003
1004 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomPlaneGetParams"), SuppressUnmanagedCodeSecurity]
1005 public static extern void GeomPlaneGetParams(IntPtr geom, ref dReal A);
1006
1007 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomPlanePointDepth"), SuppressUnmanagedCodeSecurity]
1008 public static extern dReal GeomPlanePointDepth(IntPtr geom, dReal x, dReal y, dReal z);
1009
1010 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomPlaneSetParams"), SuppressUnmanagedCodeSecurity]
1011 public static extern void GeomPlaneSetParams(IntPtr plane, dReal a, dReal b, dReal c, dReal d);
1012
1013 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGet"), SuppressUnmanagedCodeSecurity]
1014 public static extern void GeomRayGet(IntPtr ray, ref Vector3 start, ref Vector3 dir);
1015
1016 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGet"), SuppressUnmanagedCodeSecurity]
1017 public static extern void GeomRayGet(IntPtr ray, ref dReal startX, ref dReal dirX);
1018
1019 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGetClosestHit"), SuppressUnmanagedCodeSecurity]
1020 public static extern int GeomRayGetClosestHit(IntPtr ray);
1021
1022 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGetLength"), SuppressUnmanagedCodeSecurity]
1023 public static extern dReal GeomRayGetLength(IntPtr ray);
1024
1025 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRayGetParams"), SuppressUnmanagedCodeSecurity]
1026 public static extern dReal GeomRayGetParams(IntPtr g, out int firstContact, out int backfaceCull);
1027
1028 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRaySet"), SuppressUnmanagedCodeSecurity]
1029 public static extern void GeomRaySet(IntPtr ray, dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz);
1030
1031 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRaySetClosestHit"), SuppressUnmanagedCodeSecurity]
1032 public static extern void GeomRaySetClosestHit(IntPtr ray, int closestHit);
1033
1034 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRaySetLength"), SuppressUnmanagedCodeSecurity]
1035 public static extern void GeomRaySetLength(IntPtr ray, dReal length);
1036
1037 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomRaySetParams"), SuppressUnmanagedCodeSecurity]
1038 public static extern void GeomRaySetParams(IntPtr ray, int firstContact, int backfaceCull);
1039
1040 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetBody"), SuppressUnmanagedCodeSecurity]
1041 public static extern void GeomSetBody(IntPtr geom, IntPtr body);
1042
1043 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetCategoryBits"), SuppressUnmanagedCodeSecurity]
1044 public static extern void GeomSetCategoryBits(IntPtr geom, int bits);
1045
1046 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetCollideBits"), SuppressUnmanagedCodeSecurity]
1047 public static extern void GeomSetCollideBits(IntPtr geom, int bits);
1048
1049 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetConvex"), SuppressUnmanagedCodeSecurity]
1050 public static extern IntPtr GeomSetConvex(IntPtr geom, dReal[] planes, int planeCount, dReal[] points, int pointCount, int[] polygons);
1051
1052 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetData"), SuppressUnmanagedCodeSecurity]
1053 public static extern void GeomSetData(IntPtr geom, IntPtr data);
1054
1055 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetPosition"), SuppressUnmanagedCodeSecurity]
1056 public static extern void GeomSetOffsetPosition(IntPtr geom, dReal x, dReal y, dReal z);
1057
1058 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetQuaternion"), SuppressUnmanagedCodeSecurity]
1059 public static extern void GeomSetOffsetQuaternion(IntPtr geom, ref Quaternion Q);
1060
1061 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetQuaternion"), SuppressUnmanagedCodeSecurity]
1062 public static extern void GeomSetOffsetQuaternion(IntPtr geom, ref dReal X);
1063
1064 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetRotation"), SuppressUnmanagedCodeSecurity]
1065 public static extern void GeomSetOffsetRotation(IntPtr geom, ref Matrix3 R);
1066
1067 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetRotation"), SuppressUnmanagedCodeSecurity]
1068 public static extern void GeomSetOffsetRotation(IntPtr geom, ref dReal M00);
1069
1070 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldPosition"), SuppressUnmanagedCodeSecurity]
1071 public static extern void GeomSetOffsetWorldPosition(IntPtr geom, dReal x, dReal y, dReal z);
1072
1073 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldQuaternion"), SuppressUnmanagedCodeSecurity]
1074 public static extern void GeomSetOffsetWorldQuaternion(IntPtr geom, ref Quaternion Q);
1075
1076 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldQuaternion"), SuppressUnmanagedCodeSecurity]
1077 public static extern void GeomSetOffsetWorldQuaternion(IntPtr geom, ref dReal X);
1078
1079 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldRotation"), SuppressUnmanagedCodeSecurity]
1080 public static extern void GeomSetOffsetWorldRotation(IntPtr geom, ref Matrix3 R);
1081
1082 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetOffsetWorldRotation"), SuppressUnmanagedCodeSecurity]
1083 public static extern void GeomSetOffsetWorldRotation(IntPtr geom, ref dReal M00);
1084
1085 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetPosition"), SuppressUnmanagedCodeSecurity]
1086 public static extern void GeomSetPosition(IntPtr geom, dReal x, dReal y, dReal z);
1087
1088 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetQuaternion"), SuppressUnmanagedCodeSecurity]
1089 public static extern void GeomSetQuaternion(IntPtr geom, ref Quaternion quat);
1090
1091 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetQuaternion"), SuppressUnmanagedCodeSecurity]
1092 public static extern void GeomSetQuaternion(IntPtr geom, ref dReal w);
1093
1094 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetRotation"), SuppressUnmanagedCodeSecurity]
1095 public static extern void GeomSetRotation(IntPtr geom, ref Matrix3 R);
1096
1097 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSetRotation"), SuppressUnmanagedCodeSecurity]
1098 public static extern void GeomSetRotation(IntPtr geom, ref dReal M00);
1099
1100 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSphereGetRadius"), SuppressUnmanagedCodeSecurity]
1101 public static extern dReal GeomSphereGetRadius(IntPtr geom);
1102
1103 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSpherePointDepth"), SuppressUnmanagedCodeSecurity]
1104 public static extern dReal GeomSpherePointDepth(IntPtr geom, dReal x, dReal y, dReal z);
1105
1106 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomSphereSetRadius"), SuppressUnmanagedCodeSecurity]
1107 public static extern void GeomSphereSetRadius(IntPtr geom, dReal radius);
1108
1109 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformGetCleanup"), SuppressUnmanagedCodeSecurity]
1110 public static extern int GeomTransformGetCleanup(IntPtr geom);
1111
1112 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformGetGeom"), SuppressUnmanagedCodeSecurity]
1113 public static extern IntPtr GeomTransformGetGeom(IntPtr geom);
1114
1115 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformGetInfo"), SuppressUnmanagedCodeSecurity]
1116 public static extern int GeomTransformGetInfo(IntPtr geom);
1117
1118 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformSetCleanup"), SuppressUnmanagedCodeSecurity]
1119 public static extern void GeomTransformSetCleanup(IntPtr geom, int mode);
1120
1121 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformSetGeom"), SuppressUnmanagedCodeSecurity]
1122 public static extern void GeomTransformSetGeom(IntPtr geom, IntPtr obj);
1123
1124 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTransformSetInfo"), SuppressUnmanagedCodeSecurity]
1125 public static extern void GeomTransformSetInfo(IntPtr geom, int info);
1126
1127 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildDouble"), SuppressUnmanagedCodeSecurity]
1128 public static extern void GeomTriMeshDataBuildDouble(IntPtr d,
1129 double[] vertices, int vertexStride, int vertexCount,
1130 int[] indices, int indexCount, int triStride);
1131
1132 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildDouble"), SuppressUnmanagedCodeSecurity]
1133 public static extern void GeomTriMeshDataBuildDouble(IntPtr d,
1134 IntPtr vertices, int vertexStride, int vertexCount,
1135 IntPtr indices, int indexCount, int triStride);
1136
1137 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildDouble1"), SuppressUnmanagedCodeSecurity]
1138 public static extern void GeomTriMeshDataBuildDouble1(IntPtr d,
1139 double[] vertices, int vertexStride, int vertexCount,
1140 int[] indices, int indexCount, int triStride,
1141 double[] normals);
1142
1143 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildDouble1"), SuppressUnmanagedCodeSecurity]
1144 public static extern void GeomTriMeshDataBuildDouble(IntPtr d,
1145 IntPtr vertices, int vertexStride, int vertexCount,
1146 IntPtr indices, int indexCount, int triStride,
1147 IntPtr normals);
1148
1149 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSimple"), SuppressUnmanagedCodeSecurity]
1150 public static extern void GeomTriMeshDataBuildSingle(IntPtr d,
1151 dReal[] vertices, int vertexStride, int vertexCount,
1152 int[] indices, int indexCount, int triStride);
1153
1154 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSimple"), SuppressUnmanagedCodeSecurity]
1155 public static extern void GeomTriMeshDataBuildSingle(IntPtr d,
1156 IntPtr vertices, int vertexStride, int vertexCount,
1157 IntPtr indices, int indexCount, int triStride);
1158
1159 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSimple1"), SuppressUnmanagedCodeSecurity]
1160 public static extern void GeomTriMeshDataBuildSingle1(IntPtr d,
1161 dReal[] vertices, int vertexStride, int vertexCount,
1162 int[] indices, int indexCount, int triStride,
1163 dReal[] normals);
1164
1165 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSimple1"), SuppressUnmanagedCodeSecurity]
1166 public static extern void GeomTriMeshDataBuildSingle1(IntPtr d,
1167 IntPtr vertices, int vertexStride, int vertexCount,
1168 IntPtr indices, int indexCount, int triStride,
1169 IntPtr normals);
1170
1171 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSingle"), SuppressUnmanagedCodeSecurity]
1172 public static extern void GeomTriMeshDataBuildSimple(IntPtr d,
1173 float[] vertices, int vertexStride, int vertexCount,
1174 int[] indices, int indexCount, int triStride);
1175
1176 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSingle"), SuppressUnmanagedCodeSecurity]
1177 public static extern void GeomTriMeshDataBuildSimple(IntPtr d,
1178 IntPtr vertices, int vertexStride, int vertexCount,
1179 IntPtr indices, int indexCount, int triStride);
1180
1181 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSingle1"), SuppressUnmanagedCodeSecurity]
1182 public static extern void GeomTriMeshDataBuildSimple1(IntPtr d,
1183 float[] vertices, int vertexStride, int vertexCount,
1184 int[] indices, int indexCount, int triStride,
1185 float[] normals);
1186
1187 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataBuildSingle1"), SuppressUnmanagedCodeSecurity]
1188 public static extern void GeomTriMeshDataBuildSimple1(IntPtr d,
1189 IntPtr vertices, int vertexStride, int vertexCount,
1190 IntPtr indices, int indexCount, int triStride,
1191 IntPtr normals);
1192
1193 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshClearTCCache"), SuppressUnmanagedCodeSecurity]
1194 public static extern void GeomTriMeshClearTCCache(IntPtr g);
1195
1196 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataCreate"), SuppressUnmanagedCodeSecurity]
1197 public static extern IntPtr GeomTriMeshDataCreate();
1198
1199 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataDestroy"), SuppressUnmanagedCodeSecurity]
1200 public static extern void GeomTriMeshDataDestroy(IntPtr d);
1201
1202 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataGet"), SuppressUnmanagedCodeSecurity]
1203 public static extern IntPtr GeomTriMeshDataGet(IntPtr d, int data_id);
1204
1205 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataPreprocess"), SuppressUnmanagedCodeSecurity]
1206 public static extern void GeomTriMeshDataPreprocess(IntPtr d);
1207
1208 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataSet"), SuppressUnmanagedCodeSecurity]
1209 public static extern void GeomTriMeshDataSet(IntPtr d, int data_id, IntPtr in_data);
1210
1211 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshDataUpdate"), SuppressUnmanagedCodeSecurity]
1212 public static extern void GeomTriMeshDataUpdate(IntPtr d);
1213
1214 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshEnableTC"), SuppressUnmanagedCodeSecurity]
1215 public static extern void GeomTriMeshEnableTC(IntPtr g, int geomClass, bool enable);
1216
1217 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetArrayCallback"), SuppressUnmanagedCodeSecurity]
1218 public static extern TriArrayCallback GeomTriMeshGetArrayCallback(IntPtr g);
1219
1220 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetCallback"), SuppressUnmanagedCodeSecurity]
1221 public static extern TriCallback GeomTriMeshGetCallback(IntPtr g);
1222
1223 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetData"), SuppressUnmanagedCodeSecurity]
1224 public static extern IntPtr GeomTriMeshGetData(IntPtr g);
1225
1226 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetLastTransform"), SuppressUnmanagedCodeSecurity]
1227 public extern unsafe static Matrix4* GeomTriMeshGetLastTransformUnsafe(IntPtr geom);
1228 public static Matrix4 GeomTriMeshGetLastTransform(IntPtr geom)
1229 {
1230 unsafe { return *(GeomTriMeshGetLastTransformUnsafe(geom)); }
1231 }
1232
1233 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetPoint"), SuppressUnmanagedCodeSecurity]
1234 public extern static void GeomTriMeshGetPoint(IntPtr g, int index, dReal u, dReal v, ref Vector3 outVec);
1235
1236 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetRayCallback"), SuppressUnmanagedCodeSecurity]
1237 public static extern TriRayCallback GeomTriMeshGetRayCallback(IntPtr g);
1238
1239 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetTriangle"), SuppressUnmanagedCodeSecurity]
1240 public extern static void GeomTriMeshGetTriangle(IntPtr g, int index, ref Vector3 v0, ref Vector3 v1, ref Vector3 v2);
1241
1242 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetTriangleCount"), SuppressUnmanagedCodeSecurity]
1243 public extern static int GeomTriMeshGetTriangleCount(IntPtr g);
1244
1245 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshGetTriMeshDataID"), SuppressUnmanagedCodeSecurity]
1246 public static extern IntPtr GeomTriMeshGetTriMeshDataID(IntPtr g);
1247
1248 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshIsTCEnabled"), SuppressUnmanagedCodeSecurity]
1249 public static extern bool GeomTriMeshIsTCEnabled(IntPtr g, int geomClass);
1250
1251 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetArrayCallback"), SuppressUnmanagedCodeSecurity]
1252 public static extern void GeomTriMeshSetArrayCallback(IntPtr g, TriArrayCallback arrayCallback);
1253
1254 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetCallback"), SuppressUnmanagedCodeSecurity]
1255 public static extern void GeomTriMeshSetCallback(IntPtr g, TriCallback callback);
1256
1257 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetData"), SuppressUnmanagedCodeSecurity]
1258 public static extern void GeomTriMeshSetData(IntPtr g, IntPtr data);
1259
1260 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetLastTransform"), SuppressUnmanagedCodeSecurity]
1261 public static extern void GeomTriMeshSetLastTransform(IntPtr g, ref Matrix4 last_trans);
1262
1263 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetLastTransform"), SuppressUnmanagedCodeSecurity]
1264 public static extern void GeomTriMeshSetLastTransform(IntPtr g, ref dReal M00);
1265
1266 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomTriMeshSetRayCallback"), SuppressUnmanagedCodeSecurity]
1267 public static extern void GeomTriMeshSetRayCallback(IntPtr g, TriRayCallback callback);
1268
1269 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGetConfiguration"), SuppressUnmanagedCodeSecurity]
1270 public static extern string GetConfiguration(string str);
1271
1272 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dHashSpaceCreate"), SuppressUnmanagedCodeSecurity]
1273 public static extern IntPtr HashSpaceCreate(IntPtr space);
1274
1275 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dHashSpaceGetLevels"), SuppressUnmanagedCodeSecurity]
1276 public static extern void HashSpaceGetLevels(IntPtr space, out int minlevel, out int maxlevel);
1277
1278 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dHashSpaceSetLevels"), SuppressUnmanagedCodeSecurity]
1279 public static extern void HashSpaceSetLevels(IntPtr space, int minlevel, int maxlevel);
1280
1281 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dInfiniteAABB"), SuppressUnmanagedCodeSecurity]
1282 public static extern void InfiniteAABB(IntPtr geom, out AABB aabb);
1283
1284 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dInitODE"), SuppressUnmanagedCodeSecurity]
1285 public static extern void InitODE();
1286
1287 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dInitODE2"), SuppressUnmanagedCodeSecurity]
1288 public static extern int InitODE2(uint ODEInitFlags);
1289
1290 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dIsPositiveDefinite"), SuppressUnmanagedCodeSecurity]
1291 public static extern int IsPositiveDefinite(ref dReal A, int n);
1292
1293 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dInvertPDMatrix"), SuppressUnmanagedCodeSecurity]
1294 public static extern int InvertPDMatrix(ref dReal A, out dReal Ainv, int n);
1295
1296 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddAMotorTorques"), SuppressUnmanagedCodeSecurity]
1297 public static extern void JointAddAMotorTorques(IntPtr joint, dReal torque1, dReal torque2, dReal torque3);
1298
1299 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddHingeTorque"), SuppressUnmanagedCodeSecurity]
1300 public static extern void JointAddHingeTorque(IntPtr joint, dReal torque);
1301
1302 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddHinge2Torque"), SuppressUnmanagedCodeSecurity]
1303 public static extern void JointAddHinge2Torques(IntPtr joint, dReal torque1, dReal torque2);
1304
1305 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddPRTorque"), SuppressUnmanagedCodeSecurity]
1306 public static extern void JointAddPRTorque(IntPtr joint, dReal torque);
1307
1308 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddUniversalTorque"), SuppressUnmanagedCodeSecurity]
1309 public static extern void JointAddUniversalTorques(IntPtr joint, dReal torque1, dReal torque2);
1310
1311 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAddSliderForce"), SuppressUnmanagedCodeSecurity]
1312 public static extern void JointAddSliderForce(IntPtr joint, dReal force);
1313
1314 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointAttach"), SuppressUnmanagedCodeSecurity]
1315 public static extern void JointAttach(IntPtr joint, IntPtr body1, IntPtr body2);
1316
1317 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateAMotor"), SuppressUnmanagedCodeSecurity]
1318 public static extern IntPtr JointCreateAMotor(IntPtr world, IntPtr group);
1319
1320 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateBall"), SuppressUnmanagedCodeSecurity]
1321 public static extern IntPtr JointCreateBall(IntPtr world, IntPtr group);
1322
1323 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateContact"), SuppressUnmanagedCodeSecurity]
1324 public static extern IntPtr JointCreateContact(IntPtr world, IntPtr group, ref Contact contact);
1325 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateContact"), SuppressUnmanagedCodeSecurity]
1326 public static extern IntPtr JointCreateContactPtr(IntPtr world, IntPtr group, IntPtr contact);
1327
1328 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateFixed"), SuppressUnmanagedCodeSecurity]
1329 public static extern IntPtr JointCreateFixed(IntPtr world, IntPtr group);
1330
1331 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateHinge"), SuppressUnmanagedCodeSecurity]
1332 public static extern IntPtr JointCreateHinge(IntPtr world, IntPtr group);
1333
1334 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateHinge2"), SuppressUnmanagedCodeSecurity]
1335 public static extern IntPtr JointCreateHinge2(IntPtr world, IntPtr group);
1336
1337 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateLMotor"), SuppressUnmanagedCodeSecurity]
1338 public static extern IntPtr JointCreateLMotor(IntPtr world, IntPtr group);
1339
1340 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateNull"), SuppressUnmanagedCodeSecurity]
1341 public static extern IntPtr JointCreateNull(IntPtr world, IntPtr group);
1342
1343 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreatePR"), SuppressUnmanagedCodeSecurity]
1344 public static extern IntPtr JointCreatePR(IntPtr world, IntPtr group);
1345
1346 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreatePlane2D"), SuppressUnmanagedCodeSecurity]
1347 public static extern IntPtr JointCreatePlane2D(IntPtr world, IntPtr group);
1348
1349 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateSlider"), SuppressUnmanagedCodeSecurity]
1350 public static extern IntPtr JointCreateSlider(IntPtr world, IntPtr group);
1351
1352 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointCreateUniversal"), SuppressUnmanagedCodeSecurity]
1353 public static extern IntPtr JointCreateUniversal(IntPtr world, IntPtr group);
1354
1355 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointDestroy"), SuppressUnmanagedCodeSecurity]
1356 public static extern void JointDestroy(IntPtr j);
1357
1358 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorAngle"), SuppressUnmanagedCodeSecurity]
1359 public static extern dReal JointGetAMotorAngle(IntPtr j, int anum);
1360
1361 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorAngleRate"), SuppressUnmanagedCodeSecurity]
1362 public static extern dReal JointGetAMotorAngleRate(IntPtr j, int anum);
1363
1364 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorAxis"), SuppressUnmanagedCodeSecurity]
1365 public static extern void JointGetAMotorAxis(IntPtr j, int anum, out Vector3 result);
1366
1367 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorAxisRel"), SuppressUnmanagedCodeSecurity]
1368 public static extern int JointGetAMotorAxisRel(IntPtr j, int anum);
1369
1370 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorMode"), SuppressUnmanagedCodeSecurity]
1371 public static extern int JointGetAMotorMode(IntPtr j);
1372
1373 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorNumAxes"), SuppressUnmanagedCodeSecurity]
1374 public static extern int JointGetAMotorNumAxes(IntPtr j);
1375
1376 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetAMotorParam"), SuppressUnmanagedCodeSecurity]
1377 public static extern dReal JointGetAMotorParam(IntPtr j, int parameter);
1378
1379 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetBallAnchor"), SuppressUnmanagedCodeSecurity]
1380 public static extern void JointGetBallAnchor(IntPtr j, out Vector3 result);
1381
1382 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetBallAnchor2"), SuppressUnmanagedCodeSecurity]
1383 public static extern void JointGetBallAnchor2(IntPtr j, out Vector3 result);
1384
1385 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetBody"), SuppressUnmanagedCodeSecurity]
1386 public static extern IntPtr JointGetBody(IntPtr j);
1387
1388 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetData"), SuppressUnmanagedCodeSecurity]
1389 public static extern IntPtr JointGetData(IntPtr j);
1390
1391 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetFeedback"), SuppressUnmanagedCodeSecurity]
1392 public extern unsafe static JointFeedback* JointGetFeedbackUnsafe(IntPtr j);
1393 public static JointFeedback JointGetFeedback(IntPtr j)
1394 {
1395 unsafe { return *(JointGetFeedbackUnsafe(j)); }
1396 }
1397
1398 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAnchor"), SuppressUnmanagedCodeSecurity]
1399 public static extern void JointGetHingeAnchor(IntPtr j, out Vector3 result);
1400
1401 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAngle"), SuppressUnmanagedCodeSecurity]
1402 public static extern dReal JointGetHingeAngle(IntPtr j);
1403
1404 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAngleRate"), SuppressUnmanagedCodeSecurity]
1405 public static extern dReal JointGetHingeAngleRate(IntPtr j);
1406
1407 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAxis"), SuppressUnmanagedCodeSecurity]
1408 public static extern void JointGetHingeAxis(IntPtr j, out Vector3 result);
1409
1410 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeParam"), SuppressUnmanagedCodeSecurity]
1411 public static extern dReal JointGetHingeParam(IntPtr j, int parameter);
1412
1413 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Angle1"), SuppressUnmanagedCodeSecurity]
1414 public static extern dReal JointGetHinge2Angle1(IntPtr j);
1415
1416 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Angle1Rate"), SuppressUnmanagedCodeSecurity]
1417 public static extern dReal JointGetHinge2Angle1Rate(IntPtr j);
1418
1419 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Angle2Rate"), SuppressUnmanagedCodeSecurity]
1420 public static extern dReal JointGetHinge2Angle2Rate(IntPtr j);
1421
1422 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHingeAnchor2"), SuppressUnmanagedCodeSecurity]
1423 public static extern void JointGetHingeAnchor2(IntPtr j, out Vector3 result);
1424
1425 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Anchor"), SuppressUnmanagedCodeSecurity]
1426 public static extern void JointGetHinge2Anchor(IntPtr j, out Vector3 result);
1427
1428 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Anchor2"), SuppressUnmanagedCodeSecurity]
1429 public static extern void JointGetHinge2Anchor2(IntPtr j, out Vector3 result);
1430
1431 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Axis1"), SuppressUnmanagedCodeSecurity]
1432 public static extern void JointGetHinge2Axis1(IntPtr j, out Vector3 result);
1433
1434 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Axis2"), SuppressUnmanagedCodeSecurity]
1435 public static extern void JointGetHinge2Axis2(IntPtr j, out Vector3 result);
1436
1437 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetHinge2Param"), SuppressUnmanagedCodeSecurity]
1438 public static extern dReal JointGetHinge2Param(IntPtr j, int parameter);
1439
1440 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetLMotorAxis"), SuppressUnmanagedCodeSecurity]
1441 public static extern void JointGetLMotorAxis(IntPtr j, int anum, out Vector3 result);
1442
1443 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetLMotorNumAxes"), SuppressUnmanagedCodeSecurity]
1444 public static extern int JointGetLMotorNumAxes(IntPtr j);
1445
1446 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetLMotorParam"), SuppressUnmanagedCodeSecurity]
1447 public static extern dReal JointGetLMotorParam(IntPtr j, int parameter);
1448
1449 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRAnchor"), SuppressUnmanagedCodeSecurity]
1450 public static extern void JointGetPRAnchor(IntPtr j, out Vector3 result);
1451
1452 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRAxis1"), SuppressUnmanagedCodeSecurity]
1453 public static extern void JointGetPRAxis1(IntPtr j, out Vector3 result);
1454
1455 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRAxis2"), SuppressUnmanagedCodeSecurity]
1456 public static extern void JointGetPRAxis2(IntPtr j, out Vector3 result);
1457
1458 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRParam"), SuppressUnmanagedCodeSecurity]
1459 public static extern dReal JointGetPRParam(IntPtr j, int parameter);
1460
1461 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRPosition"), SuppressUnmanagedCodeSecurity]
1462 public static extern dReal JointGetPRPosition(IntPtr j);
1463
1464 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetPRPositionRate"), SuppressUnmanagedCodeSecurity]
1465 public static extern dReal JointGetPRPositionRate(IntPtr j);
1466
1467 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetSliderAxis"), SuppressUnmanagedCodeSecurity]
1468 public static extern void JointGetSliderAxis(IntPtr j, out Vector3 result);
1469
1470 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetSliderParam"), SuppressUnmanagedCodeSecurity]
1471 public static extern dReal JointGetSliderParam(IntPtr j, int parameter);
1472
1473 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetSliderPosition"), SuppressUnmanagedCodeSecurity]
1474 public static extern dReal JointGetSliderPosition(IntPtr j);
1475
1476 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetSliderPositionRate"), SuppressUnmanagedCodeSecurity]
1477 public static extern dReal JointGetSliderPositionRate(IntPtr j);
1478
1479 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetType"), SuppressUnmanagedCodeSecurity]
1480 public static extern JointType JointGetType(IntPtr j);
1481
1482 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAnchor"), SuppressUnmanagedCodeSecurity]
1483 public static extern void JointGetUniversalAnchor(IntPtr j, out Vector3 result);
1484
1485 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAnchor2"), SuppressUnmanagedCodeSecurity]
1486 public static extern void JointGetUniversalAnchor2(IntPtr j, out Vector3 result);
1487
1488 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngle1"), SuppressUnmanagedCodeSecurity]
1489 public static extern dReal JointGetUniversalAngle1(IntPtr j);
1490
1491 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngle1Rate"), SuppressUnmanagedCodeSecurity]
1492 public static extern dReal JointGetUniversalAngle1Rate(IntPtr j);
1493
1494 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngle2"), SuppressUnmanagedCodeSecurity]
1495 public static extern dReal JointGetUniversalAngle2(IntPtr j);
1496
1497 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngle2Rate"), SuppressUnmanagedCodeSecurity]
1498 public static extern dReal JointGetUniversalAngle2Rate(IntPtr j);
1499
1500 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAngles"), SuppressUnmanagedCodeSecurity]
1501 public static extern void JointGetUniversalAngles(IntPtr j, out dReal angle1, out dReal angle2);
1502
1503 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAxis1"), SuppressUnmanagedCodeSecurity]
1504 public static extern void JointGetUniversalAxis1(IntPtr j, out Vector3 result);
1505
1506 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalAxis2"), SuppressUnmanagedCodeSecurity]
1507 public static extern void JointGetUniversalAxis2(IntPtr j, out Vector3 result);
1508
1509 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGetUniversalParam"), SuppressUnmanagedCodeSecurity]
1510 public static extern dReal JointGetUniversalParam(IntPtr j, int parameter);
1511
1512 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGroupCreate"), SuppressUnmanagedCodeSecurity]
1513 public static extern IntPtr JointGroupCreate(int max_size);
1514
1515 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGroupDestroy"), SuppressUnmanagedCodeSecurity]
1516 public static extern void JointGroupDestroy(IntPtr group);
1517
1518 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointGroupEmpty"), SuppressUnmanagedCodeSecurity]
1519 public static extern void JointGroupEmpty(IntPtr group);
1520
1521 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorAngle"), SuppressUnmanagedCodeSecurity]
1522 public static extern void JointSetAMotorAngle(IntPtr j, int anum, dReal angle);
1523
1524 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorAxis"), SuppressUnmanagedCodeSecurity]
1525 public static extern void JointSetAMotorAxis(IntPtr j, int anum, int rel, dReal x, dReal y, dReal z);
1526
1527 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorMode"), SuppressUnmanagedCodeSecurity]
1528 public static extern void JointSetAMotorMode(IntPtr j, int mode);
1529
1530 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorNumAxes"), SuppressUnmanagedCodeSecurity]
1531 public static extern void JointSetAMotorNumAxes(IntPtr group, int num);
1532
1533 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetAMotorParam"), SuppressUnmanagedCodeSecurity]
1534 public static extern void JointSetAMotorParam(IntPtr group, int parameter, dReal value);
1535
1536 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetBallAnchor"), SuppressUnmanagedCodeSecurity]
1537 public static extern void JointSetBallAnchor(IntPtr j, dReal x, dReal y, dReal z);
1538
1539 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetBallAnchor2"), SuppressUnmanagedCodeSecurity]
1540 public static extern void JointSetBallAnchor2(IntPtr j, dReal x, dReal y, dReal z);
1541
1542 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetData"), SuppressUnmanagedCodeSecurity]
1543 public static extern void JointSetData(IntPtr j, IntPtr data);
1544
1545 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetFeedback"), SuppressUnmanagedCodeSecurity]
1546 public static extern void JointSetFeedback(IntPtr j, out JointFeedback feedback);
1547
1548 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetFixed"), SuppressUnmanagedCodeSecurity]
1549 public static extern void JointSetFixed(IntPtr j);
1550
1551 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHingeAnchor"), SuppressUnmanagedCodeSecurity]
1552 public static extern void JointSetHingeAnchor(IntPtr j, dReal x, dReal y, dReal z);
1553
1554 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHingeAnchorDelta"), SuppressUnmanagedCodeSecurity]
1555 public static extern void JointSetHingeAnchorDelta(IntPtr j, dReal x, dReal y, dReal z, dReal ax, dReal ay, dReal az);
1556
1557 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHingeAxis"), SuppressUnmanagedCodeSecurity]
1558 public static extern void JointSetHingeAxis(IntPtr j, dReal x, dReal y, dReal z);
1559
1560 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHingeParam"), SuppressUnmanagedCodeSecurity]
1561 public static extern void JointSetHingeParam(IntPtr j, int parameter, dReal value);
1562
1563 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHinge2Anchor"), SuppressUnmanagedCodeSecurity]
1564 public static extern void JointSetHinge2Anchor(IntPtr j, dReal x, dReal y, dReal z);
1565
1566 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHinge2Axis1"), SuppressUnmanagedCodeSecurity]
1567 public static extern void JointSetHinge2Axis1(IntPtr j, dReal x, dReal y, dReal z);
1568
1569 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHinge2Axis2"), SuppressUnmanagedCodeSecurity]
1570 public static extern void JointSetHinge2Axis2(IntPtr j, dReal x, dReal y, dReal z);
1571
1572 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetHinge2Param"), SuppressUnmanagedCodeSecurity]
1573 public static extern void JointSetHinge2Param(IntPtr j, int parameter, dReal value);
1574
1575 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetLMotorAxis"), SuppressUnmanagedCodeSecurity]
1576 public static extern void JointSetLMotorAxis(IntPtr j, int anum, int rel, dReal x, dReal y, dReal z);
1577
1578 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetLMotorNumAxes"), SuppressUnmanagedCodeSecurity]
1579 public static extern void JointSetLMotorNumAxes(IntPtr j, int num);
1580
1581 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetLMotorParam"), SuppressUnmanagedCodeSecurity]
1582 public static extern void JointSetLMotorParam(IntPtr j, int parameter, dReal value);
1583
1584 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPlane2DAngleParam"), SuppressUnmanagedCodeSecurity]
1585 public static extern void JointSetPlane2DAngleParam(IntPtr j, int parameter, dReal value);
1586
1587 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPlane2DXParam"), SuppressUnmanagedCodeSecurity]
1588 public static extern void JointSetPlane2DXParam(IntPtr j, int parameter, dReal value);
1589
1590 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPlane2DYParam"), SuppressUnmanagedCodeSecurity]
1591 public static extern void JointSetPlane2DYParam(IntPtr j, int parameter, dReal value);
1592
1593 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPRAnchor"), SuppressUnmanagedCodeSecurity]
1594 public static extern void JointSetPRAnchor(IntPtr j, dReal x, dReal y, dReal z);
1595
1596 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPRAxis1"), SuppressUnmanagedCodeSecurity]
1597 public static extern void JointSetPRAxis1(IntPtr j, dReal x, dReal y, dReal z);
1598
1599 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPRAxis2"), SuppressUnmanagedCodeSecurity]
1600 public static extern void JointSetPRAxis2(IntPtr j, dReal x, dReal y, dReal z);
1601
1602 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetPRParam"), SuppressUnmanagedCodeSecurity]
1603 public static extern void JointSetPRParam(IntPtr j, int parameter, dReal value);
1604
1605 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetSliderAxis"), SuppressUnmanagedCodeSecurity]
1606 public static extern void JointSetSliderAxis(IntPtr j, dReal x, dReal y, dReal z);
1607
1608 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetSliderAxisDelta"), SuppressUnmanagedCodeSecurity]
1609 public static extern void JointSetSliderAxisDelta(IntPtr j, dReal x, dReal y, dReal z, dReal ax, dReal ay, dReal az);
1610
1611 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetSliderParam"), SuppressUnmanagedCodeSecurity]
1612 public static extern void JointSetSliderParam(IntPtr j, int parameter, dReal value);
1613
1614 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetUniversalAnchor"), SuppressUnmanagedCodeSecurity]
1615 public static extern void JointSetUniversalAnchor(IntPtr j, dReal x, dReal y, dReal z);
1616
1617 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetUniversalAxis1"), SuppressUnmanagedCodeSecurity]
1618 public static extern void JointSetUniversalAxis1(IntPtr j, dReal x, dReal y, dReal z);
1619
1620 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetUniversalAxis2"), SuppressUnmanagedCodeSecurity]
1621 public static extern void JointSetUniversalAxis2(IntPtr j, dReal x, dReal y, dReal z);
1622
1623 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dJointSetUniversalParam"), SuppressUnmanagedCodeSecurity]
1624 public static extern void JointSetUniversalParam(IntPtr j, int parameter, dReal value);
1625
1626 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dLDLTAddTL"), SuppressUnmanagedCodeSecurity]
1627 public static extern void LDLTAddTL(ref dReal L, ref dReal d, ref dReal a, int n, int nskip);
1628
1629 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassAdd"), SuppressUnmanagedCodeSecurity]
1630 public static extern void MassAdd(ref Mass a, ref Mass b);
1631
1632 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassAdjust"), SuppressUnmanagedCodeSecurity]
1633 public static extern void MassAdjust(ref Mass m, dReal newmass);
1634
1635 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassCheck"), SuppressUnmanagedCodeSecurity]
1636 public static extern bool MassCheck(ref Mass m);
1637
1638 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassRotate"), SuppressUnmanagedCodeSecurity]
1639 public static extern void MassRotate(ref Mass mass, ref Matrix3 R);
1640
1641 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassRotate"), SuppressUnmanagedCodeSecurity]
1642 public static extern void MassRotate(ref Mass mass, ref dReal M00);
1643
1644 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetBox"), SuppressUnmanagedCodeSecurity]
1645 public static extern void MassSetBox(out Mass mass, dReal density, dReal lx, dReal ly, dReal lz);
1646
1647 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetBoxTotal"), SuppressUnmanagedCodeSecurity]
1648 public static extern void MassSetBoxTotal(out Mass mass, dReal total_mass, dReal lx, dReal ly, dReal lz);
1649
1650 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetCapsule"), SuppressUnmanagedCodeSecurity]
1651 public static extern void MassSetCapsule(out Mass mass, dReal density, int direction, dReal radius, dReal length);
1652
1653 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetCapsuleTotal"), SuppressUnmanagedCodeSecurity]
1654 public static extern void MassSetCapsuleTotal(out Mass mass, dReal total_mass, int direction, dReal radius, dReal length);
1655
1656 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetCylinder"), SuppressUnmanagedCodeSecurity]
1657 public static extern void MassSetCylinder(out Mass mass, dReal density, int direction, dReal radius, dReal length);
1658
1659 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetCylinderTotal"), SuppressUnmanagedCodeSecurity]
1660 public static extern void MassSetCylinderTotal(out Mass mass, dReal total_mass, int direction, dReal radius, dReal length);
1661
1662 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetParameters"), SuppressUnmanagedCodeSecurity]
1663 public static extern void MassSetParameters(out Mass mass, dReal themass,
1664 dReal cgx, dReal cgy, dReal cgz,
1665 dReal i11, dReal i22, dReal i33,
1666 dReal i12, dReal i13, dReal i23);
1667
1668 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetSphere"), SuppressUnmanagedCodeSecurity]
1669 public static extern void MassSetSphere(out Mass mass, dReal density, dReal radius);
1670
1671 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetSphereTotal"), SuppressUnmanagedCodeSecurity]
1672 public static extern void dMassSetSphereTotal(out Mass mass, dReal total_mass, dReal radius);
1673
1674 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetTrimesh"), SuppressUnmanagedCodeSecurity]
1675 public static extern void MassSetTrimesh(out Mass mass, dReal density, IntPtr g);
1676
1677 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassSetZero"), SuppressUnmanagedCodeSecurity]
1678 public static extern void MassSetZero(out Mass mass);
1679
1680 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMassTranslate"), SuppressUnmanagedCodeSecurity]
1681 public static extern void MassTranslate(ref Mass mass, dReal x, dReal y, dReal z);
1682
1683 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMultiply0"), SuppressUnmanagedCodeSecurity]
1684 public static extern void Multiply0(out dReal A00, ref dReal B00, ref dReal C00, int p, int q, int r);
1685
1686 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMultiply0"), SuppressUnmanagedCodeSecurity]
1687 private static extern void MultiplyiM3V3(out Vector3 vout, ref Matrix3 matrix, ref Vector3 vect,int p, int q, int r);
1688 public static void MultiplyM3V3(out Vector3 outvector, ref Matrix3 matrix, ref Vector3 invector)
1689 {
1690 MultiplyiM3V3(out outvector, ref matrix, ref invector, 3, 3, 1);
1691 }
1692
1693 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMultiply1"), SuppressUnmanagedCodeSecurity]
1694 public static extern void Multiply1(out dReal A00, ref dReal B00, ref dReal C00, int p, int q, int r);
1695
1696 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dMultiply2"), SuppressUnmanagedCodeSecurity]
1697 public static extern void Multiply2(out dReal A00, ref dReal B00, ref dReal C00, int p, int q, int r);
1698
1699 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQFromAxisAndAngle"), SuppressUnmanagedCodeSecurity]
1700 public static extern void QFromAxisAndAngle(out Quaternion q, dReal ax, dReal ay, dReal az, dReal angle);
1701
1702 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQfromR"), SuppressUnmanagedCodeSecurity]
1703 public static extern void QfromR(out Quaternion q, ref Matrix3 R);
1704
1705 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQMultiply0"), SuppressUnmanagedCodeSecurity]
1706 public static extern void QMultiply0(out Quaternion qa, ref Quaternion qb, ref Quaternion qc);
1707
1708 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQMultiply1"), SuppressUnmanagedCodeSecurity]
1709 public static extern void QMultiply1(out Quaternion qa, ref Quaternion qb, ref Quaternion qc);
1710
1711 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQMultiply2"), SuppressUnmanagedCodeSecurity]
1712 public static extern void QMultiply2(out Quaternion qa, ref Quaternion qb, ref Quaternion qc);
1713
1714 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQMultiply3"), SuppressUnmanagedCodeSecurity]
1715 public static extern void QMultiply3(out Quaternion qa, ref Quaternion qb, ref Quaternion qc);
1716
1717 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQSetIdentity"), SuppressUnmanagedCodeSecurity]
1718 public static extern void QSetIdentity(out Quaternion q);
1719
1720 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQuadTreeSpaceCreate"), SuppressUnmanagedCodeSecurity]
1721 public static extern IntPtr QuadTreeSpaceCreate(IntPtr space, ref Vector3 center, ref Vector3 extents, int depth);
1722
1723 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dQuadTreeSpaceCreate"), SuppressUnmanagedCodeSecurity]
1724 public static extern IntPtr QuadTreeSpaceCreate(IntPtr space, ref dReal centerX, ref dReal extentsX, int depth);
1725
1726 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRandReal"), SuppressUnmanagedCodeSecurity]
1727 public static extern dReal RandReal();
1728
1729 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRFrom2Axes"), SuppressUnmanagedCodeSecurity]
1730 public static extern void RFrom2Axes(out Matrix3 R, dReal ax, dReal ay, dReal az, dReal bx, dReal by, dReal bz);
1731
1732 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRFromAxisAndAngle"), SuppressUnmanagedCodeSecurity]
1733 public static extern void RFromAxisAndAngle(out Matrix3 R, dReal x, dReal y, dReal z, dReal angle);
1734
1735 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRFromEulerAngles"), SuppressUnmanagedCodeSecurity]
1736 public static extern void RFromEulerAngles(out Matrix3 R, dReal phi, dReal theta, dReal psi);
1737
1738 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRfromQ"), SuppressUnmanagedCodeSecurity]
1739 public static extern void RfromQ(out Matrix3 R, ref Quaternion q);
1740
1741 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRFromZAxis"), SuppressUnmanagedCodeSecurity]
1742 public static extern void RFromZAxis(out Matrix3 R, dReal ax, dReal ay, dReal az);
1743
1744 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dRSetIdentity"), SuppressUnmanagedCodeSecurity]
1745 public static extern void RSetIdentity(out Matrix3 R);
1746
1747 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSetValue"), SuppressUnmanagedCodeSecurity]
1748 public static extern void SetValue(out dReal a, int n);
1749
1750 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSetZero"), SuppressUnmanagedCodeSecurity]
1751 public static extern void SetZero(out dReal a, int n);
1752
1753 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSimpleSpaceCreate"), SuppressUnmanagedCodeSecurity]
1754 public static extern IntPtr SimpleSpaceCreate(IntPtr space);
1755
1756 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSolveCholesky"), SuppressUnmanagedCodeSecurity]
1757 public static extern void SolveCholesky(ref dReal L, out dReal b, int n);
1758
1759 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSolveL1"), SuppressUnmanagedCodeSecurity]
1760 public static extern void SolveL1(ref dReal L, out dReal b, int n, int nskip);
1761
1762 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSolveL1T"), SuppressUnmanagedCodeSecurity]
1763 public static extern void SolveL1T(ref dReal L, out dReal b, int n, int nskip);
1764
1765 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSolveLDLT"), SuppressUnmanagedCodeSecurity]
1766 public static extern void SolveLDLT(ref dReal L, ref dReal d, out dReal b, int n, int nskip);
1767
1768 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceAdd"), SuppressUnmanagedCodeSecurity]
1769 public static extern void SpaceAdd(IntPtr space, IntPtr geom);
1770
1771 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceLockQuery"), SuppressUnmanagedCodeSecurity]
1772 public static extern bool SpaceLockQuery(IntPtr space);
1773
1774 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceClean"), SuppressUnmanagedCodeSecurity]
1775 public static extern void SpaceClean(IntPtr space);
1776
1777 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceCollide"), SuppressUnmanagedCodeSecurity]
1778 public static extern void SpaceCollide(IntPtr space, IntPtr data, NearCallback callback);
1779
1780 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceCollide2"), SuppressUnmanagedCodeSecurity]
1781 public static extern void SpaceCollide2(IntPtr space1, IntPtr space2, IntPtr data, NearCallback callback);
1782
1783 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceDestroy"), SuppressUnmanagedCodeSecurity]
1784 public static extern void SpaceDestroy(IntPtr space);
1785
1786 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceGetCleanup"), SuppressUnmanagedCodeSecurity]
1787 public static extern bool SpaceGetCleanup(IntPtr space);
1788
1789 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceGetNumGeoms"), SuppressUnmanagedCodeSecurity]
1790 public static extern int SpaceGetNumGeoms(IntPtr space);
1791
1792 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceGetGeom"), SuppressUnmanagedCodeSecurity]
1793 public static extern IntPtr SpaceGetGeom(IntPtr space, int i);
1794
1795 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceGetSublevel"), SuppressUnmanagedCodeSecurity]
1796 public static extern int SpaceGetSublevel(IntPtr space);
1797
1798 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceQuery"), SuppressUnmanagedCodeSecurity]
1799 public static extern bool SpaceQuery(IntPtr space, IntPtr geom);
1800
1801 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceRemove"), SuppressUnmanagedCodeSecurity]
1802 public static extern void SpaceRemove(IntPtr space, IntPtr geom);
1803
1804 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceSetCleanup"), SuppressUnmanagedCodeSecurity]
1805 public static extern void SpaceSetCleanup(IntPtr space, bool mode);
1806
1807 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSpaceSetSublevel"), SuppressUnmanagedCodeSecurity]
1808 public static extern void SpaceSetSublevel(IntPtr space, int sublevel);
1809
1810 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dSweepAndPruneSpaceCreate"), SuppressUnmanagedCodeSecurity]
1811 public static extern IntPtr SweepAndPruneSpaceCreate(IntPtr space, int AxisOrder);
1812
1813 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dVectorScale"), SuppressUnmanagedCodeSecurity]
1814 public static extern void VectorScale(out dReal a, ref dReal d, int n);
1815
1816 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldCreate"), SuppressUnmanagedCodeSecurity]
1817 public static extern IntPtr WorldCreate();
1818
1819 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldDestroy"), SuppressUnmanagedCodeSecurity]
1820 public static extern void WorldDestroy(IntPtr world);
1821
1822 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableAverageSamplesCount"), SuppressUnmanagedCodeSecurity]
1823 public static extern int WorldGetAutoDisableAverageSamplesCount(IntPtr world);
1824
1825 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableAngularThreshold"), SuppressUnmanagedCodeSecurity]
1826 public static extern dReal WorldGetAutoDisableAngularThreshold(IntPtr world);
1827
1828 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableFlag"), SuppressUnmanagedCodeSecurity]
1829 public static extern bool WorldGetAutoDisableFlag(IntPtr world);
1830
1831 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableLinearThreshold"), SuppressUnmanagedCodeSecurity]
1832 public static extern dReal WorldGetAutoDisableLinearThreshold(IntPtr world);
1833
1834 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableSteps"), SuppressUnmanagedCodeSecurity]
1835 public static extern int WorldGetAutoDisableSteps(IntPtr world);
1836
1837 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoDisableTime"), SuppressUnmanagedCodeSecurity]
1838 public static extern dReal WorldGetAutoDisableTime(IntPtr world);
1839
1840 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAutoEnableDepthSF1"), SuppressUnmanagedCodeSecurity]
1841 public static extern int WorldGetAutoEnableDepthSF1(IntPtr world);
1842
1843 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetCFM"), SuppressUnmanagedCodeSecurity]
1844 public static extern dReal WorldGetCFM(IntPtr world);
1845
1846 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetERP"), SuppressUnmanagedCodeSecurity]
1847 public static extern dReal WorldGetERP(IntPtr world);
1848
1849 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetGravity"), SuppressUnmanagedCodeSecurity]
1850 public static extern void WorldGetGravity(IntPtr world, out Vector3 gravity);
1851
1852 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetGravity"), SuppressUnmanagedCodeSecurity]
1853 public static extern void WorldGetGravity(IntPtr world, out dReal X);
1854
1855 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetContactMaxCorrectingVel"), SuppressUnmanagedCodeSecurity]
1856 public static extern dReal WorldGetContactMaxCorrectingVel(IntPtr world);
1857
1858 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetContactSurfaceLayer"), SuppressUnmanagedCodeSecurity]
1859 public static extern dReal WorldGetContactSurfaceLayer(IntPtr world);
1860
1861 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAngularDamping"), SuppressUnmanagedCodeSecurity]
1862 public static extern dReal WorldGetAngularDamping(IntPtr world);
1863
1864 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetAngularDampingThreshold"), SuppressUnmanagedCodeSecurity]
1865 public static extern dReal WorldGetAngularDampingThreshold(IntPtr world);
1866
1867 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetLinearDamping"), SuppressUnmanagedCodeSecurity]
1868 public static extern dReal WorldGetLinearDamping(IntPtr world);
1869
1870 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetLinearDampingThreshold"), SuppressUnmanagedCodeSecurity]
1871 public static extern dReal WorldGetLinearDampingThreshold(IntPtr world);
1872
1873 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetQuickStepNumIterations"), SuppressUnmanagedCodeSecurity]
1874 public static extern int WorldGetQuickStepNumIterations(IntPtr world);
1875
1876 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetQuickStepW"), SuppressUnmanagedCodeSecurity]
1877 public static extern dReal WorldGetQuickStepW(IntPtr world);
1878
1879 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldGetMaxAngularSpeed"), SuppressUnmanagedCodeSecurity]
1880 public static extern dReal WorldGetMaxAngularSpeed(IntPtr world);
1881
1882 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldImpulseToForce"), SuppressUnmanagedCodeSecurity]
1883 public static extern void WorldImpulseToForce(IntPtr world, dReal stepsize, dReal ix, dReal iy, dReal iz, out Vector3 force);
1884
1885 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldImpulseToForce"), SuppressUnmanagedCodeSecurity]
1886 public static extern void WorldImpulseToForce(IntPtr world, dReal stepsize, dReal ix, dReal iy, dReal iz, out dReal forceX);
1887
1888 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldQuickStep"), SuppressUnmanagedCodeSecurity]
1889 public static extern void WorldQuickStep(IntPtr world, dReal stepsize);
1890
1891 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAngularDamping"), SuppressUnmanagedCodeSecurity]
1892 public static extern void WorldSetAngularDamping(IntPtr world, dReal scale);
1893
1894 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAngularDampingThreshold"), SuppressUnmanagedCodeSecurity]
1895 public static extern void WorldSetAngularDampingThreshold(IntPtr world, dReal threshold);
1896
1897 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableAngularThreshold"), SuppressUnmanagedCodeSecurity]
1898 public static extern void WorldSetAutoDisableAngularThreshold(IntPtr world, dReal angular_threshold);
1899
1900 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableAverageSamplesCount"), SuppressUnmanagedCodeSecurity]
1901 public static extern void WorldSetAutoDisableAverageSamplesCount(IntPtr world, int average_samples_count);
1902
1903 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableFlag"), SuppressUnmanagedCodeSecurity]
1904 public static extern void WorldSetAutoDisableFlag(IntPtr world, bool do_auto_disable);
1905
1906 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableLinearThreshold"), SuppressUnmanagedCodeSecurity]
1907 public static extern void WorldSetAutoDisableLinearThreshold(IntPtr world, dReal linear_threshold);
1908
1909 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableSteps"), SuppressUnmanagedCodeSecurity]
1910 public static extern void WorldSetAutoDisableSteps(IntPtr world, int steps);
1911
1912 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoDisableTime"), SuppressUnmanagedCodeSecurity]
1913 public static extern void WorldSetAutoDisableTime(IntPtr world, dReal time);
1914
1915 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetAutoEnableDepthSF1"), SuppressUnmanagedCodeSecurity]
1916 public static extern void WorldSetAutoEnableDepthSF1(IntPtr world, int autoEnableDepth);
1917
1918 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetCFM"), SuppressUnmanagedCodeSecurity]
1919 public static extern void WorldSetCFM(IntPtr world, dReal cfm);
1920
1921 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetContactMaxCorrectingVel"), SuppressUnmanagedCodeSecurity]
1922 public static extern void WorldSetContactMaxCorrectingVel(IntPtr world, dReal vel);
1923
1924 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetContactSurfaceLayer"), SuppressUnmanagedCodeSecurity]
1925 public static extern void WorldSetContactSurfaceLayer(IntPtr world, dReal depth);
1926
1927 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetDamping"), SuppressUnmanagedCodeSecurity]
1928 public static extern void WorldSetDamping(IntPtr world, dReal linear_scale, dReal angular_scale);
1929
1930 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetERP"), SuppressUnmanagedCodeSecurity]
1931 public static extern void WorldSetERP(IntPtr world, dReal erp);
1932
1933 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetGravity"), SuppressUnmanagedCodeSecurity]
1934 public static extern void WorldSetGravity(IntPtr world, dReal x, dReal y, dReal z);
1935
1936 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetLinearDamping"), SuppressUnmanagedCodeSecurity]
1937 public static extern void WorldSetLinearDamping(IntPtr world, dReal scale);
1938
1939 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetLinearDampingThreshold"), SuppressUnmanagedCodeSecurity]
1940 public static extern void WorldSetLinearDampingThreshold(IntPtr world, dReal threshold);
1941
1942 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetQuickStepNumIterations"), SuppressUnmanagedCodeSecurity]
1943 public static extern void WorldSetQuickStepNumIterations(IntPtr world, int num);
1944
1945 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetQuickStepW"), SuppressUnmanagedCodeSecurity]
1946 public static extern void WorldSetQuickStepW(IntPtr world, dReal over_relaxation);
1947
1948 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldSetMaxAngularSpeed"), SuppressUnmanagedCodeSecurity]
1949 public static extern void WorldSetMaxAngularSpeed(IntPtr world, dReal max_speed);
1950
1951 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldStep"), SuppressUnmanagedCodeSecurity]
1952 public static extern void WorldStep(IntPtr world, dReal stepsize);
1953
1954 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldStepFast1"), SuppressUnmanagedCodeSecurity]
1955 public static extern void WorldStepFast1(IntPtr world, dReal stepsize, int maxiterations);
1956
1957 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dWorldExportDIF"), SuppressUnmanagedCodeSecurity]
1958 public static extern void WorldExportDIF(IntPtr world, string filename, bool append, string prefix);
1959 }
1960}
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..e60b006
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
@@ -0,0 +1,2742 @@
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 int ngeoms = d.NTotalGeoms;
1864
1865 // Finished with all sim stepping. If requested, dump world state to file for debugging.
1866 // TODO: This call to the export function is already inside lock (OdeLock) - but is an extra lock needed?
1867 // TODO: This overwrites all dump files in-place. Should this be a growing logfile, or separate snapshots?
1868 if (physics_logging && (physics_logging_interval > 0) && (framecount % physics_logging_interval == 0))
1869 {
1870 string fname = "state-" + world.ToString() + ".DIF"; // give each physics world a separate filename
1871 string prefix = "world" + world.ToString(); // prefix for variable names in exported .DIF file
1872
1873 if (physics_logging_append_existing_logfile)
1874 {
1875 string header = "-------------- START OF PHYSICS FRAME " + framecount.ToString() + " --------------";
1876 TextWriter fwriter = File.AppendText(fname);
1877 fwriter.WriteLine(header);
1878 fwriter.Close();
1879 }
1880
1881 d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix);
1882 }
1883
1884 // think time dilation is not a physics issue alone.. but ok let's fake something
1885 if (step_time < ODE_STEPSIZE) // we did the required loops
1886 m_timeDilation = 1.0f;
1887 else
1888 { // we didn't forget the lost ones and let user know something
1889 m_timeDilation = 1 - step_time / timeStep;
1890 if (m_timeDilation < 0)
1891 m_timeDilation = 0;
1892 step_time = 0;
1893 }
1894 }
1895
1896// return nodeframes * ODE_STEPSIZE; // return real simulated time
1897 return 1000 * nodeframes; // return steps for now * 1000 to keep core happy
1898 }
1899
1900 /// <summary>
1901 public override void GetResults()
1902 {
1903 }
1904
1905 public override bool IsThreaded
1906 {
1907 // for now we won't be multithreaded
1908 get { return (false); }
1909 }
1910
1911 #region ODE Specific Terrain Fixes
1912 public float[] ResizeTerrain512NearestNeighbour(float[] heightMap)
1913 {
1914 float[] returnarr = new float[262144];
1915 float[,] resultarr = new float[(int)WorldExtents.X, (int)WorldExtents.Y];
1916
1917 // Filling out the array into its multi-dimensional components
1918 for (int y = 0; y < WorldExtents.Y; y++)
1919 {
1920 for (int x = 0; x < WorldExtents.X; x++)
1921 {
1922 resultarr[y, x] = heightMap[y * (int)WorldExtents.Y + x];
1923 }
1924 }
1925
1926 // Resize using Nearest Neighbour
1927
1928 // This particular way is quick but it only works on a multiple of the original
1929
1930 // The idea behind this method can be described with the following diagrams
1931 // second pass and third pass happen in the same loop really.. just separated
1932 // them to show what this does.
1933
1934 // First Pass
1935 // ResultArr:
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 // 1,1,1,1,1,1
1942
1943 // Second Pass
1944 // ResultArr2:
1945 // 1,,1,,1,,1,,1,,1,
1946 // ,,,,,,,,,,
1947 // 1,,1,,1,,1,,1,,1,
1948 // ,,,,,,,,,,
1949 // 1,,1,,1,,1,,1,,1,
1950 // ,,,,,,,,,,
1951 // 1,,1,,1,,1,,1,,1,
1952 // ,,,,,,,,,,
1953 // 1,,1,,1,,1,,1,,1,
1954 // ,,,,,,,,,,
1955 // 1,,1,,1,,1,,1,,1,
1956
1957 // Third pass fills in the blanks
1958 // ResultArr2:
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 // 1,1,1,1,1,1,1,1,1,1,1,1
1970
1971 // X,Y = .
1972 // X+1,y = ^
1973 // X,Y+1 = *
1974 // X+1,Y+1 = #
1975
1976 // Filling in like this;
1977 // .*
1978 // ^#
1979 // 1st .
1980 // 2nd *
1981 // 3rd ^
1982 // 4th #
1983 // on single loop.
1984
1985 float[,] resultarr2 = new float[512, 512];
1986 for (int y = 0; y < WorldExtents.Y; y++)
1987 {
1988 for (int x = 0; x < WorldExtents.X; x++)
1989 {
1990 resultarr2[y * 2, x * 2] = resultarr[y, x];
1991
1992 if (y < WorldExtents.Y)
1993 {
1994 resultarr2[(y * 2) + 1, x * 2] = resultarr[y, x];
1995 }
1996 if (x < WorldExtents.X)
1997 {
1998 resultarr2[y * 2, (x * 2) + 1] = resultarr[y, x];
1999 }
2000 if (x < WorldExtents.X && y < WorldExtents.Y)
2001 {
2002 resultarr2[(y * 2) + 1, (x * 2) + 1] = resultarr[y, x];
2003 }
2004 }
2005 }
2006
2007 //Flatten out the array
2008 int i = 0;
2009 for (int y = 0; y < 512; y++)
2010 {
2011 for (int x = 0; x < 512; x++)
2012 {
2013 if (resultarr2[y, x] <= 0)
2014 returnarr[i] = 0.0000001f;
2015 else
2016 returnarr[i] = resultarr2[y, x];
2017
2018 i++;
2019 }
2020 }
2021
2022 return returnarr;
2023 }
2024
2025 public float[] ResizeTerrain512Interpolation(float[] heightMap)
2026 {
2027 float[] returnarr = new float[262144];
2028 float[,] resultarr = new float[512,512];
2029
2030 // Filling out the array into its multi-dimensional components
2031 for (int y = 0; y < 256; y++)
2032 {
2033 for (int x = 0; x < 256; x++)
2034 {
2035 resultarr[y, x] = heightMap[y * 256 + x];
2036 }
2037 }
2038
2039 // Resize using interpolation
2040
2041 // This particular way is quick but it only works on a multiple of the original
2042
2043 // The idea behind this method can be described with the following diagrams
2044 // second pass and third pass happen in the same loop really.. just separated
2045 // them to show what this does.
2046
2047 // First Pass
2048 // ResultArr:
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 // 1,1,1,1,1,1
2055
2056 // Second Pass
2057 // ResultArr2:
2058 // 1,,1,,1,,1,,1,,1,
2059 // ,,,,,,,,,,
2060 // 1,,1,,1,,1,,1,,1,
2061 // ,,,,,,,,,,
2062 // 1,,1,,1,,1,,1,,1,
2063 // ,,,,,,,,,,
2064 // 1,,1,,1,,1,,1,,1,
2065 // ,,,,,,,,,,
2066 // 1,,1,,1,,1,,1,,1,
2067 // ,,,,,,,,,,
2068 // 1,,1,,1,,1,,1,,1,
2069
2070 // Third pass fills in the blanks
2071 // ResultArr2:
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 // 1,1,1,1,1,1,1,1,1,1,1,1
2083
2084 // X,Y = .
2085 // X+1,y = ^
2086 // X,Y+1 = *
2087 // X+1,Y+1 = #
2088
2089 // Filling in like this;
2090 // .*
2091 // ^#
2092 // 1st .
2093 // 2nd *
2094 // 3rd ^
2095 // 4th #
2096 // on single loop.
2097
2098 float[,] resultarr2 = new float[512,512];
2099 for (int y = 0; y < (int)Constants.RegionSize; y++)
2100 {
2101 for (int x = 0; x < (int)Constants.RegionSize; x++)
2102 {
2103 resultarr2[y*2, x*2] = resultarr[y, x];
2104
2105 if (y < (int)Constants.RegionSize)
2106 {
2107 if (y + 1 < (int)Constants.RegionSize)
2108 {
2109 if (x + 1 < (int)Constants.RegionSize)
2110 {
2111 resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x] +
2112 resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4);
2113 }
2114 else
2115 {
2116 resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x])/2);
2117 }
2118 }
2119 else
2120 {
2121 resultarr2[(y*2) + 1, x*2] = resultarr[y, x];
2122 }
2123 }
2124 if (x < (int)Constants.RegionSize)
2125 {
2126 if (x + 1 < (int)Constants.RegionSize)
2127 {
2128 if (y + 1 < (int)Constants.RegionSize)
2129 {
2130 resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] +
2131 resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4);
2132 }
2133 else
2134 {
2135 resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y, x + 1])/2);
2136 }
2137 }
2138 else
2139 {
2140 resultarr2[y*2, (x*2) + 1] = resultarr[y, x];
2141 }
2142 }
2143 if (x < (int)Constants.RegionSize && y < (int)Constants.RegionSize)
2144 {
2145 if ((x + 1 < (int)Constants.RegionSize) && (y + 1 < (int)Constants.RegionSize))
2146 {
2147 resultarr2[(y*2) + 1, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] +
2148 resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4);
2149 }
2150 else
2151 {
2152 resultarr2[(y*2) + 1, (x*2) + 1] = resultarr[y, x];
2153 }
2154 }
2155 }
2156 }
2157 //Flatten out the array
2158 int i = 0;
2159 for (int y = 0; y < 512; y++)
2160 {
2161 for (int x = 0; x < 512; x++)
2162 {
2163 if (Single.IsNaN(resultarr2[y, x]) || Single.IsInfinity(resultarr2[y, x]))
2164 {
2165 m_log.Warn("[PHYSICS]: Non finite heightfield element detected. Setting it to 0");
2166 resultarr2[y, x] = 0;
2167 }
2168 returnarr[i] = resultarr2[y, x];
2169 i++;
2170 }
2171 }
2172
2173 return returnarr;
2174 }
2175
2176 #endregion
2177
2178 public override void SetTerrain(float[] heightMap)
2179 {
2180 if (m_worldOffset != Vector3.Zero && m_parentScene != null)
2181 {
2182 if (m_parentScene is OdeScene)
2183 {
2184 ((OdeScene)m_parentScene).SetTerrain(heightMap, m_worldOffset);
2185 }
2186 }
2187 else
2188 {
2189 SetTerrain(heightMap, m_worldOffset);
2190 }
2191 }
2192
2193 public override void CombineTerrain(float[] heightMap, Vector3 pOffset)
2194 {
2195 SetTerrain(heightMap, pOffset);
2196 }
2197
2198 public void SetTerrain(float[] heightMap, Vector3 pOffset)
2199 {
2200
2201 float[] _heightmap;
2202 _heightmap = new float[(((int)Constants.RegionSize + 2) * ((int)Constants.RegionSize + 2))];
2203
2204 uint heightmapWidth = Constants.RegionSize + 2;
2205 uint heightmapHeight = Constants.RegionSize + 2;
2206
2207 uint heightmapWidthSamples;
2208
2209 uint heightmapHeightSamples;
2210
2211 heightmapWidthSamples = (uint)Constants.RegionSize + 2;
2212 heightmapHeightSamples = (uint)Constants.RegionSize + 2;
2213
2214 const float scale = 1.0f;
2215 const float offset = 0.0f;
2216 const float thickness = 10f;
2217 const int wrap = 0;
2218
2219 int regionsize = (int) Constants.RegionSize + 2;
2220
2221 float hfmin = float.MaxValue;
2222 float hfmax = float.MinValue;
2223 float val;
2224 int xx;
2225 int yy;
2226
2227 int maxXXYY = regionsize - 3;
2228 // flipping map adding one margin all around so things don't fall in edges
2229
2230 int xt = 0;
2231 xx = 0;
2232
2233 for (int x = 0; x < heightmapWidthSamples; x++)
2234 {
2235 if (x > 1 && xx < maxXXYY)
2236 xx++;
2237 yy = 0;
2238 for (int y = 0; y < heightmapHeightSamples; y++)
2239 {
2240 if (y > 1 && y < maxXXYY)
2241 yy += (int)Constants.RegionSize;
2242
2243 val = heightMap[yy + xx];
2244 _heightmap[xt + y] = val;
2245
2246 if (hfmin > val)
2247 hfmin = val;
2248 if (hfmax < val)
2249 hfmax = val;
2250
2251 }
2252
2253 xt += regionsize;
2254 }
2255 lock (OdeLock)
2256 {
2257 IntPtr GroundGeom = IntPtr.Zero;
2258 if (RegionTerrain.TryGetValue(pOffset, out GroundGeom))
2259 {
2260 RegionTerrain.Remove(pOffset);
2261 if (GroundGeom != IntPtr.Zero)
2262 {
2263 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
2264 {
2265 TerrainHeightFieldHeightsHandlers[GroundGeom].Free();
2266 TerrainHeightFieldHeightsHandlers.Remove(GroundGeom);
2267 TerrainHeightFieldHeights.Remove(GroundGeom);
2268 }
2269 d.SpaceRemove(StaticSpace, GroundGeom);
2270 d.GeomDestroy(GroundGeom);
2271 }
2272 }
2273 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
2274
2275 GCHandle _heightmaphandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned);
2276
2277 d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmaphandler.AddrOfPinnedObject(), 0, heightmapWidth , heightmapHeight,
2278 (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale,
2279 offset, thickness, wrap);
2280
2281 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
2282 GroundGeom = d.CreateHeightfield(StaticSpace, HeightmapData, 1);
2283 if (GroundGeom != IntPtr.Zero)
2284 {
2285 d.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land));
2286 d.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space));
2287
2288 }
2289 geom_name_map[GroundGeom] = "Terrain";
2290
2291 d.Matrix3 R = new d.Matrix3();
2292
2293 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
2294 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
2295
2296
2297 q1 = q1 * q2;
2298
2299 Vector3 v3;
2300 float angle;
2301 q1.GetAxisAngle(out v3, out angle);
2302
2303 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
2304 d.GeomSetRotation(GroundGeom, ref R);
2305 d.GeomSetPosition(GroundGeom, pOffset.X + (float)Constants.RegionSize * 0.5f - 0.5f, pOffset.Y + (float)Constants.RegionSize * 0.5f - 0.5f, 0);
2306 IntPtr testGround = IntPtr.Zero;
2307 if (RegionTerrain.TryGetValue(pOffset, out testGround))
2308 {
2309 RegionTerrain.Remove(pOffset);
2310 }
2311 RegionTerrain.Add(pOffset, GroundGeom, GroundGeom);
2312// TerrainHeightFieldHeights.Add(GroundGeom, ODElandMap);
2313 TerrainHeightFieldHeights.Add(GroundGeom, _heightmap);
2314 TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler);
2315
2316 }
2317 }
2318
2319 public override void DeleteTerrain()
2320 {
2321 }
2322
2323 public float GetWaterLevel()
2324 {
2325 return waterlevel;
2326 }
2327
2328 public override bool SupportsCombining()
2329 {
2330 return true;
2331 }
2332/*
2333 public override void UnCombine(PhysicsScene pScene)
2334 {
2335 IntPtr localGround = IntPtr.Zero;
2336// float[] localHeightfield;
2337 bool proceed = false;
2338 List<IntPtr> geomDestroyList = new List<IntPtr>();
2339
2340 lock (OdeLock)
2341 {
2342 if (RegionTerrain.TryGetValue(Vector3.Zero, out localGround))
2343 {
2344 foreach (IntPtr geom in TerrainHeightFieldHeights.Keys)
2345 {
2346 if (geom == localGround)
2347 {
2348// localHeightfield = TerrainHeightFieldHeights[geom];
2349 proceed = true;
2350 }
2351 else
2352 {
2353 geomDestroyList.Add(geom);
2354 }
2355 }
2356
2357 if (proceed)
2358 {
2359 m_worldOffset = Vector3.Zero;
2360 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize);
2361 m_parentScene = null;
2362
2363 foreach (IntPtr g in geomDestroyList)
2364 {
2365 // removingHeightField needs to be done or the garbage collector will
2366 // collect the terrain data before we tell ODE to destroy it causing
2367 // memory corruption
2368 if (TerrainHeightFieldHeights.ContainsKey(g))
2369 {
2370// float[] removingHeightField = TerrainHeightFieldHeights[g];
2371 TerrainHeightFieldHeights.Remove(g);
2372
2373 if (RegionTerrain.ContainsKey(g))
2374 {
2375 RegionTerrain.Remove(g);
2376 }
2377
2378 d.GeomDestroy(g);
2379 //removingHeightField = new float[0];
2380 }
2381 }
2382
2383 }
2384 else
2385 {
2386 m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data.");
2387 }
2388 }
2389 }
2390 }
2391*/
2392 public override void SetWaterLevel(float baseheight)
2393 {
2394 waterlevel = baseheight;
2395 randomizeWater(waterlevel);
2396 }
2397
2398 public void randomizeWater(float baseheight)
2399 {
2400 const uint heightmapWidth = m_regionWidth + 2;
2401 const uint heightmapHeight = m_regionHeight + 2;
2402 const uint heightmapWidthSamples = m_regionWidth + 2;
2403 const uint heightmapHeightSamples = m_regionHeight + 2;
2404 const float scale = 1.0f;
2405 const float offset = 0.0f;
2406 const float thickness = 2.9f;
2407 const int wrap = 0;
2408
2409 for (int i = 0; i < (258 * 258); i++)
2410 {
2411 _watermap[i] = (baseheight-0.1f) + ((float)fluidRandomizer.Next(1,9) / 10f);
2412 // m_log.Info((baseheight - 0.1f) + ((float)fluidRandomizer.Next(1, 9) / 10f));
2413 }
2414
2415 lock (OdeLock)
2416 {
2417 if (WaterGeom != IntPtr.Zero)
2418 {
2419 d.SpaceRemove(StaticSpace, WaterGeom);
2420 }
2421 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
2422 d.GeomHeightfieldDataBuildSingle(HeightmapData, _watermap, 0, heightmapWidth, heightmapHeight,
2423 (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale,
2424 offset, thickness, wrap);
2425 d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight);
2426 WaterGeom = d.CreateHeightfield(StaticSpace, HeightmapData, 1);
2427 if (WaterGeom != IntPtr.Zero)
2428 {
2429 d.GeomSetCategoryBits(WaterGeom, (int)(CollisionCategories.Water));
2430 d.GeomSetCollideBits(WaterGeom, (int)(CollisionCategories.Space));
2431
2432 }
2433 geom_name_map[WaterGeom] = "Water";
2434
2435 d.Matrix3 R = new d.Matrix3();
2436
2437 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
2438 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
2439
2440 q1 = q1 * q2;
2441 Vector3 v3;
2442 float angle;
2443 q1.GetAxisAngle(out v3, out angle);
2444
2445 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
2446 d.GeomSetRotation(WaterGeom, ref R);
2447 d.GeomSetPosition(WaterGeom, 128, 128, 0);
2448
2449 }
2450
2451 }
2452
2453 public override void Dispose()
2454 {
2455 m_rayCastManager.Dispose();
2456 m_rayCastManager = null;
2457
2458 lock (OdeLock)
2459 {
2460 lock (_prims)
2461 {
2462 foreach (OdePrim prm in _prims)
2463 {
2464 RemovePrim(prm);
2465 }
2466 }
2467
2468 if (ContactgeomsArray != IntPtr.Zero)
2469 Marshal.FreeHGlobal(ContactgeomsArray);
2470 if (GlobalContactsArray != IntPtr.Zero)
2471 Marshal.FreeHGlobal(GlobalContactsArray);
2472
2473 d.WorldDestroy(world);
2474 //d.CloseODE();
2475 }
2476 }
2477
2478 public override Dictionary<uint, float> GetTopColliders()
2479 {
2480 Dictionary<uint, float> returncolliders = new Dictionary<uint, float>();
2481 int cnt = 0;
2482 lock (_prims)
2483 {
2484 foreach (OdePrim prm in _prims)
2485 {
2486 if (prm.CollisionScore > 0)
2487 {
2488 returncolliders.Add(prm.m_localID, prm.CollisionScore);
2489 cnt++;
2490 prm.CollisionScore = 0f;
2491 if (cnt > 25)
2492 {
2493 break;
2494 }
2495 }
2496 }
2497 }
2498 return returncolliders;
2499 }
2500
2501 public override bool SupportsRayCast()
2502 {
2503 return true;
2504 }
2505
2506 public override void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
2507 {
2508 if (retMethod != null)
2509 {
2510 m_rayCastManager.QueueRequest(position, direction, length, retMethod);
2511 }
2512 }
2513
2514 public override void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod)
2515 {
2516 if (retMethod != null)
2517 {
2518 m_rayCastManager.QueueRequest(position, direction, length, Count, retMethod);
2519 }
2520 }
2521
2522 // don't like this
2523 public override List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count)
2524 {
2525 ContactResult[] ourResults = null;
2526 RayCallback retMethod = delegate(List<ContactResult> results)
2527 {
2528 ourResults = new ContactResult[results.Count];
2529 results.CopyTo(ourResults, 0);
2530 };
2531 int waitTime = 0;
2532 m_rayCastManager.QueueRequest(position, direction, length, Count, retMethod);
2533 while (ourResults == null && waitTime < 1000)
2534 {
2535 Thread.Sleep(1);
2536 waitTime++;
2537 }
2538 if (ourResults == null)
2539 return new List<ContactResult>();
2540 return new List<ContactResult>(ourResults);
2541 }
2542
2543 public override void RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
2544 {
2545 if (retMethod != null && actor !=null)
2546 {
2547 IntPtr geom;
2548 if (actor is OdePrim)
2549 geom = ((OdePrim)actor).prim_geom;
2550 else if (actor is OdeCharacter)
2551 geom = ((OdePrim)actor).prim_geom;
2552 else
2553 return;
2554 if (geom == IntPtr.Zero)
2555 return;
2556 m_rayCastManager.QueueRequest(geom, position, direction, length, retMethod);
2557 }
2558 }
2559
2560 public override void RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod)
2561 {
2562 if (retMethod != null && actor != null)
2563 {
2564 IntPtr geom;
2565 if (actor is OdePrim)
2566 geom = ((OdePrim)actor).prim_geom;
2567 else if (actor is OdeCharacter)
2568 geom = ((OdePrim)actor).prim_geom;
2569 else
2570 return;
2571 if (geom == IntPtr.Zero)
2572 return;
2573
2574 m_rayCastManager.QueueRequest(geom,position, direction, length, Count, retMethod);
2575 }
2576 }
2577
2578 // don't like this
2579 public override List<ContactResult> RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, int Count)
2580 {
2581 if (actor != null)
2582 {
2583 IntPtr geom;
2584 if (actor is OdePrim)
2585 geom = ((OdePrim)actor).prim_geom;
2586 else if (actor is OdeCharacter)
2587 geom = ((OdePrim)actor).prim_geom;
2588 else
2589 return new List<ContactResult>();
2590 if (geom == IntPtr.Zero)
2591 return new List<ContactResult>();
2592
2593 ContactResult[] ourResults = null;
2594 RayCallback retMethod = delegate(List<ContactResult> results)
2595 {
2596 ourResults = new ContactResult[results.Count];
2597 results.CopyTo(ourResults, 0);
2598 };
2599 int waitTime = 0;
2600 m_rayCastManager.QueueRequest(geom,position, direction, length, Count, retMethod);
2601 while (ourResults == null && waitTime < 1000)
2602 {
2603 Thread.Sleep(1);
2604 waitTime++;
2605 }
2606 if (ourResults == null)
2607 return new List<ContactResult>();
2608 return new List<ContactResult>(ourResults);
2609 }
2610 return new List<ContactResult>();
2611 }
2612
2613#if USE_DRAWSTUFF
2614 // Keyboard callback
2615 public void command(int cmd)
2616 {
2617 IntPtr geom;
2618 d.Mass mass;
2619 d.Vector3 sides = new d.Vector3(d.RandReal() * 0.5f + 0.1f, d.RandReal() * 0.5f + 0.1f, d.RandReal() * 0.5f + 0.1f);
2620
2621
2622
2623 Char ch = Char.ToLower((Char)cmd);
2624 switch ((Char)ch)
2625 {
2626 case 'w':
2627 try
2628 {
2629 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));
2630
2631 xyz.X += rotate.X; xyz.Y += rotate.Y; xyz.Z += rotate.Z;
2632 ds.SetViewpoint(ref xyz, ref hpr);
2633 }
2634 catch (ArgumentException)
2635 { hpr.X = 0; }
2636 break;
2637
2638 case 'a':
2639 hpr.X++;
2640 ds.SetViewpoint(ref xyz, ref hpr);
2641 break;
2642
2643 case 's':
2644 try
2645 {
2646 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));
2647
2648 xyz.X += rotate2.X; xyz.Y += rotate2.Y; xyz.Z += rotate2.Z;
2649 ds.SetViewpoint(ref xyz, ref hpr);
2650 }
2651 catch (ArgumentException)
2652 { hpr.X = 0; }
2653 break;
2654 case 'd':
2655 hpr.X--;
2656 ds.SetViewpoint(ref xyz, ref hpr);
2657 break;
2658 case 'r':
2659 xyz.Z++;
2660 ds.SetViewpoint(ref xyz, ref hpr);
2661 break;
2662 case 'f':
2663 xyz.Z--;
2664 ds.SetViewpoint(ref xyz, ref hpr);
2665 break;
2666 case 'e':
2667 xyz.Y++;
2668 ds.SetViewpoint(ref xyz, ref hpr);
2669 break;
2670 case 'q':
2671 xyz.Y--;
2672 ds.SetViewpoint(ref xyz, ref hpr);
2673 break;
2674 }
2675 }
2676
2677 public void step(int pause)
2678 {
2679
2680 ds.SetColor(1.0f, 1.0f, 0.0f);
2681 ds.SetTexture(ds.Texture.Wood);
2682 lock (_prims)
2683 {
2684 foreach (OdePrim prm in _prims)
2685 {
2686 //IntPtr body = d.GeomGetBody(prm.prim_geom);
2687 if (prm.prim_geom != IntPtr.Zero)
2688 {
2689 d.Vector3 pos;
2690 d.GeomCopyPosition(prm.prim_geom, out pos);
2691 //d.BodyCopyPosition(body, out pos);
2692
2693 d.Matrix3 R;
2694 d.GeomCopyRotation(prm.prim_geom, out R);
2695 //d.BodyCopyRotation(body, out R);
2696
2697
2698 d.Vector3 sides = new d.Vector3();
2699 sides.X = prm.Size.X;
2700 sides.Y = prm.Size.Y;
2701 sides.Z = prm.Size.Z;
2702
2703 ds.DrawBox(ref pos, ref R, ref sides);
2704 }
2705 }
2706 }
2707 ds.SetColor(1.0f, 0.0f, 0.0f);
2708 lock (_characters)
2709 {
2710 foreach (OdeCharacter chr in _characters)
2711 {
2712 if (chr.Shell != IntPtr.Zero)
2713 {
2714 IntPtr body = d.GeomGetBody(chr.Shell);
2715
2716 d.Vector3 pos;
2717 d.GeomCopyPosition(chr.Shell, out pos);
2718 //d.BodyCopyPosition(body, out pos);
2719
2720 d.Matrix3 R;
2721 d.GeomCopyRotation(chr.Shell, out R);
2722 //d.BodyCopyRotation(body, out R);
2723
2724 ds.DrawCapsule(ref pos, ref R, chr.Size.Z, 0.35f);
2725 d.Vector3 sides = new d.Vector3();
2726 sides.X = 0.5f;
2727 sides.Y = 0.5f;
2728 sides.Z = 0.5f;
2729
2730 ds.DrawBox(ref pos, ref R, ref sides);
2731 }
2732 }
2733 }
2734 }
2735
2736 public void start(int unused)
2737 {
2738 ds.SetViewpoint(ref xyz, ref hpr);
2739 }
2740#endif
2741 }
2742}
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}
diff --git a/bin/Physics/OpenSim.Region.Physics.UbitOdePlugin.dll.config b/bin/Physics/OpenSim.Region.Physics.UbitOdePlugin.dll.config
new file mode 100644
index 0000000..f8f071e
--- /dev/null
+++ b/bin/Physics/OpenSim.Region.Physics.UbitOdePlugin.dll.config
@@ -0,0 +1,7 @@
1<configuration>
2 <dllmap os="osx" dll="ode" target="libode.dylib" />
3 <dllmap os="!windows,osx" cpu="x86-64,ia64" dll="ode" target="libode-x86_64" />
4 <dllmap os="!windows,osx" cpu="x86" dll="ode" target="libode" />
5 <dllmap os="!windows,osx" cpu="ppc64" dll="ode" target="libode-ppc64" />
6 <dllmap os="!windows,osx" cpu="s390x" dll="ode" target="libode-s390x" />
7</configuration> \ No newline at end of file
diff --git a/bin/Physics/libode-x86_64.so b/bin/Physics/libode-x86_64.so
new file mode 100644
index 0000000..9c3070a
--- /dev/null
+++ b/bin/Physics/libode-x86_64.so
Binary files differ
diff --git a/bin/Physics/libode.so b/bin/Physics/libode.so
new file mode 100644
index 0000000..6bb85fb
--- /dev/null
+++ b/bin/Physics/libode.so
Binary files differ
diff --git a/prebuild.xml b/prebuild.xml
index 77cae6e..e666311 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -1,12 +1,12 @@
1<?xml version="1.0" ?> 1<?xml version="1.0" ?>
2<Prebuild version="1.7" xmlns="http://dnpb.sourceforge.net/schemas/prebuild-1.7.xsd"> 2<Prebuild version="1.7" xmlns="http://dnpb.sourceforge.net/schemas/prebuild-1.7.xsd">
3 <Solution activeConfig="Debug" name="OpenSim" path="./" version="0.5.0-$Rev$"> 3 <Solution activeConfig="Debug" name="Careminster" path="./" version="0.5.0-$Rev$">
4 <Configuration name="Debug"> 4 <Configuration name="Debug">
5 <Options> 5 <Options>
6 <CompilerDefines>TRACE;DEBUG</CompilerDefines> 6 <CompilerDefines>TRACE;DEBUG</CompilerDefines>
7 <OptimizeCode>false</OptimizeCode> 7 <OptimizeCode>false</OptimizeCode>
8 <CheckUnderflowOverflow>false</CheckUnderflowOverflow> 8 <CheckUnderflowOverflow>false</CheckUnderflowOverflow>
9 <AllowUnsafe>false</AllowUnsafe> 9 <AllowUnsafe>true</AllowUnsafe>
10 <WarningLevel>4</WarningLevel> 10 <WarningLevel>4</WarningLevel>
11 <WarningsAsErrors>false</WarningsAsErrors> 11 <WarningsAsErrors>false</WarningsAsErrors>
12 <SuppressWarnings/> 12 <SuppressWarnings/>
@@ -606,6 +606,36 @@
606 </Files> 606 </Files>
607 </Project> 607 </Project>
608 608
609 <Project frameworkVersion="v3_5" name="OpenSim.Region.Physics.UbitOdePlugin" path="OpenSim/Region/Physics/UbitOdePlugin" type="Library">
610 <Configuration name="Debug">
611 <Options>
612 <OutputPath>../../../../bin/Physics/</OutputPath>
613 </Options>
614 </Configuration>
615 <Configuration name="Release">
616 <Options>
617 <OutputPath>../../../../bin/Physics/</OutputPath>
618 </Options>
619 </Configuration>
620
621 <ReferencePath>../../../../bin/</ReferencePath>
622 <Reference name="System"/>
623 <Reference name="System.Core"/>
624 <Reference name="OpenMetaverseTypes" path="../../../../bin/"/>
625 <Reference name="Nini" path="../../../../bin/"/>
626
627 <Reference name="OpenSim.Framework"/>
628 <Reference name="OpenSim.Framework.Console"/>
629 <Reference name="OpenSim.Region.Physics.Manager"/>
630 <Reference name="log4net" path="../../../../bin/"/>
631
632 <Files>
633 <Match pattern="*.cs" recurse="true">
634 <Exclude name="Tests" pattern="Tests"/>
635 </Match>
636 </Files>
637 </Project>
638
609 <Project frameworkVersion="v3_5" name="OpenSim.Region.Physics.ConvexDecompositionDotNet" path="OpenSim/Region/Physics/ConvexDecompositionDotNet" type="Library"> 639 <Project frameworkVersion="v3_5" name="OpenSim.Region.Physics.ConvexDecompositionDotNet" path="OpenSim/Region/Physics/ConvexDecompositionDotNet" type="Library">
610 <Configuration name="Debug"> 640 <Configuration name="Debug">
611 <Options> 641 <Options>
@@ -3316,16 +3346,12 @@
3316 <Reference name="OpenMetaverse.StructuredData" path="../../../bin/"/> 3346 <Reference name="OpenMetaverse.StructuredData" path="../../../bin/"/>
3317 <Reference name="XMLRPC" path="../../../bin/"/> 3347 <Reference name="XMLRPC" path="../../../bin/"/>
3318 <Reference name="OpenSim.Framework"/> 3348 <Reference name="OpenSim.Framework"/>
3319 <Reference name="OpenSim.Framework.Communications"/>
3320 <Reference name="OpenSim.Framework.Console"/> 3349 <Reference name="OpenSim.Framework.Console"/>
3321 <Reference name="OpenSim.Framework.Servers.HttpServer"/> 3350 <Reference name="OpenSim.Framework.Servers.HttpServer"/>
3322 <Reference name="OpenSim.Region.CoreModules"/> 3351 <Reference name="OpenSim.Region.CoreModules"/>
3323 <Reference name="OpenSim.Region.Framework"/> 3352 <Reference name="OpenSim.Region.Framework"/>
3324 <Reference name="OpenSim.Region.OptionalModules"/>
3325 <Reference name="OpenSim.Region.ScriptEngine.Shared"/>
3326 <Reference name="OpenSim.Region.ScriptEngine.XEngine"/> 3353 <Reference name="OpenSim.Region.ScriptEngine.XEngine"/>
3327 <Reference name="OpenSim.Services.Interfaces"/> 3354 <Reference name="OpenSim.Region.ScriptEngine.Shared"/>
3328 <Reference name="OpenSim.Services.AvatarService"/>
3329 <Reference name="OpenSim.Tests.Common"/> 3355 <Reference name="OpenSim.Tests.Common"/>
3330 <Files> 3356 <Files>
3331 <Match pattern="*.cs" recurse="false"/> 3357 <Match pattern="*.cs" recurse="false"/>
diff --git a/runprebuild.bat b/runprebuild.bat
index 8927e9a..cfa5199 100755
--- a/runprebuild.bat
+++ b/runprebuild.bat
@@ -1,4 +1,4 @@
1bin\Prebuild.exe /target nant 1bin\Prebuild.exe /target nant
2bin\Prebuild.exe /target vs2008 2bin\Prebuild.exe /target vs2008
3echo C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild opensim.sln > compile.bat 3echo C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild Careminster.sln > compile.bat
4 4
diff --git a/runprebuild2010.bat b/runprebuild2010.bat
index 8c832b3..1e1caaa 100755
--- a/runprebuild2010.bat
+++ b/runprebuild2010.bat
@@ -1,2 +1,2 @@
1bin\Prebuild.exe /target vs2010 1bin\Prebuild.exe /target vs2010
2echo C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild OpenSim.sln > compile.bat 2echo C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild Careminster.sln > compile.bat