aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
diff options
context:
space:
mode:
authorAdam Frisby2007-04-11 05:19:27 +0000
committerAdam Frisby2007-04-11 05:19:27 +0000
commitadb56a46f49127911a2df169c86f2cdfde034966 (patch)
treec5a7b5e279f93538c9506f630b7304b9d55e93e8 /OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
parent(no commit message) (diff)
downloadopensim-SC_OLD-adb56a46f49127911a2df169c86f2cdfde034966.zip
opensim-SC_OLD-adb56a46f49127911a2df169c86f2cdfde034966.tar.gz
opensim-SC_OLD-adb56a46f49127911a2df169c86f2cdfde034966.tar.bz2
opensim-SC_OLD-adb56a46f49127911a2df169c86f2cdfde034966.tar.xz
Major ass changes to terrain (now uses libTerrain-BSD!) and all-round improvements to code quality. Terrain saving/loading may work now (running through setHeights1D and getHeights1D before DB4o) **WARNING: UNTESTED**
Diffstat (limited to '')
-rw-r--r--OpenSim.Terrain.BasicTerrain/TerrainEngine.cs82
1 files changed, 54 insertions, 28 deletions
diff --git a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
index 87dbf7e..bd4b85f 100644
--- a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
+++ b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
@@ -1,7 +1,7 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Text; 3using System.Text;
4using OpenSim.Terrain.BasicTerrain; 4using libTerrain;
5 5
6namespace OpenSim.Terrain 6namespace OpenSim.Terrain
7{ 7{
@@ -10,11 +10,8 @@ namespace OpenSim.Terrain
10 /// <summary> 10 /// <summary>
11 /// A [normally] 256x256 heightmap 11 /// A [normally] 256x256 heightmap
12 /// </summary> 12 /// </summary>
13 public float[,] map; 13 public Channel heightmap;
14 /// <summary> 14
15 /// A 256x256 heightmap storing water height values
16 /// </summary>
17 public float[,] water;
18 int w, h; 15 int w, h;
19 16
20 /// <summary> 17 /// <summary>
@@ -24,8 +21,7 @@ namespace OpenSim.Terrain
24 { 21 {
25 w = 256; 22 w = 256;
26 h = 256; 23 h = 256;
27 map = new float[w, h]; 24 heightmap = new Channel(w, h);
28 water = new float[w, h];
29 25
30 } 26 }
31 27
@@ -38,7 +34,21 @@ namespace OpenSim.Terrain
38 float[] heights = new float[w*h]; 34 float[] heights = new float[w*h];
39 int i; 35 int i;
40 for(i=0;i<w*h;i++) { 36 for(i=0;i<w*h;i++) {
41 heights[i] = map[i / w, i % w]; 37 heights[i] = (float)heightmap.map[i / w, i % w];
38 }
39 return heights;
40 }
41
42 public float[,] getHeights2D()
43 {
44 float[,] heights = new float[w, h];
45 int x, y;
46 for (x = 0; x < w; x++)
47 {
48 for (y = 0; y < h; y++)
49 {
50 heights[x, y] = (float)heightmap.map[x, y];
51 }
42 } 52 }
43 return heights; 53 return heights;
44 } 54 }
@@ -52,13 +62,27 @@ namespace OpenSim.Terrain
52 int i; 62 int i;
53 for (i = 0; i < w * h; i++) 63 for (i = 0; i < w * h; i++)
54 { 64 {
55 map[i / w, i % w] = heights[i]; 65 heightmap.map[i / w, i % w] = heights[i];
66 }
67 }
68
69 public float[,] setHeights2D(float[,] heights)
70 {
71 int x, y;
72 for (x = 0; x < w; x++)
73 {
74 for (y = 0; y < h; y++)
75 {
76 heightmap.set(x,y,(double)heights[x,y]);
77 }
56 } 78 }
79 return heights;
57 } 80 }
58 81
59 /// <summary> 82 /// <summary>
60 /// Loads a file consisting of 256x256 doubles and imports it as an array into the map. 83 /// Loads a file consisting of 256x256 doubles and imports it as an array into the map.
61 /// </summary> 84 /// </summary>
85 /// <remarks>TODO: Move this to libTerrain itself</remarks>
62 /// <param name="filename">The filename of the double array to import</param> 86 /// <param name="filename">The filename of the double array to import</param>
63 public void loadFromFileF64(string filename) 87 public void loadFromFileF64(string filename)
64 { 88 {
@@ -70,22 +94,12 @@ namespace OpenSim.Terrain
70 { 94 {
71 for (y = 0; y < h; y++) 95 for (y = 0; y < h; y++)
72 { 96 {
73 map[x, y] = (float)bs.ReadDouble(); 97 heightmap.map[x, y] = bs.ReadDouble();
74 } 98 }
75 } 99 }
76 } 100 }
77 101
78 /// <summary> 102 /// <summary>
79 /// 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.
80 /// </summary>
81 public void swapWaterBuffer()
82 {
83 float[,] temp = map;
84 map = water;
85 water = temp;
86 }
87
88 /// <summary>
89 /// Raises land in a sphere around the specified coordinates 103 /// Raises land in a sphere around the specified coordinates
90 /// </summary> 104 /// </summary>
91 /// <param name="rx">Center of the sphere on the X axis</param> 105 /// <param name="rx">Center of the sphere on the X axis</param>
@@ -94,9 +108,9 @@ namespace OpenSim.Terrain
94 /// <param name="amount">Scale the height of the sphere by this amount (recommended 0..2)</param> 108 /// <param name="amount">Scale the height of the sphere by this amount (recommended 0..2)</param>
95 public void raise(double rx, double ry, double size, double amount) 109 public void raise(double rx, double ry, double size, double amount)
96 { 110 {
97 lock (map) 111 lock (heightmap)
98 { 112 {
99 RaiseLower.raiseSphere(this.map, rx, ry, size, amount); 113 heightmap.raise(rx, ry, size, amount);
100 } 114 }
101 } 115 }
102 116
@@ -109,9 +123,9 @@ namespace OpenSim.Terrain
109 /// <param name="amount">Scale the height of the sphere by this amount (recommended 0..2)</param> 123 /// <param name="amount">Scale the height of the sphere by this amount (recommended 0..2)</param>
110 public void lower(double rx, double ry, double size, double amount) 124 public void lower(double rx, double ry, double size, double amount)
111 { 125 {
112 lock (map) 126 lock (heightmap)
113 { 127 {
114 RaiseLower.lowerSphere(this.map, rx, ry, size, amount); 128 heightmap.lower(rx, ry, size, amount);
115 } 129 }
116 } 130 }
117 131
@@ -120,12 +134,24 @@ namespace OpenSim.Terrain
120 /// </summary> 134 /// </summary>
121 public void hills() 135 public void hills()
122 { 136 {
123 lock (map) 137 lock (heightmap)
124 { 138 {
125 Hills.hillsSpheres(this.map, 1337, 200, 20, 40, true, true, false); 139 heightmap.hillsSpheres(200, 20, 40, true, true, false);
126 Normalise.normalise(this.map,60); 140 heightmap.normalise();
141 heightmap *= 60.0; // Raise to 60m
127 } 142 }
128 } 143 }
129 144
145 public float this[int x, int y]
146 {
147 get
148 {
149 return (float)heightmap.get(x,y);
150 }
151 set
152 {
153 heightmap.set(x,y,(double)value);
154 }
155 }
130 } 156 }
131} 157}