mirror of
https://github.com/opensim/opensim.git
synced 2026-08-06 01:06:30 +08:00
**BREAKING CHANGE** Changing the way terrain is stored and used internally.
This commit is contained in:
72
OpenSim.Terrain.BasicTerrain/Hills.cs
Normal file
72
OpenSim.Terrain.BasicTerrain/Hills.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenSim.Terrain.BasicTerrain
|
||||
{
|
||||
static class Hills
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh.
|
||||
/// </summary>
|
||||
/// <remarks>3-Clause BSD Licensed</remarks>
|
||||
/// <param name="number">The number of hills to generate</param>
|
||||
/// <param name="scale_min">The minimum size of each hill</param>
|
||||
/// <param name="scale_range">The maximum size of each hill</param>
|
||||
/// <param name="island">Whether to bias hills towards the center of the map</param>
|
||||
/// <param name="additive">Whether to add hills together or to pick the largest value</param>
|
||||
/// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param>
|
||||
public static void hillsSpheres(float[,] map,int seed, int number, double scale_min, double scale_range, bool island, bool additive, bool noisy)
|
||||
{
|
||||
Random random = new Random(seed);
|
||||
int w = map.GetLength(0);
|
||||
int h = map.GetLength(1);
|
||||
int x, y;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < number; i++)
|
||||
{
|
||||
double rx = Math.Min(255.0, random.NextDouble() * w);
|
||||
double ry = Math.Min(255.0, random.NextDouble() * h);
|
||||
double rand = random.NextDouble();
|
||||
|
||||
if (island)
|
||||
{
|
||||
// Move everything towards the center
|
||||
rx -= w / 2;
|
||||
rx /= 2;
|
||||
rx += w / 2;
|
||||
|
||||
ry -= h / 2;
|
||||
ry /= 2;
|
||||
ry += h / 2;
|
||||
}
|
||||
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
if (noisy)
|
||||
rand = random.NextDouble();
|
||||
|
||||
double z = (scale_min + (scale_range * rand));
|
||||
z *= z;
|
||||
z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
|
||||
|
||||
if (z < 0)
|
||||
z = 0;
|
||||
|
||||
if (additive)
|
||||
{
|
||||
map[x, y] += (float)z;
|
||||
}
|
||||
else
|
||||
{
|
||||
map[x, y] = (float)Math.Max(map[x, y], z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,9 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="TerrainManager.cs" />
|
||||
<Compile Include="Hills.cs" />
|
||||
<Compile Include="RaiseLower.cs" />
|
||||
<Compile Include="TerrainEngine.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
91
OpenSim.Terrain.BasicTerrain/RaiseLower.cs
Normal file
91
OpenSim.Terrain.BasicTerrain/RaiseLower.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenSim.Terrain.BasicTerrain
|
||||
{
|
||||
static class RaiseLower
|
||||
{
|
||||
/// <summary>
|
||||
/// Raises land around the selection
|
||||
/// </summary>
|
||||
/// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
|
||||
/// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
|
||||
/// <param name="size">The radius of the dimple</param>
|
||||
/// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
|
||||
public static void raise(float[,] map, double rx, double ry, double size, double amount)
|
||||
{
|
||||
raiseSphere(map, rx, ry, size, amount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises land in a sphere around the selection
|
||||
/// </summary>
|
||||
/// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
|
||||
/// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
|
||||
/// <param name="size">The radius of the sphere dimple</param>
|
||||
/// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
|
||||
public static void raiseSphere(float[,] map, double rx, double ry, double size, double amount)
|
||||
{
|
||||
int x, y;
|
||||
int w = map.GetLength(0);
|
||||
int h = map.GetLength(1);
|
||||
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
double z = size;
|
||||
z *= z;
|
||||
z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
|
||||
|
||||
if (z < 0)
|
||||
z = 0;
|
||||
|
||||
map[x, y] += (float)(z * amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lowers land in a sphere around the selection
|
||||
/// </summary>
|
||||
/// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
|
||||
/// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
|
||||
/// <param name="size">The radius of the sphere dimple</param>
|
||||
/// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
|
||||
public static void lower(float[,] map, double rx, double ry, double size, double amount)
|
||||
{
|
||||
lowerSphere(map, rx, ry, size, amount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lowers land in a sphere around the selection
|
||||
/// </summary>
|
||||
/// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
|
||||
/// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
|
||||
/// <param name="size">The radius of the sphere dimple</param>
|
||||
/// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
|
||||
public static void lowerSphere(float[,] map, double rx, double ry, double size, double amount)
|
||||
{
|
||||
int x, y;
|
||||
int w = map.GetLength(0);
|
||||
int h = map.GetLength(1);
|
||||
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
double z = size;
|
||||
z *= z;
|
||||
z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
|
||||
|
||||
if (z < 0)
|
||||
z = 0;
|
||||
|
||||
map[x, y] -= (float)(z * amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
64
OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
Normal file
64
OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OpenSim.Terrain.BasicTerrain;
|
||||
|
||||
namespace OpenSim.Terrain
|
||||
{
|
||||
public class TerrainEngine
|
||||
{
|
||||
public float[,] map;
|
||||
public float[,] water;
|
||||
int w, h;
|
||||
|
||||
public TerrainEngine()
|
||||
{
|
||||
w = 256;
|
||||
h = 256;
|
||||
map = new float[w, h];
|
||||
water = new float[w, h];
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public void swapWaterBuffer()
|
||||
{
|
||||
float[,] temp = map;
|
||||
map = water;
|
||||
water = temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises land in a sphere around the specified coordinates
|
||||
/// </summary>
|
||||
/// <param name="rx">Center of the sphere on the X axis</param>
|
||||
/// <param name="ry">Center of the sphere on the Y axis</param>
|
||||
/// <param name="size">The radius of the sphere</param>
|
||||
/// <param name="amount">Scale the height of the sphere by this amount (recommended 0..2)</param>
|
||||
public void raise(double rx, double ry, double size, double amount)
|
||||
{
|
||||
lock (map)
|
||||
{
|
||||
RaiseLower.raiseSphere(this.map, rx, ry, size, amount);
|
||||
}
|
||||
}
|
||||
public void lower(double rx, double ry, double size, double amount)
|
||||
{
|
||||
lock (map)
|
||||
{
|
||||
RaiseLower.lowerSphere(this.map, rx, ry, size, amount);
|
||||
}
|
||||
}
|
||||
|
||||
public void hills()
|
||||
{
|
||||
lock (map)
|
||||
{
|
||||
Hills.hillsSpheres(this.map, 1337, 200, 20, 40, true, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenSim.Terrain
|
||||
{
|
||||
public class TerrainManager
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
bin\Debug\OpenSim.Terrain.BasicTerrain.dll
|
||||
bin\Debug\OpenSim.Terrain.BasicTerrain.pdb
|
||||
obj\Debug\ResolveAssemblyReference.cache
|
||||
obj\Debug\OpenSim.Terrain.BasicTerrain.dll
|
||||
obj\Debug\OpenSim.Terrain.BasicTerrain.pdb
|
||||
Reference in New Issue
Block a user