From 8b5e2f2cd28510fc249bade0ca0d71e02b6b5f34 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 11 Oct 2013 13:29:43 -0700 Subject: [PATCH] BulletSim: Fix snap back from edge of region problem. Mantis 6794. --- .../Physics/BulletSPlugin/BSTerrainManager.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index c4807c41b0..c016eed70b 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs @@ -354,6 +354,8 @@ public sealed class BSTerrainManager : IDisposable // Return a new position that is over known terrain if the position is outside our terrain. public Vector3 ClampPositionIntoKnownTerrain(Vector3 pPos) { + float edgeEpsilon = 0.1f; + Vector3 ret = pPos; // First, base addresses are never negative so correct for that possible problem. @@ -378,10 +380,19 @@ public sealed class BSTerrainManager : IDisposable // NOTE that GetTerrainPhysicalAtXYZ will set 'terrainBaseXYZ' to the base of the unfound region. // Must be off the top of a region. Find an adjacent region to move into. + // The returned terrain is always 'lower'. That is, closer to <0,0>. Vector3 adjacentTerrainBase = FindAdjacentTerrainBase(terrainBaseXYZ); - ret.X = Math.Min(ret.X, adjacentTerrainBase.X + (ret.X % DefaultRegionSize.X)); - ret.Y = Math.Min(ret.Y, adjacentTerrainBase.Y + (ret.X % DefaultRegionSize.Y)); + if (adjacentTerrainBase.X < terrainBaseXYZ.X) + { + // moving down into a new region in the X dimension. New position will be the max in the new base. + ret.X = adjacentTerrainBase.X + DefaultRegionSize.X - edgeEpsilon; + } + if (adjacentTerrainBase.Y < terrainBaseXYZ.Y) + { + // moving down into a new region in the X dimension. New position will be the max in the new base. + ret.Y = adjacentTerrainBase.Y + DefaultRegionSize.Y - edgeEpsilon; + } DetailLog("{0},BSTerrainManager.ClampPositionToKnownTerrain,findingAdjacentRegion,adjacentRegBase={1},oldPos={2},newPos={3}", BSScene.DetailLogZero, adjacentTerrainBase, pPos, ret);