TerrainChannel.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.IO;
  29. using System.Text;
  30. using System.Reflection;
  31. using System.Xml;
  32. using System.Xml.Serialization;
  33. using OpenSim.Data;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenMetaverse;
  37. using log4net;
  38. namespace OpenSim.Region.Framework.Scenes
  39. {
  40. /// <summary>
  41. /// A new version of the old Channel class, simplified
  42. /// </summary>
  43. public class TerrainChannel : ITerrainChannel
  44. {
  45. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. private static string LogHeader = "[TERRAIN CHANNEL]";
  47. protected TerrainData m_terrainData;
  48. public int Width { get { return m_terrainData.SizeX; } } // X dimension
  49. // Unfortunately, for historical reasons, in this module 'Width' is X and 'Height' is Y
  50. public int Height { get { return m_terrainData.SizeY; } } // Y dimension
  51. public int Altitude { get { return m_terrainData.SizeZ; } } // Y dimension
  52. // Default, not-often-used builder
  53. public TerrainChannel()
  54. {
  55. m_terrainData = new HeightmapTerrainData((int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
  56. FlatLand();
  57. // PinHeadIsland();
  58. }
  59. // Create terrain of given size
  60. public TerrainChannel(int pX, int pY)
  61. {
  62. m_terrainData = new HeightmapTerrainData(pX, pY, (int)Constants.RegionHeight);
  63. }
  64. // Create terrain of specified size and initialize with specified terrain.
  65. // TODO: join this with the terrain initializers.
  66. public TerrainChannel(String type, int pX, int pY, int pZ)
  67. {
  68. m_terrainData = new HeightmapTerrainData(pX, pY, pZ);
  69. if (type.Equals("flat"))
  70. FlatLand();
  71. else
  72. PinHeadIsland();
  73. }
  74. // Create channel passed a heightmap and expected dimensions of the region.
  75. // The heightmap might not fit the passed size so accomodations must be made.
  76. public TerrainChannel(double[,] pM, int pSizeX, int pSizeY, int pAltitude)
  77. {
  78. int hmSizeX = pM.GetLength(0);
  79. int hmSizeY = pM.GetLength(1);
  80. m_terrainData = new HeightmapTerrainData(pSizeX, pSizeY, pAltitude);
  81. for (int xx = 0; xx < pSizeX; xx++)
  82. for (int yy = 0; yy < pSizeY; yy++)
  83. if (xx > hmSizeX || yy > hmSizeY)
  84. m_terrainData[xx, yy] = TerrainData.DefaultTerrainHeight;
  85. else
  86. m_terrainData[xx, yy] = (float)pM[xx, yy];
  87. }
  88. public TerrainChannel(TerrainData pTerrData)
  89. {
  90. m_terrainData = pTerrData;
  91. }
  92. #region ITerrainChannel Members
  93. // ITerrainChannel.MakeCopy()
  94. public ITerrainChannel MakeCopy()
  95. {
  96. return this.Copy();
  97. }
  98. // ITerrainChannel.GetTerrainData()
  99. public TerrainData GetTerrainData()
  100. {
  101. return m_terrainData;
  102. }
  103. // ITerrainChannel.GetFloatsSerialized()
  104. // This one dimensional version is ordered so height = map[y*sizeX+x];
  105. // DEPRECATED: don't use this function as it does not retain the dimensions of the terrain
  106. // and the caller will probably do the wrong thing if the terrain is not the legacy 256x256.
  107. public float[] GetFloatsSerialised()
  108. {
  109. return m_terrainData.GetFloatsSerialized();
  110. }
  111. // ITerrainChannel.GetDoubles()
  112. public double[,] GetDoubles()
  113. {
  114. double[,] heights = new double[Width, Height];
  115. int idx = 0; // index into serialized array
  116. for (int ii = 0; ii < Width; ii++)
  117. {
  118. for (int jj = 0; jj < Height; jj++)
  119. {
  120. heights[ii, jj] = (double)m_terrainData[ii, jj];
  121. idx++;
  122. }
  123. }
  124. return heights;
  125. }
  126. // ITerrainChannel.this[x,y]
  127. public double this[int x, int y]
  128. {
  129. get {
  130. if (x < 0 || x >= Width || y < 0 || y >= Height)
  131. return 0;
  132. return (double)m_terrainData[x, y];
  133. }
  134. set
  135. {
  136. if (Double.IsNaN(value) || Double.IsInfinity(value))
  137. return;
  138. m_terrainData[x, y] = (float)value;
  139. }
  140. }
  141. // ITerrainChannel.GetHieghtAtXYZ(x, y, z)
  142. public float GetHeightAtXYZ(float x, float y, float z)
  143. {
  144. if (x < 0 || x >= Width || y < 0 || y >= Height)
  145. return 0;
  146. return m_terrainData[(int)x, (int)y];
  147. }
  148. // ITerrainChannel.Tainted()
  149. public bool Tainted(int x, int y)
  150. {
  151. return m_terrainData.IsTaintedAt(x, y);
  152. }
  153. // ITerrainChannel.SaveToXmlString()
  154. public string SaveToXmlString()
  155. {
  156. XmlWriterSettings settings = new XmlWriterSettings();
  157. settings.Encoding = Util.UTF8;
  158. using (StringWriter sw = new StringWriter())
  159. {
  160. using (XmlWriter writer = XmlWriter.Create(sw, settings))
  161. {
  162. WriteXml(writer);
  163. }
  164. string output = sw.ToString();
  165. return output;
  166. }
  167. }
  168. // ITerrainChannel.LoadFromXmlString()
  169. public void LoadFromXmlString(string data)
  170. {
  171. StringReader sr = new StringReader(data);
  172. XmlTextReader reader = new XmlTextReader(sr);
  173. reader.Read();
  174. ReadXml(reader);
  175. reader.Close();
  176. sr.Close();
  177. }
  178. // ITerrainChannel.Merge
  179. public void Merge(ITerrainChannel newTerrain, Vector3 displacement, float radianRotation, Vector2 rotationDisplacement)
  180. {
  181. m_log.DebugFormat("{0} Merge. inSize=<{1},{2}>, disp={3}, rot={4}, rotDisp={5}, outSize=<{6},{7}>", LogHeader,
  182. newTerrain.Width, newTerrain.Height,
  183. displacement, radianRotation, rotationDisplacement,
  184. m_terrainData.SizeX, m_terrainData.SizeY);
  185. for (int xx = 0; xx < newTerrain.Width; xx++)
  186. {
  187. for (int yy = 0; yy < newTerrain.Height; yy++)
  188. {
  189. int dispX = (int)displacement.X;
  190. int dispY = (int)displacement.Y;
  191. float newHeight = (float)newTerrain[xx, yy] + displacement.Z;
  192. if (radianRotation == 0)
  193. {
  194. // If no rotation, place the new height in the specified location
  195. dispX += xx;
  196. dispY += yy;
  197. if (dispX >= 0 && dispX < m_terrainData.SizeX && dispY >= 0 && dispY < m_terrainData.SizeY)
  198. {
  199. m_terrainData[dispX, dispY] = newHeight;
  200. }
  201. }
  202. else
  203. {
  204. // If rotating, we have to smooth the result because the conversion
  205. // to ints will mean heightmap entries will not get changed
  206. // First compute the rotation location for the new height.
  207. dispX += (int)(rotationDisplacement.X
  208. + ((float)xx - rotationDisplacement.X) * Math.Cos(radianRotation)
  209. - ((float)yy - rotationDisplacement.Y) * Math.Sin(radianRotation) );
  210. dispY += (int)(rotationDisplacement.Y
  211. + ((float)xx - rotationDisplacement.X) * Math.Sin(radianRotation)
  212. + ((float)yy - rotationDisplacement.Y) * Math.Cos(radianRotation) );
  213. if (dispX >= 0 && dispX < m_terrainData.SizeX && dispY >= 0 && dispY < m_terrainData.SizeY)
  214. {
  215. float oldHeight = m_terrainData[dispX, dispY];
  216. // Smooth the heights around this location if the old height is far from this one
  217. for (int sxx = dispX - 2; sxx < dispX + 2; sxx++)
  218. {
  219. for (int syy = dispY - 2; syy < dispY + 2; syy++)
  220. {
  221. if (sxx >= 0 && sxx < m_terrainData.SizeX && syy >= 0 && syy < m_terrainData.SizeY)
  222. {
  223. if (sxx == dispX && syy == dispY)
  224. {
  225. // Set height for the exact rotated point
  226. m_terrainData[dispX, dispY] = newHeight;
  227. }
  228. else
  229. {
  230. if (Math.Abs(m_terrainData[sxx, syy] - newHeight) > 1f)
  231. {
  232. // If the adjacent height is far off, force it to this height
  233. m_terrainData[sxx, syy] = newHeight;
  234. }
  235. }
  236. }
  237. }
  238. }
  239. }
  240. if (dispX >= 0 && dispX < m_terrainData.SizeX && dispY >= 0 && dispY < m_terrainData.SizeY)
  241. {
  242. m_terrainData[dispX, dispY] = (float)newTerrain[xx, yy];
  243. }
  244. }
  245. }
  246. }
  247. }
  248. /// <summary>
  249. /// A new version of terrain merge that processes the terrain in a specific order and corrects the problems with rotated terrains
  250. /// having 'holes' in that need to be smoothed. The correct way to rotate something is to iterate over the target, taking data from
  251. /// the source, not the other way around. This ensures that the target has no holes in it.
  252. /// The processing order of an incoming terrain is:
  253. /// 1. Apply rotation
  254. /// 2. Apply bounding rectangle
  255. /// 3. Apply displacement
  256. /// rotationCenter is no longer needed and has been discarded.
  257. /// </summary>
  258. /// <param name="newTerrain"></param>
  259. /// <param name="displacement">&lt;x, y, z&gt;</param>
  260. /// <param name="rotationDegrees"></param>
  261. /// <param name="boundingOrigin">&lt;x, y&gt;</param>
  262. /// <param name="boundingSize">&lt;x, y&gt;</param>
  263. public void MergeWithBounding(ITerrainChannel newTerrain, Vector3 displacement, float rotationDegrees, Vector2 boundingOrigin, Vector2 boundingSize)
  264. {
  265. m_log.DebugFormat("{0} MergeWithBounding: inSize=<{1},{2}>, rot={3}, boundingOrigin={4}, boundingSize={5}, disp={6}, outSize=<{7},{8}>",
  266. LogHeader, newTerrain.Width, newTerrain.Height, rotationDegrees, boundingOrigin.ToString(),
  267. boundingSize.ToString(), displacement, m_terrainData.SizeX, m_terrainData.SizeY);
  268. // get the size of the incoming terrain
  269. int baseX = newTerrain.Width;
  270. int baseY = newTerrain.Height;
  271. // create an intermediate terrain map that is 25% bigger on each side that we can work with to handle rotation
  272. int offsetX = baseX / 4; // the original origin will now be at these coordinates so now we can have imaginary negative coordinates ;)
  273. int offsetY = baseY / 4;
  274. int tmpX = baseX + baseX / 2;
  275. int tmpY = baseY + baseY / 2;
  276. int centreX = tmpX / 2;
  277. int centreY = tmpY / 2;
  278. TerrainData terrain_tmp = new HeightmapTerrainData(tmpX, tmpY, (int)Constants.RegionHeight);
  279. for (int xx = 0; xx < tmpX; xx++)
  280. for (int yy = 0; yy < tmpY; yy++)
  281. terrain_tmp[xx, yy] = -65535f; //use this height like an 'alpha' mask channel
  282. double radianRotation = Math.PI * rotationDegrees / 180f;
  283. double cosR = Math.Cos(radianRotation);
  284. double sinR = Math.Sin(radianRotation);
  285. if (rotationDegrees < 0f) rotationDegrees += 360f; //-90=270 -180=180 -270=90
  286. // So first we apply the rotation to the incoming terrain, storing the result in terrain_tmp
  287. // We special case orthogonal rotations for accuracy because even using double precision math, Math.Cos(90 degrees) is never fully 0
  288. // and we can never rotate around a centre 'pixel' because the 'bitmap' size is always even
  289. int x, y, sx, sy;
  290. for (y = 0; y <= tmpY; y++)
  291. {
  292. for (x = 0; x <= tmpX; x++)
  293. {
  294. if (rotationDegrees == 0f)
  295. {
  296. sx = x - offsetX;
  297. sy = y - offsetY;
  298. }
  299. else if (rotationDegrees == 90f)
  300. {
  301. sx = y - offsetX;
  302. sy = tmpY - 1 - x - offsetY;
  303. }
  304. else if (rotationDegrees == 180f)
  305. {
  306. sx = tmpX - 1 - x - offsetX;
  307. sy = tmpY - 1 - y - offsetY;
  308. }
  309. else if (rotationDegrees == 270f)
  310. {
  311. sx = tmpX - 1 - y - offsetX;
  312. sy = x - offsetY;
  313. }
  314. else
  315. {
  316. // arbitary rotation: hmmm should I be using (centreX - 0.5) and (centreY - 0.5) and round cosR and sinR to say only 5 decimal places?
  317. sx = centreX + (int)Math.Round((((double)x - centreX) * cosR) + (((double)y - centreY) * sinR)) - offsetX;
  318. sy = centreY + (int)Math.Round((((double)y - centreY) * cosR) - (((double)x - centreX) * sinR)) - offsetY;
  319. }
  320. if (sx >= 0 && sx < baseX && sy >= 0 && sy < baseY)
  321. {
  322. try
  323. {
  324. terrain_tmp[x, y] = (float)newTerrain[sx, sy];
  325. }
  326. catch (Exception) //just in case we've still not taken care of every way the arrays might go out of bounds! ;)
  327. {
  328. m_log.DebugFormat("{0} MergeWithBounding - Rotate: Out of Bounds sx={1} sy={2} dx={3} dy={4}", sx, sy, x, y);
  329. }
  330. }
  331. }
  332. }
  333. // We could also incorporate the next steps, bounding-rectangle and displacement in the loop above, but it's simpler to visualise if done separately
  334. // and will also make it much easier when later I want the option for maybe a circular or oval bounding shape too ;).
  335. int newX = m_terrainData.SizeX;
  336. int newY = m_terrainData.SizeY;
  337. // displacement is relative to <0,0> in the destination region and defines where the origin of the data selected by the bounding-rectangle is placed
  338. int dispX = (int)Math.Floor(displacement.X);
  339. int dispY = (int)Math.Floor(displacement.Y);
  340. // startX/Y and endX/Y are coordinates in bitmap_tmp
  341. int startX = (int)Math.Floor(boundingOrigin.X) + offsetX;
  342. if (startX > tmpX) startX = tmpX;
  343. if (startX < 0) startX = 0;
  344. int startY = (int)Math.Floor(boundingOrigin.Y) + offsetY;
  345. if (startY > tmpY) startY = tmpY;
  346. if (startY < 0) startY = 0;
  347. int endX = (int)Math.Floor(boundingOrigin.X + boundingSize.X) + offsetX;
  348. if (endX > tmpX) endX = tmpX;
  349. if (endX < 0) endX = 0;
  350. int endY = (int)Math.Floor(boundingOrigin.Y + boundingSize.Y) + offsetY;
  351. if (endY > tmpY) endY = tmpY;
  352. if (endY < 0) endY = 0;
  353. //m_log.DebugFormat("{0} MergeWithBounding: inSize=<{1},{2}>, disp=<{3},{4}> rot={5}, offset=<{6},{7}>, boundingStart=<{8},{9}>, boundingEnd=<{10},{11}>, cosR={12}, sinR={13}, outSize=<{14},{15}>", LogHeader,
  354. // baseX, baseY, dispX, dispY, radianRotation, offsetX, offsetY, startX, startY, endX, endY, cosR, sinR, newX, newY);
  355. int dx, dy;
  356. for (y = startY; y < endY; y++)
  357. {
  358. for (x = startX; x < endX; x++)
  359. {
  360. dx = x - startX + dispX;
  361. dy = y - startY + dispY;
  362. if (dx >= 0 && dx < newX && dy >= 0 && dy < newY)
  363. {
  364. try
  365. {
  366. float newHeight = (float)terrain_tmp[x, y]; //use 'alpha' mask
  367. if (newHeight != -65535f) m_terrainData[dx, dy] = newHeight + displacement.Z;
  368. }
  369. catch (Exception) //just in case we've still not taken care of every way the arrays might go out of bounds! ;)
  370. {
  371. m_log.DebugFormat("{0} MergeWithBounding - Bound & Displace: Out of Bounds sx={1} sy={2} dx={3} dy={4}", x, y, dx, dy);
  372. }
  373. }
  374. }
  375. }
  376. }
  377. #endregion
  378. public TerrainChannel Copy()
  379. {
  380. TerrainChannel copy = new TerrainChannel();
  381. copy.m_terrainData = m_terrainData.Clone();
  382. return copy;
  383. }
  384. private void WriteXml(XmlWriter writer)
  385. {
  386. if (Width == Constants.RegionSize && Height == Constants.RegionSize)
  387. {
  388. // Downward compatibility for legacy region terrain maps.
  389. // If region is exactly legacy size, return the old format XML.
  390. writer.WriteStartElement(String.Empty, "TerrainMap", String.Empty);
  391. ToXml(writer);
  392. writer.WriteEndElement();
  393. }
  394. else
  395. {
  396. // New format XML that includes width and length.
  397. writer.WriteStartElement(String.Empty, "TerrainMap2", String.Empty);
  398. ToXml2(writer);
  399. writer.WriteEndElement();
  400. }
  401. }
  402. private void ReadXml(XmlReader reader)
  403. {
  404. // Check the first element. If legacy element, use the legacy reader.
  405. if (reader.IsStartElement("TerrainMap"))
  406. {
  407. reader.ReadStartElement("TerrainMap");
  408. FromXml(reader);
  409. }
  410. else
  411. {
  412. reader.ReadStartElement("TerrainMap2");
  413. FromXml2(reader);
  414. }
  415. }
  416. // Write legacy terrain map. Presumed to be 256x256 of data encoded as floats in a byte array.
  417. private void ToXml(XmlWriter xmlWriter)
  418. {
  419. float[] mapData = GetFloatsSerialised();
  420. byte[] buffer = new byte[mapData.Length * 4];
  421. for (int i = 0; i < mapData.Length; i++)
  422. {
  423. byte[] value = BitConverter.GetBytes(mapData[i]);
  424. Array.Copy(value, 0, buffer, (i * 4), 4);
  425. }
  426. XmlSerializer serializer = new XmlSerializer(typeof(byte[]));
  427. serializer.Serialize(xmlWriter, buffer);
  428. }
  429. // Read legacy terrain map. Presumed to be 256x256 of data encoded as floats in a byte array.
  430. private void FromXml(XmlReader xmlReader)
  431. {
  432. XmlSerializer serializer = new XmlSerializer(typeof(byte[]));
  433. byte[] dataArray = (byte[])serializer.Deserialize(xmlReader);
  434. int index = 0;
  435. m_terrainData = new HeightmapTerrainData(Height, Width, (int)Constants.RegionHeight);
  436. for (int y = 0; y < Height; y++)
  437. {
  438. for (int x = 0; x < Width; x++)
  439. {
  440. float value;
  441. value = BitConverter.ToSingle(dataArray, index);
  442. index += 4;
  443. this[x, y] = (double)value;
  444. }
  445. }
  446. }
  447. private class TerrainChannelXMLPackage
  448. {
  449. public int Version;
  450. public int SizeX;
  451. public int SizeY;
  452. public int SizeZ;
  453. public float CompressionFactor;
  454. public float[] Map;
  455. public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, float[] pMap)
  456. {
  457. Version = 1;
  458. SizeX = pX;
  459. SizeY = pY;
  460. SizeZ = pZ;
  461. CompressionFactor = pCompressionFactor;
  462. Map = pMap;
  463. }
  464. }
  465. // New terrain serialization format that includes the width and length.
  466. private void ToXml2(XmlWriter xmlWriter)
  467. {
  468. TerrainChannelXMLPackage package = new TerrainChannelXMLPackage(Width, Height, Altitude, m_terrainData.CompressionFactor,
  469. m_terrainData.GetCompressedMap());
  470. XmlSerializer serializer = new XmlSerializer(typeof(TerrainChannelXMLPackage));
  471. serializer.Serialize(xmlWriter, package);
  472. }
  473. // New terrain serialization format that includes the width and length.
  474. private void FromXml2(XmlReader xmlReader)
  475. {
  476. XmlSerializer serializer = new XmlSerializer(typeof(TerrainChannelXMLPackage));
  477. TerrainChannelXMLPackage package = (TerrainChannelXMLPackage)serializer.Deserialize(xmlReader);
  478. m_terrainData = new HeightmapTerrainData(package.Map, package.CompressionFactor, package.SizeX, package.SizeY, package.SizeZ);
  479. }
  480. // Fill the heightmap with the center bump terrain
  481. private void PinHeadIsland()
  482. {
  483. float cx = m_terrainData.SizeX * 0.5f;
  484. float cy = m_terrainData.SizeY * 0.5f;
  485. float h;
  486. for (int x = 0; x < Width; x++)
  487. {
  488. for (int y = 0; y < Height; y++)
  489. {
  490. // h = (float)TerrainUtil.PerlinNoise2D(x, y, 2, 0.125) * 10;
  491. h = 1.0f;
  492. float spherFacA = (float)(TerrainUtil.SphericalFactor(x, y, cx, cy, 50) * 0.01d);
  493. float spherFacB = (float)(TerrainUtil.SphericalFactor(x, y, cx, cy, 100) * 0.001d);
  494. if (h < spherFacA)
  495. h = spherFacA;
  496. if (h < spherFacB)
  497. h = spherFacB;
  498. m_terrainData[x, y] = h;
  499. }
  500. }
  501. }
  502. private void FlatLand()
  503. {
  504. m_terrainData.ClearLand();
  505. }
  506. }
  507. }