aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs
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/PhysicsScene.cs
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/PhysicsScene.cs')
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs358
1 files changed, 358 insertions, 0 deletions
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}