diff options
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r-- | OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs | 3 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Interfaces/ITerrainModule.cs | 2 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/TerrainChannel.cs | 72 |
3 files changed, 76 insertions, 1 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs b/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs index 469bd31..f660b8d 100644 --- a/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs +++ b/OpenSim/Region/Framework/Interfaces/ITerrainChannel.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using OpenSim.Framework; | 28 | using OpenSim.Framework; |
29 | using OpenMetaverse; | ||
29 | 30 | ||
30 | namespace OpenSim.Region.Framework.Interfaces | 31 | namespace OpenSim.Region.Framework.Interfaces |
31 | { | 32 | { |
@@ -56,5 +57,7 @@ namespace OpenSim.Region.Framework.Interfaces | |||
56 | ITerrainChannel MakeCopy(); | 57 | ITerrainChannel MakeCopy(); |
57 | string SaveToXmlString(); | 58 | string SaveToXmlString(); |
58 | void LoadFromXmlString(string data); | 59 | void LoadFromXmlString(string data); |
60 | // Merge some terrain into this channel | ||
61 | void Merge(ITerrainChannel newTerrain, Vector3 displacement, float radianRotation, Vector2 rotationDisplacement); | ||
59 | } | 62 | } |
60 | } | 63 | } |
diff --git a/OpenSim/Region/Framework/Interfaces/ITerrainModule.cs b/OpenSim/Region/Framework/Interfaces/ITerrainModule.cs index 189a30a..a6f5d98 100644 --- a/OpenSim/Region/Framework/Interfaces/ITerrainModule.cs +++ b/OpenSim/Region/Framework/Interfaces/ITerrainModule.cs | |||
@@ -51,7 +51,7 @@ namespace OpenSim.Region.Framework.Interfaces | |||
51 | /// </param> | 51 | /// </param> |
52 | /// <param name="stream"></param> | 52 | /// <param name="stream"></param> |
53 | void LoadFromStream(string filename, Stream stream); | 53 | void LoadFromStream(string filename, Stream stream); |
54 | void LoadFromStream(string filename, Vector2 displacement, Stream stream); | 54 | void LoadFromStream(string filename, Vector3 displacement, float radianRotation, Vector2 rotationDisplacement, Stream stream); |
55 | void LoadFromStream(string filename, System.Uri pathToTerrainHeightmap); | 55 | void LoadFromStream(string filename, System.Uri pathToTerrainHeightmap); |
56 | /// <summary> | 56 | /// <summary> |
57 | /// Save a terrain to a stream. | 57 | /// Save a terrain to a stream. |
diff --git a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs index b4b1823..24709dc 100644 --- a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs +++ b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs | |||
@@ -36,6 +36,8 @@ using OpenSim.Data; | |||
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
38 | 38 | ||
39 | using OpenMetaverse; | ||
40 | |||
39 | using log4net; | 41 | using log4net; |
40 | 42 | ||
41 | namespace OpenSim.Region.Framework.Scenes | 43 | namespace OpenSim.Region.Framework.Scenes |
@@ -212,6 +214,76 @@ namespace OpenSim.Region.Framework.Scenes | |||
212 | sr.Close(); | 214 | sr.Close(); |
213 | } | 215 | } |
214 | 216 | ||
217 | // ITerrainChannel.Merge | ||
218 | public void Merge(ITerrainChannel newTerrain, Vector3 displacement, float radianRotation, Vector2 rotationDisplacement) | ||
219 | { | ||
220 | for (int xx = 0; xx < newTerrain.Width; xx++) | ||
221 | { | ||
222 | for (int yy = 0; yy < newTerrain.Height; yy++) | ||
223 | { | ||
224 | int dispX = (int)displacement.X; | ||
225 | int dispY = (int)displacement.Y; | ||
226 | float newHeight = (float)newTerrain[xx, yy] + displacement.Z; | ||
227 | if (radianRotation == 0) | ||
228 | { | ||
229 | // If no rotation, place the new height in the specified location | ||
230 | dispX += xx; | ||
231 | dispY += yy; | ||
232 | if (dispX >= 0 && dispX < m_terrainData.SizeX && dispY >= 0 && dispY < m_terrainData.SizeY) | ||
233 | { | ||
234 | m_terrainData[dispX, dispY] = newHeight; | ||
235 | } | ||
236 | } | ||
237 | else | ||
238 | { | ||
239 | // If rotating, we have to smooth the result because the conversion | ||
240 | // to ints will mean heightmap entries will not get changed | ||
241 | // First compute the rotation location for the new height. | ||
242 | dispX += (int)(rotationDisplacement.X | ||
243 | + ((float)xx - rotationDisplacement.X) * Math.Cos(radianRotation) | ||
244 | - ((float)yy - rotationDisplacement.Y) * Math.Sin(radianRotation) ); | ||
245 | |||
246 | dispY += (int)(rotationDisplacement.Y | ||
247 | + ((float)xx - rotationDisplacement.X) * Math.Sin(radianRotation) | ||
248 | + ((float)yy - rotationDisplacement.Y) * Math.Cos(radianRotation) ); | ||
249 | |||
250 | if (dispX >= 0 && dispX < m_terrainData.SizeX && dispY >= 0 && dispY < m_terrainData.SizeY) | ||
251 | { | ||
252 | float oldHeight = m_terrainData[dispX, dispY]; | ||
253 | // Smooth the heights around this location if the old height is far from this one | ||
254 | for (int sxx = dispX - 2; sxx < dispX + 2; sxx++) | ||
255 | { | ||
256 | for (int syy = dispY - 2; syy < dispY + 2; syy++) | ||
257 | { | ||
258 | if (sxx >= 0 && sxx < m_terrainData.SizeX && syy >= 0 && syy < m_terrainData.SizeY) | ||
259 | { | ||
260 | if (sxx == dispX && syy == dispY) | ||
261 | { | ||
262 | // Set height for the exact rotated point | ||
263 | m_terrainData[dispX, dispY] = newHeight; | ||
264 | } | ||
265 | else | ||
266 | { | ||
267 | if (Math.Abs(m_terrainData[sxx, syy] - newHeight) > 1f) | ||
268 | { | ||
269 | // If the adjacent height is far off, force it to this height | ||
270 | m_terrainData[sxx, syy] = newHeight; | ||
271 | } | ||
272 | } | ||
273 | } | ||
274 | } | ||
275 | } | ||
276 | } | ||
277 | |||
278 | if (dispX >= 0 && dispX < m_terrainData.SizeX && dispY >= 0 && dispY < m_terrainData.SizeY) | ||
279 | { | ||
280 | m_terrainData[dispX, dispY] = (float)newTerrain[xx, yy]; | ||
281 | } | ||
282 | } | ||
283 | } | ||
284 | } | ||
285 | } | ||
286 | |||
215 | #endregion | 287 | #endregion |
216 | 288 | ||
217 | public TerrainChannel Copy() | 289 | public TerrainChannel Copy() |