diff options
author | Brian McBee | 2007-08-06 18:14:48 +0000 |
---|---|---|
committer | Brian McBee | 2007-08-06 18:14:48 +0000 |
commit | 86da47dc4e7d843d973570f8ce2158c35a3ab895 (patch) | |
tree | 8971a71474f281e6c2d1b546fe887c53532dd7aa | |
parent | OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs (diff) | |
download | opensim-SC-86da47dc4e7d843d973570f8ce2158c35a3ab895.zip opensim-SC-86da47dc4e7d843d973570f8ce2158c35a3ab895.tar.gz opensim-SC-86da47dc4e7d843d973570f8ce2158c35a3ab895.tar.bz2 opensim-SC-86da47dc4e7d843d973570f8ce2158c35a3ab895.tar.xz |
OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
This time I think I have BOTH terrain rotation AND terraforming working. Could those of you with large terrain maps please test this thoroughly?
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs | 69 |
1 files changed, 26 insertions, 43 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs index a519185..e10c51b 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs | |||
@@ -155,23 +155,6 @@ namespace OpenSim.Region.Terrain | |||
155 | /// Converts the heightmap to a 65536 value 1D floating point array | 155 | /// Converts the heightmap to a 65536 value 1D floating point array |
156 | /// </summary> | 156 | /// </summary> |
157 | /// <returns>A float[65536] array containing the heightmap</returns> | 157 | /// <returns>A float[65536] array containing the heightmap</returns> |
158 | public float[] GetHeights1DFixed() | ||
159 | { | ||
160 | float[] heights = new float[w * h]; | ||
161 | int i; | ||
162 | |||
163 | for (i = 0; i < w * h; i++) | ||
164 | { | ||
165 | heights[i] = (float)heightmap.map[i % w, i / w]; | ||
166 | } | ||
167 | |||
168 | return heights; | ||
169 | } | ||
170 | |||
171 | /// <summary> | ||
172 | /// Converts the heightmap to a 65536 value 1D floating point array | ||
173 | /// </summary> | ||
174 | /// <returns>A float[65536] array containing the heightmap</returns> | ||
175 | public float[] GetHeights1D() | 158 | public float[] GetHeights1D() |
176 | { | 159 | { |
177 | float[] heights = new float[w * h]; | 160 | float[] heights = new float[w * h]; |
@@ -179,7 +162,7 @@ namespace OpenSim.Region.Terrain | |||
179 | 162 | ||
180 | for (i = 0; i < w * h; i++) | 163 | for (i = 0; i < w * h; i++) |
181 | { | 164 | { |
182 | heights[i] = (float)heightmap.map[i / w, i % w]; | 165 | heights[i] = (float)heightmap.map[i % w, i / w]; |
183 | } | 166 | } |
184 | 167 | ||
185 | return heights; | 168 | return heights; |
@@ -221,7 +204,7 @@ namespace OpenSim.Region.Terrain | |||
221 | int i; | 204 | int i; |
222 | for (i = 0; i < w * h; i++) | 205 | for (i = 0; i < w * h; i++) |
223 | { | 206 | { |
224 | heightmap.map[i / w, i % w] = heights[i]; | 207 | heightmap.map[i % w, i / w] = heights[i]; |
225 | } | 208 | } |
226 | 209 | ||
227 | tainted++; | 210 | tainted++; |
@@ -593,9 +576,9 @@ namespace OpenSim.Region.Terrain | |||
593 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | 576 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); |
594 | BinaryReader bs = new BinaryReader(s); | 577 | BinaryReader bs = new BinaryReader(s); |
595 | int x, y; | 578 | int x, y; |
596 | for (x = 0; x < w; x++) | 579 | for (y = 0; y < h; y++) |
597 | { | 580 | { |
598 | for (y = 0; y < h; y++) | 581 | for (x = 0; x < h; x++) |
599 | { | 582 | { |
600 | heightmap.map[x, y] = bs.ReadDouble(); | 583 | heightmap.map[x, y] = bs.ReadDouble(); |
601 | } | 584 | } |
@@ -618,9 +601,9 @@ namespace OpenSim.Region.Terrain | |||
618 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | 601 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); |
619 | BinaryReader bs = new BinaryReader(s); | 602 | BinaryReader bs = new BinaryReader(s); |
620 | int x, y; | 603 | int x, y; |
621 | for (x = 0; x < w; x++) | 604 | for (y = 0; y < h; y++) |
622 | { | 605 | { |
623 | for (y = 0; y < h; y++) | 606 | for (x = 0; x < w; x++) |
624 | { | 607 | { |
625 | heightmap.map[x, y] = (double)bs.ReadSingle(); | 608 | heightmap.map[x, y] = (double)bs.ReadSingle(); |
626 | } | 609 | } |
@@ -652,19 +635,19 @@ namespace OpenSim.Region.Terrain | |||
652 | BinaryReader bs = new BinaryReader(s); | 635 | BinaryReader bs = new BinaryReader(s); |
653 | 636 | ||
654 | int x, y; | 637 | int x, y; |
655 | for (x = 0; x < dimensionX; x++) | 638 | for (y = 0; y < dimensionY; y++) |
656 | { | 639 | { |
657 | for (y = 0; y < dimensionY; y++) | 640 | for (x = 0; x < dimensionX; x++) |
658 | { | 641 | { |
659 | tempMap[y,x] = (double)bs.ReadSingle(); | 642 | tempMap[x,y] = (double)bs.ReadSingle(); |
660 | } | 643 | } |
661 | } | 644 | } |
662 | 645 | ||
663 | for (x = 0; x < w; x++) | 646 | for (y = 0; y < h; y++) |
664 | { | 647 | { |
665 | for (y = 0; y < h; y++) | 648 | for (x = 0; x < w; x++) |
666 | { | 649 | { |
667 | heightmap.Set(x, y, tempMap[x + sectionToLoadY, y + sectionToLoadX]); | 650 | heightmap.Set(x, y, tempMap[x + sectionToLoadX, y + sectionToLoadY]); |
668 | } | 651 | } |
669 | } | 652 | } |
670 | 653 | ||
@@ -685,9 +668,9 @@ namespace OpenSim.Region.Terrain | |||
685 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | 668 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); |
686 | BinaryReader bs = new BinaryReader(s); | 669 | BinaryReader bs = new BinaryReader(s); |
687 | int x, y; | 670 | int x, y; |
688 | for (x = 0; x < w; x++) | 671 | for (y = 0; y < h; y++) |
689 | { | 672 | { |
690 | for (y = 0; y < h; y++) | 673 | for (x = 0; x < w; x++) |
691 | { | 674 | { |
692 | heightmap.map[x, y] = (double)bs.ReadByte() * ((double)bs.ReadByte() / 127.0); | 675 | heightmap.map[x, y] = (double)bs.ReadByte() * ((double)bs.ReadByte() / 127.0); |
693 | bs.ReadBytes(11); // Advance the stream to next bytes. | 676 | bs.ReadBytes(11); // Advance the stream to next bytes. |
@@ -711,9 +694,9 @@ namespace OpenSim.Region.Terrain | |||
711 | BinaryWriter bs = new BinaryWriter(s); | 694 | BinaryWriter bs = new BinaryWriter(s); |
712 | 695 | ||
713 | int x, y; | 696 | int x, y; |
714 | for (x = 0; x < w; x++) | 697 | for (y = 0; y < h; y++) |
715 | { | 698 | { |
716 | for (y = 0; y < h; y++) | 699 | for (x = 0; x < w; x++) |
717 | { | 700 | { |
718 | bs.Write(heightmap.Get(x, y)); | 701 | bs.Write(heightmap.Get(x, y)); |
719 | } | 702 | } |
@@ -734,9 +717,9 @@ namespace OpenSim.Region.Terrain | |||
734 | BinaryWriter bs = new BinaryWriter(s); | 717 | BinaryWriter bs = new BinaryWriter(s); |
735 | 718 | ||
736 | int x, y; | 719 | int x, y; |
737 | for (x = 0; x < w; x++) | 720 | for (y = 0; y < h; y++) |
738 | { | 721 | { |
739 | for (y = 0; y < h; y++) | 722 | for (x = 0; x < w; x++) |
740 | { | 723 | { |
741 | bs.Write((float)heightmap.Get(x, y)); | 724 | bs.Write((float)heightmap.Get(x, y)); |
742 | } | 725 | } |
@@ -774,9 +757,9 @@ namespace OpenSim.Region.Terrain | |||
774 | if(backupMultiplier < 1) | 757 | if(backupMultiplier < 1) |
775 | backupMultiplier = 1; | 758 | backupMultiplier = 1; |
776 | 759 | ||
777 | for (x = 0; x < w; x++) | 760 | for (y = 0; y < h; y++) |
778 | { | 761 | { |
779 | for (y = 0; y < h; y++) | 762 | for (x = 0; x < h; x++) |
780 | { | 763 | { |
781 | byte red = (byte)(heightmap.Get(x, y) / ((double)avgMultiplier / 128.0)); | 764 | byte red = (byte)(heightmap.Get(x, y) / ((double)avgMultiplier / 128.0)); |
782 | byte green = avgMultiplier; | 765 | byte green = avgMultiplier; |
@@ -834,9 +817,9 @@ namespace OpenSim.Region.Terrain | |||
834 | } | 817 | } |
835 | 818 | ||
836 | // Output the calculated raw | 819 | // Output the calculated raw |
837 | for (x = 0; x < w; x++) | 820 | for (y = 0; y < h; y++) |
838 | { | 821 | { |
839 | for (y = 0; y < h; y++) | 822 | for (x = 0; x < w; x++) |
840 | { | 823 | { |
841 | double t = heightmap.Get(x, y); | 824 | double t = heightmap.Get(x, y); |
842 | double min = double.MaxValue; | 825 | double min = double.MaxValue; |
@@ -1072,9 +1055,9 @@ namespace OpenSim.Region.Terrain | |||
1072 | } | 1055 | } |
1073 | 1056 | ||
1074 | Channel copy = heightmap.Copy(); | 1057 | Channel copy = heightmap.Copy(); |
1075 | for (int x = 0; x < copy.w; x++) | 1058 | for (int y = 0; y < copy.h; y++) |
1076 | { | 1059 | { |
1077 | for (int y = 0; y < copy.h; y++) | 1060 | for (int x = 0; x < copy.w; x++) |
1078 | { | 1061 | { |
1079 | // 512 is the largest possible height before colours clamp | 1062 | // 512 is the largest possible height before colours clamp |
1080 | int colorindex = (int)(Math.Max(Math.Min(1.0, copy.Get(x, y) / 512.0), 0.0) * (pallete - 1)); | 1063 | int colorindex = (int)(Math.Max(Math.Min(1.0, copy.Get(x, y) / 512.0), 0.0) * (pallete - 1)); |
@@ -1112,9 +1095,9 @@ namespace OpenSim.Region.Terrain | |||
1112 | } | 1095 | } |
1113 | 1096 | ||
1114 | Channel copy = heightmap.Copy(); | 1097 | Channel copy = heightmap.Copy(); |
1115 | for (int x = 0; x < copy.w; x++) | 1098 | for (int y = 0; y < copy.h; y++) |
1116 | { | 1099 | { |
1117 | for (int y = 0; y < copy.h; y++) | 1100 | for (int x = 0; x < copy.w; x++) |
1118 | { | 1101 | { |
1119 | // 512 is the largest possible height before colours clamp | 1102 | // 512 is the largest possible height before colours clamp |
1120 | int colorindex = (int)(Math.Max(Math.Min(1.0, copy.Get(copy.h - y, x) / 512.0), 0.0) * (pallete - 1)); | 1103 | int colorindex = (int)(Math.Max(Math.Min(1.0, copy.Get(copy.h - y, x) / 512.0), 0.0) * (pallete - 1)); |