* Rex merge, Region/Terrain

afrisby-3
Adam Frisby 2008-02-23 04:07:00 +00:00
parent 642ced53d1
commit 9559c3f6e6
10 changed files with 2362 additions and 2263 deletions

View File

@ -1,65 +1,65 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly : AssemblyTitle("OpenSim.Region.Terrain.BasicTerrain")] [assembly : AssemblyTitle("OpenSim.Region.Terrain.BasicTerrain")]
[assembly : AssemblyDescription("")] [assembly : AssemblyDescription("")]
[assembly : AssemblyConfiguration("")] [assembly : AssemblyConfiguration("")]
[assembly : AssemblyCompany("")] [assembly : AssemblyCompany("")]
[assembly : AssemblyProduct("OpenSim.Region.Terrain.BasicTerrain")] [assembly : AssemblyProduct("OpenSim.Region.Terrain.BasicTerrain")]
[assembly : AssemblyCopyright("Copyright © 2007")] [assembly : AssemblyCopyright("Copyright © OpenSimulator.org Developers 2007-2008")]
[assembly : AssemblyTrademark("")] [assembly : AssemblyTrademark("")]
[assembly : AssemblyCulture("")] [assembly : AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly : ComVisible(false)] [assembly : ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM // The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly : Guid("3263f5b5-0a41-4ed5-91a2-9baaaeecc849")] [assembly : Guid("3263f5b5-0a41-4ed5-91a2-9baaaeecc849")]
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Revision and Build Numbers // You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly : AssemblyVersion("1.0.0.0")] [assembly : AssemblyVersion("1.0.0.0")]
[assembly : AssemblyFileVersion("1.0.0.0")] [assembly : AssemblyFileVersion("1.0.0.0")]

File diff suppressed because it is too large Load Diff

View File

@ -1,146 +1,144 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
using System; using System;
namespace libTerrain namespace libTerrain
{ {
partial class Channel partial class Channel
{ {
/// <summary> /// <summary>
/// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function. /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function.
/// </summary> /// </summary>
/// <param name="rx">The X coordinate of the terrain mask</param> /// <param name="rx">The X coordinate of the terrain mask</param>
/// <param name="ry">The Y coordinate of the terrain mask</param> /// <param name="ry">The Y coordinate of the terrain mask</param>
/// <param name="size">The size of the terrain mask</param> /// <param name="size">The size of the terrain mask</param>
/// <param name="amount">The scale 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) public void Flatten(double rx, double ry, double size, double amount)
{ {
FlattenSlow(rx, ry, size, amount); FlattenSlow(rx, ry, size, amount);
} }
private void FlattenSlow(double rx, double ry, double size, double amount) private void FlattenSlow(double rx, double ry, double size, double amount)
{ {
// Generate the mask // Generate the mask
Channel temp = new Channel(w, h); Channel temp = new Channel(w, h);
temp.Fill(0); temp.Fill(0);
temp.Raise(rx, ry, size, amount); temp.Raise(rx, ry, size, amount);
temp.Normalise(); temp.Normalise();
double total_mod = temp.Sum(); double total_mod = temp.Sum();
// Establish the average height under the area // Establish the average height under the area
Channel newmap = new Channel(w, h); Channel newmap = new Channel(w, h);
newmap.map = (double[,]) map.Clone(); newmap.map = (double[,]) map.Clone();
newmap *= temp; newmap *= temp;
double total_terrain = newmap.Sum(); double total_terrain = newmap.Sum();
double avg_height = total_terrain/total_mod; double avg_height = total_terrain/total_mod;
// Create a flat terrain using the average height // Create a flat terrain using the average height
Channel flat = new Channel(w, h); Channel flat = new Channel(w, h);
flat.Fill(avg_height); flat.Fill(avg_height);
// Blend the current terrain with the average height terrain // Blend the current terrain with the average height terrain
// using the "raised" empty terrain as a mask // using the "raised" empty terrain as a mask
Blend(flat, temp); Blend(flat, temp);
} }
private void FlattenFast(double rx, double ry, double size, double amount) private void FlattenFast(double rx, double ry, double size, double amount)
{ {
int x, y; int x, y;
double avg = 0; double avg = 0;
double div = 0; double div = 0;
int minX = Math.Max(0, (int) (rx - (size + 1))); int minX = Math.Max(0, (int) (rx - (size + 1)));
int maxX = Math.Min(w, (int) (rx + (size + 1))); int maxX = Math.Min(w, (int) (rx + (size + 1)));
int minY = Math.Max(0, (int) (ry - (size + 1))); int minY = Math.Max(0, (int) (ry - (size + 1)));
int maxY = Math.Min(h, (int) (ry + (size + 1))); int maxY = Math.Min(h, (int) (ry + (size + 1)));
for (x = minX; x < maxX; x++) for (x = minX; x < maxX; x++)
{ {
for (y = minY; y < maxY; y++) for (y = minY; y < maxY; y++)
{ {
double z = size; double z = size;
z *= z; z *= z;
z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry));
if (z < 0) if (z < 0)
z = 0; z = 0;
avg += z*amount; avg += z*amount;
div += z; div += z;
} }
} }
double height = avg/div; double height = avg/div;
for (x = minX; x < maxX; x++) for (x = minX; x < maxX; x++)
{ {
for (y = minY; y < maxY; y++) for (y = minY; y < maxY; y++)
{ {
double z = size; double z = size;
z *= z; z *= z;
z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry));
if (z < 0) if (z > 0.0)
z = 0; Set(x, y, Tools.LinearInterpolate(map[x, y], height, z));
}
Set(x, y, Tools.LinearInterpolate(map[x, y], height, z)); }
} }
}
} public void Flatten(Channel mask, double amount)
{
public void Flatten(Channel mask, double amount) // Generate the mask
{ Channel temp = mask*amount;
// Generate the mask temp.Clip(0, 1); // Cut off out-of-bounds values
Channel temp = mask*amount;
temp.Clip(0, 1); // Cut off out-of-bounds values double total_mod = temp.Sum();
double total_mod = temp.Sum(); // Establish the average height under the area
Channel map = new Channel(w, h);
// Establish the average height under the area map.map = (double[,]) this.map.Clone();
Channel map = new Channel(w, h);
map.map = (double[,]) this.map.Clone(); map *= temp;
map *= temp; double total_terrain = map.Sum();
double avg_height = total_terrain/total_mod;
double total_terrain = map.Sum();
double avg_height = total_terrain/total_mod; // Create a flat terrain using the average height
Channel flat = new Channel(w, h);
// Create a flat terrain using the average height flat.Fill(avg_height);
Channel flat = new Channel(w, h);
flat.Fill(avg_height); // Blend the current terrain with the average height terrain
// using the "raised" empty terrain as a mask
// Blend the current terrain with the average height terrain Blend(flat, temp);
// using the "raised" empty terrain as a mask }
Blend(flat, temp); }
} }
}
}

