From c18cf96824c94493263baf1cba23aa3253e6e0c9 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sat, 7 Apr 2007 16:48:38 +0000 Subject: [PATCH] Terrain can now import from a specially formatted file. --- OpenSim.Terrain.BasicTerrain/TerrainEngine.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs index cbc99bcc93..45da742a0e 100644 --- a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs +++ b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs @@ -20,6 +20,10 @@ namespace OpenSim.Terrain } + /// + /// Converts the heightmap to a 65536 value 1D floating point array + /// + /// A float[65536] array containing the heightmap public float[] getHeights1D() { float[] heights = new float[w*h]; @@ -30,6 +34,10 @@ namespace OpenSim.Terrain return heights; } + /// + /// Imports a 1D floating point array into the 2D heightmap array + /// + /// The array to import (must have 65536 members) public void setHeights1D(float[] heights) { int i; @@ -39,6 +47,25 @@ namespace OpenSim.Terrain } } + /// + /// Loads a file consisting of 256x256 doubles and imports it as an array into the map. + /// + /// The filename of the double array to import + public void loadFromFileF64(string filename) + { + System.IO.FileInfo file = new System.IO.FileInfo(filename); + System.IO.FileStream s = file.Open(System.IO.FileMode.Open, System.IO.FileAccess.Read); + System.IO.BinaryReader bs = new System.IO.BinaryReader(s); + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + map[x, y] = (float)bs.ReadDouble(); + } + } + } + /// /// Swaps the references between the height and water buffers to allow you to edit the water heightmap. Remember to swap back when you are done. ///