aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs
diff options
context:
space:
mode:
authorkitto2010-04-04 22:57:32 -0400
committerkitto2010-04-04 22:57:32 -0400
commite2a521742a737aa54e43dd934c0a0d5f2e380e8f (patch)
tree8259c800deb55b3e42faac9760cf2bcd3d6b27af /OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs
parentUpdate acceleration to 0 on no tphysical. (diff)
downloadopensim-SC-e2a521742a737aa54e43dd934c0a0d5f2e380e8f.zip
opensim-SC-e2a521742a737aa54e43dd934c0a0d5f2e380e8f.tar.gz
opensim-SC-e2a521742a737aa54e43dd934c0a0d5f2e380e8f.tar.bz2
opensim-SC-e2a521742a737aa54e43dd934c0a0d5f2e380e8f.tar.xz
ChODE Only: Corrected Heightmap load to iliminate crack at 255M. Added 'fence' option to prevent physical objects crossing region border.
Diffstat (limited to 'OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs')
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs111
1 files changed, 45 insertions, 66 deletions
diff --git a/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs
index deb6164..79e2986 100644
--- a/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs
@@ -224,6 +224,7 @@ namespace OpenSim.Region.Physics.OdePlugin
224 public float bodyPIDG = 25; 224 public float bodyPIDG = 25;
225 225
226 public int geomCrossingFailuresBeforeOutofbounds = 5; 226 public int geomCrossingFailuresBeforeOutofbounds = 5;
227 public int geomRegionFence = 0;
227 228
228 public float bodyMotorJointMaxforceTensor = 2; 229 public float bodyMotorJointMaxforceTensor = 2;
229 230
@@ -447,6 +448,7 @@ namespace OpenSim.Region.Physics.OdePlugin
447 geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 3); 448 geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 3);
448 geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15); 449 geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15);
449 geomCrossingFailuresBeforeOutofbounds = physicsconfig.GetInt("geom_crossing_failures_before_outofbounds", 5); 450 geomCrossingFailuresBeforeOutofbounds = physicsconfig.GetInt("geom_crossing_failures_before_outofbounds", 5);
451 geomRegionFence = physicsconfig.GetInt("region_border_fence", 0);
450 452
451 geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", 10.000006836f); 453 geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", 10.000006836f);
452 bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", 20); 454 bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", 20);
@@ -3419,76 +3421,56 @@ namespace OpenSim.Region.Physics.OdePlugin
3419 3421
3420 public void SetTerrain(float[] heightMap, Vector3 pOffset) 3422 public void SetTerrain(float[] heightMap, Vector3 pOffset)
3421 { 3423 {
3422 // this._heightmap[i] = (double)heightMap[i];
3423 // dbm (danx0r) -- creating a buffer zone of one extra sample all around
3424 //_origheightmap = heightMap;
3425 3424
3425 uint regionsize = (uint) Constants.RegionSize; // visible region size eg. 256(M)
3426
3427 uint heightmapWidth = regionsize + 1; // ODE map size 257 x 257 (Meters) (1 extra
3428 uint heightmapHeight = regionsize + 1;
3429
3430 uint heightmapWidthSamples = (uint)regionsize + 2; // Sample file size, 258 x 258 samples
3431 uint heightmapHeightSamples = (uint)regionsize + 2;
3432
3433 // Array of height samples for ODE
3426 float[] _heightmap; 3434 float[] _heightmap;
3435 _heightmap = new float[(heightmapWidthSamples * heightmapHeightSamples)]; // loaded samples 258 x 258
3427 3436
3428 // zero out a heightmap array float array (single dimension [flattened])) 3437 // Other ODE parameters
3429 //if ((int)Constants.RegionSize == 256)
3430 // _heightmap = new float[514 * 514];
3431 //else
3432
3433 _heightmap = new float[(((int)Constants.RegionSize + 2) * ((int)Constants.RegionSize + 2))];
3434
3435 uint heightmapWidth = Constants.RegionSize + 1;
3436 uint heightmapHeight = Constants.RegionSize + 1;
3437
3438 uint heightmapWidthSamples;
3439
3440 uint heightmapHeightSamples;
3441
3442 //if (((int)Constants.RegionSize) == 256)
3443 //{
3444 // heightmapWidthSamples = 2 * (uint)Constants.RegionSize + 2;
3445 // heightmapHeightSamples = 2 * (uint)Constants.RegionSize + 2;
3446 // heightmapWidth++;
3447 // heightmapHeight++;
3448 //}
3449 //else
3450 //{
3451
3452 heightmapWidthSamples = (uint)Constants.RegionSize + 1;
3453 heightmapHeightSamples = (uint)Constants.RegionSize + 1;
3454 //}
3455
3456 const float scale = 1.0f; 3438 const float scale = 1.0f;
3457 const float offset = 0.0f; 3439 const float offset = 0.0f;
3458 const float thickness = 0.2f; 3440 const float thickness = 2.0f; // Was 0.2f, Larger appears to prevent Av fall-through
3459 const int wrap = 0; 3441 const int wrap = 0;
3460 3442
3461 int regionsize = (int) Constants.RegionSize + 2; 3443 float hfmin = 2000f;
3462 //Double resolution 3444 float hfmax = -2000f;
3463 //if (((int)Constants.RegionSize) == 256) 3445 float minele = 0.0f; // Dont allow -ve heights
3464 // heightMap = ResizeTerrain512Interpolation(heightMap);
3465
3466
3467 // if (((int)Constants.RegionSize) == 256 && (int)Constants.RegionSize == 256)
3468 // regionsize = 512;
3469
3470 float hfmin = 2000;
3471 float hfmax = -2000;
3472 3446
3473 for (int x = 0; x < heightmapWidthSamples; x++) 3447 uint x = 0;
3448 uint y = 0;
3449 uint xx = 0;
3450 uint yy = 0;
3451
3452 // load the height samples array from the heightMap
3453 for ( x = 0; x < heightmapWidthSamples; x++) // 0 to 257
3454 {
3455 for ( y = 0; y < heightmapHeightSamples; y++) // 0 to 257
3474 { 3456 {
3475 for (int y = 0; y < heightmapHeightSamples; y++) 3457 xx = x - 1;
3476 { 3458 if (xx < 0) xx = 0;
3477 int xx = Util.Clip(x - 1, 0, regionsize - 1); 3459 if (xx > (regionsize - 1)) xx = regionsize - 1;
3478 int yy = Util.Clip(y - 1, 0, regionsize - 1); 3460
3479 3461 yy = y - 1;
3480 3462 if (yy < 0) yy = 0;
3481 float val= heightMap[yy * (int)Constants.RegionSize + xx]; 3463 if (yy > (regionsize - 1)) yy = regionsize - 1;
3482 _heightmap[x * ((int)Constants.RegionSize + 2) + y] = val; 3464 // Input xx = 0 0 1 2 ..... 254 255 255 256 total in
3483 3465 // Output x = 0 1 2 3 ..... 255 256 257 258 total out
3484 hfmin = (val < hfmin) ? val : hfmin; 3466 float val= heightMap[(yy * regionsize) + xx]; // input from heightMap, <0-255 * 256> <0-255>
3485 hfmax = (val > hfmax) ? val : hfmax; 3467 if (val < minele) val = minele;
3486 } 3468 _heightmap[x * (regionsize + 2) + y] = val; // samples output to _heightmap, <0-257 * 258> <0-257>
3469 hfmin = (val < hfmin) ? val : hfmin;
3470 hfmax = (val > hfmax) ? val : hfmax;
3487 } 3471 }
3472 }
3488 3473
3489
3490
3491
3492 lock (OdeLock) 3474 lock (OdeLock)
3493 { 3475 {
3494 IntPtr GroundGeom = IntPtr.Zero; 3476 IntPtr GroundGeom = IntPtr.Zero;
@@ -3504,19 +3486,17 @@ namespace OpenSim.Region.Physics.OdePlugin
3504 d.SpaceRemove(space, GroundGeom); 3486 d.SpaceRemove(space, GroundGeom);
3505 d.GeomDestroy(GroundGeom); 3487 d.GeomDestroy(GroundGeom);
3506 } 3488 }
3507
3508 } 3489 }
3509 IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); 3490 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
3510 d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0, heightmapWidth + 1, heightmapHeight + 1, 3491 d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0,
3511 (int)heightmapWidthSamples + 1, (int)heightmapHeightSamples + 1, scale, 3492 heightmapWidth, heightmapHeight, (int)heightmapWidthSamples,
3512 offset, thickness, wrap); 3493 (int)heightmapHeightSamples, scale, offset, thickness, wrap);
3513 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); 3494 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
3514 GroundGeom = d.CreateHeightfield(space, HeightmapData, 1); 3495 GroundGeom = d.CreateHeightfield(space, HeightmapData, 1);
3515 if (GroundGeom != IntPtr.Zero) 3496 if (GroundGeom != IntPtr.Zero)
3516 { 3497 {
3517 d.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land)); 3498 d.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land));
3518 d.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space)); 3499 d.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space));
3519
3520 } 3500 }
3521 geom_name_map[GroundGeom] = "Terrain"; 3501 geom_name_map[GroundGeom] = "Terrain";
3522 3502
@@ -3534,7 +3514,7 @@ namespace OpenSim.Region.Physics.OdePlugin
3534 3514
3535 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); 3515 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
3536 d.GeomSetRotation(GroundGeom, ref R); 3516 d.GeomSetRotation(GroundGeom, ref R);
3537 d.GeomSetPosition(GroundGeom, (pOffset.X + ((int)Constants.RegionSize * 0.5f)) - 1, (pOffset.Y + ((int)Constants.RegionSize * 0.5f)) - 1, 0); 3517 d.GeomSetPosition(GroundGeom, (pOffset.X + (regionsize * 0.5f)) - 0.5f, (pOffset.Y + (regionsize * 0.5f)) - 0.5f, 0);
3538 IntPtr testGround = IntPtr.Zero; 3518 IntPtr testGround = IntPtr.Zero;
3539 if (RegionTerrain.TryGetValue(pOffset, out testGround)) 3519 if (RegionTerrain.TryGetValue(pOffset, out testGround))
3540 { 3520 {
@@ -3542,7 +3522,6 @@ namespace OpenSim.Region.Physics.OdePlugin
3542 } 3522 }
3543 RegionTerrain.Add(pOffset, GroundGeom, GroundGeom); 3523 RegionTerrain.Add(pOffset, GroundGeom, GroundGeom);
3544 TerrainHeightFieldHeights.Add(GroundGeom,_heightmap); 3524 TerrainHeightFieldHeights.Add(GroundGeom,_heightmap);
3545
3546 } 3525 }
3547 } 3526 }
3548 3527