View File

@ -1,137 +1,131 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
using System; using System;
namespace libTerrain namespace libTerrain
{ {
partial class Channel partial class Channel
{ {
/// <summary> /// <summary>
/// Raises land around the selection /// Raises land around the selection
/// </summary> /// </summary>
/// <param name="rx">The center the X coordinate of where you wish to raise the land</param> /// <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="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="size">The radius of the dimple</param>
/// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
public void Raise(double rx, double ry, double size, double amount) public void Raise(double rx, double ry, double size, double amount)
{ {
RaiseSphere(rx, ry, size, amount); RaiseSphere(rx, ry, size, amount);
} }
/// <summary> /// <summary>
/// Raises land in a sphere around the selection /// Raises land in a sphere around the selection
/// </summary> /// </summary>
/// <param name="rx">The center the X coordinate of where you wish to raise the land</param> /// <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="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="size">The radius of the sphere dimple</param>
/// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
public void RaiseSphere(double rx, double ry, double size, double amount) public void RaiseSphere(double rx, double ry, double size, double amount)
{ {
int x, y; int x, y;
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
{ {
double z = size; double z = size;
z *= z; z *= z;
z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry));
if (z < 0) if (z > 0.0)
z = 0; Set(x, y, map[x, y] + (z * amount));
}
Set(x, y, map[x, y] + (z*amount)); }
} }
}
} /// <summary>
/// Raises land in a cone around the selection
/// <summary> /// </summary>
/// Raises land in a cone around the selection /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
/// </summary> /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
/// <param name="rx">The center the X coordinate of where you wish to raise the land</param> /// <param name="size">The radius of the cone</param>
/// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
/// <param name="size">The radius of the cone</param> public void RaiseCone(double rx, double ry, double size, double amount)
/// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> {
public void RaiseCone(double rx, double ry, double size, double amount) int x, y;
{ for (x = 0; x < w; x++)
int x, y; {
for (x = 0; x < w; x++) for (y = 0; y < h; y++)
{ {
for (y = 0; y < h; y++) double z = size;
{ z -= Math.Sqrt(((x - rx)*(x - rx)) + ((y - ry)*(y - ry)));
double z = size;
z -= Math.Sqrt(((x - rx)*(x - rx)) + ((y - ry)*(y - ry))); if (z > 0.0)
Set(x, y, map[x, y] + (z * amount));
if (z < 0) }
z = 0; }
}
Set(x, y, map[x, y] + (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>
/// <summary> /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
/// Lowers land in a sphere around the selection /// <param name="size">The radius of the sphere dimple</param>
/// </summary> /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
/// <param name="rx">The center the X coordinate of where you wish to lower the land</param> public void Lower(double rx, double ry, double size, double amount)
/// <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> LowerSphere(rx, ry, size, amount);
/// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param> }
public void Lower(double rx, double ry, double size, double amount)
{ /// <summary>
LowerSphere(rx, ry, size, amount); /// 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>
/// <summary> /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
/// Lowers land in a sphere around the selection /// <param name="size">The radius of the sphere dimple</param>
/// </summary> /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
/// <param name="rx">The center the X coordinate of where you wish to lower the land</param> public void LowerSphere(double rx, double ry, double size, double amount)
/// <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> int x, y;
/// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param> for (x = 0; x < w; x++)
public void LowerSphere(double rx, double ry, double size, double amount) {
{ for (y = 0; y < h; y++)
int x, y; {
for (x = 0; x < w; x++) double z = size;
{ z *= z;
for (y = 0; y < h; y++) z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry));
{
double z = size; if (z > 0.0)
z *= z; Set(x, y, map[x, y] - (z * amount));
z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); }
}
if (z < 0) }
z = 0; }
}
Set(x, y, map[x, y] - (z*amount));
}
}
}
}
}

