diff options
author | Teravus Ovares | 2007-12-03 13:11:15 +0000 |
---|---|---|
committer | Teravus Ovares | 2007-12-03 13:11:15 +0000 |
commit | 0ec208a2001d068327e3ca4311f16f0f0b10c2ca (patch) | |
tree | e585e0558f5c9bdaf77cd0ba511eef9f5ce5edf4 /OpenSim/Region | |
parent | Some refactoring (diff) | |
download | opensim-SC_OLD-0ec208a2001d068327e3ca4311f16f0f0b10c2ca.zip opensim-SC_OLD-0ec208a2001d068327e3ca4311f16f0f0b10c2ca.tar.gz opensim-SC_OLD-0ec208a2001d068327e3ca4311f16f0f0b10c2ca.tar.bz2 opensim-SC_OLD-0ec208a2001d068327e3ca4311f16f0f0b10c2ca.tar.xz |
* Resize terrain heightmap info going to ODE to double the resolution.
* Using the nearest neighbor method, interpolation coming soon.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 7193886..59b8ff0 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | |||
@@ -154,7 +154,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
154 | d.WorldSetContactMaxCorrectingVel(world, 1000.0f); | 154 | d.WorldSetContactMaxCorrectingVel(world, 1000.0f); |
155 | } | 155 | } |
156 | 156 | ||
157 | _heightmap = new double[258*258]; | 157 | _heightmap = new double[514*514]; |
158 | 158 | ||
159 | for (int i = 0; i < staticPrimspace.GetLength(0); i++) | 159 | for (int i = 0; i < staticPrimspace.GetLength(0); i++) |
160 | { | 160 | { |
@@ -885,25 +885,77 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
885 | get { return (false); // for now we won't be multithreaded | 885 | get { return (false); // for now we won't be multithreaded |
886 | } | 886 | } |
887 | } | 887 | } |
888 | public float[] ResizeTerrain512(float[] heightMap) | ||
889 | { | ||
890 | float[] returnarr = new float[262144]; | ||
891 | float[,] resultarr = new float[256, 256]; | ||
892 | |||
893 | // Filling out the array into it's multi-dimentional components | ||
894 | for (int y = 0; y < 256; y++) | ||
895 | { | ||
896 | for (int x = 0; x < 256; x++) | ||
897 | { | ||
898 | resultarr[y,x] = heightMap[y * 256 + x]; | ||
899 | } | ||
900 | } | ||
901 | |||
902 | // Resize using the nearest neighbor method | ||
903 | // Going to be doing interpolation here soon | ||
904 | |||
905 | // This particular way is quick but it only works on a multiple of the original | ||
906 | |||
907 | float[,] resultarr2 = new float[512, 512]; | ||
908 | for (int y = 0; y < 256; y++) | ||
909 | { | ||
910 | for (int x = 0; x < 256; x++) | ||
911 | { | ||
912 | resultarr2[y*2,x*2] = resultarr[y,x]; | ||
913 | |||
914 | if (y < 256) | ||
915 | resultarr2[(y*2)+1,x*2] = resultarr[y,x]; | ||
916 | if (x < 256) | ||
917 | resultarr2[y*2,(x*2)+1] = resultarr[y,x]; | ||
888 | 918 | ||
919 | if (x<256 && y < 256) | ||
920 | resultarr2[(y*2)+1,(x*2)+1] = resultarr[y,x]; | ||
921 | } | ||
922 | |||
923 | } | ||
924 | //Flatten out the array | ||
925 | int i = 0; | ||
926 | for (int y = 0; y < 512; y++) | ||
927 | { | ||
928 | for (int x = 0; x < 512; x++) | ||
929 | { | ||
930 | returnarr[i] = resultarr2[y, x]; | ||
931 | i++; | ||
932 | } | ||
933 | } | ||
934 | |||
935 | return returnarr; | ||
936 | |||
937 | } | ||
889 | public override void SetTerrain(float[] heightMap) | 938 | public override void SetTerrain(float[] heightMap) |
890 | { | 939 | { |
891 | // this._heightmap[i] = (double)heightMap[i]; | 940 | // this._heightmap[i] = (double)heightMap[i]; |
892 | // dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...) | 941 | // dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...) |
893 | // also, creating a buffer zone of one extra sample all around | 942 | // also, creating a buffer zone of one extra sample all around |
894 | for (int x = 0; x < 258; x++) | 943 | |
944 | //Double resolution | ||
945 | heightMap = ResizeTerrain512(heightMap); | ||
946 | for (int x = 0; x < 514; x++) | ||
895 | { | 947 | { |
896 | for (int y = 0; y < 258; y++) | 948 | for (int y = 0; y < 514; y++) |
897 | { | 949 | { |
898 | int xx = x - 1; | 950 | int xx = x - 1; |
899 | if (xx < 0) xx = 0; | 951 | if (xx < 0) xx = 0; |
900 | if (xx > 255) xx = 255; | 952 | if (xx > 511) xx = 511; |
901 | int yy = y - 1; | 953 | int yy = y - 1; |
902 | if (yy < 0) yy = 0; | 954 | if (yy < 0) yy = 0; |
903 | if (yy > 255) yy = 255; | 955 | if (yy > 511) yy = 511; |
904 | 956 | ||
905 | double val = (double) heightMap[yy*256 + xx]; | 957 | double val = (double) heightMap[yy*512 + xx]; |
906 | _heightmap[x*258 + y] = val; | 958 | _heightmap[x*514 + y] = val; |
907 | } | 959 | } |
908 | } | 960 | } |
909 | 961 | ||
@@ -914,7 +966,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
914 | d.SpaceRemove(space, LandGeom); | 966 | d.SpaceRemove(space, LandGeom); |
915 | } | 967 | } |
916 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); | 968 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); |
917 | d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 258, 258, 258, 258, 1.0f, 0.0f, 2.0f, 0); | 969 | d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 258, 258, 514, 514, 1.0f, 0.0f, 2.0f, 0); |
918 | d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256); | 970 | d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256); |
919 | LandGeom = d.CreateHeightfield(space, HeightmapData, 1); | 971 | LandGeom = d.CreateHeightfield(space, HeightmapData, 1); |
920 | geom_name_map[LandGeom] = "Terrain"; | 972 | geom_name_map[LandGeom] = "Terrain"; |