aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics
diff options
context:
space:
mode:
authorMelanie2012-04-13 03:03:44 +0100
committerMelanie2012-04-13 03:03:44 +0100
commit5e3a76361fa097a2c47f6d37884786ec5777590c (patch)
tree85d791855e6e3646194a572fae5f2fb3d7a84110 /OpenSim/Region/Physics
parentMerge branch 'master' into careminster (diff)
parentmake llGetGeometricCenter() work as in current SL. Now this is not real geom ... (diff)
downloadopensim-SC-5e3a76361fa097a2c47f6d37884786ec5777590c.zip
opensim-SC-5e3a76361fa097a2c47f6d37884786ec5777590c.tar.gz
opensim-SC-5e3a76361fa097a2c47f6d37884786ec5777590c.tar.bz2
opensim-SC-5e3a76361fa097a2c47f6d37884786ec5777590c.tar.xz
Merge branch 'master' of ssh://melanie@3dhosting.de/var/git/careminster into careminster
Diffstat (limited to 'OpenSim/Region/Physics')
-rw-r--r--OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs11
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs2
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs53
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs318
4 files changed, 315 insertions, 69 deletions
diff --git a/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs
index 3e2b71c..77ea2af 100644
--- a/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs
@@ -179,6 +179,8 @@ namespace OpenSim.Region.Physics.OdePlugin
179 public bool m_outofBounds; 179 public bool m_outofBounds;
180 private float m_density = 10.000006836f; // Aluminum g/cm3; 180 private float m_density = 10.000006836f; // Aluminum g/cm3;
181 181
182 private float m_primMass = 10.000006836f; // Aluminum g/cm3;
183
182 private byte m_shapetype; 184 private byte m_shapetype;
183 private byte m_taintshapetype; 185 private byte m_taintshapetype;
184 186
@@ -538,7 +540,11 @@ namespace OpenSim.Region.Physics.OdePlugin
538 540
539 public override float Mass 541 public override float Mass
540 { 542 {
541 get { return CalculateMass(); } 543 get
544 {
545 CalculateMass();
546 return m_primMass;
547 }
542 } 548 }
543 549
544 public override Vector3 Force 550 public override Vector3 Force
@@ -1316,6 +1322,9 @@ namespace OpenSim.Region.Physics.OdePlugin
1316 1322
1317 1323
1318 1324
1325 m_primMass = returnMass;
1326 if (m_primMass > _parent_scene.maximumMassObject)
1327 m_primMass = _parent_scene.maximumMassObject;
1319 1328
1320 // Recursively calculate mass 1329 // Recursively calculate mass
1321 bool HasChildPrim = false; 1330 bool HasChildPrim = false;
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
index c4dc793..f739183 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
@@ -395,7 +395,7 @@ namespace OpenSim.Region.Physics.OdePlugin
395 395
396 public override float Mass 396 public override float Mass
397 { 397 {
398 get { return _mass; } 398 get { return primMass; }
399 } 399 }
400 400
401 public override Vector3 Force 401 public override Vector3 Force
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs
index 2b6bc59..f5129cb 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs
@@ -107,16 +107,17 @@ namespace OdeAPI
107 ConvexClass, 107 ConvexClass,
108 GeomTransformClass, 108 GeomTransformClass,
109 TriMeshClass, 109 TriMeshClass,
110 HeightfieldClass, 110 HeightfieldClass,
111 FirstSpaceClass, 111 FirstSpaceClass,
112 SimpleSpaceClass = FirstSpaceClass, 112 SimpleSpaceClass = FirstSpaceClass,
113 HashSpaceClass, 113 HashSpaceClass,
114 QuadTreeSpaceClass, 114 QuadTreeSpaceClass,
115 LastSpaceClass = QuadTreeSpaceClass, 115 LastSpaceClass = QuadTreeSpaceClass,
116 UbitTerrainClass,
116 FirstUserClass, 117 FirstUserClass,
117 LastUserClass = FirstUserClass + MaxUserClasses - 1, 118 LastUserClass = FirstUserClass + MaxUserClasses - 1,
118 NumClasses, 119 NumClasses,
119 MaxUserClasses = 4 120 MaxUserClasses = 5
120 } 121 }
121 122
122 public enum JointType : int 123 public enum JointType : int
@@ -201,8 +202,11 @@ namespace OdeAPI
201 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 202 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
202 public delegate void GeomDtorFn(IntPtr o); 203 public delegate void GeomDtorFn(IntPtr o);
203 204
204 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 205 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
205 public delegate dReal HeightfieldGetHeight(IntPtr p_user_data, int x, int z); 206 public delegate dReal HeightfieldGetHeight(IntPtr p_user_data, int x, int z);
207
208 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
209 public delegate dReal UbitTerrainGetHeight(IntPtr p_user_data, int x, int z);
206 210
207 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 211 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
208 public delegate void NearCallback(IntPtr data, IntPtr geom1, IntPtr geom2); 212 public delegate void NearCallback(IntPtr data, IntPtr geom1, IntPtr geom2);
@@ -729,6 +733,18 @@ namespace OdeAPI
729 return CreateiHeightfield(space, data, bPlaceable); 733 return CreateiHeightfield(space, data, bPlaceable);
730 } 734 }
731 735
736 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateUbitTerrain"), SuppressUnmanagedCodeSecurity]
737 public static extern IntPtr CreateiUbitTerrain(IntPtr space, IntPtr data, int bPlaceable);
738 public static IntPtr CreateUbitTerrain(IntPtr space, IntPtr data, int bPlaceable)
739 {
740 NTotalGeoms++;
741 return CreateiUbitTerrain(space, data, bPlaceable);
742 }
743
744
745
746
747
732 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeom"), SuppressUnmanagedCodeSecurity] 748 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeom"), SuppressUnmanagedCodeSecurity]
733 public static extern IntPtr CreateiGeom(int classnum); 749 public static extern IntPtr CreateiGeom(int classnum);
734 public static IntPtr CreateGeom(int classnum) 750 public static IntPtr CreateGeom(int classnum)
@@ -964,6 +980,8 @@ namespace OdeAPI
964 dReal width, dReal depth, int widthSamples, int depthSamples, 980 dReal width, dReal depth, int widthSamples, int depthSamples,
965 dReal scale, dReal offset, dReal thickness, int bWrap); 981 dReal scale, dReal offset, dReal thickness, int bWrap);
966 982
983
984
967 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildDouble"), SuppressUnmanagedCodeSecurity] 985 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldDataBuildDouble"), SuppressUnmanagedCodeSecurity]
968 public static extern void GeomHeightfieldDataBuildDouble(IntPtr d, double[] pHeightData, int bCopyHeightData, 986 public static extern void GeomHeightfieldDataBuildDouble(IntPtr d, double[] pHeightData, int bCopyHeightData,
969 dReal width, dReal depth, int widthSamples, int depthSamples, 987 dReal width, dReal depth, int widthSamples, int depthSamples,
@@ -989,6 +1007,33 @@ namespace OdeAPI
989 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldSetHeightfieldData"), SuppressUnmanagedCodeSecurity] 1007 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomHeightfieldSetHeightfieldData"), SuppressUnmanagedCodeSecurity]
990 public static extern void GeomHeightfieldSetHeightfieldData(IntPtr g, IntPtr d); 1008 public static extern void GeomHeightfieldSetHeightfieldData(IntPtr g, IntPtr d);
991 1009
1010
1011 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainDataBuild"), SuppressUnmanagedCodeSecurity]
1012 public static extern void GeomUbitTerrainDataBuild(IntPtr d, float[] pHeightData, int bCopyHeightData,
1013 dReal sampleSize, int widthSamples, int depthSamples,
1014 dReal offset, dReal thickness, int bWrap);
1015
1016 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainDataBuild"), SuppressUnmanagedCodeSecurity]
1017 public static extern void GeomUbitTerrainDataBuild(IntPtr d, IntPtr pHeightData, int bCopyHeightData,
1018 dReal sampleSize, int widthSamples, int depthSamples,
1019 dReal thickness, int bWrap);
1020
1021 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainDataCreate"), SuppressUnmanagedCodeSecurity]
1022 public static extern IntPtr GeomUbitTerrainDataCreate();
1023
1024 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainDataDestroy"), SuppressUnmanagedCodeSecurity]
1025 public static extern void GeomUbitTerrainDataDestroy(IntPtr d);
1026
1027 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainDataSetBounds"), SuppressUnmanagedCodeSecurity]
1028 public static extern void GeomUbitTerrainDataSetBounds(IntPtr d, dReal minHeight, dReal maxHeight);
1029
1030 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainGetHeightfieldData"), SuppressUnmanagedCodeSecurity]
1031 public static extern IntPtr GeomUbitTerrainGetHeightfieldData(IntPtr g);
1032
1033 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomUbitTerrainSetHeightfieldData"), SuppressUnmanagedCodeSecurity]
1034 public static extern void GeomUbitTerrainSetHeightfieldData(IntPtr g, IntPtr d);
1035
1036
992 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomIsEnabled"), SuppressUnmanagedCodeSecurity] 1037 [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomIsEnabled"), SuppressUnmanagedCodeSecurity]
993 public static extern bool GeomIsEnabled(IntPtr geom); 1038 public static extern bool GeomIsEnabled(IntPtr geom);
994 1039
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
index 1a6907d..3e0ccef 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
@@ -156,6 +156,7 @@ namespace OpenSim.Region.Physics.OdePlugin
156 private readonly ILog m_log; 156 private readonly ILog m_log;
157 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>(); 157 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>();
158 158
159 public bool OdeUbitLib = false;
159// private int threadid = 0; 160// private int threadid = 0;
160 private Random fluidRandomizer = new Random(Environment.TickCount); 161 private Random fluidRandomizer = new Random(Environment.TickCount);
161 162
@@ -374,7 +375,14 @@ namespace OpenSim.Region.Physics.OdePlugin
374 mesher = meshmerizer; 375 mesher = meshmerizer;
375 m_config = config; 376 m_config = config;
376 377
377// m_log.WarnFormat("ODE configuration: {0}", d.GetConfiguration("ODE")); 378 string ode_config = d.GetConfiguration("ODE");
379 m_log.WarnFormat("ODE configuration: {0}", ode_config);
380
381 if (ode_config.Contains("ODE_Ubit"))
382 {
383 OdeUbitLib = true;
384 }
385
378 /* 386 /*
379 if (region != null) 387 if (region != null)
380 { 388 {
@@ -527,13 +535,24 @@ namespace OpenSim.Region.Physics.OdePlugin
527 535
528 // sets a global contact for a joint for contactgeom , and base contact description) 536 // sets a global contact for a joint for contactgeom , and base contact description)
529 537
530 private IntPtr CreateContacJoint(ref d.ContactGeom contactGeom, float mu, float bounce,float cfm,float erp) 538 private IntPtr CreateContacJoint(ref d.ContactGeom contactGeom, float mu, float bounce, float cfm, float erpscale, float dscale)
531 { 539 {
532 if (GlobalContactsArray == IntPtr.Zero || m_global_contactcount >= maxContactsbeforedeath) 540 if (GlobalContactsArray == IntPtr.Zero || m_global_contactcount >= maxContactsbeforedeath)
533 return IntPtr.Zero; 541 return IntPtr.Zero;
534 542
543 float erp = contactGeom.depth;
544 erp *= erpscale;
545 if (erp < minERP)
546 erp = minERP;
547 else if (erp > MaxERP)
548 erp = MaxERP;
549
550 float depth = contactGeom.depth * dscale;
551 if (depth > 0.5f)
552 depth = 0.5f;
553
535 d.Contact newcontact = new d.Contact(); 554 d.Contact newcontact = new d.Contact();
536 newcontact.geom.depth = contactGeom.depth; 555 newcontact.geom.depth = depth;
537 newcontact.geom.g1 = contactGeom.g1; 556 newcontact.geom.g1 = contactGeom.g1;
538 newcontact.geom.g2 = contactGeom.g2; 557 newcontact.geom.g2 = contactGeom.g2;
539 newcontact.geom.pos = contactGeom.pos; 558 newcontact.geom.pos = contactGeom.pos;
@@ -692,6 +711,10 @@ namespace OpenSim.Region.Physics.OdePlugin
692 float bounce = 0; 711 float bounce = 0;
693 float cfm = 0.0001f; 712 float cfm = 0.0001f;
694 float erp = 0.1f; 713 float erp = 0.1f;
714 float erpscale = 1.0f;
715 float dscale = 1.0f;
716 bool IgnoreNegSides = false;
717
695 718
696 ContactData contactdata1 = new ContactData(0, 0, false); 719 ContactData contactdata1 = new ContactData(0, 0, false);
697 ContactData contactdata2 = new ContactData(0, 0, false); 720 ContactData contactdata2 = new ContactData(0, 0, false);
@@ -781,10 +804,14 @@ namespace OpenSim.Region.Physics.OdePlugin
781 cfm = p1.Mass; 804 cfm = p1.Mass;
782 if (cfm > p2.Mass) 805 if (cfm > p2.Mass)
783 cfm = p2.Mass; 806 cfm = p2.Mass;
784 cfm = (float)Math.Sqrt(cfm); 807 dscale = 10 / cfm;
785 cfm *= 0.0001f; 808 dscale = (float)Math.Sqrt(dscale);
786 if (cfm > 0.8f) 809 if (dscale > 1.0f)
787 cfm = 0.8f; 810 dscale = 1.0f;
811 erpscale = cfm * 0.01f;
812 cfm = 0.0001f / cfm;
813 if (cfm > 0.01f)
814 cfm = 0.01f;
788 815
789 if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f)) 816 if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f))
790 mu *= frictionMovementMult; 817 mu *= frictionMovementMult;
@@ -801,11 +828,22 @@ namespace OpenSim.Region.Physics.OdePlugin
801 if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f) 828 if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f)
802 mu *= frictionMovementMult; 829 mu *= frictionMovementMult;
803 p1.CollidingGround = true; 830 p1.CollidingGround = true;
831
804 cfm = p1.Mass; 832 cfm = p1.Mass;
805 cfm = (float)Math.Sqrt(cfm); 833 dscale = 10 / cfm;
806 cfm *= 0.0001f; 834 dscale = (float)Math.Sqrt(dscale);
807 if (cfm > 0.8f) 835 if (dscale > 1.0f)
808 cfm = 0.8f; 836 dscale = 1.0f;
837 erpscale = cfm * 0.01f;
838 cfm = 0.0001f / cfm;
839 if (cfm > 0.01f)
840 cfm = 0.01f;
841
842 if (d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass)
843 {
844 if (curContact.side1 > 0)
845 IgnoreNegSides = true;
846 }
809 847
810 } 848 }
811 else if (name == "Water") 849 else if (name == "Water")
@@ -830,11 +868,21 @@ namespace OpenSim.Region.Physics.OdePlugin
830 p2.getContactData(ref contactdata2); 868 p2.getContactData(ref contactdata2);
831 bounce = contactdata2.bounce * TerrainBounce; 869 bounce = contactdata2.bounce * TerrainBounce;
832 mu = (float)Math.Sqrt(contactdata2.mu * TerrainFriction); 870 mu = (float)Math.Sqrt(contactdata2.mu * TerrainFriction);
871
833 cfm = p2.Mass; 872 cfm = p2.Mass;
834 cfm = (float)Math.Sqrt(cfm); 873 dscale = 10 / cfm;
835 cfm *= 0.0001f; 874 dscale = (float)Math.Sqrt(dscale);
836 if (cfm > 0.8f) 875
837 cfm = 0.8f; 876 if (dscale > 1.0f)
877 dscale = 1.0f;
878
879 erpscale = cfm * 0.01f;
880 cfm = 0.0001f / cfm;
881 if (cfm > 0.01f)
882 cfm = 0.01f;
883
884 if (curContact.side1 > 0) // should be 2 ?
885 IgnoreNegSides = true;
838 886
839 if (Math.Abs(p2.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y) > 0.1f) 887 if (Math.Abs(p2.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y) > 0.1f)
840 mu *= frictionMovementMult; 888 mu *= frictionMovementMult;
@@ -862,39 +910,45 @@ namespace OpenSim.Region.Physics.OdePlugin
862 int i = 0; 910 int i = 0;
863 while(true) 911 while(true)
864 { 912 {
865 if (dop1foot && (p1.Position.Z - curContact.pos.Z) > (p1.Size.Z - avCapRadius) * 0.5f)
866 p1.IsColliding = true;
867 if (dop2foot && (p2.Position.Z - curContact.pos.Z) > (p2.Size.Z - avCapRadius) * 0.5f)
868 p2.IsColliding = true;
869 913
914 if (IgnoreNegSides && curContact.side1 < 0)
915 {
916 if (++i >= count)
917 break;
870 918
871 erp = curContact.depth; 919 if (!GetCurContactGeom(i, ref curContact))
872 if (erp < minERP) 920 break;
873 erp = minERP; 921 }
874 else if (erp > MaxERP) 922 else
875 erp = MaxERP;
876 923
877 Joint = CreateContacJoint(ref curContact, mu, bounce,cfm,erp); 924 {
878 d.JointAttach(Joint, b1, b2); 925 if (dop1foot && (p1.Position.Z - curContact.pos.Z) > (p1.Size.Z - avCapRadius) * 0.5f)
926 p1.IsColliding = true;
927 if (dop2foot && (p2.Position.Z - curContact.pos.Z) > (p2.Size.Z - avCapRadius) * 0.5f)
928 p2.IsColliding = true;
879 929
880 if (++m_global_contactcount >= maxContactsbeforedeath) 930 Joint = CreateContacJoint(ref curContact, mu, bounce, cfm, erpscale, dscale);
881 break; 931 d.JointAttach(Joint, b1, b2);
882 932
883 if(++i >= count) 933 if (++m_global_contactcount >= maxContactsbeforedeath)
884 break; 934 break;
885 935
886 if (!GetCurContactGeom(i, ref curContact)) 936 if (++i >= count)
887 break; 937 break;
888 938
889 if (curContact.depth > maxDepthContact.PenetrationDepth) 939 if (!GetCurContactGeom(i, ref curContact))
890 { 940 break;
891 maxDepthContact.Position.X = curContact.pos.X; 941
892 maxDepthContact.Position.Y = curContact.pos.Y; 942 if (curContact.depth > maxDepthContact.PenetrationDepth)
893 maxDepthContact.Position.Z = curContact.pos.Z; 943 {
894 maxDepthContact.SurfaceNormal.X = curContact.normal.X; 944 maxDepthContact.Position.X = curContact.pos.X;
895 maxDepthContact.SurfaceNormal.Y = curContact.normal.Y; 945 maxDepthContact.Position.Y = curContact.pos.Y;
896 maxDepthContact.SurfaceNormal.Z = curContact.normal.Z; 946 maxDepthContact.Position.Z = curContact.pos.Z;
897 maxDepthContact.PenetrationDepth = curContact.depth; 947 maxDepthContact.SurfaceNormal.X = curContact.normal.X;
948 maxDepthContact.SurfaceNormal.Y = curContact.normal.Y;
949 maxDepthContact.SurfaceNormal.Z = curContact.normal.Z;
950 maxDepthContact.PenetrationDepth = curContact.depth;
951 }
898 } 952 }
899 } 953 }
900 954
@@ -1865,13 +1919,12 @@ namespace OpenSim.Region.Physics.OdePlugin
1865 1919
1866 public float GetTerrainHeightAtXY(float x, float y) 1920 public float GetTerrainHeightAtXY(float x, float y)
1867 { 1921 {
1868 // assumes 1m size grid and constante size square regions 1922
1869 // needs to know about sims around in future
1870 // region offset in mega position
1871 1923
1872 int offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize; 1924 int offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1873 int offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize; 1925 int offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1874 1926
1927
1875 IntPtr heightFieldGeom = IntPtr.Zero; 1928 IntPtr heightFieldGeom = IntPtr.Zero;
1876 1929
1877 // get region map 1930 // get region map
@@ -1903,28 +1956,55 @@ namespace OpenSim.Region.Physics.OdePlugin
1903 1956
1904 int regsize = (int)Constants.RegionSize + 3; // map size see setterrain number of samples 1957 int regsize = (int)Constants.RegionSize + 3; // map size see setterrain number of samples
1905 1958
1906 // we still have square fixed size regions 1959 if (OdeUbitLib)
1907 // also flip x and y because of how map is done for ODE fliped axis
1908 // so ix,iy,dx and dy are inter exchanged
1909 if (x < regsize - 1)
1910 {
1911 iy = (int)x;
1912 dy = x - (float)iy;
1913 }
1914 else // out world use external height
1915 { 1960 {
1916 iy = regsize - 1; 1961 if (x < regsize - 1)
1917 dy = 0; 1962 {
1918 } 1963 ix = (int)x;
1919 if (y < regsize - 1) 1964 dx = x - (float)ix;
1920 { 1965 }
1921 ix = (int)y; 1966 else // out world use external height
1922 dx = y - (float)ix; 1967 {
1968 ix = regsize - 1;
1969 dx = 0;
1970 }
1971 if (y < regsize - 1)
1972 {
1973 iy = (int)y;
1974 dy = y - (float)iy;
1975 }
1976 else
1977 {
1978 iy = regsize - 1;
1979 dy = 0;
1980 }
1923 } 1981 }
1982
1924 else 1983 else
1925 { 1984 {
1926 ix = regsize - 1; 1985 // we still have square fixed size regions
1927 dx = 0; 1986 // also flip x and y because of how map is done for ODE fliped axis
1987 // so ix,iy,dx and dy are inter exchanged
1988 if (x < regsize - 1)
1989 {
1990 iy = (int)x;
1991 dy = x - (float)iy;
1992 }
1993 else // out world use external height
1994 {
1995 iy = regsize - 1;
1996 dy = 0;
1997 }
1998 if (y < regsize - 1)
1999 {
2000 ix = (int)y;
2001 dx = y - (float)ix;
2002 }
2003 else
2004 {
2005 ix = regsize - 1;
2006 dx = 0;
2007 }
1928 } 2008 }
1929 2009
1930 float h0; 2010 float h0;
@@ -1951,6 +2031,8 @@ namespace OpenSim.Region.Physics.OdePlugin
1951 2031
1952 return h0 + h1 + h2; 2032 return h0 + h1 + h2;
1953 } 2033 }
2034
2035
1954 public override void SetTerrain(float[] heightMap) 2036 public override void SetTerrain(float[] heightMap)
1955 { 2037 {
1956 if (m_worldOffset != Vector3.Zero && m_parentScene != null) 2038 if (m_worldOffset != Vector3.Zero && m_parentScene != null)
@@ -1972,7 +2054,15 @@ namespace OpenSim.Region.Physics.OdePlugin
1972 } 2054 }
1973 2055
1974 public void SetTerrain(float[] heightMap, Vector3 pOffset) 2056 public void SetTerrain(float[] heightMap, Vector3 pOffset)
1975 { 2057 {
2058 if (OdeUbitLib)
2059 UbitSetTerrain(heightMap, pOffset);
2060 else
2061 OriSetTerrain(heightMap, pOffset);
2062 }
2063
2064 public void OriSetTerrain(float[] heightMap, Vector3 pOffset)
2065 {
1976 // assumes 1m size grid and constante size square regions 2066 // assumes 1m size grid and constante size square regions
1977 // needs to know about sims around in future 2067 // needs to know about sims around in future
1978 2068
@@ -2086,6 +2176,108 @@ namespace OpenSim.Region.Physics.OdePlugin
2086 } 2176 }
2087 } 2177 }
2088 2178
2179 public void UbitSetTerrain(float[] heightMap, Vector3 pOffset)
2180 {
2181 // assumes 1m size grid and constante size square regions
2182 // needs to know about sims around in future
2183
2184 float[] _heightmap;
2185
2186 uint heightmapWidth = Constants.RegionSize + 2;
2187 uint heightmapHeight = Constants.RegionSize + 2;
2188
2189 uint heightmapWidthSamples = heightmapWidth + 1;
2190 uint heightmapHeightSamples = heightmapHeight + 1;
2191
2192 _heightmap = new float[heightmapWidthSamples * heightmapHeightSamples];
2193
2194
2195 uint regionsize = Constants.RegionSize;
2196
2197 float hfmin = float.MaxValue;
2198// float hfmax = float.MinValue;
2199 float val;
2200
2201
2202 uint maxXXYY = regionsize - 1;
2203 // adding one margin all around so things don't fall in edges
2204
2205 uint xx;
2206 uint yy = 0;
2207 uint yt = 0;
2208
2209 for (uint y = 0; y < heightmapHeightSamples; y++)
2210 {
2211 if (y > 1 && y < maxXXYY)
2212 yy += regionsize;
2213 xx = 0;
2214 for (uint x = 0; x < heightmapWidthSamples; x++)
2215 {
2216 if (x > 1 && x < maxXXYY)
2217 xx++;
2218
2219 val = heightMap[yy + xx];
2220 if (val < 0.0f)
2221 val = 0.0f; // no neg terrain as in chode
2222 _heightmap[yt + x] = val;
2223
2224 if (hfmin > val)
2225 hfmin = val;
2226// if (hfmax < val)
2227// hfmax = val;
2228 }
2229 yt += heightmapWidthSamples;
2230 }
2231 lock (OdeLock)
2232 {
2233 IntPtr GroundGeom = IntPtr.Zero;
2234 if (RegionTerrain.TryGetValue(pOffset, out GroundGeom))
2235 {
2236 RegionTerrain.Remove(pOffset);
2237 if (GroundGeom != IntPtr.Zero)
2238 {
2239 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
2240 {
2241 TerrainHeightFieldHeightsHandlers[GroundGeom].Free();
2242 TerrainHeightFieldHeightsHandlers.Remove(GroundGeom);
2243 TerrainHeightFieldHeights.Remove(GroundGeom);
2244 }
2245 d.SpaceRemove(StaticSpace, GroundGeom);
2246 d.GeomDestroy(GroundGeom);
2247 }
2248 }
2249 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
2250
2251 const int wrap = 0;
2252 float thickness = hfmin;
2253 if (thickness < 0)
2254 thickness = 1;
2255
2256 GCHandle _heightmaphandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned);
2257
2258 d.GeomUbitTerrainDataBuild(HeightmapData, _heightmaphandler.AddrOfPinnedObject(), 0, 1.0f,
2259 (int)heightmapWidthSamples, (int)heightmapHeightSamples,
2260 thickness, wrap);
2261
2262// d.GeomUbitTerrainDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
2263 GroundGeom = d.CreateUbitTerrain(StaticSpace, HeightmapData, 1);
2264 if (GroundGeom != IntPtr.Zero)
2265 {
2266 d.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land));
2267 d.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space));
2268
2269 }
2270 geom_name_map[GroundGeom] = "Terrain";
2271
2272 d.GeomSetPosition(GroundGeom, pOffset.X + (float)Constants.RegionSize * 0.5f, pOffset.Y + (float)Constants.RegionSize * 0.5f, 0);
2273 RegionTerrain.Add(pOffset, GroundGeom, GroundGeom);
2274 // TerrainHeightFieldHeights.Add(GroundGeom, ODElandMap);
2275 TerrainHeightFieldHeights.Add(GroundGeom, _heightmap);
2276 TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler);
2277 }
2278 }
2279
2280
2089 public override void DeleteTerrain() 2281 public override void DeleteTerrain()
2090 { 2282 {
2091 } 2283 }