diff options
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 125 |
1 files changed, 118 insertions, 7 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index bfc16fd..47839ca 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | |||
@@ -85,8 +85,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
85 | private static float metersInSpace = 29.9f; | 85 | private static float metersInSpace = 29.9f; |
86 | private IntPtr contactgroup; | 86 | private IntPtr contactgroup; |
87 | private IntPtr LandGeom = (IntPtr) 0; | 87 | private IntPtr LandGeom = (IntPtr) 0; |
88 | private double[] _heightmap; | 88 | private float[] _heightmap; |
89 | private float[] _origheightmap; | 89 | private float[] _origheightmap; |
90 | |||
90 | private d.NearCallback nearCallback; | 91 | private d.NearCallback nearCallback; |
91 | public d.TriCallback triCallback; | 92 | public d.TriCallback triCallback; |
92 | public d.TriArrayCallback triArrayCallback; | 93 | public d.TriArrayCallback triArrayCallback; |
@@ -185,7 +186,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
185 | } | 186 | } |
186 | 187 | ||
187 | // zero out a heightmap array float array (single dimention [flattened])) | 188 | // zero out a heightmap array float array (single dimention [flattened])) |
188 | _heightmap = new double[514*514]; | 189 | _heightmap = new float[514*514]; |
189 | 190 | ||
190 | 191 | ||
191 | // Zero out the prim spaces array (we split our space into smaller spaces so | 192 | // Zero out the prim spaces array (we split our space into smaller spaces so |
@@ -1152,8 +1153,118 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1152 | get { return (false); // for now we won't be multithreaded | 1153 | get { return (false); // for now we won't be multithreaded |
1153 | } | 1154 | } |
1154 | } | 1155 | } |
1156 | public float[] ResizeTerrain512NearestNeighbour(float[] heightMap) | ||
1157 | { | ||
1158 | float[] returnarr = new float[262144]; | ||
1159 | float[,] resultarr = new float[m_regionWidth, m_regionHeight]; | ||
1160 | |||
1161 | // Filling out the array into it's multi-dimentional components | ||
1162 | for (int y = 0; y < m_regionHeight; y++) | ||
1163 | { | ||
1164 | for (int x = 0; x < m_regionWidth; x++) | ||
1165 | { | ||
1166 | resultarr[y, x] = heightMap[y * m_regionWidth + x]; | ||
1167 | } | ||
1168 | } | ||
1169 | |||
1170 | // Resize using Nearest Neighbour | ||
1171 | |||
1172 | // This particular way is quick but it only works on a multiple of the original | ||
1173 | |||
1174 | // The idea behind this method can be described with the following diagrams | ||
1175 | // second pass and third pass happen in the same loop really.. just separated | ||
1176 | // them to show what this does. | ||
1177 | |||
1178 | // First Pass | ||
1179 | // ResultArr: | ||
1180 | // 1,1,1,1,1,1 | ||
1181 | // 1,1,1,1,1,1 | ||
1182 | // 1,1,1,1,1,1 | ||
1183 | // 1,1,1,1,1,1 | ||
1184 | // 1,1,1,1,1,1 | ||
1185 | // 1,1,1,1,1,1 | ||
1155 | 1186 | ||
1156 | public float[] ResizeTerrain512(float[] heightMap) | 1187 | // Second Pass |
1188 | // ResultArr2: | ||
1189 | // 1,,1,,1,,1,,1,,1, | ||
1190 | // ,,,,,,,,,, | ||
1191 | // 1,,1,,1,,1,,1,,1, | ||
1192 | // ,,,,,,,,,, | ||
1193 | // 1,,1,,1,,1,,1,,1, | ||
1194 | // ,,,,,,,,,, | ||
1195 | // 1,,1,,1,,1,,1,,1, | ||
1196 | // ,,,,,,,,,, | ||
1197 | // 1,,1,,1,,1,,1,,1, | ||
1198 | // ,,,,,,,,,, | ||
1199 | // 1,,1,,1,,1,,1,,1, | ||
1200 | |||
1201 | // Third pass fills in the blanks | ||
1202 | // ResultArr2: | ||
1203 | // 1,1,1,1,1,1,1,1,1,1,1,1 | ||
1204 | // 1,1,1,1,1,1,1,1,1,1,1,1 | ||
1205 | // 1,1,1,1,1,1,1,1,1,1,1,1 | ||
1206 | // 1,1,1,1,1,1,1,1,1,1,1,1 | ||
1207 | // 1,1,1,1,1,1,1,1,1,1,1,1 | ||
1208 | // 1,1,1,1,1,1,1,1,1,1,1,1 | ||
1209 | // 1,1,1,1,1,1,1,1,1,1,1,1 | ||
1210 | // 1,1,1,1,1,1,1,1,1,1,1,1 | ||
1211 | // 1,1,1,1,1,1,1,1,1,1,1,1 | ||
1212 | // 1,1,1,1,1,1,1,1,1,1,1,1 | ||
1213 | // 1,1,1,1,1,1,1,1,1,1,1,1 | ||
1214 | |||
1215 | // X,Y = . | ||
1216 | // X+1,y = ^ | ||
1217 | // X,Y+1 = * | ||
1218 | // X+1,Y+1 = # | ||
1219 | |||
1220 | // Filling in like this; | ||
1221 | // .* | ||
1222 | // ^# | ||
1223 | // 1st . | ||
1224 | // 2nd * | ||
1225 | // 3rd ^ | ||
1226 | // 4th # | ||
1227 | // on single loop. | ||
1228 | |||
1229 | float[,] resultarr2 = new float[512, 512]; | ||
1230 | for (int y = 0; y < m_regionHeight; y++) | ||
1231 | { | ||
1232 | for (int x = 0; x < m_regionWidth; x++) | ||
1233 | { | ||
1234 | resultarr2[y * 2, x * 2] = resultarr[y, x]; | ||
1235 | |||
1236 | if (y < m_regionHeight) | ||
1237 | { | ||
1238 | resultarr2[(y * 2) + 1, x * 2] = resultarr[y, x]; | ||
1239 | } | ||
1240 | if (x < m_regionWidth) | ||
1241 | { | ||
1242 | resultarr2[y * 2, (x * 2) + 1] = resultarr[y, x]; | ||
1243 | } | ||
1244 | if (x < m_regionWidth && y < m_regionHeight) | ||
1245 | { | ||
1246 | resultarr2[(y * 2) + 1, (x * 2) + 1] = resultarr[y, x]; | ||
1247 | } | ||
1248 | } | ||
1249 | } | ||
1250 | //Flatten out the array | ||
1251 | int i = 0; | ||
1252 | for (int y = 0; y < 512; y++) | ||
1253 | { | ||
1254 | for (int x = 0; x < 512; x++) | ||
1255 | { | ||
1256 | if (resultarr2[y, x] <= 0) | ||
1257 | returnarr[i] = 0.0000001f; | ||
1258 | else | ||
1259 | returnarr[i] = resultarr2[y, x]; | ||
1260 | |||
1261 | i++; | ||
1262 | } | ||
1263 | } | ||
1264 | |||
1265 | return returnarr; | ||
1266 | } | ||
1267 | public float[] ResizeTerrain512Interpolation(float[] heightMap) | ||
1157 | { | 1268 | { |
1158 | float[] returnarr = new float[262144]; | 1269 | float[] returnarr = new float[262144]; |
1159 | float[,] resultarr = new float[m_regionWidth,m_regionHeight]; | 1270 | float[,] resultarr = new float[m_regionWidth,m_regionHeight]; |
@@ -1315,11 +1426,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1315 | const uint heightmapHeightSamples = 2*m_regionHeight + 2; | 1426 | const uint heightmapHeightSamples = 2*m_regionHeight + 2; |
1316 | const float scale = 1.0f; | 1427 | const float scale = 1.0f; |
1317 | const float offset = 0.0f; | 1428 | const float offset = 0.0f; |
1318 | const float thickness = 2.0f; | 1429 | const float thickness = 0.2f; |
1319 | const int wrap = 0; | 1430 | const int wrap = 0; |
1320 | 1431 | ||
1321 | //Double resolution | 1432 | //Double resolution |
1322 | heightMap = ResizeTerrain512(heightMap); | 1433 | heightMap = ResizeTerrain512Interpolation(heightMap); |
1323 | for (int x = 0; x < heightmapWidthSamples; x++) | 1434 | for (int x = 0; x < heightmapWidthSamples; x++) |
1324 | { | 1435 | { |
1325 | for (int y = 0; y < heightmapHeightSamples; y++) | 1436 | for (int y = 0; y < heightmapHeightSamples; y++) |
@@ -1327,7 +1438,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1327 | int xx = Util.Clip(x - 1, 0, 511); | 1438 | int xx = Util.Clip(x - 1, 0, 511); |
1328 | int yy = Util.Clip(y - 1, 0, 511); | 1439 | int yy = Util.Clip(y - 1, 0, 511); |
1329 | 1440 | ||
1330 | double val = (double) heightMap[yy*512 + xx]; | 1441 | float val = heightMap[yy*512 + xx]; |
1331 | _heightmap[x*heightmapHeightSamples + y] = val; | 1442 | _heightmap[x*heightmapHeightSamples + y] = val; |
1332 | } | 1443 | } |
1333 | } | 1444 | } |
@@ -1339,7 +1450,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1339 | d.SpaceRemove(space, LandGeom); | 1450 | d.SpaceRemove(space, LandGeom); |
1340 | } | 1451 | } |
1341 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); | 1452 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); |
1342 | d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, heightmapWidth, heightmapHeight, | 1453 | d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0, heightmapWidth, heightmapHeight, |
1343 | (int) heightmapWidthSamples, (int) heightmapHeightSamples, scale, | 1454 | (int) heightmapWidthSamples, (int) heightmapHeightSamples, scale, |
1344 | offset, thickness, wrap); | 1455 | offset, thickness, wrap); |
1345 | d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight); | 1456 | d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight); |