aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs
diff options
context:
space:
mode:
authorDiva Canto2015-08-30 20:06:53 -0700
committerDiva Canto2015-08-30 20:06:53 -0700
commit1d6b33bc2da3b312cff1d1802a73aacdf72b0385 (patch)
tree393736b501aac3b31eb0810bb72d926c7f14fbf8 /OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs
parentMoved instantiation of SceneCommunicationService object to inside the scene c... (diff)
downloadopensim-SC-1d6b33bc2da3b312cff1d1802a73aacdf72b0385.zip
opensim-SC-1d6b33bc2da3b312cff1d1802a73aacdf72b0385.tar.gz
opensim-SC-1d6b33bc2da3b312cff1d1802a73aacdf72b0385.tar.bz2
opensim-SC-1d6b33bc2da3b312cff1d1802a73aacdf72b0385.tar.xz
Major renaming of Physics dlls / folders. No functional changes, just renames.
Diffstat (limited to 'OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs')
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs361
1 files changed, 361 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..9cdedbf
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs
@@ -0,0 +1,361 @@
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.Physics.Manager
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 Name { 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 public virtual void TriggerPhysicsBasedRestart()
121 {
122 physicsCrash handler = OnPhysicsCrash;
123 if (handler != null)
124 {
125 OnPhysicsCrash();
126 }
127 }
128
129 // Deprecated. Do not use this for new physics engines.
130 public abstract void Initialise(IMesher meshmerizer, IConfigSource config);
131
132 // For older physics engines that do not implement non-legacy region sizes.
133 // If the physics engine handles the region extent feature, it overrides this function.
134 public virtual void Initialise(IMesher meshmerizer, IConfigSource config, Vector3 regionExtent)
135 {
136 // If not overridden, call the old initialization entry.
137 Initialise(meshmerizer, config);
138 }
139
140 /// <summary>
141 /// Add an avatar
142 /// </summary>
143 /// <param name="avName"></param>
144 /// <param name="position"></param>
145 /// <param name="velocity"></param>
146 /// <param name="size"></param>
147 /// <param name="isFlying"></param>
148 /// <returns></returns>
149 public abstract PhysicsActor AddAvatar(
150 string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying);
151
152 /// <summary>
153 /// Add an avatar
154 /// </summary>
155 /// <param name="localID"></param>
156 /// <param name="avName"></param>
157 /// <param name="position"></param>
158 /// <param name="velocity"></param>
159 /// <param name="size"></param>
160 /// <param name="isFlying"></param>
161 /// <returns></returns>
162 public virtual PhysicsActor AddAvatar(
163 uint localID, string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
164 {
165 PhysicsActor ret = AddAvatar(avName, position, velocity, size, isFlying);
166
167 if (ret != null)
168 ret.LocalID = localID;
169
170 return ret;
171 }
172
173 /// <summary>
174 /// Remove an avatar.
175 /// </summary>
176 /// <param name="actor"></param>
177 public abstract void RemoveAvatar(PhysicsActor actor);
178
179 /// <summary>
180 /// Remove a prim.
181 /// </summary>
182 /// <param name="prim"></param>
183 public abstract void RemovePrim(PhysicsActor prim);
184
185 public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
186 Vector3 size, Quaternion rotation, bool isPhysical, uint localid);
187
188 public virtual PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
189 Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapetype, uint localid)
190 {
191 return AddPrimShape(primName, pbs, position, size, rotation, isPhysical, localid);
192 }
193
194 public virtual float TimeDilation
195 {
196 get { return 1.0f; }
197 }
198
199 public virtual bool SupportsNINJAJoints
200 {
201 get { return false; }
202 }
203
204 public virtual PhysicsJoint RequestJointCreation(string objectNameInScene, PhysicsJointType jointType, Vector3 position,
205 Quaternion rotation, string parms, List<string> bodyNames, string trackedBodyName, Quaternion localRotation)
206 { return null; }
207
208 public virtual void RequestJointDeletion(string objectNameInScene)
209 { return; }
210
211 public virtual void RemoveAllJointsConnectedToActorThreadLocked(PhysicsActor actor)
212 { return; }
213
214 public virtual void DumpJointInfo()
215 { return; }
216
217 public event JointMoved OnJointMoved;
218
219 protected virtual void DoJointMoved(PhysicsJoint joint)
220 {
221 // We need this to allow subclasses (but not other classes) to invoke the event; C# does
222 // not allow subclasses to invoke the parent class event.
223 if (OnJointMoved != null)
224 {
225 OnJointMoved(joint);
226 }
227 }
228
229 public event JointDeactivated OnJointDeactivated;
230
231 protected virtual void DoJointDeactivated(PhysicsJoint joint)
232 {
233 // We need this to allow subclasses (but not other classes) to invoke the event; C# does
234 // not allow subclasses to invoke the parent class event.
235 if (OnJointDeactivated != null)
236 {
237 OnJointDeactivated(joint);
238 }
239 }
240
241 public event JointErrorMessage OnJointErrorMessage;
242
243 protected virtual void DoJointErrorMessage(PhysicsJoint joint, string message)
244 {
245 // We need this to allow subclasses (but not other classes) to invoke the event; C# does
246 // not allow subclasses to invoke the parent class event.
247 if (OnJointErrorMessage != null)
248 {
249 OnJointErrorMessage(joint, message);
250 }
251 }
252
253 public virtual Vector3 GetJointAnchor(PhysicsJoint joint)
254 { return Vector3.Zero; }
255
256 public virtual Vector3 GetJointAxis(PhysicsJoint joint)
257 { return Vector3.Zero; }
258
259 public abstract void AddPhysicsActorTaint(PhysicsActor prim);
260
261 /// <summary>
262 /// Perform a simulation of the current physics scene over the given timestep.
263 /// </summary>
264 /// <param name="timeStep"></param>
265 /// <returns>The number of frames simulated over that period.</returns>
266 public abstract float Simulate(float timeStep);
267
268 /// <summary>
269 /// Get statistics about this scene.
270 /// </summary>
271 /// <remarks>This facility is currently experimental and subject to change.</remarks>
272 /// <returns>
273 /// A dictionary where the key is the statistic name. If no statistics are supplied then returns null.
274 /// </returns>
275 public virtual Dictionary<string, float> GetStats() { return null; }
276
277 public abstract void GetResults();
278
279 public abstract void SetTerrain(float[] heightMap);
280
281 public abstract void SetWaterLevel(float baseheight);
282
283 public abstract void DeleteTerrain();
284
285 public abstract void Dispose();
286
287 public abstract Dictionary<uint, float> GetTopColliders();
288
289 public abstract bool IsThreaded { get; }
290
291 /// <summary>
292 /// True if the physics plugin supports raycasting against the physics scene
293 /// </summary>
294 public virtual bool SupportsRayCast()
295 {
296 return false;
297 }
298
299 public virtual bool SupportsCombining()
300 {
301 return false;
302 }
303
304 public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {}
305
306 public virtual void UnCombine(PhysicsScene pScene) {}
307
308 /// <summary>
309 /// Queue a raycast against the physics scene.
310 /// The provided callback method will be called when the raycast is complete
311 ///
312 /// Many physics engines don't support collision testing at the same time as
313 /// manipulating the physics scene, so we queue the request up and callback
314 /// a custom method when the raycast is complete.
315 /// This allows physics engines that give an immediate result to callback immediately
316 /// and ones that don't, to callback when it gets a result back.
317 ///
318 /// ODE for example will not allow you to change the scene while collision testing or
319 /// it asserts, 'opteration not valid for locked space'. This includes adding a ray to the scene.
320 ///
321 /// This is named RayCastWorld to not conflict with modrex's Raycast method.
322 /// </summary>
323 /// <param name="position">Origin of the ray</param>
324 /// <param name="direction">Direction of the ray</param>
325 /// <param name="length">Length of ray in meters</param>
326 /// <param name="retMethod">Method to call when the raycast is complete</param>
327 public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
328 {
329 if (retMethod != null)
330 retMethod(false, Vector3.Zero, 0, 999999999999f, Vector3.Zero);
331 }
332
333 public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod)
334 {
335 if (retMethod != null)
336 retMethod(new List<ContactResult>());
337 }
338
339 public virtual List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count)
340 {
341 return new List<ContactResult>();
342 }
343
344 public virtual object RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
345 {
346 return null;
347 }
348
349 public virtual bool SupportsRaycastWorldFiltered()
350 {
351 return false;
352 }
353
354 // Extendable interface for new, physics engine specific operations
355 public virtual object Extension(string pFunct, params object[] pParams)
356 {
357 // A NOP if the extension thing is not implemented by the physics engine
358 return null;
359 }
360 }
361}