aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/UbitOdePlugin
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin')
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs12
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs80
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs218
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs250
4 files changed, 349 insertions, 211 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs
index 793e281..94cadb2 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs
@@ -136,7 +136,8 @@ namespace OpenSim.Region.Physics.OdePlugin
136 public UUID m_uuid; 136 public UUID m_uuid;
137 public bool bad = false; 137 public bool bad = false;
138 138
139 public ContactData AvatarContactData = new ContactData(10f, 0.3f); 139 float mu;
140 float bounce;
140 141
141 public OdeCharacter(String avName, OdeScene parent_scene, Vector3 pos, Vector3 size, float pid_d, float pid_p, float capsule_radius, float density, float walk_divisor, float rundivisor) 142 public OdeCharacter(String avName, OdeScene parent_scene, Vector3 pos, Vector3 size, float pid_d, float pid_p, float capsule_radius, float density, float walk_divisor, float rundivisor)
142 { 143 {
@@ -168,8 +169,8 @@ namespace OpenSim.Region.Physics.OdePlugin
168 m_density = density; 169 m_density = density;
169 m_mass = 80f; // sure we have a default 170 m_mass = 80f; // sure we have a default
170 171
171 AvatarContactData.mu = parent_scene.AvatarFriction; 172 mu = parent_scene.AvatarFriction;
172 AvatarContactData.bounce = parent_scene.AvatarBounce; 173 bounce = parent_scene.AvatarBounce;
173 174
174 walkDivisor = walk_divisor; 175 walkDivisor = walk_divisor;
175 runDivisor = rundivisor; 176 runDivisor = rundivisor;
@@ -190,9 +191,10 @@ namespace OpenSim.Region.Physics.OdePlugin
190 set { return; } 191 set { return; }
191 } 192 }
192 193
193 public override ContactData ContactData 194 public override void getContactData(ref ContactData cdata)
194 { 195 {
195 get { return AvatarContactData; } 196 cdata.mu = mu;
197 cdata.bounce = bounce;
196 } 198 }
197 199
198 public override bool Building { get; set; } 200 public override bool Building { get; set; }
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs
index c9d0909..d0b4546 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs
@@ -38,7 +38,7 @@
38 * settings use. 38 * settings use.
39 */ 39 */
40 40
41// Ubit 2012 41// Extensive change Ubit 2012
42 42
43using System; 43using System;
44using System.Collections.Generic; 44using System.Collections.Generic;
@@ -119,7 +119,15 @@ namespace OpenSim.Region.Physics.OdePlugin
119 // auxiliar 119 // auxiliar
120 private float m_lmEfect = 0; // current linear motor eficiency 120 private float m_lmEfect = 0; // current linear motor eficiency
121 private float m_amEfect = 0; // current angular motor eficiency 121 private float m_amEfect = 0; // current angular motor eficiency
122 private float m_ffactor = 1.0f;
122 123
124 public float FrictionFactor
125 {
126 get
127 {
128 return m_ffactor;
129 }
130 }
123 131
124 public ODEDynamics(OdePrim rootp) 132 public ODEDynamics(OdePrim rootp)
125 { 133 {
@@ -127,7 +135,6 @@ namespace OpenSim.Region.Physics.OdePlugin
127 _pParentScene = rootPrim._parent_scene; 135 _pParentScene = rootPrim._parent_scene;
128 } 136 }
129 137
130
131 public void DoSetVehicle(VehicleData vd) 138 public void DoSetVehicle(VehicleData vd)
132 { 139 {
133 140
@@ -152,6 +159,7 @@ namespace OpenSim.Region.Physics.OdePlugin
152 m_linearMotorTimescale = vd.m_linearMotorTimescale; 159 m_linearMotorTimescale = vd.m_linearMotorTimescale;
153 if (m_linearMotorTimescale < timestep) m_linearMotorTimescale = timestep; 160 if (m_linearMotorTimescale < timestep) m_linearMotorTimescale = timestep;
154 161
162
155 m_linearMotorOffset = vd.m_linearMotorOffset; 163 m_linearMotorOffset = vd.m_linearMotorOffset;
156 164
157 //Angular properties 165 //Angular properties
@@ -201,6 +209,7 @@ namespace OpenSim.Region.Physics.OdePlugin
201 209
202 m_lmEfect = 0; 210 m_lmEfect = 0;
203 m_amEfect = 0; 211 m_amEfect = 0;
212 m_ffactor = 1.0f;
204 } 213 }
205 214
206 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue) 215 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
@@ -318,6 +327,7 @@ namespace OpenSim.Region.Physics.OdePlugin
318 if (len > 30.0f) 327 if (len > 30.0f)
319 m_linearMotorDirection *= (30.0f / len); 328 m_linearMotorDirection *= (30.0f / len);
320 m_lmEfect = 1.0f; // turn it on 329 m_lmEfect = 1.0f; // turn it on
330 m_ffactor = 0.01f;
321 if (rootPrim.Body != IntPtr.Zero && !d.BodyIsEnabled(rootPrim.Body) 331 if (rootPrim.Body != IntPtr.Zero && !d.BodyIsEnabled(rootPrim.Body)
322 && !rootPrim.m_isSelected && !rootPrim.m_disabled) 332 && !rootPrim.m_isSelected && !rootPrim.m_disabled)
323 d.BodyEnable(rootPrim.Body); 333 d.BodyEnable(rootPrim.Body);
@@ -368,6 +378,7 @@ namespace OpenSim.Region.Physics.OdePlugin
368 if (len > 30.0f) 378 if (len > 30.0f)
369 m_linearMotorDirection *= (30.0f / len); 379 m_linearMotorDirection *= (30.0f / len);
370 m_lmEfect = 1.0f; // turn it on 380 m_lmEfect = 1.0f; // turn it on
381 m_ffactor = 0.01f;
371 if (rootPrim.Body != IntPtr.Zero && !d.BodyIsEnabled(rootPrim.Body) 382 if (rootPrim.Body != IntPtr.Zero && !d.BodyIsEnabled(rootPrim.Body)
372 && !rootPrim.m_isSelected && !rootPrim.m_disabled) 383 && !rootPrim.m_isSelected && !rootPrim.m_disabled)
373 d.BodyEnable(rootPrim.Body); 384 d.BodyEnable(rootPrim.Body);
@@ -414,6 +425,7 @@ namespace OpenSim.Region.Physics.OdePlugin
414 float invtimestep = _pParentScene.ODE_STEPSIZE; 425 float invtimestep = _pParentScene.ODE_STEPSIZE;
415 m_lmEfect = 0; 426 m_lmEfect = 0;
416 m_amEfect = 0; 427 m_amEfect = 0;
428 m_ffactor = 1f;
417 429
418 m_linearMotorDirection = Vector3.Zero; 430 m_linearMotorDirection = Vector3.Zero;
419 m_angularMotorDirection = Vector3.Zero; 431 m_angularMotorDirection = Vector3.Zero;
@@ -591,6 +603,7 @@ namespace OpenSim.Region.Physics.OdePlugin
591 { 603 {
592 m_lmEfect = 0; 604 m_lmEfect = 0;
593 m_amEfect = 0; 605 m_amEfect = 0;
606 m_ffactor = 1f;
594 } 607 }
595 608
596 public static Vector3 Xrot(Quaternion rot) 609 public static Vector3 Xrot(Quaternion rot)
@@ -614,6 +627,7 @@ namespace OpenSim.Region.Physics.OdePlugin
614 return vec; 627 return vec;
615 } 628 }
616 629
630 private const float pi = (float)Math.PI;
617 private const float halfpi = 0.5f * (float)Math.PI; 631 private const float halfpi = 0.5f * (float)Math.PI;
618 632
619 public static Vector3 ubitRot2Euler(Quaternion rot) 633 public static Vector3 ubitRot2Euler(Quaternion rot)
@@ -740,9 +754,14 @@ namespace OpenSim.Region.Physics.OdePlugin
740 force.Z += tmpV.Z; 754 force.Z += tmpV.Z;
741 } 755 }
742 m_lmEfect *= (1.0f - 1.0f / m_linearMotorDecayTimescale); 756 m_lmEfect *= (1.0f - 1.0f / m_linearMotorDecayTimescale);
757
758 m_ffactor = 0.01f + 1e-4f * curVel.LengthSquared();
743 } 759 }
744 else 760 else
761 {
745 m_lmEfect = 0; 762 m_lmEfect = 0;
763 m_ffactor = 1f;
764 }
746 765
747 // friction 766 // friction
748 if (curLocalVel.X != 0 || curLocalVel.Y != 0 || curLocalVel.Z != 0) 767 if (curLocalVel.X != 0 || curLocalVel.Y != 0 || curLocalVel.Z != 0)
@@ -884,35 +903,64 @@ namespace OpenSim.Region.Physics.OdePlugin
884 float ftmp = 1.0f / m_verticalAttractionTimescale / m_verticalAttractionTimescale / _pParentScene.ODE_STEPSIZE; 903 float ftmp = 1.0f / m_verticalAttractionTimescale / m_verticalAttractionTimescale / _pParentScene.ODE_STEPSIZE;
885 float ftmp2 = m_verticalAttractionEfficiency / _pParentScene.ODE_STEPSIZE; 904 float ftmp2 = m_verticalAttractionEfficiency / _pParentScene.ODE_STEPSIZE;
886 905
887 if (Math.Abs(roll) > 0.01) // roll 906 if (roll > halfpi)
907 roll = pi - roll;
908 else if (roll < -halfpi)
909 roll = -pi - roll;
910
911 float effroll = pitch / halfpi;
912 effroll *= effroll;
913 effroll = 1 - effroll;
914 effroll *= roll;
915
916 if (Math.Abs(effroll) > 0.01) // roll
888 { 917 {
889 torque.X -= -roll * ftmp + curLocalAngVel.X * ftmp2; 918 torque.X -= -effroll * ftmp + curLocalAngVel.X * ftmp2;
890 } 919 }
891 920
892 if (Math.Abs(pitch) > 0.01 && ((m_flags & VehicleFlag.LIMIT_ROLL_ONLY) == 0)) // pitch 921 if ((m_flags & VehicleFlag.LIMIT_ROLL_ONLY) == 0)
893 { 922 {
894 torque.Y -= -pitch * ftmp + curLocalAngVel.Y * ftmp2; 923 float effpitch = roll / halfpi;
924 effpitch *= effpitch;
925 effpitch = 1 - effpitch;
926 effpitch *= pitch;
927
928 if (Math.Abs(effpitch) > 0.01) // pitch
929 {
930 torque.Y -= -effpitch * ftmp + curLocalAngVel.Y * ftmp2;
931 }
895 } 932 }
896 933
897 if (m_bankingEfficiency != 0 && Math.Abs(roll) > 0.01) 934 if (m_bankingEfficiency != 0 && Math.Abs(effroll) > 0.01)
898 { 935 {
899 float broll = roll * m_bankingEfficiency; ; 936
937 float broll = effroll;
938/*
939 if (broll > halfpi)
940 broll = pi - broll;
941 else if (broll < -halfpi)
942 broll = -pi - broll;
943*/
944 broll *= m_bankingEfficiency;
900 if (m_bankingMix != 0) 945 if (m_bankingMix != 0)
901 { 946 {
902 float vfact = Math.Abs(curLocalVel.X) / 10.0f; 947 float vfact = Math.Abs(curLocalVel.X) / 10.0f;
903 if (vfact > 1.0f) vfact = 1.0f; 948 if (vfact > 1.0f) vfact = 1.0f;
949
904 if (curLocalVel.X >= 0) 950 if (curLocalVel.X >= 0)
905 broll *= ((1 - m_bankingMix) + vfact); 951 broll *= (1 + (vfact - 1) * m_bankingMix);
906 else 952 else
907 broll *= -((1 - m_bankingMix) + vfact); 953 broll *= -(1 + (vfact - 1) * m_bankingMix);
908 } 954 }
909 broll = (broll - curLocalAngVel.Z) / m_bankingTimescale;
910 // torque.Z += broll;
911
912 // make z rot be in world Z not local as seems to be in sl 955 // make z rot be in world Z not local as seems to be in sl
913 tmpV.X = 0; 956
914 tmpV.Y = 0; 957 broll = broll / m_bankingTimescale;
915 tmpV.Z = broll; 958
959 ftmp = -Math.Abs(m_bankingEfficiency) / m_bankingTimescale;
960
961 tmpV.X = ftmp * curAngVel.X;
962 tmpV.Y = ftmp * curAngVel.Y;
963 tmpV.Z = broll + ftmp * curAngVel.Z;
916 tmpV *= irotq; 964 tmpV *= irotq;
917 965
918 torque.X += tmpV.X; 966 torque.X += tmpV.X;
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
index 0ccdbc0..db07565 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
@@ -155,6 +155,8 @@ namespace OpenSim.Region.Physics.OdePlugin
155 public float m_collisionscore; 155 public float m_collisionscore;
156 int m_colliderfilter = 0; 156 int m_colliderfilter = 0;
157 157
158 public IntPtr collide_geom; // for objects: geom if single prim space it linkset
159
158 private float m_density = 10.000006836f; // Aluminum g/cm3; 160 private float m_density = 10.000006836f; // Aluminum g/cm3;
159 161
160 public bool _zeroFlag; 162 public bool _zeroFlag;
@@ -185,7 +187,8 @@ namespace OpenSim.Region.Physics.OdePlugin
185 public ODEDynamics m_vehicle; 187 public ODEDynamics m_vehicle;
186 188
187 internal int m_material = (int)Material.Wood; 189 internal int m_material = (int)Material.Wood;
188 protected ContactData primContactData = new ContactData { mu = 0f, bounce = 0.1f }; 190 private float mu;
191 private float bounce;
189 192
190 /// <summary> 193 /// <summary>
191 /// Is this prim subject to physics? Even if not, it's still solid for collision purposes. 194 /// Is this prim subject to physics? Even if not, it's still solid for collision purposes.
@@ -216,13 +219,23 @@ namespace OpenSim.Region.Physics.OdePlugin
216 } 219 }
217 } 220 }
218 221
219 public override ContactData ContactData 222 public override void getContactData(ref ContactData cdata)
220 { 223 {
221 get 224 cdata.mu = mu;
225 cdata.bounce = bounce;
226
227 if (m_isphysical)
222 { 228 {
223 return primContactData; 229 ODEDynamics veh;
230 if (_parent != null)
231 veh = ((OdePrim)_parent).m_vehicle;
232 else
233 veh = m_vehicle;
234
235 if (veh != null && veh.Type != Vehicle.TYPE_NONE)
236 cdata.mu *= veh.FrictionFactor;
224 } 237 }
225 } 238 }
226 239
227 public override int PhysicsActorType 240 public override int PhysicsActorType
228 { 241 {
@@ -453,8 +466,6 @@ namespace OpenSim.Region.Physics.OdePlugin
453 { 466 {
454 get 467 get
455 { 468 {
456 // Averate previous velocity with the new one so
457 // client object interpolation works a 'little' better
458 if (_zeroFlag) 469 if (_zeroFlag)
459 return Vector3.Zero; 470 return Vector3.Zero;
460 return _velocity; 471 return _velocity;
@@ -733,8 +744,8 @@ namespace OpenSim.Region.Physics.OdePlugin
733 public override void SetMaterial(int pMaterial) 744 public override void SetMaterial(int pMaterial)
734 { 745 {
735 m_material = pMaterial; 746 m_material = pMaterial;
736 primContactData.mu = _parent_scene.m_materialContactsData[pMaterial].mu; 747 mu = _parent_scene.m_materialContactsData[pMaterial].mu;
737 primContactData.bounce = _parent_scene.m_materialContactsData[pMaterial].bounce; 748 bounce = _parent_scene.m_materialContactsData[pMaterial].bounce;
738 } 749 }
739 750
740 public void setPrimForRemoval() 751 public void setPrimForRemoval()
@@ -833,6 +844,7 @@ namespace OpenSim.Region.Physics.OdePlugin
833 body_autodisable_frames = parent_scene.bodyFramesAutoDisable; 844 body_autodisable_frames = parent_scene.bodyFramesAutoDisable;
834 845
835 prim_geom = IntPtr.Zero; 846 prim_geom = IntPtr.Zero;
847 collide_geom = IntPtr.Zero;
836 Body = IntPtr.Zero; 848 Body = IntPtr.Zero;
837 849
838 if (!size.IsFinite()) 850 if (!size.IsFinite())
@@ -886,8 +898,8 @@ namespace OpenSim.Region.Physics.OdePlugin
886 m_isSelected = false; 898 m_isSelected = false;
887 m_delaySelect = false; 899 m_delaySelect = false;
888 900
889 primContactData.mu = parent_scene.m_materialContactsData[(int)Material.Wood].mu; 901 mu = parent_scene.m_materialContactsData[(int)Material.Wood].mu;
890 primContactData.bounce = parent_scene.m_materialContactsData[(int)Material.Wood].bounce; 902 bounce = parent_scene.m_materialContactsData[(int)Material.Wood].bounce;
891 903
892 CalcPrimBodyData(); 904 CalcPrimBodyData();
893 905
@@ -1367,7 +1379,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1367 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 1379 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1368 m_collisionscore = 0; 1380 m_collisionscore = 0;
1369 1381
1370 if (m_targetSpace != _parent_scene.ActiveSpace) 1382// if (m_targetSpace != _parent_scene.ActiveSpace)
1371 { 1383 {
1372 if (m_targetSpace != IntPtr.Zero) 1384 if (m_targetSpace != IntPtr.Zero)
1373 { 1385 {
@@ -1376,9 +1388,26 @@ namespace OpenSim.Region.Physics.OdePlugin
1376 d.SpaceRemove(m_targetSpace, prim_geom); 1388 d.SpaceRemove(m_targetSpace, prim_geom);
1377 } 1389 }
1378 1390
1391// m_targetSpace = _parent_scene.ActiveSpace;
1392// d.SpaceAdd(m_targetSpace, prim_geom);
1393 }
1394
1395
1396 if (childrenPrim.Count == 0)
1397 {
1398 collide_geom = prim_geom;
1379 m_targetSpace = _parent_scene.ActiveSpace; 1399 m_targetSpace = _parent_scene.ActiveSpace;
1380 d.SpaceAdd(m_targetSpace, prim_geom); 1400 d.SpaceAdd(m_targetSpace, prim_geom);
1381 } 1401 }
1402 else
1403 {
1404 m_targetSpace = d.HashSpaceCreate(_parent_scene.ActiveSpace);
1405 d.HashSpaceSetLevels(m_targetSpace, -2, 8);
1406 d.SpaceSetSublevel(m_targetSpace, 3);
1407 d.SpaceSetCleanup(m_targetSpace, false);
1408 d.SpaceAdd(m_targetSpace, prim_geom);
1409 collide_geom = m_targetSpace;
1410 }
1382 1411
1383 lock (childrenPrim) 1412 lock (childrenPrim)
1384 { 1413 {
@@ -1396,15 +1425,15 @@ namespace OpenSim.Region.Physics.OdePlugin
1396 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); 1425 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
1397 prm.m_collisionscore = 0; 1426 prm.m_collisionscore = 0;
1398 1427
1399 if (prm.m_targetSpace != _parent_scene.ActiveSpace) 1428 if (prm.m_targetSpace != m_targetSpace)
1400 { 1429 {
1401 if (prm.m_targetSpace != IntPtr.Zero) 1430 if (prm.m_targetSpace != IntPtr.Zero)
1402 { 1431 {
1403 _parent_scene.waitForSpaceUnlock(m_targetSpace); 1432 _parent_scene.waitForSpaceUnlock(prm.m_targetSpace);
1404 if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom)) 1433 if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom))
1405 d.SpaceRemove(prm.m_targetSpace, prm.prim_geom); 1434 d.SpaceRemove(prm.m_targetSpace, prm.prim_geom);
1406 } 1435 }
1407 prm.m_targetSpace = _parent_scene.ActiveSpace; 1436 prm.m_targetSpace = m_targetSpace;
1408 d.SpaceAdd(m_targetSpace, prm.prim_geom); 1437 d.SpaceAdd(m_targetSpace, prm.prim_geom);
1409 } 1438 }
1410 1439
@@ -1427,8 +1456,14 @@ namespace OpenSim.Region.Physics.OdePlugin
1427 d.GeomDisable(prim_geom); 1456 d.GeomDisable(prim_geom);
1428 d.BodyDisable(Body); 1457 d.BodyDisable(Body);
1429 } 1458 }
1459 else
1460 {
1461 d.BodySetAngularVel(Body, m_rotationalVelocity.X, m_rotationalVelocity.Y, m_rotationalVelocity.Z);
1462 d.BodySetLinearVel(Body, _velocity.X, _velocity.Y, _velocity.Z);
1463 }
1430 1464
1431 _parent_scene.addActivePrim(this); 1465 _parent_scene.addActivePrim(this);
1466 _parent_scene.addActiveGroups(this);
1432 } 1467 }
1433 1468
1434 private void DestroyBody() 1469 private void DestroyBody()
@@ -1473,6 +1508,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1473 d.JointDestroy(Amotor); 1508 d.JointDestroy(Amotor);
1474 Amotor = IntPtr.Zero; 1509 Amotor = IntPtr.Zero;
1475 } 1510 }
1511 _parent_scene.remActiveGroup(this);
1476 d.BodyDestroy(Body); 1512 d.BodyDestroy(Body);
1477 } 1513 }
1478 Body = IntPtr.Zero; 1514 Body = IntPtr.Zero;
@@ -2390,8 +2426,8 @@ namespace OpenSim.Region.Physics.OdePlugin
2390 else 2426 else
2391 */ 2427 */
2392 DestroyBody(); 2428 DestroyBody();
2393 Stop();
2394 } 2429 }
2430 Stop();
2395 } 2431 }
2396 } 2432 }
2397 2433
@@ -2576,7 +2612,8 @@ namespace OpenSim.Region.Physics.OdePlugin
2576 if ((bool)newbuilding) 2612 if ((bool)newbuilding)
2577 { 2613 {
2578 m_building = true; 2614 m_building = true;
2579 DestroyBody(); 2615 if (!childPrim)
2616 DestroyBody();
2580 } 2617 }
2581 else 2618 else
2582 { 2619 {
@@ -2648,12 +2685,95 @@ namespace OpenSim.Region.Physics.OdePlugin
2648 public void Move() 2685 public void Move()
2649 { 2686 {
2650 if (!childPrim && m_isphysical && Body != IntPtr.Zero && 2687 if (!childPrim && m_isphysical && Body != IntPtr.Zero &&
2651 !m_disabled && !m_isSelected && d.BodyIsEnabled(Body) && !m_building) // KF: Only move root prims. 2688 !m_disabled && !m_isSelected && d.BodyIsEnabled(Body) && !m_building && !m_outbounds)
2689 // !m_disabled && !m_isSelected && !m_building && !m_outbounds)
2652 { 2690 {
2653 // if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body); // KF add 161009 2691// if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body); // KF add 161009
2654 2692
2655 float timestep = _parent_scene.ODE_STEPSIZE; 2693 float timestep = _parent_scene.ODE_STEPSIZE;
2656 2694
2695 // check outside region
2696 d.Vector3 lpos;
2697 d.GeomCopyPosition(prim_geom, out lpos); // root position that is seem by rest of simulator
2698
2699 if (lpos.Z < -100 || lpos.Z > 100000f)
2700 {
2701 m_outbounds = true;
2702
2703 lpos.Z = Util.Clip(lpos.Z, -100f, 100000f);
2704 _acceleration.X = 0;
2705 _acceleration.Y = 0;
2706 _acceleration.Z = 0;
2707
2708 _velocity.X = 0;
2709 _velocity.Y = 0;
2710 _velocity.Z = 0;
2711 m_rotationalVelocity.X = 0;
2712 m_rotationalVelocity.Y = 0;
2713 m_rotationalVelocity.Z = 0;
2714
2715 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
2716 d.BodySetAngularVel(Body, 0, 0, 0); // stop it
2717 d.BodySetPosition(Body, lpos.X, lpos.Y, lpos.Z); // put it somewhere
2718 m_lastposition = _position;
2719 m_lastorientation = _orientation;
2720
2721 base.RequestPhysicsterseUpdate();
2722
2723 m_throttleUpdates = false;
2724 throttleCounter = 0;
2725 _zeroFlag = true;
2726
2727 disableBodySoft(); // disable it and colisions
2728 base.RaiseOutOfBounds(_position);
2729 return;
2730 }
2731
2732 if (lpos.X < 0f)
2733 {
2734 _position.X = Util.Clip(lpos.X, -2f, -0.1f);
2735 m_outbounds = true;
2736 }
2737 else if(lpos.X > _parent_scene.WorldExtents.X)
2738 {
2739 _position.X = Util.Clip(lpos.X, _parent_scene.WorldExtents.X + 0.1f, _parent_scene.WorldExtents.X + 2f);
2740 m_outbounds = true;
2741 }
2742 if (lpos.Y < 0f)
2743 {
2744 _position.Y = Util.Clip(lpos.Y, -2f, -0.1f);
2745 m_outbounds = true;
2746 }
2747 else if(lpos.Y > _parent_scene.WorldExtents.Y)
2748 {
2749 _position.Y = Util.Clip(lpos.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f);
2750 m_outbounds = true;
2751 }
2752
2753 if(m_outbounds)
2754 {
2755 m_lastposition = _position;
2756 m_lastorientation = _orientation;
2757
2758 d.Vector3 dtmp = d.BodyGetAngularVel(Body);
2759 m_rotationalVelocity.X = dtmp.X;
2760 m_rotationalVelocity.Y = dtmp.Y;
2761 m_rotationalVelocity.Z = dtmp.Z;
2762
2763 dtmp = d.BodyGetLinearVel(Body);
2764 _velocity.X = dtmp.X;
2765 _velocity.Y = dtmp.Y;
2766 _velocity.Z = dtmp.Z;
2767
2768 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
2769 d.BodySetAngularVel(Body, 0, 0, 0);
2770 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2771 disableBodySoft(); // stop collisions
2772 base.RequestPhysicsterseUpdate();
2773 return;
2774 }
2775
2776
2657 float fx = 0; 2777 float fx = 0;
2658 float fy = 0; 2778 float fy = 0;
2659 float fz = 0; 2779 float fz = 0;
@@ -2862,7 +2982,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2862 public void UpdatePositionAndVelocity(float simulatedtime) 2982 public void UpdatePositionAndVelocity(float simulatedtime)
2863 { 2983 {
2864 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! 2984 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
2865 if (_parent == null && !m_disabled && !m_building) 2985 if (_parent == null && !m_disabled && !m_building && !m_outbounds)
2866 { 2986 {
2867 if (Body != IntPtr.Zero) 2987 if (Body != IntPtr.Zero)
2868 { 2988 {
@@ -2872,64 +2992,6 @@ namespace OpenSim.Region.Physics.OdePlugin
2872 d.Vector3 lpos; 2992 d.Vector3 lpos;
2873 d.GeomCopyPosition(prim_geom, out lpos); // root position that is seem by rest of simulator 2993 d.GeomCopyPosition(prim_geom, out lpos); // root position that is seem by rest of simulator
2874 2994
2875 // we need to use root position since that's all the rest of scene uses
2876 if (lpos.X < 0f || lpos.X > _parent_scene.WorldExtents.X
2877 || lpos.Y < 0f || lpos.Y > _parent_scene.WorldExtents.Y
2878 )
2879 {
2880 // we are outside current region
2881 // we can't let it keeping moving and having colisions
2882 // since it can be stucked between something like terrain and edge
2883 // so lets stop and disable it until something else kicks it
2884
2885 _position.X = Util.Clip(lpos.X, -0.2f, _parent_scene.WorldExtents.X + 0.2f);
2886 _position.Y = Util.Clip(lpos.Y, -0.2f, _parent_scene.WorldExtents.Y + 0.2f);
2887 _position.Z = Util.Clip(lpos.Z, -100f, 50000f);
2888
2889 m_lastposition = _position;
2890// m_lastorientation = _orientation;
2891
2892 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
2893// d.BodySetAngularVel(Body, 0, 0, 0);
2894 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2895 disableBodySoft(); // stop collisions
2896 m_outbounds = true;
2897 base.RequestPhysicsterseUpdate();
2898 return;
2899 }
2900
2901 if (lpos.Z < -100 || lpos.Z > 100000f)
2902 {
2903 lpos.Z = Util.Clip(lpos.Z, -100f, 50000f);
2904
2905 _acceleration.X = 0;
2906 _acceleration.Y = 0;
2907 _acceleration.Z = 0;
2908
2909 _velocity.X = 0;
2910 _velocity.Y = 0;
2911 _velocity.Z = 0;
2912 m_rotationalVelocity.X = 0;
2913 m_rotationalVelocity.Y = 0;
2914 m_rotationalVelocity.Z = 0;
2915
2916 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
2917 d.BodySetAngularVel(Body, 0, 0, 0); // stop it
2918 d.BodySetPosition(Body, lpos.X, lpos.Y, lpos.Z); // put it somewhere
2919 m_lastposition = _position;
2920 m_lastorientation = _orientation;
2921
2922 base.RequestPhysicsterseUpdate();
2923
2924 m_throttleUpdates = false;
2925 throttleCounter = 0;
2926 _zeroFlag = true;
2927
2928 disableBodySoft(); // disable it and colisions
2929 base.RaiseOutOfBounds(_position);
2930
2931 return;
2932 }
2933 2995
2934 d.Quaternion ori; 2996 d.Quaternion ori;
2935 d.GeomCopyQuaternion(prim_geom, out ori); 2997 d.GeomCopyQuaternion(prim_geom, out ori);
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
index 6e4c373..884a5a7 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
@@ -155,7 +155,7 @@ namespace OpenSim.Region.Physics.OdePlugin
155 private readonly ILog m_log; 155 private readonly ILog m_log;
156 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>(); 156 // private Dictionary<string, sCollisionData> m_storedCollisions = new Dictionary<string, sCollisionData>();
157 157
158 private int threadid = 0; 158// private int threadid = 0;
159 private Random fluidRandomizer = new Random(Environment.TickCount); 159 private Random fluidRandomizer = new Random(Environment.TickCount);
160 160
161 const d.ContactFlags comumContactFlags = d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM |d.ContactFlags.Approx1 | d.ContactFlags.Bounce; 161 const d.ContactFlags comumContactFlags = d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM |d.ContactFlags.Approx1 | d.ContactFlags.Bounce;
@@ -163,12 +163,10 @@ namespace OpenSim.Region.Physics.OdePlugin
163 const float comumSoftContactERP = 0.1f; 163 const float comumSoftContactERP = 0.1f;
164 const float comumContactCFM = 0.0001f; 164 const float comumContactCFM = 0.0001f;
165 165
166 float frictionScale = 1.0f;
167
168 float frictionMovementMult = 0.3f; 166 float frictionMovementMult = 0.3f;
169 167
170 float TerrainBounce = 0.1f; 168 float TerrainBounce = 0.1f;
171 float TerrainFriction = 0.1f; 169 float TerrainFriction = 0.3f;
172 170
173 public float AvatarBounce = 0.3f; 171 public float AvatarBounce = 0.3f;
174 public float AvatarFriction = 0;// 0.9f * 0.5f; 172 public float AvatarFriction = 0;// 0.9f * 0.5f;
@@ -189,8 +187,8 @@ namespace OpenSim.Region.Physics.OdePlugin
189 187
190 internal IntPtr WaterGeom; 188 internal IntPtr WaterGeom;
191 189
192 public float avPIDD = 3200f; // make it visible 190 public float avPIDD = 2200f; // make it visible
193 public float avPIDP = 1400f; // make it visible 191 public float avPIDP = 900f; // make it visible
194 private float avCapRadius = 0.37f; 192 private float avCapRadius = 0.37f;
195 private float avDensity = 3f; 193 private float avDensity = 3f;
196 private float avMovementDivisorWalk = 1.3f; 194 private float avMovementDivisorWalk = 1.3f;
@@ -202,7 +200,7 @@ namespace OpenSim.Region.Physics.OdePlugin
202 public bool forceSimplePrimMeshing = false; 200 public bool forceSimplePrimMeshing = false;
203 201
204 public float meshSculptLOD = 32; 202 public float meshSculptLOD = 32;
205 public float MeshSculptphysicalLOD = 16; 203 public float MeshSculptphysicalLOD = 32;
206 204
207 public float geomDefaultDensity = 10.000006836f; 205 public float geomDefaultDensity = 10.000006836f;
208 206
@@ -212,18 +210,18 @@ namespace OpenSim.Region.Physics.OdePlugin
212 public float bodyPIDD = 35f; 210 public float bodyPIDD = 35f;
213 public float bodyPIDG = 25; 211 public float bodyPIDG = 25;
214 212
215 public int geomCrossingFailuresBeforeOutofbounds = 6; 213// public int geomCrossingFailuresBeforeOutofbounds = 6;
216 214
217 public int bodyFramesAutoDisable = 20; 215 public int bodyFramesAutoDisable = 20;
218 216
219 private float[] _watermap; 217 private float[] _watermap;
220 private bool m_filterCollisions = true;
221 218
222 private d.NearCallback nearCallback; 219 private d.NearCallback nearCallback;
223 220
224 private readonly HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>(); 221 private readonly HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>();
225 private readonly HashSet<OdePrim> _prims = new HashSet<OdePrim>(); 222 private readonly HashSet<OdePrim> _prims = new HashSet<OdePrim>();
226 private readonly HashSet<OdePrim> _activeprims = new HashSet<OdePrim>(); 223 private readonly HashSet<OdePrim> _activeprims = new HashSet<OdePrim>();
224 private readonly HashSet<OdePrim> _activegroups = new HashSet<OdePrim>();
227 225
228 public OpenSim.Framework.LocklessQueue<ODEchangeitem> ChangesQueue = new OpenSim.Framework.LocklessQueue<ODEchangeitem>(); 226 public OpenSim.Framework.LocklessQueue<ODEchangeitem> ChangesQueue = new OpenSim.Framework.LocklessQueue<ODEchangeitem>();
229 227
@@ -387,9 +385,6 @@ namespace OpenSim.Region.Physics.OdePlugin
387 385
388 // Defaults 386 // Defaults
389 387
390 avPIDD = 2200.0f;
391 avPIDP = 900.0f;
392
393 int contactsPerCollision = 80; 388 int contactsPerCollision = 80;
394 389
395 if (m_config != null) 390 if (m_config != null)
@@ -397,90 +392,86 @@ namespace OpenSim.Region.Physics.OdePlugin
397 IConfig physicsconfig = m_config.Configs["ODEPhysicsSettings"]; 392 IConfig physicsconfig = m_config.Configs["ODEPhysicsSettings"];
398 if (physicsconfig != null) 393 if (physicsconfig != null)
399 { 394 {
400 gravityx = physicsconfig.GetFloat("world_gravityx", 0f); 395 gravityx = physicsconfig.GetFloat("world_gravityx", gravityx);
401 gravityy = physicsconfig.GetFloat("world_gravityy", 0f); 396 gravityy = physicsconfig.GetFloat("world_gravityy", gravityy);
402 gravityz = physicsconfig.GetFloat("world_gravityz", -9.8f); 397 gravityz = physicsconfig.GetFloat("world_gravityz", gravityz);
403 398
404 metersInSpace = physicsconfig.GetFloat("meters_in_small_space", 29.9f); 399 metersInSpace = physicsconfig.GetFloat("meters_in_small_space", metersInSpace);
405 400
406 contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", contactsurfacelayer); 401 contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", contactsurfacelayer);
407 402
408 ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", 0.020f); 403 ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE);
409 m_physicsiterations = physicsconfig.GetInt("world_internal_steps_without_collisions", 10); 404 m_physicsiterations = physicsconfig.GetInt("world_internal_steps_without_collisions", m_physicsiterations);
410 405
411 avDensity = physicsconfig.GetFloat("av_density", avDensity); 406 avDensity = physicsconfig.GetFloat("av_density", avDensity);
412 avMovementDivisorWalk = physicsconfig.GetFloat("av_movement_divisor_walk", 1.3f); 407 avMovementDivisorWalk = physicsconfig.GetFloat("av_movement_divisor_walk", avMovementDivisorWalk);
413 avMovementDivisorRun = physicsconfig.GetFloat("av_movement_divisor_run", 0.8f); 408 avMovementDivisorRun = physicsconfig.GetFloat("av_movement_divisor_run", avMovementDivisorRun);
414 avCapRadius = physicsconfig.GetFloat("av_capsule_radius", 0.37f); 409 avCapRadius = physicsconfig.GetFloat("av_capsule_radius", avCapRadius);
415 410
416 contactsPerCollision = physicsconfig.GetInt("contacts_per_collision", 80); 411 contactsPerCollision = physicsconfig.GetInt("contacts_per_collision", contactsPerCollision);
417 412
418 geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 3); 413 geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 3);
419 geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15); 414 geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15);
420 geomCrossingFailuresBeforeOutofbounds = physicsconfig.GetInt("geom_crossing_failures_before_outofbounds", 5); 415// geomCrossingFailuresBeforeOutofbounds = physicsconfig.GetInt("geom_crossing_failures_before_outofbounds", 5);
421 416
422 geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", 10.000006836f); 417 geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", geomDefaultDensity);
423 bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", 20); 418 bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", bodyFramesAutoDisable);
424 419
425 bodyPIDD = physicsconfig.GetFloat("body_pid_derivative", 35f); 420 bodyPIDD = physicsconfig.GetFloat("body_pid_derivative", bodyPIDD);
426 bodyPIDG = physicsconfig.GetFloat("body_pid_gain", 25f); 421 bodyPIDG = physicsconfig.GetFloat("body_pid_gain", bodyPIDG);
427 422
428 forceSimplePrimMeshing = physicsconfig.GetBoolean("force_simple_prim_meshing", forceSimplePrimMeshing); 423 forceSimplePrimMeshing = physicsconfig.GetBoolean("force_simple_prim_meshing", forceSimplePrimMeshing);
429 meshSculptedPrim = physicsconfig.GetBoolean("mesh_sculpted_prim", true); 424 meshSculptedPrim = physicsconfig.GetBoolean("mesh_sculpted_prim", meshSculptedPrim);
430 meshSculptLOD = physicsconfig.GetFloat("mesh_lod", 32f); 425 meshSculptLOD = physicsconfig.GetFloat("mesh_lod", meshSculptLOD);
431 MeshSculptphysicalLOD = physicsconfig.GetFloat("mesh_physical_lod", 16f); 426 MeshSculptphysicalLOD = physicsconfig.GetFloat("mesh_physical_lod", MeshSculptphysicalLOD);
432 m_filterCollisions = physicsconfig.GetBoolean("filter_collisions", false);
433 427
434 if (Environment.OSVersion.Platform == PlatformID.Unix) 428 if (Environment.OSVersion.Platform == PlatformID.Unix)
435 { 429 {
436 avPIDD = physicsconfig.GetFloat("av_pid_derivative_linux", 2200.0f); 430 avPIDD = physicsconfig.GetFloat("av_pid_derivative_linux", avPIDD);
437 avPIDP = physicsconfig.GetFloat("av_pid_proportional_linux", 900.0f); 431 avPIDP = physicsconfig.GetFloat("av_pid_proportional_linux", avPIDP);
438 } 432 }
439 else 433 else
440 { 434 {
441 avPIDD = physicsconfig.GetFloat("av_pid_derivative_win", 2200.0f); 435 avPIDD = physicsconfig.GetFloat("av_pid_derivative_win", avPIDD);
442 avPIDP = physicsconfig.GetFloat("av_pid_proportional_win", 900.0f); 436 avPIDP = physicsconfig.GetFloat("av_pid_proportional_win", avPIDP);
443 } 437 }
444 438
445 physics_logging = physicsconfig.GetBoolean("physics_logging", false); 439 physics_logging = physicsconfig.GetBoolean("physics_logging", false);
446 physics_logging_interval = physicsconfig.GetInt("physics_logging_interval", 0); 440 physics_logging_interval = physicsconfig.GetInt("physics_logging_interval", 0);
447 physics_logging_append_existing_logfile = physicsconfig.GetBoolean("physics_logging_append_existing_logfile", false); 441 physics_logging_append_existing_logfile = physicsconfig.GetBoolean("physics_logging_append_existing_logfile", false);
448 442
449 minimumGroundFlightOffset = physicsconfig.GetFloat("minimum_ground_flight_offset", 3f); 443 minimumGroundFlightOffset = physicsconfig.GetFloat("minimum_ground_flight_offset", minimumGroundFlightOffset);
450 maximumMassObject = physicsconfig.GetFloat("maximum_mass_object", 10000.01f); 444 maximumMassObject = physicsconfig.GetFloat("maximum_mass_object", maximumMassObject);
451 } 445 }
452 } 446 }
453 447
454 ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf); 448 ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf);
455 GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf); 449 GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf);
456 450
457 m_materialContactsData[(int)Material.Stone].mu = frictionScale * 0.8f; 451 m_materialContactsData[(int)Material.Stone].mu = 0.8f;
458 m_materialContactsData[(int)Material.Stone].bounce = 0.4f; 452 m_materialContactsData[(int)Material.Stone].bounce = 0.4f;
459 453
460 m_materialContactsData[(int)Material.Metal].mu = frictionScale * 0.3f; 454 m_materialContactsData[(int)Material.Metal].mu = 0.3f;
461 m_materialContactsData[(int)Material.Metal].bounce = 0.4f; 455 m_materialContactsData[(int)Material.Metal].bounce = 0.4f;
462 456
463 m_materialContactsData[(int)Material.Glass].mu = frictionScale * 0.2f; 457 m_materialContactsData[(int)Material.Glass].mu = 0.2f;
464 m_materialContactsData[(int)Material.Glass].bounce = 0.7f; 458 m_materialContactsData[(int)Material.Glass].bounce = 0.7f;
465 459
466 m_materialContactsData[(int)Material.Wood].mu = frictionScale * 0.6f; 460 m_materialContactsData[(int)Material.Wood].mu = 0.6f;
467 m_materialContactsData[(int)Material.Wood].bounce = 0.5f; 461 m_materialContactsData[(int)Material.Wood].bounce = 0.5f;
468 462
469 m_materialContactsData[(int)Material.Flesh].mu = frictionScale * 0.9f; 463 m_materialContactsData[(int)Material.Flesh].mu = 0.9f;
470 m_materialContactsData[(int)Material.Flesh].bounce = 0.3f; 464 m_materialContactsData[(int)Material.Flesh].bounce = 0.3f;
471 465
472 m_materialContactsData[(int)Material.Plastic].mu = frictionScale * 0.4f; 466 m_materialContactsData[(int)Material.Plastic].mu = 0.4f;
473 m_materialContactsData[(int)Material.Plastic].bounce = 0.7f; 467 m_materialContactsData[(int)Material.Plastic].bounce = 0.7f;
474 468
475 m_materialContactsData[(int)Material.Rubber].mu = frictionScale * 0.9f; 469 m_materialContactsData[(int)Material.Rubber].mu = 0.9f;
476 m_materialContactsData[(int)Material.Rubber].bounce = 0.95f; 470 m_materialContactsData[(int)Material.Rubber].bounce = 0.95f;
477 471
478 m_materialContactsData[(int)Material.light].mu = 0.0f; 472 m_materialContactsData[(int)Material.light].mu = 0.0f;
479 m_materialContactsData[(int)Material.light].bounce = 0.0f; 473 m_materialContactsData[(int)Material.light].bounce = 0.0f;
480 474
481 TerrainFriction *= frictionScale;
482// AvatarFriction *= frictionScale;
483
484 // Set the gravity,, don't disable things automatically (we set it explicitly on some things) 475 // Set the gravity,, don't disable things automatically (we set it explicitly on some things)
485 476
486 d.WorldSetGravity(world, gravityx, gravityy, gravityz); 477 d.WorldSetGravity(world, gravityx, gravityy, gravityz);
@@ -566,13 +557,6 @@ namespace OpenSim.Region.Physics.OdePlugin
566 } 557 }
567 558
568 559
569 /// <summary>
570 /// This is our near callback. A geometry is near a body
571 /// </summary>
572 /// <param name="space">The space that contains the geoms. Remember, spaces are also geoms</param>
573 /// <param name="g1">a geometry or space</param>
574 /// <param name="g2">another geometry or space</param>
575 ///
576 560
577 private bool GetCurContactGeom(int index, ref d.ContactGeom newcontactgeom) 561 private bool GetCurContactGeom(int index, ref d.ContactGeom newcontactgeom)
578 { 562 {
@@ -584,7 +568,13 @@ namespace OpenSim.Region.Physics.OdePlugin
584 return true; 568 return true;
585 } 569 }
586 570
587 571 /// <summary>
572 /// This is our near callback. A geometry is near a body
573 /// </summary>
574 /// <param name="space">The space that contains the geoms. Remember, spaces are also geoms</param>
575 /// <param name="g1">a geometry or space</param>
576 /// <param name="g2">another geometry or space</param>
577 ///
588 578
589 private void near(IntPtr space, IntPtr g1, IntPtr g2) 579 private void near(IntPtr space, IntPtr g1, IntPtr g2)
590 { 580 {
@@ -703,8 +693,8 @@ namespace OpenSim.Region.Physics.OdePlugin
703 // big messy collision analises 693 // big messy collision analises
704 float mu = 0; 694 float mu = 0;
705 float bounce = 0; 695 float bounce = 0;
706 ContactData contactdata1; 696 ContactData contactdata1 = new ContactData(0, 0);
707 ContactData contactdata2; 697 ContactData contactdata2 = new ContactData(0, 0);
708 bool erpSoft = false; 698 bool erpSoft = false;
709 699
710 String name = null; 700 String name = null;
@@ -718,8 +708,9 @@ namespace OpenSim.Region.Physics.OdePlugin
718 switch (p2.PhysicsActorType) 708 switch (p2.PhysicsActorType)
719 { 709 {
720 case (int)ActorTypes.Agent: 710 case (int)ActorTypes.Agent:
721 contactdata1 = p1.ContactData; 711 p1.getContactData(ref contactdata1);
722 contactdata2 = p2.ContactData; 712 p2.getContactData(ref contactdata2);
713
723 bounce = contactdata1.bounce * contactdata2.bounce; 714 bounce = contactdata1.bounce * contactdata2.bounce;
724 715
725 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); 716 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
@@ -731,8 +722,8 @@ namespace OpenSim.Region.Physics.OdePlugin
731 p2.CollidingObj = true; 722 p2.CollidingObj = true;
732 break; 723 break;
733 case (int)ActorTypes.Prim: 724 case (int)ActorTypes.Prim:
734 contactdata1 = p1.ContactData; 725 p1.getContactData(ref contactdata1);
735 contactdata2 = p2.ContactData; 726 p2.getContactData(ref contactdata2);
736 bounce = contactdata1.bounce * contactdata2.bounce; 727 bounce = contactdata1.bounce * contactdata2.bounce;
737 728
738 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); 729 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
@@ -753,8 +744,8 @@ namespace OpenSim.Region.Physics.OdePlugin
753 switch (p2.PhysicsActorType) 744 switch (p2.PhysicsActorType)
754 { 745 {
755 case (int)ActorTypes.Agent: 746 case (int)ActorTypes.Agent:
756 contactdata1 = p1.ContactData; 747 p1.getContactData(ref contactdata1);
757 contactdata2 = p2.ContactData; 748 p2.getContactData(ref contactdata2);
758 bounce = contactdata1.bounce * contactdata2.bounce; 749 bounce = contactdata1.bounce * contactdata2.bounce;
759 750
760 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); 751 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
@@ -772,8 +763,8 @@ namespace OpenSim.Region.Physics.OdePlugin
772 p1.CollidingObj = true; 763 p1.CollidingObj = true;
773 p2.CollidingObj = true; 764 p2.CollidingObj = true;
774 } 765 }
775 contactdata1 = p1.ContactData; 766 p1.getContactData(ref contactdata1);
776 contactdata2 = p2.ContactData; 767 p2.getContactData(ref contactdata2);
777 bounce = contactdata1.bounce * contactdata2.bounce; 768 bounce = contactdata1.bounce * contactdata2.bounce;
778 erpSoft = true; 769 erpSoft = true;
779 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); 770 mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
@@ -788,7 +779,7 @@ namespace OpenSim.Region.Physics.OdePlugin
788 if (name == "Terrain") 779 if (name == "Terrain")
789 { 780 {
790 erpSoft = true; 781 erpSoft = true;
791 contactdata1 = p1.ContactData; 782 p1.getContactData(ref contactdata1);
792 bounce = contactdata1.bounce * TerrainBounce; 783 bounce = contactdata1.bounce * TerrainBounce;
793 mu = (float)Math.Sqrt(contactdata1.mu * TerrainFriction); 784 mu = (float)Math.Sqrt(contactdata1.mu * TerrainFriction);
794 if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f) 785 if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f)
@@ -815,7 +806,7 @@ namespace OpenSim.Region.Physics.OdePlugin
815 { 806 {
816 erpSoft = true; 807 erpSoft = true;
817 p2.CollidingGround = true; 808 p2.CollidingGround = true;
818 contactdata2 = p2.ContactData; 809 p2.getContactData(ref contactdata2);
819 bounce = contactdata2.bounce * TerrainBounce; 810 bounce = contactdata2.bounce * TerrainBounce;
820 mu = (float)Math.Sqrt(contactdata2.mu * TerrainFriction); 811 mu = (float)Math.Sqrt(contactdata2.mu * TerrainFriction);
821 812
@@ -1013,15 +1004,24 @@ namespace OpenSim.Region.Physics.OdePlugin
1013 1004
1014 } 1005 }
1015 1006
1016 // collide active prims with static enviroment
1017 lock (_activeprims) 1007 lock (_activeprims)
1018 { 1008 {
1009 foreach (OdePrim aprim in _activeprims)
1010 {
1011 aprim.CollisionScore = 0;
1012 aprim.IsColliding = false;
1013 }
1014 }
1015
1016 // collide active prims with static enviroment
1017 lock (_activegroups)
1018 {
1019 try 1019 try
1020 { 1020 {
1021 foreach (OdePrim prm in _activeprims) 1021 foreach (OdePrim prm in _activegroups)
1022 { 1022 {
1023 if (d.BodyIsEnabled(prm.Body)) 1023 if (d.BodyIsEnabled(prm.Body) && !prm.m_outbounds)
1024 d.SpaceCollide2(StaticSpace, prm.prim_geom, IntPtr.Zero, nearCallback); 1024 d.SpaceCollide2(StaticSpace, prm.collide_geom, IntPtr.Zero, nearCallback);
1025 } 1025 }
1026 } 1026 }
1027 catch (AccessViolationException) 1027 catch (AccessViolationException)
@@ -1029,7 +1029,6 @@ namespace OpenSim.Region.Physics.OdePlugin
1029 m_log.Warn("[PHYSICS]: Unable to collide Active prim to static space"); 1029 m_log.Warn("[PHYSICS]: Unable to collide Active prim to static space");
1030 } 1030 }
1031 } 1031 }
1032
1033 // finally colide active things amoung them 1032 // finally colide active things amoung them
1034 try 1033 try
1035 { 1034 {
@@ -1039,7 +1038,6 @@ namespace OpenSim.Region.Physics.OdePlugin
1039 { 1038 {
1040 m_log.Warn("[PHYSICS]: Unable to collide in Active space"); 1039 m_log.Warn("[PHYSICS]: Unable to collide in Active space");
1041 } 1040 }
1042
1043// _perloopContact.Clear(); 1041// _perloopContact.Clear();
1044 } 1042 }
1045 1043
@@ -1148,13 +1146,20 @@ namespace OpenSim.Region.Physics.OdePlugin
1148 1146
1149 public void addActivePrim(OdePrim activatePrim) 1147 public void addActivePrim(OdePrim activatePrim)
1150 { 1148 {
1151 // adds active prim.. (ones that should be iterated over in collisions_optimized 1149 // adds active prim..
1152 lock (_activeprims) 1150 lock (_activeprims)
1153 { 1151 {
1154 if (!_activeprims.Contains(activatePrim)) 1152 if (!_activeprims.Contains(activatePrim))
1155 _activeprims.Add(activatePrim); 1153 _activeprims.Add(activatePrim);
1156 //else 1154 }
1157 // m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent"); 1155 }
1156
1157 public void addActiveGroups(OdePrim activatePrim)
1158 {
1159 lock (_activegroups)
1160 {
1161 if (!_activegroups.Contains(activatePrim))
1162 _activegroups.Add(activatePrim);
1158 } 1163 }
1159 } 1164 }
1160 1165
@@ -1186,6 +1191,13 @@ namespace OpenSim.Region.Physics.OdePlugin
1186 _activeprims.Remove(deactivatePrim); 1191 _activeprims.Remove(deactivatePrim);
1187 } 1192 }
1188 } 1193 }
1194 public void remActiveGroup(OdePrim deactivatePrim)
1195 {
1196 lock (_activegroups)
1197 {
1198 _activegroups.Remove(deactivatePrim);
1199 }
1200 }
1189 1201
1190 public override void RemovePrim(PhysicsActor prim) 1202 public override void RemovePrim(PhysicsActor prim)
1191 { 1203 {
@@ -1258,6 +1270,11 @@ namespace OpenSim.Region.Physics.OdePlugin
1258 { 1270 {
1259 waitForSpaceUnlock(currentspace); 1271 waitForSpaceUnlock(currentspace);
1260 d.SpaceRemove(currentspace, geom); 1272 d.SpaceRemove(currentspace, geom);
1273
1274 if (d.SpaceGetSublevel(currentspace) > 2 && d.SpaceGetNumGeoms(currentspace) == 0)
1275 {
1276 d.SpaceDestroy(currentspace);
1277 }
1261 } 1278 }
1262 else 1279 else
1263 { 1280 {
@@ -1274,6 +1291,12 @@ namespace OpenSim.Region.Physics.OdePlugin
1274 { 1291 {
1275 waitForSpaceUnlock(currentspace); 1292 waitForSpaceUnlock(currentspace);
1276 d.SpaceRemove(currentspace, geom); 1293 d.SpaceRemove(currentspace, geom);
1294
1295 if (d.SpaceGetSublevel(currentspace) > 2 && d.SpaceGetNumGeoms(currentspace) == 0)
1296 {
1297 d.SpaceDestroy(currentspace);
1298 }
1299
1277 } 1300 }
1278 } 1301 }
1279 } 1302 }
@@ -1577,42 +1600,14 @@ namespace OpenSim.Region.Physics.OdePlugin
1577 1600
1578 statchanges += Util.EnvironmentTickCountSubtract(statstart); 1601 statchanges += Util.EnvironmentTickCountSubtract(statstart);
1579 1602
1580 // Move characters
1581 lock (_characters)
1582 {
1583 List<OdeCharacter> defects = new List<OdeCharacter>();
1584 foreach (OdeCharacter actor in _characters)
1585 {
1586 if (actor != null)
1587 actor.Move(ODE_STEPSIZE, defects);
1588 }
1589 if (defects.Count != 0)
1590 {
1591 foreach (OdeCharacter defect in defects)
1592 {
1593 RemoveCharacter(defect);
1594 }
1595 }
1596 }
1597 statchmove += Util.EnvironmentTickCountSubtract(statstart);
1598
1599 // Move other active objects
1600 lock (_activeprims)
1601 {
1602 foreach (OdePrim aprim in _activeprims)
1603 {
1604 aprim.CollisionScore = 0;
1605 aprim.IsColliding = false;
1606 aprim.Move();
1607 }
1608 }
1609
1610 statactmove += Util.EnvironmentTickCountSubtract(statstart); 1603 statactmove += Util.EnvironmentTickCountSubtract(statstart);
1611 //if ((framecount % m_randomizeWater) == 0) 1604 //if ((framecount % m_randomizeWater) == 0)
1612 // randomizeWater(waterlevel); 1605 // randomizeWater(waterlevel);
1613 1606
1614 m_rayCastManager.ProcessQueuedRequests(); 1607 m_rayCastManager.ProcessQueuedRequests();
1615 1608
1609
1610
1616 statray += Util.EnvironmentTickCountSubtract(statstart); 1611 statray += Util.EnvironmentTickCountSubtract(statstart);
1617 collision_optimized(); 1612 collision_optimized();
1618 statcol += Util.EnvironmentTickCountSubtract(statstart); 1613 statcol += Util.EnvironmentTickCountSubtract(statstart);
@@ -1642,8 +1637,35 @@ namespace OpenSim.Region.Physics.OdePlugin
1642 1637
1643 d.WorldQuickStep(world, ODE_STEPSIZE); 1638 d.WorldQuickStep(world, ODE_STEPSIZE);
1644 statstep += Util.EnvironmentTickCountSubtract(statstart); 1639 statstep += Util.EnvironmentTickCountSubtract(statstart);
1645 d.JointGroupEmpty(contactgroup); 1640
1646 totjcontact += m_global_contactcount; 1641 // Move characters
1642 lock (_characters)
1643 {
1644 List<OdeCharacter> defects = new List<OdeCharacter>();
1645 foreach (OdeCharacter actor in _characters)
1646 {
1647 if (actor != null)
1648 actor.Move(ODE_STEPSIZE, defects);
1649 }
1650 if (defects.Count != 0)
1651 {
1652 foreach (OdeCharacter defect in defects)
1653 {
1654 RemoveCharacter(defect);
1655 }
1656 }
1657 }
1658 statchmove += Util.EnvironmentTickCountSubtract(statstart);
1659
1660 // Move other active objects
1661 lock (_activegroups)
1662 {
1663 foreach (OdePrim aprim in _activegroups)
1664 {
1665 aprim.Move();
1666 }
1667 }
1668
1647 //ode.dunlock(world); 1669 //ode.dunlock(world);
1648 } 1670 }
1649 catch (Exception e) 1671 catch (Exception e)
@@ -1652,6 +1674,9 @@ namespace OpenSim.Region.Physics.OdePlugin
1652// ode.dunlock(world); 1674// ode.dunlock(world);
1653 } 1675 }
1654 1676
1677 d.JointGroupEmpty(contactgroup);
1678 totjcontact += m_global_contactcount;
1679
1655 step_time -= ODE_STEPSIZE; 1680 step_time -= ODE_STEPSIZE;
1656 nodeframes++; 1681 nodeframes++;
1657 } 1682 }
@@ -1686,10 +1711,10 @@ namespace OpenSim.Region.Physics.OdePlugin
1686 } 1711 }
1687 statmovchar = Util.EnvironmentTickCountSubtract(statstart); 1712 statmovchar = Util.EnvironmentTickCountSubtract(statstart);
1688 1713
1689 lock (_activeprims) 1714 lock (_activegroups)
1690 { 1715 {
1691 { 1716 {
1692 foreach (OdePrim actor in _activeprims) 1717 foreach (OdePrim actor in _activegroups)
1693 { 1718 {
1694 if (actor.IsPhysical) 1719 if (actor.IsPhysical)
1695 { 1720 {
@@ -1906,13 +1931,14 @@ namespace OpenSim.Region.Physics.OdePlugin
1906 yy += regionsize; 1931 yy += regionsize;
1907 1932
1908 val = heightMap[yy + xx]; 1933 val = heightMap[yy + xx];
1934 if (val < 0.0f)
1935 val = 0.0f; // no neg terrain as in chode
1909 _heightmap[xt + y] = val; 1936 _heightmap[xt + y] = val;
1910 1937
1911 if (hfmin > val) 1938 if (hfmin > val)
1912 hfmin = val; 1939 hfmin = val;
1913 if (hfmax < val) 1940 if (hfmax < val)
1914 hfmax = val; 1941 hfmax = val;
1915
1916 } 1942 }
1917 xt += heightmapHeightSamples; 1943 xt += heightmapHeightSamples;
1918 } 1944 }
@@ -1966,7 +1992,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1966 1992
1967 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); 1993 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
1968 d.GeomSetRotation(GroundGeom, ref R); 1994 d.GeomSetRotation(GroundGeom, ref R);
1969 d.GeomSetPosition(GroundGeom, pOffset.X + (float)Constants.RegionSize * 0.5f - 0.5f, pOffset.Y + (float)Constants.RegionSize * 0.5f - 0.5f, 0); 1995 d.GeomSetPosition(GroundGeom, pOffset.X + (float)Constants.RegionSize * 0.5f, pOffset.Y + (float)Constants.RegionSize * 0.5f, 0);
1970 RegionTerrain.Add(pOffset, GroundGeom, GroundGeom); 1996 RegionTerrain.Add(pOffset, GroundGeom, GroundGeom);
1971// TerrainHeightFieldHeights.Add(GroundGeom, ODElandMap); 1997// TerrainHeightFieldHeights.Add(GroundGeom, ODElandMap);
1972 TerrainHeightFieldHeights.Add(GroundGeom, _heightmap); 1998 TerrainHeightFieldHeights.Add(GroundGeom, _heightmap);