View File

@ -1,29 +1,29 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
/* Needs BSD rewrite */ /* Needs BSD rewrite */

View File

@ -1,29 +1,29 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
/* Needs BSD rewrite */ /* Needs BSD rewrite */

View File

@ -1,29 +1,29 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
/* Needs BSD rewrite */ /* Needs BSD rewrite */

View File

@ -1,359 +1,377 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
using System; using System;
namespace libTerrain namespace libTerrain
{ {
partial class Channel partial class Channel
{ {
public Channel Normalise() public Channel Normalise()
{ {
SetDiff(); SetDiff();
double max = FindMax(); double max = FindMax();
double min = FindMin(); double min = FindMin();
int x, y; int x, y;
if (max != min) if (max != min)
{ {
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
{ {
map[x, y] = (map[x, y] - min)*(1.0/(max - min)); map[x, y] = (map[x, y] - min)*(1.0/(max - min));
} }
} }
} }
else else
{ {
Fill(0.5); Fill(0.5);
} }
return this; return this;
} }
public Channel Normalise(double minv, double maxv) public Channel Normalise(double minv, double maxv)
{ {
SetDiff(); SetDiff();
if (minv == maxv) if (minv == maxv)
{ {
Fill(minv); Fill(minv);
return this; return this;
} }
double max = FindMax(); double max = FindMax();
double min = FindMin(); double min = FindMin();
int x, y; int x, y;
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
{ {
if (min != max) if (min != max)
{ {
double val = (map[x, y] - min)*(1.0/(max - min)); double val = (map[x, y] - min)*(1.0/(max - min));
val *= maxv - minv; val *= maxv - minv;
val += minv; val += minv;
map[x, y] = val; map[x, y] = val;
} }
else else
{ {
map[x, y] = 0.5; map[x, y] = 0.5;
} }
} }
} }
return this; return this;
} }
public Channel Clip() public Channel Elevate(double meters)
{ {
int x, y; SetDiff();
for (x = 0; x < w; x++) int x, y;
{
for (y = 0; y < h; y++) for (x = 0; x < w; x++)
{ {
SetClip(x, y, map[x, y]); for (y = 0; y < h; y++)
} {
} map[x, y] += meters;
}
return this; }
}
return this;
public Channel Clip(double min, double max) }
{
int x, y;
for (x = 0; x < w; x++) public Channel Clip()
{ {
for (y = 0; y < h; y++) int x, y;
{
double val = map[x, y]; for (x = 0; x < w; x++)
if (val > max) val = max; {
if (val < min) val = min; for (y = 0; y < h; y++)
{
Set(x, y, val); SetClip(x, y, map[x, y]);
} }
} }
return this;
} return this;
}
public Channel Crop(int x1, int y1, int x2, int y2)
{ public Channel Clip(double min, double max)
int width = x1 - x2 + 1; {
int height = y1 - y2 + 1; int x, y;
Channel chan = new Channel(width, height); for (x = 0; x < w; x++)
{
int x, y; for (y = 0; y < h; y++)
int nx, ny; {
double val = map[x, y];
nx = 0; if (val > max) val = max;
for (x = x1; x < x2; x++) if (val < min) val = min;
{
ny = 0; Set(x, y, val);
for (y = y1; y < y2; y++) }
{ }
chan.map[nx, ny] = map[x, y]; return this;
}
ny++;
} public Channel Crop(int x1, int y1, int x2, int y2)
nx++; {
} int width = x1 - x2 + 1;
int height = y1 - y2 + 1;
return this; Channel chan = new Channel(width, height);
}
int x, y;
public Channel AddClip(Channel other) int nx, ny;
{
SetDiff(); nx = 0;
for (x = x1; x < x2; x++)
int x, y; {
for (x = 0; x < w; x++) ny = 0;
{ for (y = y1; y < y2; y++)
for (y = 0; y < h; y++) {
{ chan.map[nx, ny] = map[x, y];
map[x, y] = other.map[x, y];
if (map[x, y] > 1) ny++;
map[x, y] = 1; }
if (map[x, y] < 0) nx++;
map[x, y] = 0; }
}
} return this;
return this; }
}
public Channel AddClip(Channel other)
public void Smooth(double amount) {
{ SetDiff();
SetDiff();
int x, y;
double area = amount; for (x = 0; x < w; x++)
double step = amount/4.0; {
for (y = 0; y < h; y++)
double[,] manipulate = new double[w,h]; {
int x, y; map[x, y] = other.map[x, y];
double n, l; if (map[x, y] > 1)
for (x = 0; x < w; x++) map[x, y] = 1;
{ if (map[x, y] < 0)
for (y = 0; y < h; y++) map[x, y] = 0;
{ }
double average = 0.0; }
int avgsteps = 0; return this;
}
for (n = 0.0 - area; n < area; n += step)
{ public void Smooth(double amount)
for (l = 0.0 - area; l < area; l += step) {
{ SetDiff();
avgsteps++;
average += GetBilinearInterpolate(x + n, y + l); double area = amount;
} double step = amount/4.0;
}
double[,] manipulate = new double[w,h];
manipulate[x, y] = average/avgsteps; int x, y;
} double n, l;
} for (x = 0; x < w; x++)
map = manipulate; {
} for (y = 0; y < h; y++)
{
public void Pertubation(double amount) double average = 0.0;
{ int avgsteps = 0;
SetDiff();
for (n = 0.0 - area; n < area; n += step)
// Simple pertubation filter {
double[,] manipulated = new double[w,h]; for (l = 0.0 - area; l < area; l += step)
Random generator = new Random(seed); // Seeds FTW! {
//double amount = 8.0; avgsteps++;
average += GetBilinearInterpolate(x + n, y + l);
int x, y; }
for (x = 0; x < w; x++) }
{
for (y = 0; y < h; y++) manipulate[x, y] = average/avgsteps;
{ }
double offset_x = (double) x + (generator.NextDouble()*amount) - (amount/2.0); }
double offset_y = (double) y + (generator.NextDouble()*amount) - (amount/2.0); map = manipulate;
double p = GetBilinearInterpolate(offset_x, offset_y); }
manipulated[x, y] = p;
} public void Pertubation(double amount)
} {
map = manipulated; SetDiff();
}
// Simple pertubation filter
public void PertubationMask(Channel mask) double[,] manipulated = new double[w,h];
{ Random generator = new Random(seed); // Seeds FTW!
// Simple pertubation filter //double amount = 8.0;
double[,] manipulated = new double[w,h];
Random generator = new Random(seed); // Seeds FTW! int x, y;
//double amount = 8.0; for (x = 0; x < w; x++)
{
double amount; for (y = 0; y < h; y++)
{
int x, y; double offset_x = (double) x + (generator.NextDouble()*amount) - (amount/2.0);
for (x = 0; x < w; x++) double offset_y = (double) y + (generator.NextDouble()*amount) - (amount/2.0);
{ double p = GetBilinearInterpolate(offset_x, offset_y);
for (y = 0; y < h; y++) manipulated[x, y] = p;
{ }
amount = mask.map[x, y]; }
double offset_x = (double) x + (generator.NextDouble()*amount) - (amount/2.0); map = manipulated;
double offset_y = (double) y + (generator.NextDouble()*amount) - (amount/2.0); }
if (offset_x > w) public void PertubationMask(Channel mask)
offset_x = w - 1; {
if (offset_y > h) // Simple pertubation filter
offset_y = h - 1; double[,] manipulated = new double[w,h];
if (offset_y < 0) Random generator = new Random(seed); // Seeds FTW!
offset_y = 0; //double amount = 8.0;
if (offset_x < 0)
offset_x = 0; double amount;
double p = GetBilinearInterpolate(offset_x, offset_y); int x, y;
manipulated[x, y] = p; for (x = 0; x < w; x++)
SetDiff(x, y); {
} for (y = 0; y < h; y++)
} {
map = manipulated; amount = mask.map[x, y];
} double offset_x = (double) x + (generator.NextDouble()*amount) - (amount/2.0);
double offset_y = (double) y + (generator.NextDouble()*amount) - (amount/2.0);
public void Distort(Channel mask, double str)
{ if (offset_x > w)
// Simple pertubation filter offset_x = w - 1;
double[,] manipulated = new double[w,h]; if (offset_y > h)
offset_y = h - 1;
double amount; if (offset_y < 0)
offset_y = 0;
int x, y; if (offset_x < 0)
for (x = 0; x < w; x++) offset_x = 0;
{
for (y = 0; y < h; y++) double p = GetBilinearInterpolate(offset_x, offset_y);
{ manipulated[x, y] = p;
amount = mask.map[x, y]; SetDiff(x, y);
double offset_x = (double) x + (amount*str) - (0.5*str); }
double offset_y = (double) y + (amount*str) - (0.5*str); }
map = manipulated;
if (offset_x > w) }
offset_x = w - 1;
if (offset_y > h) public void Distort(Channel mask, double str)
offset_y = h - 1; {
if (offset_y < 0) // Simple pertubation filter
offset_y = 0; double[,] manipulated = new double[w,h];
if (offset_x < 0)
offset_x = 0; double amount;
double p = GetBilinearInterpolate(offset_x, offset_y); int x, y;
manipulated[x, y] = p; for (x = 0; x < w; x++)
SetDiff(x, y); {
} for (y = 0; y < h; y++)
} {
map = manipulated; amount = mask.map[x, y];
} double offset_x = (double) x + (amount*str) - (0.5*str);
double offset_y = (double) y + (amount*str) - (0.5*str);
public void Distort(Channel mask, Channel mask2, double str)
{ if (offset_x > w)
// Simple pertubation filter offset_x = w - 1;
double[,] manipulated = new double[w,h]; if (offset_y > h)
offset_y = h - 1;
double amountX; if (offset_y < 0)
double amountY; offset_y = 0;
if (offset_x < 0)
int x, y; offset_x = 0;
for (x = 0; x < w; x++)
{ double p = GetBilinearInterpolate(offset_x, offset_y);
for (y = 0; y < h; y++) manipulated[x, y] = p;
{ SetDiff(x, y);
amountX = mask.map[x, y]; }
amountY = mask2.map[x, y]; }
double offset_x = (double) x + (amountX*str) - (0.5*str); map = manipulated;
double offset_y = (double) y + (amountY*str) - (0.5*str); }
if (offset_x > w) public void Distort(Channel mask, Channel mask2, double str)
offset_x = w - 1; {
if (offset_y > h) // Simple pertubation filter
offset_y = h - 1; double[,] manipulated = new double[w,h];
if (offset_y < 0)
offset_y = 0; double amountX;
if (offset_x < 0) double amountY;
offset_x = 0;
int x, y;
double p = GetBilinearInterpolate(offset_x, offset_y); for (x = 0; x < w; x++)
manipulated[x, y] = p; {
SetDiff(x, y); for (y = 0; y < h; y++)
} {
} amountX = mask.map[x, y];
map = manipulated; amountY = mask2.map[x, y];
} double offset_x = (double) x + (amountX*str) - (0.5*str);
double offset_y = (double) y + (amountY*str) - (0.5*str);
public Channel Blend(Channel other, double amount)
{ if (offset_x > w)
int x, y; offset_x = w - 1;
for (x = 0; x < w; x++) if (offset_y > h)
{ offset_y = h - 1;
for (y = 0; y < h; y++) if (offset_y < 0)
{ offset_y = 0;
Set(x, y, Tools.LinearInterpolate(map[x, y], other.map[x, y], amount)); if (offset_x < 0)
} offset_x = 0;
}
return this; double p = GetBilinearInterpolate(offset_x, offset_y);
} manipulated[x, y] = p;
SetDiff(x, y);
public Channel Blend(Channel other, Channel amount) }
{ }
int x, y; map = manipulated;
for (x = 0; x < w; x++) }
{
for (y = 0; y < h; y++) public Channel Blend(Channel other, double amount)
{ {
Set(x, y, Tools.LinearInterpolate(map[x, y], other.map[x, y], amount.map[x, y])); int x, y;
} for (x = 0; x < w; x++)
} {
return this; for (y = 0; y < h; y++)
} {
} Set(x, y, Tools.LinearInterpolate(map[x, y], other.map[x, y], amount));
} }
}
return this;
}
public Channel Blend(Channel other, Channel amount)
{
int x, y;
for (x = 0; x < w; x++)
{
for (y = 0; y < h; y++)
{
Set(x, y, Tools.LinearInterpolate(map[x, y], other.map[x, y], amount.map[x, y]));
}
}
return this;
}
}
}

