BulletSim: Fix snap back from edge of region problem. Mantis 6794.

link-sitting
Robert Adams 2013-10-11 13:29:43 -07:00
parent 75f63ecfcd
commit 8b5e2f2cd2
1 changed files with 13 additions and 2 deletions

View File

@ -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. // Return a new position that is over known terrain if the position is outside our terrain.
public Vector3 ClampPositionIntoKnownTerrain(Vector3 pPos) public Vector3 ClampPositionIntoKnownTerrain(Vector3 pPos)
{ {
float edgeEpsilon = 0.1f;
Vector3 ret = pPos; Vector3 ret = pPos;
// First, base addresses are never negative so correct for that possible problem. // 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. // 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. // 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); Vector3 adjacentTerrainBase = FindAdjacentTerrainBase(terrainBaseXYZ);
ret.X = Math.Min(ret.X, adjacentTerrainBase.X + (ret.X % DefaultRegionSize.X)); if (adjacentTerrainBase.X < terrainBaseXYZ.X)
ret.Y = Math.Min(ret.Y, adjacentTerrainBase.Y + (ret.X % DefaultRegionSize.Y)); {
// 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}", DetailLog("{0},BSTerrainManager.ClampPositionToKnownTerrain,findingAdjacentRegion,adjacentRegBase={1},oldPos={2},newPos={3}",
BSScene.DetailLogZero, adjacentTerrainBase, pPos, ret); BSScene.DetailLogZero, adjacentTerrainBase, pPos, ret);