diff options
author | Robert Adams | 2017-08-14 21:20:59 -0700 |
---|---|---|
committer | Robert Adams | 2017-08-14 21:20:59 -0700 |
commit | 36ee8e39411c1eedf72ba082b159528dec8c7880 (patch) | |
tree | ff1d9f807d3fbe40f2783ddb32043ce2757f63c2 /OpenSim/Region | |
parent | Merge branch 'master' into BulletSim2017 (diff) | |
download | opensim-SC-36ee8e39411c1eedf72ba082b159528dec8c7880.zip opensim-SC-36ee8e39411c1eedf72ba082b159528dec8c7880.tar.gz opensim-SC-36ee8e39411c1eedf72ba082b159528dec8c7880.tar.bz2 opensim-SC-36ee8e39411c1eedf72ba082b159528dec8c7880.tar.xz |
BUlletSim: return better terrain height in
BSTerrainHeightMap.GetTerrainHeightAtXYZ().
Partial fix for Mantis 8011. Problem is that computed terrain height
is different than mesh height in the physics engine. For small shapes,
they would have their position corrected to above terrain so they would
never collide.
Diffstat (limited to 'OpenSim/Region')
-rwxr-xr-x | OpenSim/Region/PhysicsModules/BulletS/BSTerrainHeightmap.cs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSTerrainHeightmap.cs b/OpenSim/Region/PhysicsModules/BulletS/BSTerrainHeightmap.cs index 42fc11b..efdf479 100755 --- a/OpenSim/Region/PhysicsModules/BulletS/BSTerrainHeightmap.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSTerrainHeightmap.cs | |||
@@ -141,14 +141,30 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
141 | } | 141 | } |
142 | 142 | ||
143 | // The passed position is relative to the base of the region. | 143 | // The passed position is relative to the base of the region. |
144 | // There are many assumptions herein that the heightmap increment is 1. | ||
144 | public override float GetTerrainHeightAtXYZ(Vector3 pos) | 145 | public override float GetTerrainHeightAtXYZ(Vector3 pos) |
145 | { | 146 | { |
146 | float ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; | 147 | float ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; |
147 | 148 | ||
148 | int mapIndex = (int)pos.Y * (int)m_mapInfo.sizeY + (int)pos.X; | 149 | try { |
149 | try | 150 | int baseX = (int)pos.X; |
150 | { | 151 | int baseY = (int)pos.Y; |
151 | ret = m_mapInfo.heightMap[mapIndex]; | 152 | int maxX = (int)m_mapInfo.sizeX; |
153 | int maxY = (int)m_mapInfo.sizeY; | ||
154 | float diffX = pos.X - (float)baseX; | ||
155 | float diffY = pos.Y - (float)baseY; | ||
156 | |||
157 | float mapHeight1 = m_mapInfo.heightMap[baseY * maxY + baseX]; | ||
158 | float mapHeight2 = m_mapInfo.heightMap[Math.Min(baseY + 1, maxY - 1) * maxY + baseX]; | ||
159 | float mapHeight3 = m_mapInfo.heightMap[baseY * maxY + Math.Min(baseX + 1, maxX - 1)]; | ||
160 | float mapHeight4 = m_mapInfo.heightMap[Math.Min(baseY + 1, maxY - 1) * maxY + Math.Min(baseX + 1, maxX - 1)]; | ||
161 | |||
162 | float Xrise = (mapHeight4 - mapHeight3) * diffX; | ||
163 | float Yrise = (mapHeight2 - mapHeight1) * diffY; | ||
164 | |||
165 | ret = mapHeight1 + ((Xrise + Yrise) / 2f); | ||
166 | m_physicsScene.DetailLog("{0},BSTerrainHeightMap,GetTerrainHeightAtXYZ,pos={1},{2}/{3}/{4}/{5},ret={6}", | ||
167 | BSScene.DetailLogZero, pos, mapHeight1, mapHeight2, mapHeight3, mapHeight4, ret); | ||
152 | } | 168 | } |
153 | catch | 169 | catch |
154 | { | 170 | { |