View File

@ -1,42 +1,42 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
namespace libTerrain namespace libTerrain
{ {
public class Point2D public class Point2D
{ {
public double x; public double x;
public double y; public double y;
public Point2D(double X, double Y) public Point2D(double X, double Y)
{ {
x = X; x = X;
y = Y; y = Y;
} }
} }
} }

View File

@ -1,60 +1,60 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
using System; using System;
namespace libTerrain namespace libTerrain
{ {
internal class Tools internal class Tools
{ {
public static double LinearInterpolate(double a, double b, double amount) public static double LinearInterpolate(double a, double b, double amount)
{ {
return a + ((b - a)*amount); return a + ((b - a)*amount);
} }
public static double ExponentialInterpolate(double a, double b, double amount) public static double ExponentialInterpolate(double a, double b, double amount)
{ {
a = Math.Pow(a, amount); a = Math.Pow(a, amount);
b = Math.Pow(b - a, 1.0 - amount); b = Math.Pow(b - a, 1.0 - amount);
return a + b; return a + b;
} }
public static int PowerOf2Log2(int n) public static int PowerOf2Log2(int n)
{ {
for (int i = 0; i < 31; i++) for (int i = 0; i < 31; i++)
{ {
if ((n & 1) == 1) if ((n & 1) == 1)
{ {
return i; return i;
} }
n >>= 1; n >>= 1;
} }
return 0; return 0;
} }
} }
} }