diff options
author | Justin Clarke Casey | 2009-03-26 17:42:02 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2009-03-26 17:42:02 +0000 |
commit | 0db166ed3d7f9c230349a34eec9dca1ae335bb1a (patch) | |
tree | 082964675541cae294e768cd5dbe45b26669e303 | |
parent | * Fix build break from last commit (diff) | |
download | opensim-SC-0db166ed3d7f9c230349a34eec9dca1ae335bb1a.zip opensim-SC-0db166ed3d7f9c230349a34eec9dca1ae335bb1a.tar.gz opensim-SC-0db166ed3d7f9c230349a34eec9dca1ae335bb1a.tar.bz2 opensim-SC-0db166ed3d7f9c230349a34eec9dca1ae335bb1a.tar.xz |
* Apply http://opensimulator.org/mantis/view.php?id=865
* Reimplements "terrain rescale <min> <max>" command which rescales current terrain to be inbetween min and max
* Thanks jonc
-rw-r--r-- | OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs index bc8fc95..239ff55 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | |||
@@ -801,6 +801,66 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
801 | CheckForTerrainUpdates(); | 801 | CheckForTerrainUpdates(); |
802 | } | 802 | } |
803 | 803 | ||
804 | private void InterfaceRescaleTerrain(Object[] args) | ||
805 | { | ||
806 | double desiredMin = (double)args[0]; | ||
807 | double desiredMax = (double)args[1]; | ||
808 | |||
809 | // determine desired scaling factor | ||
810 | double desiredRange = desiredMax - desiredMin; | ||
811 | //m_log.InfoFormat("Desired {0}, {1} = {2}", new Object[] { desiredMin, desiredMax, desiredRange }); | ||
812 | |||
813 | if (desiredRange == 0d) | ||
814 | { | ||
815 | // delta is zero so flatten at requested height | ||
816 | InterfaceFillTerrain(new Object[] { args[1] }); | ||
817 | } | ||
818 | else | ||
819 | { | ||
820 | //work out current heightmap range | ||
821 | double currMin = double.MaxValue; | ||
822 | double currMax = double.MinValue; | ||
823 | |||
824 | int width = m_channel.Width; | ||
825 | int height = m_channel.Height; | ||
826 | |||
827 | for (int x = 0; x < width; x++) | ||
828 | { | ||
829 | for (int y = 0; y < height; y++) | ||
830 | { | ||
831 | double currHeight = m_channel[x, y]; | ||
832 | if (currHeight < currMin) | ||
833 | { | ||
834 | currMin = currHeight; | ||
835 | } | ||
836 | else if (currHeight > currMax) | ||
837 | { | ||
838 | currMax = currHeight; | ||
839 | } | ||
840 | } | ||
841 | } | ||
842 | |||
843 | double currRange = currMax - currMin; | ||
844 | double scale = desiredRange / currRange; | ||
845 | |||
846 | //m_log.InfoFormat("Current {0}, {1} = {2}", new Object[] { currMin, currMax, currRange }); | ||
847 | //m_log.InfoFormat("Scale = {0}", scale); | ||
848 | |||
849 | // scale the heightmap accordingly | ||
850 | for (int x = 0; x < width; x++) | ||
851 | { | ||
852 | for (int y = 0; y < height; y++) | ||
853 | { | ||
854 | double currHeight = m_channel[x, y] - currMin; | ||
855 | m_channel[x, y] = desiredMin + (currHeight * scale); | ||
856 | } | ||
857 | } | ||
858 | |||
859 | CheckForTerrainUpdates(); | ||
860 | } | ||
861 | |||
862 | } | ||
863 | |||
804 | private void InterfaceElevateTerrain(Object[] args) | 864 | private void InterfaceElevateTerrain(Object[] args) |
805 | { | 865 | { |
806 | int x, y; | 866 | int x, y; |
@@ -963,6 +1023,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
963 | new Command("flip", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFlipTerrain, "Flips the current terrain about the X or Y axis"); | 1023 | new Command("flip", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFlipTerrain, "Flips the current terrain about the X or Y axis"); |
964 | flipCommand.AddArgument("direction", "[x|y] the direction to flip the terrain in", "String"); | 1024 | flipCommand.AddArgument("direction", "[x|y] the direction to flip the terrain in", "String"); |
965 | 1025 | ||
1026 | Command rescaleCommand = | ||
1027 | new Command("rescale", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRescaleTerrain, "Rescales the current terrain to fit between the given min and max heights"); | ||
1028 | rescaleCommand.AddArgument("min", "min terrain height after rescaling", "Double"); | ||
1029 | rescaleCommand.AddArgument("max", "max terrain height after rescaling", "Double"); | ||
1030 | |||
1031 | |||
966 | // Debug | 1032 | // Debug |
967 | Command showDebugStatsCommand = | 1033 | Command showDebugStatsCommand = |
968 | new Command("stats", CommandIntentions.COMMAND_STATISTICAL, InterfaceShowDebugStats, | 1034 | new Command("stats", CommandIntentions.COMMAND_STATISTICAL, InterfaceShowDebugStats, |
@@ -991,6 +1057,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
991 | m_commander.RegisterCommand("stats", showDebugStatsCommand); | 1057 | m_commander.RegisterCommand("stats", showDebugStatsCommand); |
992 | m_commander.RegisterCommand("effect", pluginRunCommand); | 1058 | m_commander.RegisterCommand("effect", pluginRunCommand); |
993 | m_commander.RegisterCommand("flip", flipCommand); | 1059 | m_commander.RegisterCommand("flip", flipCommand); |
1060 | m_commander.RegisterCommand("rescale", rescaleCommand); | ||
994 | 1061 | ||
995 | // Add this to our scene so scripts can call these functions | 1062 | // Add this to our scene so scripts can call these functions |
996 | m_scene.RegisterModuleCommander(m_commander); | 1063 | m_scene.RegisterModuleCommander(m_commander); |