* Refactored some terrain brushes to move out some common functions into TerrainUtil class. More needs doing.
* Adjusted strength of brushes to Math.Pow(2,size), this should in theory work closer to how it was before.0.6.0-stable
parent
df104e6f84
commit
8e27656fcc
|
@ -146,51 +146,14 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
return coord;
|
||||
}
|
||||
|
||||
private double SphericalFactor(double x, double y, double rx, double ry, double size)
|
||||
{
|
||||
double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
|
||||
return z;
|
||||
}
|
||||
|
||||
private double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
|
||||
{
|
||||
int w = map.Width;
|
||||
int h = map.Height;
|
||||
|
||||
if (x > w - 2.0)
|
||||
x = w - 2.0;
|
||||
if (y > h - 2.0)
|
||||
y = h - 2.0;
|
||||
if (x < 0.0)
|
||||
x = 0.0;
|
||||
if (y < 0.0)
|
||||
y = 0.0;
|
||||
|
||||
int stepSize = 1;
|
||||
double h00 = map[(int)x, (int)y];
|
||||
double h10 = map[(int)x + stepSize, (int)y];
|
||||
double h01 = map[(int)x, (int)y + stepSize];
|
||||
double h11 = map[(int)x + stepSize, (int)y + stepSize];
|
||||
double h1 = h00;
|
||||
double h2 = h10;
|
||||
double h3 = h01;
|
||||
double h4 = h11;
|
||||
double a00 = h1;
|
||||
double a10 = h2 - h1;
|
||||
double a01 = h3 - h1;
|
||||
double a11 = h1 - h2 - h3 + h4;
|
||||
double partialx = x - (int)x;
|
||||
double partialz = y - (int)y;
|
||||
double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
|
||||
return hi;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ITerrainPaintableEffect Members
|
||||
|
||||
public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
|
||||
{
|
||||
strength = TerrainUtil.MetersToSphericalStrength(strength);
|
||||
|
||||
int x, y;
|
||||
// Using one 'rain' round for this, so skipping a useless loop
|
||||
// Will need to adapt back in for the Flood brush
|
||||
|
@ -201,7 +164,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
// Fill with rain
|
||||
for (x = 0; x < water.Width; x++)
|
||||
for (y = 0; y < water.Height; y++)
|
||||
water[x, y] = Math.Max(0.0, SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration);
|
||||
water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration);
|
||||
|
||||
for (int i = 0; i < rounds; i++)
|
||||
{
|
||||
|
|
|
@ -74,6 +74,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
|
||||
public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
|
||||
{
|
||||
strength = TerrainUtil.MetersToSphericalStrength(strength);
|
||||
|
||||
int x, y;
|
||||
double[,] tweak = new double[map.Width, map.Height];
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
|
||||
public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
|
||||
{
|
||||
strength = TerrainUtil.MetersToSphericalStrength(strength);
|
||||
|
||||
int x, y;
|
||||
for (x = 0; x < map.Width; x++)
|
||||
{
|
||||
|
|
|
@ -37,6 +37,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
|
||||
public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
|
||||
{
|
||||
strength = TerrainUtil.MetersToSphericalStrength(strength);
|
||||
|
||||
int x, y;
|
||||
for (x = 0; x < map.Width; x++)
|
||||
{
|
||||
|
|
|
@ -159,6 +159,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
|
||||
public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
|
||||
{
|
||||
strength = TerrainUtil.MetersToSphericalStrength(strength);
|
||||
|
||||
int x, y;
|
||||
|
||||
for (x = 0; x < map.Width; x++)
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
|
||||
public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
|
||||
{
|
||||
strength = TerrainUtil.MetersToSphericalStrength(strength);
|
||||
|
||||
int x, y;
|
||||
for (x = 0; x < map.Width; x++)
|
||||
{
|
||||
|
|
|
@ -43,6 +43,13 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
|
||||
public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
|
||||
{
|
||||
strength = TerrainUtil.MetersToSphericalStrength(strength);
|
||||
|
||||
if (duration > 1.0)
|
||||
duration = 1.0;
|
||||
if (duration < 0)
|
||||
return;
|
||||
|
||||
int x, y;
|
||||
for (x = 0; x < map.Width; x++)
|
||||
{
|
||||
|
|
|
@ -31,49 +31,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
{
|
||||
public class SmoothSphere : ITerrainPaintableEffect
|
||||
{
|
||||
private double SphericalFactor(double x, double y, double rx, double ry, double size)
|
||||
{
|
||||
double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
|
||||
return z;
|
||||
}
|
||||
|
||||
private double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
|
||||
{
|
||||
int w = map.Width;
|
||||
int h = map.Height;
|
||||
|
||||
if (x > w - 2.0)
|
||||
x = w - 2.0;
|
||||
if (y > h - 2.0)
|
||||
y = h - 2.0;
|
||||
if (x < 0.0)
|
||||
x = 0.0;
|
||||
if (y < 0.0)
|
||||
y = 0.0;
|
||||
|
||||
int stepSize = 1;
|
||||
double h00 = map[(int)x, (int)y];
|
||||
double h10 = map[(int)x + stepSize, (int)y];
|
||||
double h01 = map[(int)x, (int)y + stepSize];
|
||||
double h11 = map[(int)x + stepSize, (int)y + stepSize];
|
||||
double h1 = h00;
|
||||
double h2 = h10;
|
||||
double h3 = h01;
|
||||
double h4 = h11;
|
||||
double a00 = h1;
|
||||
double a10 = h2 - h1;
|
||||
double a01 = h3 - h1;
|
||||
double a11 = h1 - h2 - h3 + h4;
|
||||
double partialx = x - (int)x;
|
||||
double partialz = y - (int)y;
|
||||
double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
|
||||
return hi;
|
||||
}
|
||||
|
||||
#region ITerrainPaintableEffect Members
|
||||
|
||||
public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
|
||||
{
|
||||
strength = TerrainUtil.MetersToSphericalStrength(strength);
|
||||
|
||||
int x, y;
|
||||
double[,] tweak = new double[map.Width, map.Height];
|
||||
|
||||
|
@ -86,7 +49,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
{
|
||||
for (y = 0; y < map.Height; y++)
|
||||
{
|
||||
double z = SphericalFactor(x, y, rx, ry, strength);
|
||||
double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
|
||||
|
||||
if (z > 0) // add in non-zero amount
|
||||
{
|
||||
|
@ -98,7 +61,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
for (l = 0.0 - area; l < area; l += step)
|
||||
{
|
||||
avgsteps++;
|
||||
average += GetBilinearInterpolate(x + n, y + l, map);
|
||||
average += TerrainUtil.GetBilinearInterpolate(x + n, y + l, map);
|
||||
}
|
||||
}
|
||||
tweak[x, y] = average / avgsteps;
|
||||
|
@ -110,7 +73,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
{
|
||||
for (y = 0; y < map.Height; y++)
|
||||
{
|
||||
double z = SphericalFactor(x, y, rx, ry, strength);
|
||||
double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
|
||||
|
||||
if (z > 0) // add in non-zero amount
|
||||
{
|
||||
|
|
|
@ -142,58 +142,21 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
|
|||
return coord;
|
||||
}
|
||||
|
||||
private double SphericalFactor(double x, double y, double rx, double ry, double size)
|
||||
{
|
||||
double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
|
||||
return z;
|
||||
}
|
||||
|
||||
private double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
|
||||
{
|
||||
int w = map.Width;
|
||||
int h = map.Height;
|
||||
|
||||
if (x > w - 2.0)
|
||||
x = w - 2.0;
|
||||
if (y > h - 2.0)
|
||||
y = h - 2.0;
|
||||
if (x < 0.0)
|
||||
x = 0.0;
|
||||
if (y < 0.0)
|
||||
y = 0.0;
|
||||
|
||||
int stepSize = 1;
|
||||
double h00 = map[(int)x, (int)y];
|
||||
double h10 = map[(int)x + stepSize, (int)y];
|
||||
double h01 = map[(int)x, (int)y + stepSize];
|
||||
double h11 = map[(int)x + stepSize, (int)y + stepSize];
|
||||
double h1 = h00;
|
||||
double h2 = h10;
|
||||
double h3 = h01;
|
||||
double h4 = h11;
|
||||
double a00 = h1;
|
||||
double a10 = h2 - h1;
|
||||
double a01 = h3 - h1;
|
||||
double a11 = h1 - h2 - h3 + h4;
|
||||
double partialx = x - (int)x;
|
||||
double partialz = y - (int)y;
|
||||
double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
|
||||
return hi;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ITerrainPaintableEffect Members
|
||||
|
||||
public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration)
|
||||
{
|
||||
strength = TerrainUtil.MetersToSphericalStrength(strength);
|
||||
|
||||
int x, y;
|
||||
|
||||
for (x = 0; x < map.Width; x++)
|
||||
{
|
||||
for (y = 0; y < map.Height; y++)
|
||||
{
|
||||
double z = SphericalFactor(x, y, rx, ry, strength);
|
||||
double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
|
||||
|
||||
if (z > 0) // add in non-zero amount
|
||||
{
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules.Terrain
|
||||
{
|
||||
public static class TerrainUtil
|
||||
{
|
||||
public static double MetersToSphericalStrength(double size)
|
||||
{
|
||||
return Math.Pow(2, size);
|
||||
}
|
||||
|
||||
public static double SphericalFactor(double x, double y, double rx, double ry, double size)
|
||||
{
|
||||
return size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
|
||||
}
|
||||
|
||||
public static double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
|
||||
{
|
||||
int w = map.Width;
|
||||
int h = map.Height;
|
||||
|
||||
if (x > w - 2.0)
|
||||
x = w - 2.0;
|
||||
if (y > h - 2.0)
|
||||
y = h - 2.0;
|
||||
if (x < 0.0)
|
||||
x = 0.0;
|
||||
if (y < 0.0)
|
||||
y = 0.0;
|
||||
|
||||
int stepSize = 1;
|
||||
double h00 = map[(int)x, (int)y];
|
||||
double h10 = map[(int)x + stepSize, (int)y];
|
||||
double h01 = map[(int)x, (int)y + stepSize];
|
||||
double h11 = map[(int)x + stepSize, (int)y + stepSize];
|
||||
double h1 = h00;
|
||||
double h2 = h10;
|
||||
double h3 = h01;
|
||||
double h4 = h11;
|
||||
double a00 = h1;
|
||||
double a10 = h2 - h1;
|
||||
double a01 = h3 - h1;
|
||||
double a11 = h1 - h2 - h3 + h4;
|
||||
double partialx = x - (int)x;
|
||||
double partialz = y - (int)y;
|
||||
double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
|
||||
return hi;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue