/// <summary> /// Set the height at a point specified by sample coordinates /// </summary> /// <param name="sampleX"></param> /// <param name="sampleZ"></param> /// <param name="height"></param> /// <returns></returns> public void SetSampleHeightMM(int sampleX, int sampleZ, float height) { int tileX; int tileZ; int xOff; int zOff; SampleToTileCoords(sampleX, sampleZ, out tileX, out tileZ, out xOff, out zOff); if ((tileX < 0) || (tileX >= sizeXTiles) || (tileZ < 0) || (tileZ >= sizeZTiles)) { //throw new IndexOutOfRangeException(); // It's possible to go off the end of the terrain, so just ignore it if it happens. return; } HeightfieldTile tile = tiles[tileX, tileZ] as HeightfieldTile; if (tile == null) { // This shouldn't happen throw new Exception("Tile [" + tileX + "," + tileZ + "] not found for coord [" + sampleX + "," + sampleZ + "] while attempting to set height to: " + height); } tile.SetHeightMM(xOff, zOff, height); }
/// <summary> /// Get the height at a point specified by sample coordinates /// </summary> /// <param name="sampleX"></param> /// <param name="sampleZ"></param> /// <returns></returns> public float GetSampleHeightMM(int sampleX, int sampleZ) { int tileX; int tileZ; int xOff; int zOff; SampleToTileCoords(sampleX, sampleZ, out tileX, out tileZ, out xOff, out zOff); if ((tileX < 0) || (tileX >= sizeXTiles) || (tileZ < 0) || (tileZ >= sizeZTiles)) { return(defaultHeightMM); } HeightfieldTile tile = tiles[tileX, tileZ] as HeightfieldTile; if (tile == null) { return(defaultHeightMM); } return(tile.GetHeightMM(xOff, zOff)); }