aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs234
1 files changed, 172 insertions, 62 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
index 3e0ccef..7632e25 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
@@ -60,19 +60,31 @@ namespace OpenSim.Region.Physics.OdePlugin
60 public int lastframe; 60 public int lastframe;
61 } 61 }
62 62
63 // colision flags of things others can colide with
64 // rays, sensors, probes removed since can't be colided with
65 // The top space where things are placed provided further selection
66 // ie physical are in active space nonphysical in static
67 // this should be exclusive as possible
68
63 [Flags] 69 [Flags]
64 public enum CollisionCategories : int 70 public enum CollisionCategories : uint
65 { 71 {
66 Disabled = 0, 72 Disabled = 0,
67 Geom = 0x00000001, 73 //by 'things' types
68 Body = 0x00000002, 74 Space = 0x01,
69 Space = 0x00000004, 75 Geom = 0x02, // aka prim/part
70 Character = 0x00000008, 76 Character = 0x04,
71 Land = 0x00000010, 77 Land = 0x08,
72 Water = 0x00000020, 78 Water = 0x010,
73 Wind = 0x00000040, 79
74 Sensor = 0x00000080, 80 // by state
75 Selected = 0x00000100 81 Phantom = 0x01000,
82 VolumeDtc = 0x02000,
83 Selected = 0x04000,
84 NoShape = 0x08000,
85
86
87 All = 0xffffffff
76 } 88 }
77 89
78 /// <summary> 90 /// <summary>
@@ -116,6 +128,7 @@ namespace OpenSim.Region.Physics.OdePlugin
116 Acceleration, 128 Acceleration,
117 Force, 129 Force,
118 Torque, 130 Torque,
131 Momentum,
119 132
120 AddForce, 133 AddForce,
121 AddAngForce, 134 AddAngForce,
@@ -186,7 +199,9 @@ namespace OpenSim.Region.Physics.OdePlugin
186 private float waterlevel = 0f; 199 private float waterlevel = 0f;
187 private int framecount = 0; 200 private int framecount = 0;
188 201
189 internal IntPtr WaterGeom; 202 private IntPtr WaterGeom = IntPtr.Zero;
203 private IntPtr WaterHeightmapData = IntPtr.Zero;
204 private GCHandle WaterMapHandler = new GCHandle();
190 205
191 public float avPIDD = 2200f; // make it visible 206 public float avPIDD = 2200f; // make it visible
192 public float avPIDP = 900f; // make it visible 207 public float avPIDP = 900f; // make it visible
@@ -213,9 +228,8 @@ namespace OpenSim.Region.Physics.OdePlugin
213 228
214// public int geomCrossingFailuresBeforeOutofbounds = 6; 229// public int geomCrossingFailuresBeforeOutofbounds = 6;
215 230
216 public int bodyFramesAutoDisable = 20; 231 public int bodyFramesAutoDisable = 5;
217 232
218 private float[] _watermap;
219 233
220 private d.NearCallback nearCallback; 234 private d.NearCallback nearCallback;
221 235
@@ -350,7 +364,7 @@ namespace OpenSim.Region.Physics.OdePlugin
350 // i must RtC#FM 364 // i must RtC#FM
351 } 365 }
352 366
353 d.HashSpaceSetLevels(TopSpace, -2, 8); // cell sizes from .25 to 256 ?? need check what this really does 367 d.HashSpaceSetLevels(TopSpace, -2, 8);
354 d.HashSpaceSetLevels(ActiveSpace, -2, 8); 368 d.HashSpaceSetLevels(ActiveSpace, -2, 8);
355 d.HashSpaceSetLevels(StaticSpace, -2, 8); 369 d.HashSpaceSetLevels(StaticSpace, -2, 8);
356 370
@@ -358,13 +372,27 @@ namespace OpenSim.Region.Physics.OdePlugin
358 d.SpaceSetSublevel(ActiveSpace, 1); 372 d.SpaceSetSublevel(ActiveSpace, 1);
359 d.SpaceSetSublevel(StaticSpace, 1); 373 d.SpaceSetSublevel(StaticSpace, 1);
360 374
375 d.GeomSetCategoryBits(ActiveSpace, (uint)(CollisionCategories.Space |
376 CollisionCategories.Geom |
377 CollisionCategories.Character |
378 CollisionCategories.Phantom |
379 CollisionCategories.VolumeDtc
380 ));
381 d.GeomSetCollideBits(ActiveSpace, 0);
382 d.GeomSetCategoryBits(StaticSpace, (uint)(CollisionCategories.Space |
383 CollisionCategories.Geom |
384 CollisionCategories.Land |
385 CollisionCategories.Water |
386 CollisionCategories.Phantom |
387 CollisionCategories.VolumeDtc
388 ));
389 d.GeomSetCollideBits(StaticSpace, 0);
390
361 contactgroup = d.JointGroupCreate(0); 391 contactgroup = d.JointGroupCreate(0);
362 //contactgroup 392 //contactgroup
363 393
364 d.WorldSetAutoDisableFlag(world, false); 394 d.WorldSetAutoDisableFlag(world, false);
365 } 395 }
366
367 _watermap = new float[258 * 258];
368 } 396 }
369 397
370 // Initialize the mesh plugin 398 // Initialize the mesh plugin
@@ -374,15 +402,18 @@ namespace OpenSim.Region.Physics.OdePlugin
374// checkThread(); 402// checkThread();
375 mesher = meshmerizer; 403 mesher = meshmerizer;
376 m_config = config; 404 m_config = config;
377 405/*
378 string ode_config = d.GetConfiguration("ODE"); 406 string ode_config = d.GetConfiguration("ODE");
379 m_log.WarnFormat("ODE configuration: {0}", ode_config); 407 if (ode_config != null && ode_config != "")
380
381 if (ode_config.Contains("ODE_Ubit"))
382 { 408 {
383 OdeUbitLib = true; 409 m_log.WarnFormat("ODE configuration: {0}", ode_config);
384 }
385 410
411 if (ode_config.Contains("ODE_Ubit"))
412 {
413 OdeUbitLib = true;
414 }
415 }
416*/
386 /* 417 /*
387 if (region != null) 418 if (region != null)
388 { 419 {
@@ -518,6 +549,15 @@ namespace OpenSim.Region.Physics.OdePlugin
518 waitForSpaceUnlock(newspace); 549 waitForSpaceUnlock(newspace);
519 d.SpaceSetSublevel(newspace, 2); 550 d.SpaceSetSublevel(newspace, 2);
520 d.HashSpaceSetLevels(newspace, -2, 8); 551 d.HashSpaceSetLevels(newspace, -2, 8);
552 d.GeomSetCategoryBits(newspace, (uint)(CollisionCategories.Space |
553 CollisionCategories.Geom |
554 CollisionCategories.Land |
555 CollisionCategories.Water |
556 CollisionCategories.Phantom |
557 CollisionCategories.VolumeDtc
558 ));
559 d.GeomSetCollideBits(newspace, 0);
560
521 staticPrimspace[i, j] = newspace; 561 staticPrimspace[i, j] = newspace;
522 } 562 }
523 // let this now be real maximum values 563 // let this now be real maximum values
@@ -1745,8 +1785,6 @@ namespace OpenSim.Region.Physics.OdePlugin
1745 1785
1746 m_rayCastManager.ProcessQueuedRequests(); 1786 m_rayCastManager.ProcessQueuedRequests();
1747 1787
1748
1749
1750 statray += Util.EnvironmentTickCountSubtract(statstart); 1788 statray += Util.EnvironmentTickCountSubtract(statstart);
1751 collision_optimized(); 1789 collision_optimized();
1752 statcol += Util.EnvironmentTickCountSubtract(statstart); 1790 statcol += Util.EnvironmentTickCountSubtract(statstart);
@@ -2125,14 +2163,14 @@ namespace OpenSim.Region.Physics.OdePlugin
2125 RegionTerrain.Remove(pOffset); 2163 RegionTerrain.Remove(pOffset);
2126 if (GroundGeom != IntPtr.Zero) 2164 if (GroundGeom != IntPtr.Zero)
2127 { 2165 {
2166 d.GeomDestroy(GroundGeom);
2167
2128 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom)) 2168 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
2129 { 2169 {
2130 TerrainHeightFieldHeightsHandlers[GroundGeom].Free(); 2170 TerrainHeightFieldHeightsHandlers[GroundGeom].Free();
2131 TerrainHeightFieldHeightsHandlers.Remove(GroundGeom); 2171 TerrainHeightFieldHeightsHandlers.Remove(GroundGeom);
2132 TerrainHeightFieldHeights.Remove(GroundGeom); 2172 TerrainHeightFieldHeights.Remove(GroundGeom);
2133 } 2173 }
2134 d.SpaceRemove(StaticSpace, GroundGeom);
2135 d.GeomDestroy(GroundGeom);
2136 } 2174 }
2137 } 2175 }
2138 IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); 2176 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
@@ -2147,8 +2185,8 @@ namespace OpenSim.Region.Physics.OdePlugin
2147 GroundGeom = d.CreateHeightfield(StaticSpace, HeightmapData, 1); 2185 GroundGeom = d.CreateHeightfield(StaticSpace, HeightmapData, 1);
2148 if (GroundGeom != IntPtr.Zero) 2186 if (GroundGeom != IntPtr.Zero)
2149 { 2187 {
2150 d.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land)); 2188 d.GeomSetCategoryBits(GroundGeom, (uint)(CollisionCategories.Land));
2151 d.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space)); 2189 d.GeomSetCollideBits(GroundGeom, 0);
2152 2190
2153 } 2191 }
2154 geom_name_map[GroundGeom] = "Terrain"; 2192 geom_name_map[GroundGeom] = "Terrain";
@@ -2236,14 +2274,15 @@ namespace OpenSim.Region.Physics.OdePlugin
2236 RegionTerrain.Remove(pOffset); 2274 RegionTerrain.Remove(pOffset);
2237 if (GroundGeom != IntPtr.Zero) 2275 if (GroundGeom != IntPtr.Zero)
2238 { 2276 {
2277 d.GeomDestroy(GroundGeom);
2278
2239 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom)) 2279 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
2240 { 2280 {
2241 TerrainHeightFieldHeightsHandlers[GroundGeom].Free(); 2281 if (TerrainHeightFieldHeightsHandlers[GroundGeom].IsAllocated)
2282 TerrainHeightFieldHeightsHandlers[GroundGeom].Free();
2242 TerrainHeightFieldHeightsHandlers.Remove(GroundGeom); 2283 TerrainHeightFieldHeightsHandlers.Remove(GroundGeom);
2243 TerrainHeightFieldHeights.Remove(GroundGeom); 2284 TerrainHeightFieldHeights.Remove(GroundGeom);
2244 } 2285 }
2245 d.SpaceRemove(StaticSpace, GroundGeom);
2246 d.GeomDestroy(GroundGeom);
2247 } 2286 }
2248 } 2287 }
2249 IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); 2288 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
@@ -2263,8 +2302,8 @@ namespace OpenSim.Region.Physics.OdePlugin
2263 GroundGeom = d.CreateUbitTerrain(StaticSpace, HeightmapData, 1); 2302 GroundGeom = d.CreateUbitTerrain(StaticSpace, HeightmapData, 1);
2264 if (GroundGeom != IntPtr.Zero) 2303 if (GroundGeom != IntPtr.Zero)
2265 { 2304 {
2266 d.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land)); 2305 d.GeomSetCategoryBits(GroundGeom, (uint)(CollisionCategories.Land));
2267 d.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space)); 2306 d.GeomSetCollideBits(GroundGeom, 0);
2268 2307
2269 } 2308 }
2270 geom_name_map[GroundGeom] = "Terrain"; 2309 geom_name_map[GroundGeom] = "Terrain";
@@ -2359,57 +2398,76 @@ namespace OpenSim.Region.Physics.OdePlugin
2359 2398
2360 public void randomizeWater(float baseheight) 2399 public void randomizeWater(float baseheight)
2361 { 2400 {
2362 const uint heightmapWidth = m_regionWidth + 2; 2401 const uint heightmapWidth = Constants.RegionSize + 2;
2363 const uint heightmapHeight = m_regionHeight + 2; 2402 const uint heightmapHeight = Constants.RegionSize + 2;
2364 const uint heightmapWidthSamples = m_regionWidth + 2; 2403 const uint heightmapWidthSamples = heightmapWidth + 1;
2365 const uint heightmapHeightSamples = m_regionHeight + 2; 2404 const uint heightmapHeightSamples = heightmapHeight + 1;
2405
2366 const float scale = 1.0f; 2406 const float scale = 1.0f;
2367 const float offset = 0.0f; 2407 const float offset = 0.0f;
2368 const float thickness = 2.9f;
2369 const int wrap = 0; 2408 const int wrap = 0;
2370 2409
2371 for (int i = 0; i < (258 * 258); i++) 2410 float[] _watermap = new float[heightmapWidthSamples * heightmapWidthSamples];
2411
2412 float maxheigh = float.MinValue;
2413 float minheigh = float.MaxValue;
2414 float val;
2415 for (int i = 0; i < (heightmapWidthSamples * heightmapHeightSamples); i++)
2372 { 2416 {
2373 _watermap[i] = (baseheight-0.1f) + ((float)fluidRandomizer.Next(1,9) / 10f); 2417
2374 // m_log.Info((baseheight - 0.1f) + ((float)fluidRandomizer.Next(1, 9) / 10f)); 2418 val = (baseheight - 0.1f) + ((float)fluidRandomizer.Next(1, 9) / 10f);
2419 _watermap[i] = val;
2420 if (maxheigh < val)
2421 maxheigh = val;
2422 if (minheigh > val)
2423 minheigh = val;
2375 } 2424 }
2376 2425
2426 float thickness = minheigh;
2427
2377 lock (OdeLock) 2428 lock (OdeLock)
2378 { 2429 {
2379 if (WaterGeom != IntPtr.Zero) 2430 if (WaterGeom != IntPtr.Zero)
2380 { 2431 {
2381 d.SpaceRemove(StaticSpace, WaterGeom); 2432 d.GeomDestroy(WaterGeom);
2433 d.GeomHeightfieldDataDestroy(WaterHeightmapData);
2434 WaterGeom = IntPtr.Zero;
2435 WaterHeightmapData = IntPtr.Zero;
2436 if(WaterMapHandler.IsAllocated)
2437 WaterMapHandler.Free();
2382 } 2438 }
2383 IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); 2439
2384 d.GeomHeightfieldDataBuildSingle(HeightmapData, _watermap, 0, heightmapWidth, heightmapHeight, 2440 WaterHeightmapData = d.GeomHeightfieldDataCreate();
2441
2442 WaterMapHandler = GCHandle.Alloc(_watermap, GCHandleType.Pinned);
2443
2444 d.GeomHeightfieldDataBuildSingle(WaterHeightmapData, WaterMapHandler.AddrOfPinnedObject(), 0, heightmapWidth, heightmapHeight,
2385 (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale, 2445 (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale,
2386 offset, thickness, wrap); 2446 offset, thickness, wrap);
2387 d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight); 2447 d.GeomHeightfieldDataSetBounds(WaterHeightmapData, minheigh, maxheigh);
2388 WaterGeom = d.CreateHeightfield(StaticSpace, HeightmapData, 1); 2448 WaterGeom = d.CreateHeightfield(StaticSpace, WaterHeightmapData, 1);
2389 if (WaterGeom != IntPtr.Zero) 2449 if (WaterGeom != IntPtr.Zero)
2390 { 2450 {
2391 d.GeomSetCategoryBits(WaterGeom, (int)(CollisionCategories.Water)); 2451 d.GeomSetCategoryBits(WaterGeom, (uint)(CollisionCategories.Water));
2392 d.GeomSetCollideBits(WaterGeom, (int)(CollisionCategories.Space)); 2452 d.GeomSetCollideBits(WaterGeom, 0);
2393 2453
2394 } 2454 geom_name_map[WaterGeom] = "Water";
2395 geom_name_map[WaterGeom] = "Water";
2396 2455
2397 d.Matrix3 R = new d.Matrix3(); 2456 d.Matrix3 R = new d.Matrix3();
2398 2457
2399 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f); 2458 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
2400 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f); 2459 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
2401 2460
2402 q1 = q1 * q2; 2461 q1 = q1 * q2;
2403 Vector3 v3; 2462 Vector3 v3;
2404 float angle; 2463 float angle;
2405 q1.GetAxisAngle(out v3, out angle); 2464 q1.GetAxisAngle(out v3, out angle);
2406 2465
2407 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); 2466 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
2408 d.GeomSetRotation(WaterGeom, ref R); 2467 d.GeomSetRotation(WaterGeom, ref R);
2409 d.GeomSetPosition(WaterGeom, 128, 128, 0); 2468 d.GeomSetPosition(WaterGeom, (float)Constants.RegionSize * 0.5f, (float)Constants.RegionSize * 0.5f, 0);
2410 2469 }
2411 } 2470 }
2412
2413 } 2471 }
2414 2472
2415 public override void Dispose() 2473 public override void Dispose()
@@ -2427,11 +2485,34 @@ namespace OpenSim.Region.Physics.OdePlugin
2427 } 2485 }
2428 } 2486 }
2429 2487
2488 if (TerrainHeightFieldHeightsHandlers.Count > 0)
2489 {
2490 foreach (GCHandle gch in TerrainHeightFieldHeightsHandlers.Values)
2491 {
2492 if (gch.IsAllocated)
2493 gch.Free();
2494 }
2495 }
2496
2497 if (WaterGeom != IntPtr.Zero)
2498 {
2499 d.GeomDestroy(WaterGeom);
2500 WaterGeom = IntPtr.Zero;
2501 if (WaterHeightmapData != IntPtr.Zero)
2502 d.GeomHeightfieldDataDestroy(WaterHeightmapData);
2503 WaterHeightmapData = IntPtr.Zero;
2504
2505 if (WaterMapHandler.IsAllocated)
2506 WaterMapHandler.Free();
2507 }
2508
2509
2430 if (ContactgeomsArray != IntPtr.Zero) 2510 if (ContactgeomsArray != IntPtr.Zero)
2431 Marshal.FreeHGlobal(ContactgeomsArray); 2511 Marshal.FreeHGlobal(ContactgeomsArray);
2432 if (GlobalContactsArray != IntPtr.Zero) 2512 if (GlobalContactsArray != IntPtr.Zero)
2433 Marshal.FreeHGlobal(GlobalContactsArray); 2513 Marshal.FreeHGlobal(GlobalContactsArray);
2434 2514
2515
2435 d.WorldDestroy(world); 2516 d.WorldDestroy(world);
2436 //d.CloseODE(); 2517 //d.CloseODE();
2437 } 2518 }
@@ -2502,6 +2583,35 @@ namespace OpenSim.Region.Physics.OdePlugin
2502 return new List<ContactResult>(ourResults); 2583 return new List<ContactResult>(ourResults);
2503 } 2584 }
2504 2585
2586 public override bool SuportsRaycastWorldFiltered()
2587 {
2588 return true;
2589 }
2590
2591 public override object RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
2592 {
2593 object SyncObject = new object();
2594 List<ContactResult> ourresults = new List<ContactResult>();
2595
2596 RayCallback retMethod = delegate(List<ContactResult> results)
2597 {
2598 lock (SyncObject)
2599 {
2600 ourresults = results;
2601 Monitor.PulseAll(SyncObject);
2602 }
2603 };
2604
2605 lock (SyncObject)
2606 {
2607 m_rayCastManager.QueueRequest(position, direction, length, Count,filter, retMethod);
2608 if (!Monitor.Wait(SyncObject, 500))
2609 return null;
2610 else
2611 return ourresults;
2612 }
2613 }
2614
2505 public override void RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, RaycastCallback retMethod) 2615 public override void RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
2506 { 2616 {
2507 if (retMethod != null && actor !=null) 2617 if (retMethod != null && actor !=null)