* Terrain Fracture Generator now produces more appropriate results.
* Terrain Flatten Brush has been optimised, now affects an appropriate sized section of terrain. * Navier-Stokes handler bounds issue partially fixed.afrisby
parent
ad5548de9f
commit
4b0734c4ad
|
@ -43,6 +43,11 @@ namespace libTerrain
|
|||
/// <param name="size">The size of the terrain mask</param>
|
||||
/// <param name="amount">The scale of the terrain mask</param>
|
||||
public void Flatten(double rx, double ry, double size, double amount)
|
||||
{
|
||||
FlattenFast(rx, ry, size, amount);
|
||||
}
|
||||
|
||||
private void FlattenSlow(double rx, double ry, double size, double amount)
|
||||
{
|
||||
// Generate the mask
|
||||
Channel temp = new Channel(w, h);
|
||||
|
@ -70,6 +75,51 @@ namespace libTerrain
|
|||
|
||||
}
|
||||
|
||||
private void FlattenFast(double rx, double ry, double size, double amount)
|
||||
{
|
||||
int x, y;
|
||||
double avg = 0;
|
||||
double div = 0;
|
||||
|
||||
int minX = Math.Max(0, (int)(rx - (size + 1)));
|
||||
int maxX = Math.Min(w, (int)(rx + (size + 1)));
|
||||
int minY = Math.Max(0, (int)(ry - (size + 1)));
|
||||
int maxY = Math.Min(h, (int)(ry + (size + 1)));
|
||||
|
||||
for (x = minX; x < maxX; x++)
|
||||
{
|
||||
for (y = minY; y < maxY; y++)
|
||||
{
|
||||
double z = size;
|
||||
z *= z;
|
||||
z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
|
||||
|
||||
if (z < 0)
|
||||
z = 0;
|
||||
|
||||
avg += z * amount;
|
||||
div += z;
|
||||
}
|
||||
}
|
||||
|
||||
double height = avg / div;
|
||||
|
||||
for (x = minX; x < maxX; x++)
|
||||
{
|
||||
for (y = minY; y < maxY; y++)
|
||||
{
|
||||
double z = size;
|
||||
z *= z;
|
||||
z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
|
||||
|
||||
if (z < 0)
|
||||
z = 0;
|
||||
|
||||
map[x, y] = Tools.linearInterpolate(map[x, y], height, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Flatten(Channel mask, double amount)
|
||||
{
|
||||
// Generate the mask
|
||||
|
|
|
@ -79,6 +79,7 @@ namespace libTerrain
|
|||
|
||||
throw new Exception("Out of bounds parameter (val)");
|
||||
}
|
||||
|
||||
public void Fracture(int number, double scalemin, double scalemax)
|
||||
{
|
||||
Random rand = new Random(seed);
|
||||
|
@ -90,6 +91,8 @@ namespace libTerrain
|
|||
a = RadialEdge256(rand.Next(1023)); // TODO: Broken
|
||||
b = RadialEdge256(rand.Next(1023)); // TODO: Broken
|
||||
double z = rand.NextDouble();
|
||||
double u = rand.NextDouble();
|
||||
double v = rand.NextDouble();
|
||||
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
|
@ -97,11 +100,41 @@ namespace libTerrain
|
|||
{
|
||||
double miny = Tools.linearInterpolate(a[1], b[1], (double)x / (double)w);
|
||||
|
||||
if (v >= 0.5)
|
||||
{
|
||||
if (u >= 0.5)
|
||||
{
|
||||
if (y > miny)
|
||||
{
|
||||
map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (y < miny)
|
||||
{
|
||||
map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (u >= 0.5)
|
||||
{
|
||||
if (x > miny)
|
||||
{
|
||||
map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x < miny)
|
||||
{
|
||||
map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Normalise();
|
||||
|
|
|
@ -225,9 +225,9 @@ namespace libTerrain
|
|||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i <= N; i++)
|
||||
for (i = 1; i <= N; i++)
|
||||
{
|
||||
for (j = 0; j <= N; j++)
|
||||
for (j = 1; j <= N; j++)
|
||||
{
|
||||
dens[nsIX(i, j, N)] = doubles[i, j];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue