aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/SharedBase
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/PhysicsModules/SharedBase
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Region/PhysicsModules/SharedBase')
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/AssemblyInfo.cs58
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/CollisionLocker.cs73
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/IMesher.cs71
-rwxr-xr-xOpenSim/Region/PhysicsModules/SharedBase/IPhysicsParameters.cs73
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/NullPhysicsScene.cs117
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs584
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/PhysicsJoint.cs55
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs358
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/PhysicsSensor.cs78
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/PhysicsVector.cs186
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/VehicleConstants.cs121
11 files changed, 1774 insertions, 0 deletions
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/AssemblyInfo.cs b/OpenSim/Region/PhysicsModules/SharedBase/AssemblyInfo.cs
new file mode 100644
index 0000000..33f60e4
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/SharedBase/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("PhysicsManager")]
38[assembly : AssemblyDescription("")]
39[assembly : AssemblyConfiguration("")]
40[assembly : AssemblyCompany("http://opensimulator.org")]
41[assembly : AssemblyProduct("PhysicsManager")]
42[assembly : AssemblyCopyright("Copyright (c) OpenSimulator.org Developers")]
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.8.2.*")]
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/CollisionLocker.cs b/OpenSim/Region/PhysicsModules/SharedBase/CollisionLocker.cs
new file mode 100644
index 0000000..6e658b5
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/SharedBase/CollisionLocker.cs
@@ -0,0 +1,73 @@
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;
30
31namespace OpenSim.Region.PhysicsModules.SharedBase
32{
33 public class CollisionLocker
34 {
35 private List<IntPtr> worldlock = new List<IntPtr>();
36
37 public CollisionLocker()
38 {
39
40 }
41
42 public void dlock(IntPtr world)
43 {
44 lock (worldlock)
45 {
46 worldlock.Add(world);
47 }
48
49 }
50
51 public void dunlock(IntPtr world)
52 {
53 lock (worldlock)
54 {
55 worldlock.Remove(world);
56 }
57 }
58
59 public bool lockquery()
60 {
61 return (worldlock.Count > 0);
62 }
63
64 public void drelease(IntPtr world)
65 {
66 lock (worldlock)
67 {
68 if (worldlock.Contains(world))
69 worldlock.Remove(world);
70 }
71 }
72 }
73}
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/IMesher.cs b/OpenSim/Region/PhysicsModules/SharedBase/IMesher.cs
new file mode 100644
index 0000000..5c75307
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/SharedBase/IMesher.cs
@@ -0,0 +1,71 @@
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 OpenSim.Framework;
31using OpenMetaverse;
32
33namespace OpenSim.Region.PhysicsModules.SharedBase
34{
35 public interface IMesher
36 {
37 IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod);
38 IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical);
39 IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache);
40 }
41
42 // Values for level of detail to be passed to the mesher.
43 // Values origionally chosen for the LOD of sculpties (the sqrt(width*heigth) of sculpt texture)
44 // Lower level of detail reduces the number of vertices used to represent the meshed shape.
45 public enum LevelOfDetail
46 {
47 High = 32,
48 Medium = 16,
49 Low = 8,
50 VeryLow = 4
51 }
52
53 public interface IVertex
54 {
55 }
56
57 public interface IMesh
58 {
59 List<Vector3> getVertexList();
60 int[] getIndexListAsInt();
61 int[] getIndexListAsIntLocked();
62 float[] getVertexListAsFloat();
63 float[] getVertexListAsFloatLocked();
64 void getIndexListAsPtrToIntArray(out IntPtr indices, out int triStride, out int indexCount);
65 void getVertexListAsPtrToFloatArray(out IntPtr vertexList, out int vertexStride, out int vertexCount);
66 void releaseSourceMeshData();
67 void releasePinned();
68 void Append(IMesh newMesh);
69 void TransformLinear(float[,] matrix, float[] offset);
70 }
71}
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/IPhysicsParameters.cs b/OpenSim/Region/PhysicsModules/SharedBase/IPhysicsParameters.cs
new file mode 100755
index 0000000..fb0c9e2
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/SharedBase/IPhysicsParameters.cs
@@ -0,0 +1,73 @@
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 OpenSim.Framework;
31using OpenMetaverse;
32
33namespace OpenSim.Region.PhysicsModules.SharedBase
34{
35 public struct PhysParameterEntry
36 {
37 // flags to say to apply to all or no instances (I wish one could put consts into interfaces)
38 public const uint APPLY_TO_ALL = 0xfffffff3;
39 public const uint APPLY_TO_NONE = 0xfffffff4;
40
41 // values that denote true and false values
42 public const float NUMERIC_TRUE = 1f;
43 public const float NUMERIC_FALSE = 0f;
44
45 public string name;
46 public string desc;
47
48 public PhysParameterEntry(string n, string d)
49 {
50 name = n;
51 desc = d;
52 }
53 }
54
55 // Interface for a physics scene that implements the runtime setting and getting of physics parameters
56 public interface IPhysicsParameters
57 {
58 // Get the list of parameters this physics engine supports
59 PhysParameterEntry[] GetParameterList();
60
61 // Set parameter on a specific or all instances.
62 // Return 'false' if not able to set the parameter.
63 bool SetPhysicsParameter(string parm, string value, uint localID);
64
65 // Get parameter.
66 // Return 'false' if not able to get the parameter.
67 bool GetPhysicsParameter(string parm, out string value);
68
69 // Get parameter from a particular object
70 // TODO:
71 // bool GetPhysicsParameter(string parm, out string value, uint localID);
72 }
73}
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/NullPhysicsScene.cs b/OpenSim/Region/PhysicsModules/SharedBase/NullPhysicsScene.cs
new file mode 100644
index 0000000..432708c
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/SharedBase/NullPhysicsScene.cs
@@ -0,0 +1,117 @@
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.Collections.Generic;
29using System.Reflection;
30using log4net;
31using Nini.Config;
32using OpenSim.Framework;
33using OpenMetaverse;
34
35namespace OpenSim.Region.PhysicsModules.SharedBase
36{
37 class NullPhysicsScene : PhysicsScene
38 {
39 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
40
41 private static int m_workIndicator;
42
43 public override PhysicsActor AddAvatar(
44 string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
45 {
46 m_log.InfoFormat("[PHYSICS]: NullPhysicsScene : AddAvatar({0})", position);
47 return PhysicsActor.Null;
48 }
49
50 public override void RemoveAvatar(PhysicsActor actor)
51 {
52 }
53
54 public override void RemovePrim(PhysicsActor prim)
55 {
56 }
57 public override void SetWaterLevel(float baseheight)
58 {
59
60 }
61
62/*
63 public override PhysicsActor AddPrim(Vector3 position, Vector3 size, Quaternion rotation)
64 {
65 m_log.InfoFormat("NullPhysicsScene : AddPrim({0},{1})", position, size);
66 return PhysicsActor.Null;
67 }
68*/
69
70 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
71 Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
72 {
73 m_log.InfoFormat("[PHYSICS]: NullPhysicsScene : AddPrim({0},{1})", position, size);
74 return PhysicsActor.Null;
75 }
76
77 public override void AddPhysicsActorTaint(PhysicsActor prim)
78 {
79 }
80
81 public override float Simulate(float timeStep)
82 {
83 m_workIndicator = (m_workIndicator + 1) % 10;
84
85 return 0f;
86 }
87
88 public override void GetResults()
89 {
90 m_log.Info("[PHYSICS]: NullPhysicsScene : GetResults()");
91 }
92
93 public override void SetTerrain(float[] heightMap)
94 {
95 m_log.InfoFormat("[PHYSICS]: NullPhysicsScene : SetTerrain({0} items)", heightMap.Length);
96 }
97
98 public override void DeleteTerrain()
99 {
100 }
101
102 public override bool IsThreaded
103 {
104 get { return false; }
105 }
106
107 public override void Dispose()
108 {
109 }
110
111 public override Dictionary<uint,float> GetTopColliders()
112 {
113 Dictionary<uint, float> returncolliders = new Dictionary<uint, float>();
114 return returncolliders;
115 }
116 }
117} \ No newline at end of file
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs
new file mode 100644
index 0000000..c04ff58
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs
@@ -0,0 +1,584 @@
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 log4net;
29using System;
30using System.Collections.Generic;
31using System.Reflection;
32using OpenSim.Framework;
33using OpenMetaverse;
34
35namespace OpenSim.Region.PhysicsModules.SharedBase
36{
37 public delegate void PositionUpdate(Vector3 position);
38 public delegate void VelocityUpdate(Vector3 velocity);
39 public delegate void OrientationUpdate(Quaternion orientation);
40
41 public enum ActorTypes : int
42 {
43 Unknown = 0,
44 Agent = 1,
45 Prim = 2,
46 Ground = 3
47 }
48
49 public enum PIDHoverType
50 {
51 Ground,
52 GroundAndWater,
53 Water,
54 Absolute
55 }
56
57 public struct ContactPoint
58 {
59 public Vector3 Position;
60 public Vector3 SurfaceNormal;
61 public float PenetrationDepth;
62
63 public ContactPoint(Vector3 position, Vector3 surfaceNormal, float penetrationDepth)
64 {
65 Position = position;
66 SurfaceNormal = surfaceNormal;
67 PenetrationDepth = penetrationDepth;
68 }
69 }
70
71 /// <summary>
72 /// Used to pass collision information to OnCollisionUpdate listeners.
73 /// </summary>
74 public class CollisionEventUpdate : EventArgs
75 {
76 /// <summary>
77 /// Number of collision events in this update.
78 /// </summary>
79 public int Count { get { return m_objCollisionList.Count; } }
80
81 public bool CollisionsOnPreviousFrame { get; private set; }
82
83 public Dictionary<uint, ContactPoint> m_objCollisionList;
84
85 public CollisionEventUpdate(Dictionary<uint, ContactPoint> objCollisionList)
86 {
87 m_objCollisionList = objCollisionList;
88 }
89
90 public CollisionEventUpdate()
91 {
92 m_objCollisionList = new Dictionary<uint, ContactPoint>();
93 }
94
95 public void AddCollider(uint localID, ContactPoint contact)
96 {
97 if (!m_objCollisionList.ContainsKey(localID))
98 {
99 m_objCollisionList.Add(localID, contact);
100 }
101 else
102 {
103 if (m_objCollisionList[localID].PenetrationDepth < contact.PenetrationDepth)
104 m_objCollisionList[localID] = contact;
105 }
106 }
107
108 /// <summary>
109 /// Clear added collision events.
110 /// </summary>
111 public void Clear()
112 {
113 m_objCollisionList.Clear();
114 }
115 }
116
117 public abstract class PhysicsActor
118 {
119// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
120
121 public delegate void RequestTerseUpdate();
122 public delegate void CollisionUpdate(EventArgs e);
123 public delegate void OutOfBounds(Vector3 pos);
124
125// disable warning: public events
126#pragma warning disable 67
127 public event PositionUpdate OnPositionUpdate;
128 public event VelocityUpdate OnVelocityUpdate;
129 public event OrientationUpdate OnOrientationUpdate;
130 public event RequestTerseUpdate OnRequestTerseUpdate;
131
132 /// <summary>
133 /// Subscribers to this event must synchronously handle the dictionary of collisions received, since the event
134 /// object is reused in subsequent physics frames.
135 /// </summary>
136 public event CollisionUpdate OnCollisionUpdate;
137
138 public event OutOfBounds OnOutOfBounds;
139#pragma warning restore 67
140
141 public static PhysicsActor Null
142 {
143 get { return new NullPhysicsActor(); }
144 }
145
146 public abstract bool Stopped { get; }
147
148 public abstract Vector3 Size { get; set; }
149
150 public virtual byte PhysicsShapeType { get; set; }
151
152 public abstract PrimitiveBaseShape Shape { set; }
153
154 uint m_baseLocalID;
155 public virtual uint LocalID
156 {
157 set { m_baseLocalID = value; }
158 get { return m_baseLocalID; }
159 }
160
161 public abstract bool Grabbed { set; }
162
163 public abstract bool Selected { set; }
164
165 /// <summary>
166 /// Name of this actor.
167 /// </summary>
168 /// <remarks>
169 /// XXX: Bizarrely, this cannot be "Terrain" or "Water" right now unless it really is simulating terrain or
170 /// water. This is not a problem due to the formatting of names given by prims and avatars.
171 /// </remarks>
172 public string Name { get; protected set; }
173
174 /// <summary>
175 /// This is being used by ODE joint code.
176 /// </summary>
177 public string SOPName;
178
179 public abstract void CrossingFailure();
180
181 public abstract void link(PhysicsActor obj);
182
183 public abstract void delink();
184
185 public abstract void LockAngularMotion(Vector3 axis);
186
187 public virtual void RequestPhysicsterseUpdate()
188 {
189 // Make a temporary copy of the event to avoid possibility of
190 // a race condition if the last subscriber unsubscribes
191 // immediately after the null check and before the event is raised.
192 RequestTerseUpdate handler = OnRequestTerseUpdate;
193
194 if (handler != null)
195 {
196 handler();
197 }
198 }
199
200 public virtual void RaiseOutOfBounds(Vector3 pos)
201 {
202 // Make a temporary copy of the event to avoid possibility of
203 // a race condition if the last subscriber unsubscribes
204 // immediately after the null check and before the event is raised.
205 OutOfBounds handler = OnOutOfBounds;
206
207 if (handler != null)
208 {
209 handler(pos);
210 }
211 }
212
213 public virtual void SendCollisionUpdate(EventArgs e)
214 {
215 CollisionUpdate handler = OnCollisionUpdate;
216
217// m_log.DebugFormat("[PHYSICS ACTOR]: Sending collision for {0}", LocalID);
218
219 if (handler != null)
220 handler(e);
221 }
222
223 public virtual void SetMaterial (int material) { }
224 public virtual float Density { get; set; }
225 public virtual float GravModifier { get; set; }
226 public virtual float Friction { get; set; }
227 public virtual float Restitution { get; set; }
228
229 /// <summary>
230 /// Position of this actor.
231 /// </summary>
232 /// <remarks>
233 /// Setting this directly moves the actor to a given position.
234 /// Getting this retrieves the position calculated by physics scene updates, using factors such as velocity and
235 /// collisions.
236 /// </remarks>
237 public abstract Vector3 Position { get; set; }
238
239 public abstract float Mass { get; }
240 public abstract Vector3 Force { get; set; }
241
242 public abstract int VehicleType { get; set; }
243 public abstract void VehicleFloatParam(int param, float value);
244 public abstract void VehicleVectorParam(int param, Vector3 value);
245 public abstract void VehicleRotationParam(int param, Quaternion rotation);
246 public abstract void VehicleFlags(int param, bool remove);
247
248 /// <summary>
249 /// Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more
250 /// </summary>
251 public abstract void SetVolumeDetect(int param);
252
253 public abstract Vector3 GeometricCenter { get; }
254 public abstract Vector3 CenterOfMass { get; }
255
256 /// <summary>
257 /// The desired velocity of this actor.
258 /// </summary>
259 /// <remarks>
260 /// Setting this provides a target velocity for physics scene updates.
261 /// Getting this returns the last set target. Fetch Velocity to get the current velocity.
262 /// </remarks>
263 protected Vector3 m_targetVelocity;
264 public virtual Vector3 TargetVelocity
265 {
266 get { return m_targetVelocity; }
267 set {
268 m_targetVelocity = value;
269 Velocity = m_targetVelocity;
270 }
271 }
272
273 public abstract Vector3 Velocity { get; set; }
274
275 public abstract Vector3 Torque { get; set; }
276 public abstract float CollisionScore { get; set;}
277 public abstract Vector3 Acceleration { get; set; }
278 public abstract Quaternion Orientation { get; set; }
279 public abstract int PhysicsActorType { get; set; }
280 public abstract bool IsPhysical { get; set; }
281 public abstract bool Flying { get; set; }
282 public abstract bool SetAlwaysRun { get; set; }
283 public abstract bool ThrottleUpdates { get; set; }
284 public abstract bool IsColliding { get; set; }
285 public abstract bool CollidingGround { get; set; }
286 public abstract bool CollidingObj { get; set; }
287 public abstract bool FloatOnWater { set; }
288 public abstract Vector3 RotationalVelocity { get; set; }
289 public abstract bool Kinematic { get; set; }
290 public abstract float Buoyancy { get; set; }
291
292 // Used for MoveTo
293 public abstract Vector3 PIDTarget { set; }
294 public abstract bool PIDActive { get; set; }
295 public abstract float PIDTau { set; }
296
297 // Used for llSetHoverHeight and maybe vehicle height
298 // Hover Height will override MoveTo target's Z
299 public abstract bool PIDHoverActive { set;}
300 public abstract float PIDHoverHeight { set;}
301 public abstract PIDHoverType PIDHoverType { set;}
302 public abstract float PIDHoverTau { set;}
303
304 // For RotLookAt
305 public abstract Quaternion APIDTarget { set;}
306 public abstract bool APIDActive { set;}
307 public abstract float APIDStrength { set;}
308 public abstract float APIDDamping { set;}
309
310 public abstract void AddForce(Vector3 force, bool pushforce);
311 public abstract void AddAngularForce(Vector3 force, bool pushforce);
312 public abstract void SetMomentum(Vector3 momentum);
313 public abstract void SubscribeEvents(int ms);
314 public abstract void UnSubscribeEvents();
315 public abstract bool SubscribedEvents();
316
317 // Extendable interface for new, physics engine specific operations
318 public virtual object Extension(string pFunct, params object[] pParams)
319 {
320 // A NOP of the physics engine does not implement this feature
321 return null;
322 }
323 }
324
325 public class NullPhysicsActor : PhysicsActor
326 {
327 public override bool Stopped
328 {
329 get{ return false; }
330 }
331
332 public override Vector3 Position
333 {
334 get { return Vector3.Zero; }
335 set { return; }
336 }
337
338 public override bool SetAlwaysRun
339 {
340 get { return false; }
341 set { return; }
342 }
343
344 public override uint LocalID
345 {
346 set { return; }
347 }
348
349 public override bool Grabbed
350 {
351 set { return; }
352 }
353
354 public override bool Selected
355 {
356 set { return; }
357 }
358
359 public override float Buoyancy
360 {
361 get { return 0f; }
362 set { return; }
363 }
364
365 public override bool FloatOnWater
366 {
367 set { return; }
368 }
369
370 public override bool CollidingGround
371 {
372 get { return false; }
373 set { return; }
374 }
375
376 public override bool CollidingObj
377 {
378 get { return false; }
379 set { return; }
380 }
381
382 public override Vector3 Size
383 {
384 get { return Vector3.Zero; }
385 set { return; }
386 }
387
388 public override float Mass
389 {
390 get { return 0f; }
391 }
392
393 public override Vector3 Force
394 {
395 get { return Vector3.Zero; }
396 set { return; }
397 }
398
399 public override int VehicleType
400 {
401 get { return 0; }
402 set { return; }
403 }
404
405 public override void VehicleFloatParam(int param, float value)
406 {
407
408 }
409
410 public override void VehicleVectorParam(int param, Vector3 value)
411 {
412
413 }
414
415 public override void VehicleRotationParam(int param, Quaternion rotation)
416 {
417
418 }
419
420 public override void VehicleFlags(int param, bool remove)
421 {
422
423 }
424
425 public override void SetVolumeDetect(int param)
426 {
427
428 }
429
430 public override void SetMaterial(int material)
431 {
432
433 }
434
435 public override Vector3 CenterOfMass
436 {
437 get { return Vector3.Zero; }
438 }
439
440 public override Vector3 GeometricCenter
441 {
442 get { return Vector3.Zero; }
443 }
444
445 public override PrimitiveBaseShape Shape
446 {
447 set { return; }
448 }
449
450 public override Vector3 Velocity
451 {
452 get { return Vector3.Zero; }
453 set { return; }
454 }
455
456 public override Vector3 Torque
457 {
458 get { return Vector3.Zero; }
459 set { return; }
460 }
461
462 public override float CollisionScore
463 {
464 get { return 0f; }
465 set { }
466 }
467
468 public override void CrossingFailure()
469 {
470 }
471
472 public override Quaternion Orientation
473 {
474 get { return Quaternion.Identity; }
475 set { }
476 }
477
478 public override Vector3 Acceleration
479 {
480 get { return Vector3.Zero; }
481 set { }
482 }
483
484 public override bool IsPhysical
485 {
486 get { return false; }
487 set { return; }
488 }
489
490 public override bool Flying
491 {
492 get { return false; }
493 set { return; }
494 }
495
496 public override bool ThrottleUpdates
497 {
498 get { return false; }
499 set { return; }
500 }
501
502 public override bool IsColliding
503 {
504 get { return false; }
505 set { return; }
506 }
507
508 public override int PhysicsActorType
509 {
510 get { return (int) ActorTypes.Unknown; }
511 set { return; }
512 }
513
514 public override bool Kinematic
515 {
516 get { return true; }
517 set { return; }
518 }
519
520 public override void link(PhysicsActor obj)
521 {
522 }
523
524 public override void delink()
525 {
526 }
527
528 public override void LockAngularMotion(Vector3 axis)
529 {
530 }
531
532 public override void AddForce(Vector3 force, bool pushforce)
533 {
534 }
535
536 public override void AddAngularForce(Vector3 force, bool pushforce)
537 {
538
539 }
540
541 public override Vector3 RotationalVelocity
542 {
543 get { return Vector3.Zero; }
544 set { return; }
545 }
546
547 public override Vector3 PIDTarget { set { return; } }
548
549 public override bool PIDActive
550 {
551 get { return false; }
552 set { return; }
553 }
554
555 public override float PIDTau { set { return; } }
556
557 public override float PIDHoverHeight { set { return; } }
558 public override bool PIDHoverActive { set { return; } }
559 public override PIDHoverType PIDHoverType { set { return; } }
560 public override float PIDHoverTau { set { return; } }
561
562 public override Quaternion APIDTarget { set { return; } }
563 public override bool APIDActive { set { return; } }
564 public override float APIDStrength { set { return; } }
565 public override float APIDDamping { set { return; } }
566
567 public override void SetMomentum(Vector3 momentum)
568 {
569 }
570
571 public override void SubscribeEvents(int ms)
572 {
573
574 }
575 public override void UnSubscribeEvents()
576 {
577
578 }
579 public override bool SubscribedEvents()
580 {
581 return false;
582 }
583 }
584}
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsJoint.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsJoint.cs
new file mode 100644
index 0000000..ce2bf05
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsJoint.cs
@@ -0,0 +1,55 @@
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 OpenSim.Framework;
31using OpenMetaverse;
32
33namespace OpenSim.Region.PhysicsModules.SharedBase
34{
35 public enum PhysicsJointType : int
36 {
37 Ball = 0,
38 Hinge = 1
39 }
40
41 public class PhysicsJoint
42 {
43 public virtual bool IsInPhysicsEngine { get { return false; } } // set internally to indicate if this joint has already been passed to the physics engine or is still pending
44 public PhysicsJointType Type;
45 public string RawParams;
46 public List<string> BodyNames = new List<string>();
47 public Vector3 Position; // global coords
48 public Quaternion Rotation; // global coords
49 public string ObjectNameInScene; // proxy object in scene that represents the joint position/orientation
50 public string TrackedBodyName; // body name that this joint is attached to (ObjectNameInScene will follow TrackedBodyName)
51 public Quaternion LocalRotation; // joint orientation relative to one of the involved bodies, the tracked body
52 public int ErrorMessageCount; // total # of error messages printed for this joint since its creation. if too many, further error messages are suppressed to prevent flooding.
53 public const int maxErrorMessages = 100; // no more than this # of error messages will be printed for each joint
54 }
55}
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs
new file mode 100644
index 0000000..32691fc
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs
@@ -0,0 +1,358 @@
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;
31
32using log4net;
33using Nini.Config;
34
35using OpenSim.Framework;
36using OpenMetaverse;
37
38namespace OpenSim.Region.PhysicsModules.SharedBase
39{
40 public delegate void physicsCrash();
41
42 public delegate void RaycastCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal);
43 public delegate void RayCallback(List<ContactResult> list);
44
45 public delegate void JointMoved(PhysicsJoint joint);
46 public delegate void JointDeactivated(PhysicsJoint joint);
47 public delegate void JointErrorMessage(PhysicsJoint joint, string message); // this refers to an "error message due to a problem", not "amount of joint constraint violation"
48
49 public enum RayFilterFlags : ushort
50 {
51 // the flags
52 water = 0x01,
53 land = 0x02,
54 agent = 0x04,
55 nonphysical = 0x08,
56 physical = 0x10,
57 phantom = 0x20,
58 volumedtc = 0x40,
59
60 // ray cast colision control (may only work for meshs)
61 ContactsUnImportant = 0x2000,
62 BackFaceCull = 0x4000,
63 ClosestHit = 0x8000,
64
65 // some combinations
66 LSLPhantom = phantom | volumedtc,
67 PrimsNonPhantom = nonphysical | physical,
68 PrimsNonPhantomAgents = nonphysical | physical | agent,
69
70 AllPrims = nonphysical | phantom | volumedtc | physical,
71 AllButLand = agent | nonphysical | physical | phantom | volumedtc,
72
73 ClosestAndBackCull = ClosestHit | BackFaceCull,
74
75 All = 0x3f
76 }
77
78 public delegate void RequestAssetDelegate(UUID assetID, AssetReceivedDelegate callback);
79 public delegate void AssetReceivedDelegate(AssetBase asset);
80
81 /// <summary>
82 /// Contact result from a raycast.
83 /// </summary>
84 public struct ContactResult
85 {
86 public Vector3 Pos;
87 public float Depth;
88 public uint ConsumerID;
89 public Vector3 Normal;
90 }
91
92 public abstract class PhysicsScene
93 {
94// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
95
96 /// <summary>
97 /// A unique identifying string for this instance of the physics engine.
98 /// Useful in debug messages to distinguish one OdeScene instance from another.
99 /// Usually set to include the region name that the physics engine is acting for.
100 /// </summary>
101 public string PhysicsSceneName { get; protected set; }
102
103 /// <summary>
104 /// A string identifying the family of this physics engine. Most common values returned
105 /// are "OpenDynamicsEngine" and "BulletSim" but others are possible.
106 /// </summary>
107 public string EngineType { get; protected set; }
108
109 // The only thing that should register for this event is the SceneGraph
110 // Anything else could cause problems.
111 public event physicsCrash OnPhysicsCrash;
112
113 public static PhysicsScene Null
114 {
115 get { return new NullPhysicsScene(); }
116 }
117
118 public RequestAssetDelegate RequestAssetMethod { get; set; }
119
120 protected void Initialise(RequestAssetDelegate m, float[] terrain, float waterHeight)
121 {
122 RequestAssetMethod = m;
123 SetTerrain(terrain);
124 SetWaterLevel(waterHeight);
125
126 }
127
128 public virtual void TriggerPhysicsBasedRestart()
129 {
130 physicsCrash handler = OnPhysicsCrash;
131 if (handler != null)
132 {
133 OnPhysicsCrash();
134 }
135 }
136
137 /// <summary>
138 /// Add an avatar
139 /// </summary>
140 /// <param name="avName"></param>
141 /// <param name="position"></param>
142 /// <param name="velocity"></param>
143 /// <param name="size"></param>
144 /// <param name="isFlying"></param>
145 /// <returns></returns>
146 public abstract PhysicsActor AddAvatar(
147 string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying);
148
149 /// <summary>
150 /// Add an avatar
151 /// </summary>
152 /// <param name="localID"></param>
153 /// <param name="avName"></param>
154 /// <param name="position"></param>
155 /// <param name="velocity"></param>
156 /// <param name="size"></param>
157 /// <param name="isFlying"></param>
158 /// <returns></returns>
159 public virtual PhysicsActor AddAvatar(
160 uint localID, string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
161 {
162 PhysicsActor ret = AddAvatar(avName, position, velocity, size, isFlying);
163
164 if (ret != null)
165 ret.LocalID = localID;
166
167 return ret;
168 }
169
170 /// <summary>
171 /// Remove an avatar.
172 /// </summary>
173 /// <param name="actor"></param>
174 public abstract void RemoveAvatar(PhysicsActor actor);
175
176 /// <summary>
177 /// Remove a prim.
178 /// </summary>
179 /// <param name="prim"></param>
180 public abstract void RemovePrim(PhysicsActor prim);
181
182 public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
183 Vector3 size, Quaternion rotation, bool isPhysical, uint localid);
184
185 public virtual PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
186 Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapetype, uint localid)
187 {
188 return AddPrimShape(primName, pbs, position, size, rotation, isPhysical, localid);
189 }
190
191 public virtual float TimeDilation
192 {
193 get { return 1.0f; }
194 }
195
196 public virtual bool SupportsNINJAJoints
197 {
198 get { return false; }
199 }
200
201 public virtual PhysicsJoint RequestJointCreation(string objectNameInScene, PhysicsJointType jointType, Vector3 position,
202 Quaternion rotation, string parms, List<string> bodyNames, string trackedBodyName, Quaternion localRotation)
203 { return null; }
204
205 public virtual void RequestJointDeletion(string objectNameInScene)
206 { return; }
207
208 public virtual void RemoveAllJointsConnectedToActorThreadLocked(PhysicsActor actor)
209 { return; }
210
211 public virtual void DumpJointInfo()
212 { return; }
213
214 public event JointMoved OnJointMoved;
215
216 protected virtual void DoJointMoved(PhysicsJoint joint)
217 {
218 // We need this to allow subclasses (but not other classes) to invoke the event; C# does
219 // not allow subclasses to invoke the parent class event.
220 if (OnJointMoved != null)
221 {
222 OnJointMoved(joint);
223 }
224 }
225
226 public event JointDeactivated OnJointDeactivated;
227
228 protected virtual void DoJointDeactivated(PhysicsJoint joint)
229 {
230 // We need this to allow subclasses (but not other classes) to invoke the event; C# does
231 // not allow subclasses to invoke the parent class event.
232 if (OnJointDeactivated != null)
233 {
234 OnJointDeactivated(joint);
235 }
236 }
237
238 public event JointErrorMessage OnJointErrorMessage;
239
240 protected virtual void DoJointErrorMessage(PhysicsJoint joint, string message)
241 {
242 // We need this to allow subclasses (but not other classes) to invoke the event; C# does
243 // not allow subclasses to invoke the parent class event.
244 if (OnJointErrorMessage != null)
245 {
246 OnJointErrorMessage(joint, message);
247 }
248 }
249
250 public virtual Vector3 GetJointAnchor(PhysicsJoint joint)
251 { return Vector3.Zero; }
252
253 public virtual Vector3 GetJointAxis(PhysicsJoint joint)
254 { return Vector3.Zero; }
255
256 public abstract void AddPhysicsActorTaint(PhysicsActor prim);
257
258 /// <summary>
259 /// Perform a simulation of the current physics scene over the given timestep.
260 /// </summary>
261 /// <param name="timeStep"></param>
262 /// <returns>The number of frames simulated over that period.</returns>
263 public abstract float Simulate(float timeStep);
264
265 /// <summary>
266 /// Get statistics about this scene.
267 /// </summary>
268 /// <remarks>This facility is currently experimental and subject to change.</remarks>
269 /// <returns>
270 /// A dictionary where the key is the statistic name. If no statistics are supplied then returns null.
271 /// </returns>
272 public virtual Dictionary<string, float> GetStats() { return null; }
273
274 public abstract void GetResults();
275
276 public abstract void SetTerrain(float[] heightMap);
277
278 public abstract void SetWaterLevel(float baseheight);
279
280 public abstract void DeleteTerrain();
281
282 public abstract void Dispose();
283
284 public abstract Dictionary<uint, float> GetTopColliders();
285
286 public abstract bool IsThreaded { get; }
287
288 /// <summary>
289 /// True if the physics plugin supports raycasting against the physics scene
290 /// </summary>
291 public virtual bool SupportsRayCast()
292 {
293 return false;
294 }
295
296 public virtual bool SupportsCombining()
297 {
298 return false;
299 }
300
301 public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {}
302
303 public virtual void UnCombine(PhysicsScene pScene) {}
304
305 /// <summary>
306 /// Queue a raycast against the physics scene.
307 /// The provided callback method will be called when the raycast is complete
308 ///
309 /// Many physics engines don't support collision testing at the same time as
310 /// manipulating the physics scene, so we queue the request up and callback
311 /// a custom method when the raycast is complete.
312 /// This allows physics engines that give an immediate result to callback immediately
313 /// and ones that don't, to callback when it gets a result back.
314 ///
315 /// ODE for example will not allow you to change the scene while collision testing or
316 /// it asserts, 'opteration not valid for locked space'. This includes adding a ray to the scene.
317 ///
318 /// This is named RayCastWorld to not conflict with modrex's Raycast method.
319 /// </summary>
320 /// <param name="position">Origin of the ray</param>
321 /// <param name="direction">Direction of the ray</param>
322 /// <param name="length">Length of ray in meters</param>
323 /// <param name="retMethod">Method to call when the raycast is complete</param>
324 public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
325 {
326 if (retMethod != null)
327 retMethod(false, Vector3.Zero, 0, 999999999999f, Vector3.Zero);
328 }
329
330 public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod)
331 {
332 if (retMethod != null)
333 retMethod(new List<ContactResult>());
334 }
335
336 public virtual List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count)
337 {
338 return new List<ContactResult>();
339 }
340
341 public virtual object RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
342 {
343 return null;
344 }
345
346 public virtual bool SupportsRaycastWorldFiltered()
347 {
348 return false;
349 }
350
351 // Extendable interface for new, physics engine specific operations
352 public virtual object Extension(string pFunct, params object[] pParams)
353 {
354 // A NOP if the extension thing is not implemented by the physics engine
355 return null;
356 }
357 }
358}
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsSensor.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsSensor.cs
new file mode 100644
index 0000000..da9c96c
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsSensor.cs
@@ -0,0 +1,78 @@
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.Timers;
30using OpenMetaverse;
31
32namespace OpenSim.Region.PhysicsModules.SharedBase
33{
34 [Flags]
35 public enum SenseType : uint
36 {
37 NONE = 0,
38 AGENT = 1,
39 ACTIVE = 2,
40 PASSIVE = 3,
41 SCRIPTED = 4
42 }
43
44 public abstract class PhysicsSensor
45 {
46 public static PhysicsSensor Null
47 {
48 get { return new NullPhysicsSensor(); }
49 }
50 public abstract Vector3 Position { get; set; }
51 public abstract void TimerCallback (object obj, ElapsedEventArgs eea);
52 public abstract float radianarc {get; set;}
53 public abstract string targetname {get; set;}
54 public abstract Guid targetKey{get;set;}
55 public abstract SenseType sensetype { get;set;}
56 public abstract float range { get;set;}
57 public abstract float rateSeconds { get;set;}
58 }
59
60 public class NullPhysicsSensor : PhysicsSensor
61 {
62 public override Vector3 Position
63 {
64 get { return Vector3.Zero; }
65 set { return; }
66 }
67 public override void TimerCallback(object obj, ElapsedEventArgs eea)
68 {
69 // don't do squat
70 }
71 public override float radianarc { get { return 0f; } set { } }
72 public override string targetname { get { return ""; } set { } }
73 public override Guid targetKey { get { return Guid.Empty; } set { } }
74 public override SenseType sensetype { get { return SenseType.NONE; } set { } }
75 public override float range { get { return 0; } set { } }
76 public override float rateSeconds { get { return 0; } set { } }
77 }
78}
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsVector.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsVector.cs
new file mode 100644
index 0000000..76a82fa
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsVector.cs
@@ -0,0 +1,186 @@
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;
29
30namespace OpenSim.Region.PhysicsModules.SharedBase
31{
32 /*public class PhysicsVector
33 {
34 public float X;
35 public float Y;
36 public float Z;
37
38 public Vector3()
39 {
40 }
41
42 public Vector3(float x, float y, float z)
43 {
44 X = x;
45 Y = y;
46 Z = z;
47 }
48
49 public Vector3(Vector3 pv) : this(pv.X, pv.Y, pv.Z)
50 {
51 }
52
53 public void setValues(float x, float y, float z)
54 {
55 X = x;
56 Y = y;
57 Z = z;
58 }
59
60 public static readonly PhysicsVector Zero = new PhysicsVector(0f, 0f, 0f);
61
62 public override string ToString()
63 {
64 return "<" + X + "," + Y + "," + Z + ">";
65 }
66
67 /// <summary>
68 /// These routines are the easiest way to store XYZ values in an Vector3 without requiring 3 calls.
69 /// </summary>
70 /// <returns></returns>
71 public byte[] GetBytes()
72 {
73 byte[] byteArray = new byte[12];
74
75 Buffer.BlockCopy(BitConverter.GetBytes(X), 0, byteArray, 0, 4);
76 Buffer.BlockCopy(BitConverter.GetBytes(Y), 0, byteArray, 4, 4);
77 Buffer.BlockCopy(BitConverter.GetBytes(Z), 0, byteArray, 8, 4);
78
79 if (!BitConverter.IsLittleEndian)
80 {
81 Array.Reverse(byteArray, 0, 4);
82 Array.Reverse(byteArray, 4, 4);
83 Array.Reverse(byteArray, 8, 4);
84 }
85
86 return byteArray;
87 }
88
89 public void FromBytes(byte[] byteArray, int pos)
90 {
91 byte[] conversionBuffer = null;
92 if (!BitConverter.IsLittleEndian)
93 {
94 // Big endian architecture
95 if (conversionBuffer == null)
96 conversionBuffer = new byte[12];
97
98 Buffer.BlockCopy(byteArray, pos, conversionBuffer, 0, 12);
99
100 Array.Reverse(conversionBuffer, 0, 4);
101 Array.Reverse(conversionBuffer, 4, 4);
102 Array.Reverse(conversionBuffer, 8, 4);
103
104 X = BitConverter.ToSingle(conversionBuffer, 0);
105 Y = BitConverter.ToSingle(conversionBuffer, 4);
106 Z = BitConverter.ToSingle(conversionBuffer, 8);
107 }
108 else
109 {
110 // Little endian architecture
111 X = BitConverter.ToSingle(byteArray, pos);
112 Y = BitConverter.ToSingle(byteArray, pos + 4);
113 Z = BitConverter.ToSingle(byteArray, pos + 8);
114 }
115 }
116
117 // Operations
118 public static PhysicsVector operator +(Vector3 a, Vector3 b)
119 {
120 return new PhysicsVector(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
121 }
122
123 public static PhysicsVector operator -(Vector3 a, Vector3 b)
124 {
125 return new PhysicsVector(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
126 }
127
128 public static PhysicsVector cross(Vector3 a, Vector3 b)
129 {
130 return new PhysicsVector(a.Y*b.Z - a.Z*b.Y, a.Z*b.X - a.X*b.Z, a.X*b.Y - a.Y*b.X);
131 }
132
133 public float length()
134 {
135 return (float) Math.Sqrt(X*X + Y*Y + Z*Z);
136 }
137
138 public static float GetDistanceTo(Vector3 a, Vector3 b)
139 {
140 float dx = a.X - b.X;
141 float dy = a.Y - b.Y;
142 float dz = a.Z - b.Z;
143 return (float) Math.Sqrt(dx * dx + dy * dy + dz * dz);
144 }
145
146 public static PhysicsVector operator /(Vector3 v, float f)
147 {
148 return new PhysicsVector(v.X/f, v.Y/f, v.Z/f);
149 }
150
151 public static PhysicsVector operator *(Vector3 v, float f)
152 {
153 return new PhysicsVector(v.X*f, v.Y*f, v.Z*f);
154 }
155
156 public static PhysicsVector operator *(float f, Vector3 v)
157 {
158 return v*f;
159 }
160
161 public static bool isFinite(Vector3 v)
162 {
163 if (v == null)
164 return false;
165 if (Single.IsInfinity(v.X) || Single.IsNaN(v.X))
166 return false;
167 if (Single.IsInfinity(v.Y) || Single.IsNaN(v.Y))
168 return false;
169 if (Single.IsInfinity(v.Z) || Single.IsNaN(v.Z))
170 return false;
171
172 return true;
173 }
174
175 public virtual bool IsIdentical(Vector3 v, float tolerance)
176 {
177 PhysicsVector diff = this - v;
178 float d = diff.length();
179 if (d <= tolerance)
180 return true;
181
182 return false;
183 }
184
185 }*/
186}
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/VehicleConstants.cs b/OpenSim/Region/PhysicsModules/SharedBase/VehicleConstants.cs
new file mode 100644
index 0000000..63a8cb8
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/SharedBase/VehicleConstants.cs
@@ -0,0 +1,121 @@
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;
29
30namespace OpenSim.Region.PhysicsModules.SharedBase
31{
32 public enum Vehicle : int
33 {
34 /// <summary>
35 /// Turns off Vehicle Support
36 /// </summary>
37 TYPE_NONE = 0,
38
39 /// <summary>
40 /// No Angular motor, High Left right friction, No Hover, Linear Deflection 1, no angular deflection
41 /// no vertical attractor, No banking, Identity rotation frame
42 /// </summary>
43 TYPE_SLED = 1,
44
45 /// <summary>
46 /// Needs Motors to be driven by timer or control events High left/right friction, No angular friction
47 /// Linear Motor wins in a second, decays in 60 seconds. Angular motor wins in a second, decays in 8/10ths of a second
48 /// linear deflection 2 seconds
49 /// Vertical Attractor locked UP
50 /// </summary>
51 TYPE_CAR = 2,
52 TYPE_BOAT = 3,
53 TYPE_AIRPLANE = 4,
54 TYPE_BALLOON = 5,
55 LINEAR_FRICTION_TIMESCALE = 16,
56 /// <summary>
57 /// vector of timescales for exponential decay of angular velocity about three axis
58 /// </summary>
59 ANGULAR_FRICTION_TIMESCALE = 17,
60 /// <summary>
61 /// linear velocity vehicle will try for
62 /// </summary>
63 LINEAR_MOTOR_DIRECTION = 18,
64
65 /// <summary>
66 /// Offset from center of mass where linear motor forces are added
67 /// </summary>
68 LINEAR_MOTOR_OFFSET = 20,
69 /// <summary>
70 /// angular velocity that vehicle will try for
71 /// </summary>
72 ANGULAR_MOTOR_DIRECTION = 19,
73 HOVER_HEIGHT = 24,
74 HOVER_EFFICIENCY = 25,
75 HOVER_TIMESCALE = 26,
76 BUOYANCY = 27,
77 LINEAR_DEFLECTION_EFFICIENCY = 28,
78 LINEAR_DEFLECTION_TIMESCALE = 29,
79 LINEAR_MOTOR_TIMESCALE = 30,
80 LINEAR_MOTOR_DECAY_TIMESCALE = 31,
81
82 /// <summary>
83 /// slide between 0 and 1
84 /// </summary>
85 ANGULAR_DEFLECTION_EFFICIENCY = 32,
86 ANGULAR_DEFLECTION_TIMESCALE = 33,
87 ANGULAR_MOTOR_TIMESCALE = 34,
88 ANGULAR_MOTOR_DECAY_TIMESCALE = 35,
89 VERTICAL_ATTRACTION_EFFICIENCY = 36,
90 VERTICAL_ATTRACTION_TIMESCALE = 37,
91 BANKING_EFFICIENCY = 38,
92 BANKING_MIX = 39,
93 BANKING_TIMESCALE = 40,
94 REFERENCE_FRAME = 44,
95 BLOCK_EXIT = 45,
96 ROLL_FRAME = 46
97
98 }
99
100 [Flags]
101 public enum VehicleFlag
102 {
103 NO_DEFLECTION_UP = 1,
104 LIMIT_ROLL_ONLY = 2,
105 HOVER_WATER_ONLY = 4,
106 HOVER_TERRAIN_ONLY = 8,
107 HOVER_GLOBAL_HEIGHT = 16,
108 HOVER_UP_ONLY = 32,
109 LIMIT_MOTOR_UP = 64,
110 MOUSELOOK_STEER = 128,
111 MOUSELOOK_BANK = 256,
112 CAMERA_DECOUPLED = 512,
113 NO_X = 1024,
114 NO_Y = 2048,
115 NO_Z = 4096,
116 LOCK_HOVER_HEIGHT = 8192,
117 NO_DEFLECTION = 16392,
118 LOCK_ROTATION = 32784
119 }
120
121}