aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
diff options
context:
space:
mode:
authorTeravus Ovares2008-12-07 04:03:09 +0000
committerTeravus Ovares2008-12-07 04:03:09 +0000
commit76e1462dff5594252af8e26cc6fc9b9560af090d (patch)
treed2496eef6233445d05ea21d043344d95e4fa16c8 /OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
parentSend the creation-date of items to the viewer. This fixes Mantis#2769. (diff)
downloadopensim-SC_OLD-76e1462dff5594252af8e26cc6fc9b9560af090d.zip
opensim-SC_OLD-76e1462dff5594252af8e26cc6fc9b9560af090d.tar.gz
opensim-SC_OLD-76e1462dff5594252af8e26cc6fc9b9560af090d.tar.bz2
opensim-SC_OLD-76e1462dff5594252af8e26cc6fc9b9560af090d.tar.xz
* Tweaks physics so that linked prim are a single body. This will make linked prim more stable and probably the last obstacle to vehicles physics wise.
* Fixed a bug that caused physics proxies to be scattered when you link an object. * Single physical prim work exactly the same as before, just linked physical prim will have changed.
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/OdePlugin.cs')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs183
1 files changed, 177 insertions, 6 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 0dab05c..a50c5ae 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -24,6 +24,7 @@
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27//#define USE_DRAWSTUFF
27 28
28using System; 29using System;
29using System.Collections.Generic; 30using System.Collections.Generic;
@@ -34,6 +35,9 @@ using System.IO;
34using log4net; 35using log4net;
35using Nini.Config; 36using Nini.Config;
36using Ode.NET; 37using Ode.NET;
38#if USE_DRAWSTUFF
39using Drawstuff.NET;
40#endif
37using OpenSim.Framework; 41using OpenSim.Framework;
38using OpenSim.Region.Physics.Manager; 42using OpenSim.Region.Physics.Manager;
39using OpenMetaverse; 43using OpenMetaverse;
@@ -257,6 +261,9 @@ namespace OpenSim.Region.Physics.OdePlugin
257 public int physics_logging_interval = 0; 261 public int physics_logging_interval = 0;
258 public bool physics_logging_append_existing_logfile = false; 262 public bool physics_logging_append_existing_logfile = false;
259 263
264 public d.Vector3 xyz = new d.Vector3(2.1640f, -1.3079f, 1.7600f);
265 public d.Vector3 hpr = new d.Vector3(125.5000f, -17.0000f, 0.0000f);
266
260 /// <summary> 267 /// <summary>
261 /// Initiailizes the scene 268 /// Initiailizes the scene
262 /// Sets many properties that ODE requires to be stable 269 /// Sets many properties that ODE requires to be stable
@@ -280,6 +287,11 @@ namespace OpenSim.Region.Physics.OdePlugin
280 //contactgroup 287 //contactgroup
281 288
282 d.WorldSetAutoDisableFlag(world, false); 289 d.WorldSetAutoDisableFlag(world, false);
290 #if USE_DRAWSTUFF
291
292 Thread viewthread = new Thread(new ParameterizedThreadStart(startvisualization));
293 viewthread.Start();
294 #endif
283 } 295 }
284 296
285 // zero out a heightmap array float array (single dimention [flattened])) 297 // zero out a heightmap array float array (single dimention [flattened]))
@@ -290,6 +302,21 @@ namespace OpenSim.Region.Physics.OdePlugin
290 // we can hit test less. 302 // we can hit test less.
291 } 303 }
292 304
305#if USE_DRAWSTUFF
306 public void startvisualization(object o)
307 {
308 ds.Functions fn;
309 fn.version = ds.VERSION;
310 fn.start = new ds.CallbackFunction(start);
311 fn.step = new ds.CallbackFunction(step);
312 fn.command = new ds.CallbackFunction(command);
313 fn.stop = null;
314 fn.path_to_textures = "./textures";
315 string[] args = new string[0];
316 ds.SimulationLoop(args.Length, args, 352, 288, ref fn);
317 }
318#endif
319
293 // Initialize the mesh plugin 320 // Initialize the mesh plugin
294 public override void Initialise(IMesher meshmerizer, IConfigSource config) 321 public override void Initialise(IMesher meshmerizer, IConfigSource config)
295 { 322 {
@@ -787,6 +814,10 @@ namespace OpenSim.Region.Physics.OdePlugin
787 _perloopContact.Add(contacts[i]); 814 _perloopContact.Add(contacts[i]);
788 joint = d.JointCreateContact(world, contactgroup, ref TerrainContact); 815 joint = d.JointCreateContact(world, contactgroup, ref TerrainContact);
789 } 816 }
817 //if (p2.PhysicsActorType == (int)ActorTypes.Prim)
818 //{
819 //m_log.Debug("[PHYSICS]: prim contacting with ground");
820 //}
790 } 821 }
791 else if (name1 == "Water" || name2 == "Water") 822 else if (name1 == "Water" || name2 == "Water")
792 { 823 {
@@ -1137,7 +1168,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1137 List<OdePrim> removeprims = null; 1168 List<OdePrim> removeprims = null;
1138 foreach (OdePrim chr in _activeprims) 1169 foreach (OdePrim chr in _activeprims)
1139 { 1170 {
1140 if (d.BodyIsEnabled(chr.Body) && (!chr.m_disabled)) 1171 if (chr.Body != IntPtr.Zero && d.BodyIsEnabled(chr.Body) && (!chr.m_disabled))
1141 { 1172 {
1142 try 1173 try
1143 { 1174 {
@@ -1243,7 +1274,8 @@ namespace OpenSim.Region.Physics.OdePlugin
1243 { 1274 {
1244 newPrim = new OdePrim(name, this, pos, siz, rot, mesh, pbs, isphysical, ode); 1275 newPrim = new OdePrim(name, this, pos, siz, rot, mesh, pbs, isphysical, ode);
1245 1276
1246 _prims.Add(newPrim); 1277 lock (_prims)
1278 _prims.Add(newPrim);
1247 } 1279 }
1248 1280
1249 return newPrim; 1281 return newPrim;
@@ -1252,8 +1284,13 @@ namespace OpenSim.Region.Physics.OdePlugin
1252 public void addActivePrim(OdePrim activatePrim) 1284 public void addActivePrim(OdePrim activatePrim)
1253 { 1285 {
1254 // adds active prim.. (ones that should be iterated over in collisions_optimized 1286 // adds active prim.. (ones that should be iterated over in collisions_optimized
1255 1287 lock (_activeprims)
1256 _activeprims.Add(activatePrim); 1288 {
1289 if (!_activeprims.Contains(activatePrim))
1290 _activeprims.Add(activatePrim);
1291 //else
1292 // m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent");
1293 }
1257 } 1294 }
1258 1295
1259 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, 1296 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
@@ -1334,6 +1371,15 @@ namespace OpenSim.Region.Physics.OdePlugin
1334 if (prim.IsPhysical) 1371 if (prim.IsPhysical)
1335 { 1372 {
1336 prim.disableBody(); 1373 prim.disableBody();
1374 if (prim.childPrim)
1375 {
1376 prim.childPrim = false;
1377 prim.Body = IntPtr.Zero;
1378 prim.m_disabled = true;
1379 prim.IsPhysical = false;
1380 }
1381
1382
1337 } 1383 }
1338 // we don't want to remove the main space 1384 // we don't want to remove the main space
1339 1385
@@ -1376,6 +1422,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1376 { 1422 {
1377 m_log.Info("[PHYSICS]: Couldn't remove prim from physics scene, it was already be removed."); 1423 m_log.Info("[PHYSICS]: Couldn't remove prim from physics scene, it was already be removed.");
1378 } 1424 }
1425 lock (_prims)
1379 _prims.Remove(prim); 1426 _prims.Remove(prim);
1380 1427
1381 //If there are no more geometries in the sub-space, we don't need it in the main space anymore 1428 //If there are no more geometries in the sub-space, we don't need it in the main space anymore
@@ -2376,9 +2423,12 @@ namespace OpenSim.Region.Physics.OdePlugin
2376 { 2423 {
2377 lock (OdeLock) 2424 lock (OdeLock)
2378 { 2425 {
2379 foreach (OdePrim prm in _prims) 2426 lock (_prims)
2380 { 2427 {
2381 RemovePrim(prm); 2428 foreach (OdePrim prm in _prims)
2429 {
2430 RemovePrim(prm);
2431 }
2382 } 2432 }
2383 2433
2384 //foreach (OdeCharacter act in _characters) 2434 //foreach (OdeCharacter act in _characters)
@@ -2411,5 +2461,126 @@ namespace OpenSim.Region.Physics.OdePlugin
2411 } 2461 }
2412 return returncolliders; 2462 return returncolliders;
2413 } 2463 }
2464#if USE_DRAWSTUFF
2465 // Keyboard callback
2466 public void command(int cmd)
2467 {
2468 IntPtr geom;
2469 d.Mass mass;
2470 d.Vector3 sides = new d.Vector3(d.RandReal() * 0.5f + 0.1f, d.RandReal() * 0.5f + 0.1f, d.RandReal() * 0.5f + 0.1f);
2471
2472
2473
2474 Char ch = Char.ToLower((Char)cmd);
2475 switch ((Char)ch)
2476 {
2477 case 'w':
2478 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));
2479
2480 xyz.X += rotate.X; xyz.Y += rotate.Y; xyz.Z += rotate.Z;
2481 ds.SetViewpoint(ref xyz, ref hpr);
2482 break;
2483
2484 case 'a':
2485 hpr.X++;
2486 ds.SetViewpoint(ref xyz, ref hpr);
2487 break;
2488
2489 case 's':
2490 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));
2491
2492 xyz.X += rotate2.X; xyz.Y += rotate2.Y; xyz.Z += rotate2.Z;
2493 ds.SetViewpoint(ref xyz, ref hpr);
2494 break;
2495 case 'd':
2496 hpr.X--;
2497 ds.SetViewpoint(ref xyz, ref hpr);
2498 break;
2499 case 'r':
2500 xyz.Z++;
2501 ds.SetViewpoint(ref xyz, ref hpr);
2502 break;
2503 case 'f':
2504 xyz.Z--;
2505 ds.SetViewpoint(ref xyz, ref hpr);
2506 break;
2507 case 'e':
2508 xyz.Y++;
2509 ds.SetViewpoint(ref xyz, ref hpr);
2510 break;
2511 case 'q':
2512 xyz.Y--;
2513 ds.SetViewpoint(ref xyz, ref hpr);
2514 break;
2515 }
2516 }
2517
2518 public void step(int pause)
2519 {
2520
2521 ds.SetColor(1.0f, 1.0f, 0.0f);
2522 ds.SetTexture(ds.Texture.Wood);
2523 lock (_prims)
2524 {
2525 foreach (OdePrim prm in _prims)
2526 {
2527 //IntPtr body = d.GeomGetBody(prm.prim_geom);
2528 if (prm.prim_geom != IntPtr.Zero)
2529 {
2530 d.Vector3 pos;
2531 d.GeomCopyPosition(prm.prim_geom, out pos);
2532 //d.BodyCopyPosition(body, out pos);
2533
2534 d.Matrix3 R;
2535 d.GeomCopyRotation(prm.prim_geom, out R);
2536 //d.BodyCopyRotation(body, out R);
2537
2538
2539 d.Vector3 sides = new d.Vector3();
2540 sides.X = prm.Size.X;
2541 sides.Y = prm.Size.Y;
2542 sides.Z = prm.Size.Z;
2543
2544 ds.DrawBox(ref pos, ref R, ref sides);
2545 }
2546 }
2547 }
2548 ds.SetColor(1.0f, 0.0f, 0.0f);
2549 lock (_characters)
2550 {
2551 foreach (OdeCharacter chr in _characters)
2552 {
2553 if (chr.Shell != IntPtr.Zero)
2554 {
2555 IntPtr body = d.GeomGetBody(chr.Shell);
2556
2557 d.Vector3 pos;
2558 d.GeomCopyPosition(chr.Shell, out pos);
2559 //d.BodyCopyPosition(body, out pos);
2560
2561 d.Matrix3 R;
2562 d.GeomCopyRotation(chr.Shell, out R);
2563 //d.BodyCopyRotation(body, out R);
2564
2565 ds.DrawCapsule(ref pos, ref R, chr.Size.Z, 0.35f);
2566 d.Vector3 sides = new d.Vector3();
2567 sides.X = 0.5f;
2568 sides.Y = 0.5f;
2569 sides.Z = 0.5f;
2570
2571 ds.DrawBox(ref pos, ref R, ref sides);
2572
2573
2574 }
2575 }
2576 }
2577 }
2578
2579 public void start(int unused)
2580 {
2581
2582 ds.SetViewpoint(ref xyz, ref hpr);
2583 }
2584#endif
2414 } 2585 }
2415} 2586}