From adb56a46f49127911a2df169c86f2cdfde034966 Mon Sep 17 00:00:00 2001
From: Adam Frisby
Date: Wed, 11 Apr 2007 05:19:27 +0000
Subject: 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**
---
OpenSim.Terrain.BasicTerrain/TerrainEngine.cs | 82 ++++++++++++++++++---------
1 file changed, 54 insertions(+), 28 deletions(-)
(limited to 'OpenSim.Terrain.BasicTerrain/TerrainEngine.cs')
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 @@
using System;
using System.Collections.Generic;
using System.Text;
-using OpenSim.Terrain.BasicTerrain;
+using libTerrain;
namespace OpenSim.Terrain
{
@@ -10,11 +10,8 @@ namespace OpenSim.Terrain
///
/// A [normally] 256x256 heightmap
///
- public float[,] map;
- ///
- /// A 256x256 heightmap storing water height values
- ///
- public float[,] water;
+ public Channel heightmap;
+
int w, h;
///
@@ -24,8 +21,7 @@ namespace OpenSim.Terrain
{
w = 256;
h = 256;
- map = new float[w, h];
- water = new float[w, h];
+ heightmap = new Channel(w, h);
}
@@ -38,7 +34,21 @@ namespace OpenSim.Terrain
float[] heights = new float[w*h];
int i;
for(i=0;i
/// Loads a file consisting of 256x256 doubles and imports it as an array into the map.
///
+ /// TODO: Move this to libTerrain itself
/// The filename of the double array to import
public void loadFromFileF64(string filename)
{
@@ -70,22 +94,12 @@ namespace OpenSim.Terrain
{
for (y = 0; y < h; y++)
{
- map[x, y] = (float)bs.ReadDouble();
+ heightmap.map[x, y] = 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.
- ///
- public void swapWaterBuffer()
- {
- float[,] temp = map;
- map = water;
- water = temp;
- }
-
- ///
/// Raises land in a sphere around the specified coordinates
///
/// Center of the sphere on the X axis
@@ -94,9 +108,9 @@ namespace OpenSim.Terrain
/// Scale the height of the sphere by this amount (recommended 0..2)
public void raise(double rx, double ry, double size, double amount)
{
- lock (map)
+ lock (heightmap)
{
- RaiseLower.raiseSphere(this.map, rx, ry, size, amount);
+ heightmap.raise(rx, ry, size, amount);
}
}
@@ -109,9 +123,9 @@ namespace OpenSim.Terrain
/// Scale the height of the sphere by this amount (recommended 0..2)
public void lower(double rx, double ry, double size, double amount)
{
- lock (map)
+ lock (heightmap)
{
- RaiseLower.lowerSphere(this.map, rx, ry, size, amount);
+ heightmap.lower(rx, ry, size, amount);
}
}
@@ -120,12 +134,24 @@ namespace OpenSim.Terrain
///
public void hills()
{
- lock (map)
+ lock (heightmap)
{
- Hills.hillsSpheres(this.map, 1337, 200, 20, 40, true, true, false);
- Normalise.normalise(this.map,60);
+ heightmap.hillsSpheres(200, 20, 40, true, true, false);
+ heightmap.normalise();
+ heightmap *= 60.0; // Raise to 60m
}
}
+ public float this[int x, int y]
+ {
+ get
+ {
+ return (float)heightmap.get(x,y);
+ }
+ set
+ {
+ heightmap.set(x,y,(double)value);
+ }
+ }
}
}
--
cgit v1.1