TerrainChannel.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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 TerrainData((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 TerrainData(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 TerrainData(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 TerrainData(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. using(StringReader sr = new StringReader(data))
  172. {
  173. using(XmlTextReader reader = new XmlTextReader(sr))
  174. ReadXml(reader);
  175. }
  176. }
  177. // ITerrainChannel.Merge
  178. public void Merge(ITerrainChannel newTerrain, Vector3 displacement, float radianRotation, Vector2 rotationDisplacement)
  179. {
  180. m_log.DebugFormat("{0} Merge. inSize=<{1},{2}>, disp={3}, rot={4}, rotDisp={5}, outSize=<{6},{7}>", LogHeader,
  181. newTerrain.Width, newTerrain.Height,
  182. displacement, radianRotation, rotationDisplacement,
  183. m_terrainData.SizeX, m_terrainData.SizeY);
  184. for (int xx = 0; xx < newTerrain.Width; xx++)
  185. {
  186. for (int yy = 0; yy < newTerrain.Height; yy++)
  187. {
  188. int dispX = (int)displacement.X;
  189. int dispY = (int)displacement.Y;
  190. float newHeight = (float)newTerrain[xx, yy] + displacement.Z;
  191. if (radianRotation == 0)
  192. {
  193. // If no rotation, place the new height in the specified location
  194. dispX += xx;
  195. dispY += yy;
  196. if (dispX >= 0 && dispX < m_terrainData.SizeX && dispY >= 0 && dispY < m_terrainData.SizeY)
  197. {
  198. m_terrainData[dispX, dispY] = newHeight;
  199. }
  200. }
  201. else
  202. {
  203. // If rotating, we have to smooth the result because the conversion
  204. // to ints will mean heightmap entries will not get changed
  205. // First compute the rotation location for the new height.
  206. dispX += (int)(rotationDisplacement.X
  207. + ((float)xx - rotationDisplacement.X) * Math.Cos(radianRotation)
  208. - ((float)yy - rotationDisplacement.Y) * Math.Sin(radianRotation) );
  209. dispY += (int)(rotationDisplacement.Y
  210. + ((float)xx - rotationDisplacement.X) * Math.Sin(radianRotation)
  211. + ((float)yy - rotationDisplacement.Y) * Math.Cos(radianRotation) );
  212. if (dispX >= 0 && dispX < m_terrainData.SizeX && dispY >= 0 && dispY < m_terrainData.SizeY)
  213. {
  214. float oldHeight = m_terrainData[dispX, dispY];
  215. // Smooth the heights around this location if the old height is far from this one
  216. for (int sxx = dispX - 2; sxx < dispX + 2; sxx++)
  217. {
  218. for (int syy = dispY - 2; syy < dispY + 2; syy++)
  219. {
  220. if (sxx >= 0 && sxx < m_terrainData.SizeX && syy >= 0 && syy < m_terrainData.SizeY)
  221. {
  222. if (sxx == dispX && syy == dispY)
  223. {
  224. // Set height for the exact rotated point
  225. m_terrainData[dispX, dispY] = newHeight;
  226. }
  227. else
  228. {
  229. if (Math.Abs(m_terrainData[sxx, syy] - newHeight) > 1f)
  230. {
  231. // If the adjacent height is far off, force it to this height
  232. m_terrainData[sxx, syy] = newHeight;
  233. }
  234. }
  235. }
  236. }
  237. }
  238. }
  239. if (dispX >= 0 && dispX < m_terrainData.SizeX && dispY >= 0 && dispY < m_terrainData.SizeY)
  240. {
  241. m_terrainData[dispX, dispY] = (float)newTerrain[xx, yy];
  242. }
  243. }
  244. }
  245. }
  246. }
  247. /// <summary>
  248. /// A new version of terrain merge that processes the terrain in a specific order and corrects the problems with rotated terrains
  249. /// having 'holes' in that need to be smoothed. The correct way to rotate something is to iterate over the target, taking data from
  250. /// the source, not the other way around. This ensures that the target has no holes in it.
  251. /// The processing order of an incoming terrain is:
  252. /// 1. Apply rotation
  253. /// 2. Apply bounding rectangle
  254. /// 3. Apply displacement
  255. /// rotationCenter is no longer needed and has been discarded.
  256. /// </summary>
  257. /// <param name="newTerrain"></param>
  258. /// <param name="displacement">&lt;x, y, z&gt;</param>
  259. /// <param name="rotationDegrees"></param>
  260. /// <param name="boundingOrigin">&lt;x, y&gt;</param>
  261. /// <param name="boundingSize">&lt;x, y&gt;</param>
  262. public void MergeWithBounding(ITerrainChannel newTerrain, Vector3 displacement, float rotationDegrees, Vector2 boundingOrigin, Vector2 boundingSize)
  263. {
  264. m_log.DebugFormat("{0} MergeWithBounding: inSize=<{1},{2}>, rot={3}, boundingOrigin={4}, boundingSize={5}, disp={6}, outSize=<{7},{8}>",
  265. LogHeader, newTerrain.Width, newTerrain.Height, rotationDegrees, boundingOrigin.ToString(),
  266. boundingSize.ToString(), displacement, m_terrainData.SizeX, m_terrainData.SizeY);
  267. // get the size of the incoming terrain
  268. int baseX = newTerrain.Width;
  269. int baseY = newTerrain.Height;
  270. // create an intermediate terrain map that is 25% bigger on each side that we can work with to handle rotation
  271. int offsetX = baseX / 4; // the original origin will now be at these coordinates so now we can have imaginary negative coordinates ;)
  272. int offsetY = baseY / 4;
  273. int tmpX = baseX + baseX / 2;
  274. int tmpY = baseY + baseY / 2;
  275. int centreX = tmpX / 2;
  276. int centreY = tmpY / 2;
  277. TerrainData terrain_tmp = new TerrainData(tmpX, tmpY, (int)Constants.RegionHeight);
  278. for (int xx = 0; xx < tmpX; xx++)
  279. for (int yy = 0; yy < tmpY; yy++)
  280. terrain_tmp[xx, yy] = -65535f; //use this height like an 'alpha' mask channel
  281. double radianRotation = Math.PI * rotationDegrees / 180f;
  282. double cosR = Math.Cos(radianRotation);
  283. double sinR = Math.Sin(radianRotation);
  284. if (rotationDegrees < 0f) rotationDegrees += 360f; //-90=270 -180=180 -270=90
  285. // So first we apply the rotation to the incoming terrain, storing the result in terrain_tmp
  286. // We special case orthogonal rotations for accuracy because even using double precision math, Math.Cos(90 degrees) is never fully 0
  287. // and we can never rotate around a centre 'pixel' because the 'bitmap' size is always even
  288. int x, y, sx, sy;
  289. for (y = 0; y <= tmpY; y++)
  290. {
  291. for (x = 0; x <= tmpX; x++)
  292. {
  293. if (rotationDegrees == 0f)
  294. {
  295. sx = x - offsetX;
  296. sy = y - offsetY;
  297. }
  298. else if (rotationDegrees == 90f)
  299. {
  300. sx = y - offsetX;
  301. sy = tmpY - 1 - x - offsetY;
  302. }
  303. else if (rotationDegrees == 180f)
  304. {
  305. sx = tmpX - 1 - x - offsetX;
  306. sy = tmpY - 1 - y - offsetY;
  307. }
  308. else if (rotationDegrees == 270f)
  309. {
  310. sx = tmpX - 1 - y - offsetX;
  311. sy = x - offsetY;
  312. }
  313. else
  314. {
  315. // 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?
  316. sx = centreX + (int)Math.Round((((double)x - centreX) * cosR) + (((double)y - centreY) * sinR)) - offsetX;
  317. sy = centreY + (int)Math.Round((((double)y - centreY) * cosR) - (((double)x - centreX) * sinR)) - offsetY;
  318. }
  319. if (sx >= 0 && sx < baseX && sy >= 0 && sy < baseY)
  320. {
  321. try
  322. {
  323. terrain_tmp[x, y] = (float)newTerrain[sx, sy];
  324. }
  325. catch (Exception) //just in case we've still not taken care of every way the arrays might go out of bounds! ;)
  326. {
  327. m_log.DebugFormat("{0} MergeWithBounding - Rotate: Out of Bounds sx={1} sy={2} dx={3} dy={4}", sx, sy, x, y);
  328. }
  329. }
  330. }
  331. }
  332. // We could also incorporate the next steps, bounding-rectangle and displacement in the loop above, but it's simpler to visualise if done separately
  333. // and will also make it much easier when later I want the option for maybe a circular or oval bounding shape too ;).
  334. int newX = m_terrainData.SizeX;
  335. int newY = m_terrainData.SizeY;
  336. // 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
  337. int dispX = (int)Math.Floor(displacement.X);
  338. int dispY = (int)Math.Floor(displacement.Y);
  339. // startX/Y and endX/Y are coordinates in bitmap_tmp
  340. int startX = (int)Math.Floor(boundingOrigin.X) + offsetX;
  341. if (startX > tmpX) startX = tmpX;
  342. if (startX < 0) startX = 0;
  343. int startY = (int)Math.Floor(boundingOrigin.Y) + offsetY;
  344. if (startY > tmpY) startY = tmpY;
  345. if (startY < 0) startY = 0;
  346. int endX = (int)Math.Floor(boundingOrigin.X + boundingSize.X) + offsetX;
  347. if (endX > tmpX) endX = tmpX;
  348. if (endX < 0) endX = 0;
  349. int endY = (int)Math.Floor(boundingOrigin.Y + boundingSize.Y) + offsetY;
  350. if (endY > tmpY) endY = tmpY;
  351. if (endY < 0) endY = 0;
  352. //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,
  353. // baseX, baseY, dispX, dispY, radianRotation, offsetX, offsetY, startX, startY, endX, endY, cosR, sinR, newX, newY);
  354. int dx, dy;
  355. for (y = startY; y < endY; y++)
  356. {
  357. for (x = startX; x < endX; x++)
  358. {
  359. dx = x - startX + dispX;
  360. dy = y - startY + dispY;
  361. if (dx >= 0 && dx < newX && dy >= 0 && dy < newY)
  362. {
  363. try
  364. {
  365. float newHeight = (float)terrain_tmp[x, y]; //use 'alpha' mask
  366. if (newHeight != -65535f) m_terrainData[dx, dy] = newHeight + displacement.Z;
  367. }
  368. catch (Exception) //just in case we've still not taken care of every way the arrays might go out of bounds! ;)
  369. {
  370. m_log.DebugFormat("{0} MergeWithBounding - Bound & Displace: Out of Bounds sx={1} sy={2} dx={3} dy={4}", x, y, dx, dy);
  371. }
  372. }
  373. }
  374. }
  375. }
  376. #endregion
  377. public TerrainChannel Copy()
  378. {
  379. TerrainChannel copy = new TerrainChannel();
  380. copy.m_terrainData = m_terrainData.Clone();
  381. return copy;
  382. }
  383. private void WriteXml(XmlWriter writer)
  384. {
  385. if (Width == Constants.RegionSize && Height == Constants.RegionSize)
  386. {
  387. // Downward compatibility for legacy region terrain maps.
  388. // If region is exactly legacy size, return the old format XML.
  389. writer.WriteStartElement(String.Empty, "TerrainMap", String.Empty);
  390. ToXml(writer);
  391. writer.WriteEndElement();
  392. }
  393. else
  394. {
  395. // New format XML that includes width and length.
  396. writer.WriteStartElement(String.Empty, "TerrainMap2", String.Empty);
  397. ToXml2(writer);
  398. writer.WriteEndElement();
  399. }
  400. }
  401. private void ReadXml(XmlReader reader)
  402. {
  403. // Check the first element. If legacy element, use the legacy reader.
  404. if (reader.IsStartElement("TerrainMap"))
  405. {
  406. reader.ReadStartElement("TerrainMap");
  407. FromXml(reader);
  408. }
  409. else
  410. {
  411. reader.ReadStartElement("TerrainMap2");
  412. FromXml2(reader);
  413. }
  414. }
  415. // Write legacy terrain map. Presumed to be 256x256 of data encoded as floats in a byte array.
  416. private void ToXml(XmlWriter xmlWriter)
  417. {
  418. float[] mapData = GetFloatsSerialised();
  419. byte[] buffer = new byte[mapData.Length * 4];
  420. for (int i = 0; i < mapData.Length; i++)
  421. {
  422. byte[] value = BitConverter.GetBytes(mapData[i]);
  423. Array.Copy(value, 0, buffer, (i * 4), 4);
  424. }
  425. XmlSerializer serializer = new XmlSerializer(typeof(byte[]));
  426. serializer.Serialize(xmlWriter, buffer);
  427. }
  428. // Read legacy terrain map. Presumed to be 256x256 of data encoded as floats in a byte array.
  429. private void FromXml(XmlReader xmlReader)
  430. {
  431. XmlSerializer serializer = new XmlSerializer(typeof(byte[]));
  432. byte[] dataArray = (byte[])serializer.Deserialize(xmlReader);
  433. int index = 0;
  434. m_terrainData = new TerrainData(Height, Width, (int)Constants.RegionHeight);
  435. for (int y = 0; y < Height; y++)
  436. {
  437. for (int x = 0; x < Width; x++)
  438. {
  439. float value;
  440. value = BitConverter.ToSingle(dataArray, index);
  441. index += 4;
  442. this[x, y] = (double)value;
  443. }
  444. }
  445. }
  446. private class TerrainChannelXMLPackage
  447. {
  448. public int Version;
  449. public int SizeX;
  450. public int SizeY;
  451. public int SizeZ;
  452. public float CompressionFactor;
  453. public float[] Map;
  454. public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, float[] pMap)
  455. {
  456. Version = 1;
  457. SizeX = pX;
  458. SizeY = pY;
  459. SizeZ = pZ;
  460. CompressionFactor = pCompressionFactor;
  461. Map = pMap;
  462. }
  463. }
  464. // New terrain serialization format that includes the width and length.
  465. private void ToXml2(XmlWriter xmlWriter)
  466. {
  467. TerrainChannelXMLPackage package = new TerrainChannelXMLPackage(Width, Height, Altitude, m_terrainData.CompressionFactor,
  468. m_terrainData.GetCompressedMap());
  469. XmlSerializer serializer = new XmlSerializer(typeof(TerrainChannelXMLPackage));
  470. serializer.Serialize(xmlWriter, package);
  471. }
  472. // New terrain serialization format that includes the width and length.
  473. private void FromXml2(XmlReader xmlReader)
  474. {
  475. XmlSerializer serializer = new XmlSerializer(typeof(TerrainChannelXMLPackage));
  476. TerrainChannelXMLPackage package = (TerrainChannelXMLPackage)serializer.Deserialize(xmlReader);
  477. m_terrainData = new TerrainData(package.Map, package.CompressionFactor, package.SizeX, package.SizeY, package.SizeZ);
  478. }
  479. // Fill the heightmap with the center bump terrain
  480. private void PinHeadIsland()
  481. {
  482. float cx = m_terrainData.SizeX * 0.5f;
  483. float cy = m_terrainData.SizeY * 0.5f;
  484. float h;
  485. for (int x = 0; x < Width; x++)
  486. {
  487. for (int y = 0; y < Height; y++)
  488. {
  489. // h = (float)TerrainUtil.PerlinNoise2D(x, y, 2, 0.125) * 10;
  490. h = 1.0f;
  491. float spherFacA = (float)(TerrainUtil.SphericalFactor(x, y, cx, cy, 50) * 0.01d);
  492. float spherFacB = (float)(TerrainUtil.SphericalFactor(x, y, cx, cy, 100) * 0.001d);
  493. if (h < spherFacA)
  494. h = spherFacA;
  495. if (h < spherFacB)
  496. h = spherFacB;
  497. m_terrainData[x, y] = h;
  498. }
  499. }
  500. }
  501. private void FlatLand()
  502. {
  503. m_terrainData.ClearLand();
  504. }
  505. }
  506. }