diff options
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs')
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | 290 |
1 files changed, 113 insertions, 177 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index 754bc86..8abf6cf 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | |||
@@ -25,6 +25,7 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | // Revision 2011/12/13 by Ubit Umarov | ||
28 | //#define SPAM | 29 | //#define SPAM |
29 | 30 | ||
30 | using System; | 31 | using System; |
@@ -43,25 +44,7 @@ using OpenMetaverse; | |||
43 | 44 | ||
44 | namespace OpenSim.Region.Physics.OdePlugin | 45 | namespace OpenSim.Region.Physics.OdePlugin |
45 | { | 46 | { |
46 | public enum StatusIndicators : int | 47 | // colision flags of things others can colide with |
47 | { | ||
48 | Generic = 0, | ||
49 | Start = 1, | ||
50 | End = 2 | ||
51 | } | ||
52 | |||
53 | public struct sCollisionData | ||
54 | { | ||
55 | public uint ColliderLocalId; | ||
56 | public uint CollidedWithLocalId; | ||
57 | public int NumberOfCollisions; | ||
58 | public int CollisionType; | ||
59 | public int StatusIndicator; | ||
60 | public int lastframe; | ||
61 | } | ||
62 | |||
63 | |||
64 | // colision flags of things others can colide with | ||
65 | // rays, sensors, probes removed since can't be colided with | 48 | // rays, sensors, probes removed since can't be colided with |
66 | // The top space where things are placed provided further selection | 49 | // The top space where things are placed provided further selection |
67 | // ie physical are in active space nonphysical in static | 50 | // ie physical are in active space nonphysical in static |
@@ -188,12 +171,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
188 | 171 | ||
189 | public bool OdeUbitLib = false; | 172 | public bool OdeUbitLib = false; |
190 | // private int threadid = 0; | 173 | // private int threadid = 0; |
191 | private Random fluidRandomizer = new Random(Environment.TickCount); | 174 | // private Random fluidRandomizer = new Random(Environment.TickCount); |
175 | |||
176 | // const d.ContactFlags comumContactFlags = d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM |d.ContactFlags.Approx1 | d.ContactFlags.Bounce; | ||
192 | 177 | ||
193 | const d.ContactFlags comumContactFlags = d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM |d.ContactFlags.Approx1 | d.ContactFlags.Bounce; | 178 | const d.ContactFlags comumContactFlags = d.ContactFlags.Bounce | d.ContactFlags.Approx1 | d.ContactFlags.Slip1 | d.ContactFlags.Slip2; |
194 | const float MaxERP = 0.8f; | 179 | const float comumContactERP = 0.7f; |
195 | const float minERP = 0.1f; | ||
196 | const float comumContactCFM = 0.0001f; | 180 | const float comumContactCFM = 0.0001f; |
181 | const float comumContactSLIP = 0f; | ||
197 | 182 | ||
198 | float frictionMovementMult = 0.8f; | 183 | float frictionMovementMult = 0.8f; |
199 | 184 | ||
@@ -236,8 +221,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
236 | 221 | ||
237 | public float geomDefaultDensity = 10.000006836f; | 222 | public float geomDefaultDensity = 10.000006836f; |
238 | 223 | ||
239 | public int geomContactPointsStartthrottle = 3; | 224 | // public int geomContactPointsStartthrottle = 3; |
240 | public int geomUpdatesPerThrottledUpdate = 15; | 225 | // public int geomUpdatesPerThrottledUpdate = 15; |
241 | 226 | ||
242 | public float bodyPIDD = 35f; | 227 | public float bodyPIDD = 35f; |
243 | public float bodyPIDG = 25; | 228 | public float bodyPIDG = 25; |
@@ -246,7 +231,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
246 | 231 | ||
247 | public int bodyFramesAutoDisable = 5; | 232 | public int bodyFramesAutoDisable = 5; |
248 | 233 | ||
249 | |||
250 | private d.NearCallback nearCallback; | 234 | private d.NearCallback nearCallback; |
251 | 235 | ||
252 | private HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>(); | 236 | private HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>(); |
@@ -266,11 +250,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
266 | // public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); | 250 | // public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); |
267 | public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>(); | 251 | public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>(); |
268 | 252 | ||
269 | private float contactsurfacelayer = 0.002f; | 253 | private float contactsurfacelayer = 0.001f; |
270 | 254 | ||
271 | private int contactsPerCollision = 80; | 255 | private int contactsPerCollision = 80; |
272 | internal IntPtr ContactgeomsArray = IntPtr.Zero; | 256 | internal IntPtr ContactgeomsArray = IntPtr.Zero; |
273 | private IntPtr GlobalContactsArray = IntPtr.Zero; | 257 | private IntPtr GlobalContactsArray = IntPtr.Zero; |
258 | private d.Contact SharedTmpcontact = new d.Contact(); | ||
274 | 259 | ||
275 | const int maxContactsbeforedeath = 4000; | 260 | const int maxContactsbeforedeath = 4000; |
276 | private volatile int m_global_contactcount = 0; | 261 | private volatile int m_global_contactcount = 0; |
@@ -283,7 +268,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
283 | private Dictionary<IntPtr, float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>(); | 268 | private Dictionary<IntPtr, float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>(); |
284 | private Dictionary<IntPtr, GCHandle> TerrainHeightFieldHeightsHandlers = new Dictionary<IntPtr, GCHandle>(); | 269 | private Dictionary<IntPtr, GCHandle> TerrainHeightFieldHeightsHandlers = new Dictionary<IntPtr, GCHandle>(); |
285 | 270 | ||
286 | private int m_physicsiterations = 10; | 271 | private int m_physicsiterations = 15; |
287 | private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag | 272 | private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag |
288 | // private PhysicsActor PANull = new NullPhysicsActor(); | 273 | // private PhysicsActor PANull = new NullPhysicsActor(); |
289 | private float step_time = 0.0f; | 274 | private float step_time = 0.0f; |
@@ -303,8 +288,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
303 | public IntPtr StaticSpace; // space for the static things around | 288 | public IntPtr StaticSpace; // space for the static things around |
304 | public IntPtr GroundSpace; // space for ground | 289 | public IntPtr GroundSpace; // space for ground |
305 | 290 | ||
306 | public IntPtr SharedRay; | ||
307 | |||
308 | // some speedup variables | 291 | // some speedup variables |
309 | private int spaceGridMaxX; | 292 | private int spaceGridMaxX; |
310 | private int spaceGridMaxY; | 293 | private int spaceGridMaxY; |
@@ -428,11 +411,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
428 | d.GeomSetCategoryBits(GroundSpace, (uint)(CollisionCategories.Land)); | 411 | d.GeomSetCategoryBits(GroundSpace, (uint)(CollisionCategories.Land)); |
429 | d.GeomSetCollideBits(GroundSpace, 0); | 412 | d.GeomSetCollideBits(GroundSpace, 0); |
430 | 413 | ||
431 | contactgroup = d.JointGroupCreate(0); | 414 | contactgroup = d.JointGroupCreate(maxContactsbeforedeath + 1); |
432 | //contactgroup | 415 | //contactgroup |
433 | 416 | ||
434 | SharedRay = d.CreateRay(TopSpace, 1.0f); | ||
435 | |||
436 | d.WorldSetAutoDisableFlag(world, false); | 417 | d.WorldSetAutoDisableFlag(world, false); |
437 | } | 418 | } |
438 | } | 419 | } |
@@ -481,10 +462,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
481 | 462 | ||
482 | metersInSpace = physicsconfig.GetFloat("meters_in_small_space", metersInSpace); | 463 | metersInSpace = physicsconfig.GetFloat("meters_in_small_space", metersInSpace); |
483 | 464 | ||
484 | contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", contactsurfacelayer); | 465 | // contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", contactsurfacelayer); |
485 | 466 | ||
486 | ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE); | 467 | ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE); |
487 | m_physicsiterations = physicsconfig.GetInt("world_internal_steps_without_collisions", m_physicsiterations); | 468 | // m_physicsiterations = physicsconfig.GetInt("world_internal_steps_without_collisions", m_physicsiterations); |
488 | 469 | ||
489 | avDensity = physicsconfig.GetFloat("av_density", avDensity); | 470 | avDensity = physicsconfig.GetFloat("av_density", avDensity); |
490 | avMovementDivisorWalk = physicsconfig.GetFloat("av_movement_divisor_walk", avMovementDivisorWalk); | 471 | avMovementDivisorWalk = physicsconfig.GetFloat("av_movement_divisor_walk", avMovementDivisorWalk); |
@@ -492,8 +473,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
492 | 473 | ||
493 | contactsPerCollision = physicsconfig.GetInt("contacts_per_collision", contactsPerCollision); | 474 | contactsPerCollision = physicsconfig.GetInt("contacts_per_collision", contactsPerCollision); |
494 | 475 | ||
495 | geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 3); | 476 | // geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 3); |
496 | geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15); | 477 | // geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15); |
497 | // geomCrossingFailuresBeforeOutofbounds = physicsconfig.GetInt("geom_crossing_failures_before_outofbounds", 5); | 478 | // geomCrossingFailuresBeforeOutofbounds = physicsconfig.GetInt("geom_crossing_failures_before_outofbounds", 5); |
498 | 479 | ||
499 | geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", geomDefaultDensity); | 480 | geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", geomDefaultDensity); |
@@ -508,6 +489,23 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
508 | } | 489 | } |
509 | } | 490 | } |
510 | 491 | ||
492 | |||
493 | d.WorldSetCFM(world, comumContactCFM); | ||
494 | d.WorldSetERP(world, comumContactERP); | ||
495 | |||
496 | d.WorldSetGravity(world, gravityx, gravityy, gravityz); | ||
497 | |||
498 | d.WorldSetLinearDamping(world, 0.002f); | ||
499 | d.WorldSetAngularDamping(world, 0.002f); | ||
500 | d.WorldSetAngularDampingThreshold(world, 0f); | ||
501 | d.WorldSetLinearDampingThreshold(world, 0f); | ||
502 | d.WorldSetMaxAngularSpeed(world, 100f); | ||
503 | |||
504 | d.WorldSetQuickStepNumIterations(world, m_physicsiterations); | ||
505 | |||
506 | d.WorldSetContactSurfaceLayer(world, contactsurfacelayer); | ||
507 | d.WorldSetContactMaxCorrectingVel(world, 60.0f); | ||
508 | |||
511 | m_meshWorker = new ODEMeshWorker(this, m_log, meshmerizer, physicsconfig); | 509 | m_meshWorker = new ODEMeshWorker(this, m_log, meshmerizer, physicsconfig); |
512 | 510 | ||
513 | HalfOdeStep = ODE_STEPSIZE * 0.5f; | 511 | HalfOdeStep = ODE_STEPSIZE * 0.5f; |
@@ -516,6 +514,20 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
516 | ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf); | 514 | ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf); |
517 | GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf); | 515 | GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf); |
518 | 516 | ||
517 | SharedTmpcontact.geom.g1 = IntPtr.Zero; | ||
518 | SharedTmpcontact.geom.g2 = IntPtr.Zero; | ||
519 | |||
520 | SharedTmpcontact.geom.side1 = -1; | ||
521 | SharedTmpcontact.geom.side2 = -1; | ||
522 | |||
523 | SharedTmpcontact.surface.mode = comumContactFlags; | ||
524 | SharedTmpcontact.surface.mu = 0; | ||
525 | SharedTmpcontact.surface.bounce = 0; | ||
526 | SharedTmpcontact.surface.soft_cfm = comumContactCFM; | ||
527 | SharedTmpcontact.surface.soft_erp = comumContactERP; | ||
528 | SharedTmpcontact.surface.slip1 = comumContactSLIP; | ||
529 | SharedTmpcontact.surface.slip2 = comumContactSLIP; | ||
530 | |||
519 | m_materialContactsData[(int)Material.Stone].mu = 0.8f; | 531 | m_materialContactsData[(int)Material.Stone].mu = 0.8f; |
520 | m_materialContactsData[(int)Material.Stone].bounce = 0.4f; | 532 | m_materialContactsData[(int)Material.Stone].bounce = 0.4f; |
521 | 533 | ||
@@ -540,27 +552,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
540 | m_materialContactsData[(int)Material.light].mu = 0.0f; | 552 | m_materialContactsData[(int)Material.light].mu = 0.0f; |
541 | m_materialContactsData[(int)Material.light].bounce = 0.0f; | 553 | m_materialContactsData[(int)Material.light].bounce = 0.0f; |
542 | 554 | ||
543 | // Set the gravity,, don't disable things automatically (we set it explicitly on some things) | ||
544 | |||
545 | d.WorldSetGravity(world, gravityx, gravityy, gravityz); | ||
546 | d.WorldSetContactSurfaceLayer(world, contactsurfacelayer); | ||
547 | |||
548 | d.WorldSetLinearDamping(world, 0.002f); | ||
549 | d.WorldSetAngularDamping(world, 0.002f); | ||
550 | d.WorldSetAngularDampingThreshold(world, 0f); | ||
551 | d.WorldSetLinearDampingThreshold(world, 0f); | ||
552 | d.WorldSetMaxAngularSpeed(world, 100f); | ||
553 | |||
554 | d.WorldSetCFM(world,1e-6f); // a bit harder than default | ||
555 | //d.WorldSetCFM(world, 1e-4f); // a bit harder than default | ||
556 | d.WorldSetERP(world, 0.6f); // higher than original | ||
557 | |||
558 | // Set how many steps we go without running collision testing | ||
559 | // This is in addition to the step size. | ||
560 | // Essentially Steps * m_physicsiterations | ||
561 | d.WorldSetQuickStepNumIterations(world, m_physicsiterations); | ||
562 | |||
563 | d.WorldSetContactMaxCorrectingVel(world, 60.0f); | ||
564 | 555 | ||
565 | spacesPerMeter = 1 / metersInSpace; | 556 | spacesPerMeter = 1 / metersInSpace; |
566 | spaceGridMaxX = (int)(WorldExtents.X * spacesPerMeter); | 557 | spaceGridMaxX = (int)(WorldExtents.X * spacesPerMeter); |
@@ -631,40 +622,21 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
631 | 622 | ||
632 | // sets a global contact for a joint for contactgeom , and base contact description) | 623 | // sets a global contact for a joint for contactgeom , and base contact description) |
633 | 624 | ||
634 | private IntPtr CreateContacJoint(ref d.ContactGeom contactGeom, float mu, float bounce, float cfm, float erpscale, float dscale) | 625 | |
626 | |||
627 | private IntPtr CreateContacJoint(ref d.ContactGeom contactGeom) | ||
635 | { | 628 | { |
636 | if (GlobalContactsArray == IntPtr.Zero || m_global_contactcount >= maxContactsbeforedeath) | 629 | if (m_global_contactcount >= maxContactsbeforedeath) |
637 | return IntPtr.Zero; | 630 | return IntPtr.Zero; |
638 | 631 | ||
639 | float erp = contactGeom.depth; | 632 | m_global_contactcount++; |
640 | erp *= erpscale; | 633 | |
641 | if (erp < minERP) | 634 | SharedTmpcontact.geom.depth = contactGeom.depth; |
642 | erp = minERP; | 635 | SharedTmpcontact.geom.pos = contactGeom.pos; |
643 | else if (erp > MaxERP) | 636 | SharedTmpcontact.geom.normal = contactGeom.normal; |
644 | erp = MaxERP; | ||
645 | |||
646 | float depth = contactGeom.depth * dscale; | ||
647 | if (depth > 0.5f) | ||
648 | depth = 0.5f; | ||
649 | |||
650 | d.Contact newcontact = new d.Contact(); | ||
651 | newcontact.geom.depth = depth; | ||
652 | newcontact.geom.g1 = contactGeom.g1; | ||
653 | newcontact.geom.g2 = contactGeom.g2; | ||
654 | newcontact.geom.pos = contactGeom.pos; | ||
655 | newcontact.geom.normal = contactGeom.normal; | ||
656 | newcontact.geom.side1 = contactGeom.side1; | ||
657 | newcontact.geom.side2 = contactGeom.side2; | ||
658 | |||
659 | // this needs bounce also | ||
660 | newcontact.surface.mode = comumContactFlags; | ||
661 | newcontact.surface.mu = mu; | ||
662 | newcontact.surface.bounce = bounce; | ||
663 | newcontact.surface.soft_cfm = cfm; | ||
664 | newcontact.surface.soft_erp = erp; | ||
665 | 637 | ||
666 | IntPtr contact = new IntPtr(GlobalContactsArray.ToInt64() + (Int64)(m_global_contactcount * d.Contact.unmanagedSizeOf)); | 638 | IntPtr contact = new IntPtr(GlobalContactsArray.ToInt64() + (Int64)(m_global_contactcount * d.Contact.unmanagedSizeOf)); |
667 | Marshal.StructureToPtr(newcontact, contact, true); | 639 | Marshal.StructureToPtr(SharedTmpcontact, contact, true); |
668 | return d.JointCreateContactPtr(world, contactgroup, contact); | 640 | return d.JointCreateContactPtr(world, contactgroup, contact); |
669 | } | 641 | } |
670 | 642 | ||
@@ -825,10 +797,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
825 | if (!GetCurContactGeom(0, ref curContact)) | 797 | if (!GetCurContactGeom(0, ref curContact)) |
826 | return; | 798 | return; |
827 | 799 | ||
800 | ContactPoint maxDepthContact = new ContactPoint(); | ||
801 | |||
828 | // do volume detection case | 802 | // do volume detection case |
829 | if ((p1.IsVolumeDtc || p2.IsVolumeDtc)) | 803 | if ((p1.IsVolumeDtc || p2.IsVolumeDtc)) |
830 | { | 804 | { |
831 | ContactPoint maxDepthContact = new ContactPoint( | 805 | maxDepthContact = new ContactPoint( |
832 | new Vector3(curContact.pos.X, curContact.pos.Y, curContact.pos.Z), | 806 | new Vector3(curContact.pos.X, curContact.pos.Y, curContact.pos.Z), |
833 | new Vector3(curContact.normal.X, curContact.normal.Y, curContact.normal.Z), | 807 | new Vector3(curContact.normal.X, curContact.normal.Y, curContact.normal.Z), |
834 | curContact.depth, false | 808 | curContact.depth, false |
@@ -842,10 +816,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
842 | 816 | ||
843 | float mu = 0; | 817 | float mu = 0; |
844 | float bounce = 0; | 818 | float bounce = 0; |
845 | float cfm = 0.0001f; | 819 | // bool IgnoreNegSides = false; |
846 | float erpscale = 1.0f; | ||
847 | float dscale = 1.0f; | ||
848 | bool IgnoreNegSides = false; | ||
849 | 820 | ||
850 | ContactData contactdata1 = new ContactData(0, 0, false); | 821 | ContactData contactdata1 = new ContactData(0, 0, false); |
851 | ContactData contactdata2 = new ContactData(0, 0, false); | 822 | ContactData contactdata2 = new ContactData(0, 0, false); |
@@ -890,7 +861,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
890 | break; | 861 | break; |
891 | 862 | ||
892 | case (int)ActorTypes.Prim: | 863 | case (int)ActorTypes.Prim: |
893 | if ((p1.Velocity - p2.Velocity).LengthSquared() > 0.0f) | 864 | Vector3 relV = p1.Velocity - p2.Velocity; |
865 | float relVlenSQ = relV.LengthSquared(); | ||
866 | if (relVlenSQ > 0.0001f) | ||
894 | { | 867 | { |
895 | p1.CollidingObj = true; | 868 | p1.CollidingObj = true; |
896 | p2.CollidingObj = true; | 869 | p2.CollidingObj = true; |
@@ -900,21 +873,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
900 | bounce = contactdata1.bounce * contactdata2.bounce; | 873 | bounce = contactdata1.bounce * contactdata2.bounce; |
901 | mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); | 874 | mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); |
902 | 875 | ||
903 | cfm = p1.Mass; | 876 | if (relVlenSQ > 0.01f) |
904 | if (cfm > p2.Mass) | ||
905 | cfm = p2.Mass; | ||
906 | dscale = 10 / cfm; | ||
907 | dscale = (float)Math.Sqrt(dscale); | ||
908 | if (dscale > 1.0f) | ||
909 | dscale = 1.0f; | ||
910 | erpscale = cfm * 0.01f; | ||
911 | cfm = 0.0001f / cfm; | ||
912 | if (cfm > 0.01f) | ||
913 | cfm = 0.01f; | ||
914 | else if (cfm < 0.00001f) | ||
915 | cfm = 0.00001f; | ||
916 | |||
917 | if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f)) | ||
918 | mu *= frictionMovementMult; | 877 | mu *= frictionMovementMult; |
919 | 878 | ||
920 | break; | 879 | break; |
@@ -923,27 +882,17 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
923 | p1.getContactData(ref contactdata1); | 882 | p1.getContactData(ref contactdata1); |
924 | bounce = contactdata1.bounce * TerrainBounce; | 883 | bounce = contactdata1.bounce * TerrainBounce; |
925 | mu = (float)Math.Sqrt(contactdata1.mu * TerrainFriction); | 884 | mu = (float)Math.Sqrt(contactdata1.mu * TerrainFriction); |
885 | |||
926 | if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f) | 886 | if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f) |
927 | mu *= frictionMovementMult; | 887 | mu *= frictionMovementMult; |
928 | p1.CollidingGround = true; | 888 | p1.CollidingGround = true; |
929 | 889 | /* | |
930 | cfm = p1.Mass; | ||
931 | dscale = 10 / cfm; | ||
932 | dscale = (float)Math.Sqrt(dscale); | ||
933 | if (dscale > 1.0f) | ||
934 | dscale = 1.0f; | ||
935 | erpscale = cfm * 0.01f; | ||
936 | cfm = 0.0001f / cfm; | ||
937 | if (cfm > 0.01f) | ||
938 | cfm = 0.01f; | ||
939 | else if (cfm < 0.00001f) | ||
940 | cfm = 0.00001f; | ||
941 | |||
942 | if (d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass) | 890 | if (d.GeomGetClass(g1) == d.GeomClassID.TriMeshClass) |
943 | { | 891 | { |
944 | if (curContact.side1 > 0) | 892 | if (curContact.side1 > 0) |
945 | IgnoreNegSides = true; | 893 | IgnoreNegSides = true; |
946 | } | 894 | } |
895 | */ | ||
947 | break; | 896 | break; |
948 | 897 | ||
949 | case (int)ActorTypes.Water: | 898 | case (int)ActorTypes.Water: |
@@ -961,22 +910,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
961 | bounce = contactdata2.bounce * TerrainBounce; | 910 | bounce = contactdata2.bounce * TerrainBounce; |
962 | mu = (float)Math.Sqrt(contactdata2.mu * TerrainFriction); | 911 | mu = (float)Math.Sqrt(contactdata2.mu * TerrainFriction); |
963 | 912 | ||
964 | cfm = p2.Mass; | 913 | // if (curContact.side1 > 0) // should be 2 ? |
965 | dscale = 10 / cfm; | 914 | // IgnoreNegSides = true; |
966 | dscale = (float)Math.Sqrt(dscale); | ||
967 | |||
968 | if (dscale > 1.0f) | ||
969 | dscale = 1.0f; | ||
970 | |||
971 | erpscale = cfm * 0.01f; | ||
972 | cfm = 0.0001f / cfm; | ||
973 | if (cfm > 0.01f) | ||
974 | cfm = 0.01f; | ||
975 | else if (cfm < 0.00001f) | ||
976 | cfm = 0.00001f; | ||
977 | |||
978 | if (curContact.side1 > 0) // should be 2 ? | ||
979 | IgnoreNegSides = true; | ||
980 | 915 | ||
981 | if (Math.Abs(p2.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y) > 0.1f) | 916 | if (Math.Abs(p2.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y) > 0.1f) |
982 | mu *= frictionMovementMult; | 917 | mu *= frictionMovementMult; |
@@ -993,26 +928,24 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
993 | if (ignore) | 928 | if (ignore) |
994 | return; | 929 | return; |
995 | 930 | ||
996 | |||
997 | d.ContactGeom maxContact = curContact; | ||
998 | // if (IgnoreNegSides && curContact.side1 < 0) | ||
999 | // maxContact.depth = float.MinValue; | ||
1000 | |||
1001 | d.ContactGeom minContact = curContact; | ||
1002 | // if (IgnoreNegSides && curContact.side1 < 0) | ||
1003 | // minContact.depth = float.MaxValue; | ||
1004 | |||
1005 | IntPtr Joint; | 931 | IntPtr Joint; |
1006 | bool FeetCollision = false; | 932 | bool FeetCollision = false; |
1007 | int ncontacts = 0; | 933 | int ncontacts = 0; |
1008 | 934 | ||
1009 | |||
1010 | int i = 0; | 935 | int i = 0; |
1011 | 936 | ||
937 | maxDepthContact = new ContactPoint(); | ||
938 | maxDepthContact.PenetrationDepth = float.MinValue; | ||
939 | ContactPoint minDepthContact = new ContactPoint(); | ||
940 | minDepthContact.PenetrationDepth = float.MaxValue; | ||
941 | |||
942 | SharedTmpcontact.geom.depth = 0; | ||
943 | SharedTmpcontact.surface.mu = mu; | ||
944 | SharedTmpcontact.surface.bounce = bounce; | ||
945 | |||
1012 | while (true) | 946 | while (true) |
1013 | { | 947 | { |
1014 | 948 | // if (!(IgnoreNegSides && curContact.side1 < 0)) | |
1015 | // if (!(IgnoreNegSides && curContact.side1 < 0)) | ||
1016 | { | 949 | { |
1017 | bool noskip = true; | 950 | bool noskip = true; |
1018 | if (dop1ava) | 951 | if (dop1ava) |
@@ -1029,26 +962,32 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1029 | 962 | ||
1030 | if (noskip) | 963 | if (noskip) |
1031 | { | 964 | { |
1032 | m_global_contactcount++; | 965 | Joint = CreateContacJoint(ref curContact); |
1033 | if (m_global_contactcount >= maxContactsbeforedeath) | ||
1034 | break; | ||
1035 | |||
1036 | ncontacts++; | ||
1037 | |||
1038 | Joint = CreateContacJoint(ref curContact, mu, bounce, cfm, erpscale, dscale); | ||
1039 | if (Joint == IntPtr.Zero) | 966 | if (Joint == IntPtr.Zero) |
1040 | break; | 967 | break; |
1041 | 968 | ||
1042 | d.JointAttach(Joint, b1, b2); | 969 | d.JointAttach(Joint, b1, b2); |
1043 | 970 | ||
1044 | if (curContact.depth > maxContact.depth) | 971 | ncontacts++; |
1045 | maxContact = curContact; | 972 | |
973 | if (curContact.depth > maxDepthContact.PenetrationDepth) | ||
974 | { | ||
975 | maxDepthContact.Position.X = curContact.pos.X; | ||
976 | maxDepthContact.Position.Y = curContact.pos.Y; | ||
977 | maxDepthContact.Position.Z = curContact.pos.Z; | ||
978 | maxDepthContact.PenetrationDepth = curContact.depth; | ||
979 | maxDepthContact.CharacterFeet = FeetCollision; | ||
980 | } | ||
1046 | 981 | ||
1047 | if (curContact.depth < minContact.depth) | 982 | if (curContact.depth < minDepthContact.PenetrationDepth) |
1048 | minContact = curContact; | 983 | { |
984 | minDepthContact.PenetrationDepth = curContact.depth; | ||
985 | minDepthContact.SurfaceNormal.X = curContact.normal.X; | ||
986 | minDepthContact.SurfaceNormal.Y = curContact.normal.Y; | ||
987 | minDepthContact.SurfaceNormal.Z = curContact.normal.Z; | ||
988 | } | ||
1049 | } | 989 | } |
1050 | } | 990 | } |
1051 | |||
1052 | if (++i >= count) | 991 | if (++i >= count) |
1053 | break; | 992 | break; |
1054 | 993 | ||
@@ -1058,11 +997,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1058 | 997 | ||
1059 | if (ncontacts > 0) | 998 | if (ncontacts > 0) |
1060 | { | 999 | { |
1061 | ContactPoint maxDepthContact = new ContactPoint( | 1000 | maxDepthContact.SurfaceNormal.X = minDepthContact.SurfaceNormal.X; |
1062 | new Vector3(maxContact.pos.X, maxContact.pos.Y, maxContact.pos.Z), | 1001 | maxDepthContact.SurfaceNormal.Y = minDepthContact.SurfaceNormal.Y; |
1063 | new Vector3(minContact.normal.X, minContact.normal.Y, minContact.normal.Z), | 1002 | maxDepthContact.SurfaceNormal.Z = minDepthContact.SurfaceNormal.Z; |
1064 | maxContact.depth, FeetCollision | 1003 | |
1065 | ); | ||
1066 | collision_accounting_events(p1, p2, maxDepthContact); | 1004 | collision_accounting_events(p1, p2, maxDepthContact); |
1067 | } | 1005 | } |
1068 | } | 1006 | } |
@@ -1629,16 +1567,15 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1629 | if (framecount < 0) | 1567 | if (framecount < 0) |
1630 | framecount = 0; | 1568 | framecount = 0; |
1631 | 1569 | ||
1632 | |||
1633 | framecount++; | 1570 | framecount++; |
1634 | 1571 | ||
1635 | int curphysiteractions; | 1572 | // int curphysiteractions; |
1636 | 1573 | ||
1637 | // if in trouble reduce step resolution | 1574 | // if in trouble reduce step resolution |
1638 | if (step_time >= m_SkipFramesAtms) | 1575 | // if (step_time >= m_SkipFramesAtms) |
1639 | curphysiteractions = m_physicsiterations / 2; | 1576 | // curphysiteractions = m_physicsiterations / 2; |
1640 | else | 1577 | // else |
1641 | curphysiteractions = m_physicsiterations; | 1578 | // curphysiteractions = m_physicsiterations; |
1642 | 1579 | ||
1643 | // checkThread(); | 1580 | // checkThread(); |
1644 | int nodeframes = 0; | 1581 | int nodeframes = 0; |
@@ -1653,14 +1590,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1653 | } | 1590 | } |
1654 | 1591 | ||
1655 | ODEchangeitem item; | 1592 | ODEchangeitem item; |
1656 | |||
1657 | |||
1658 | 1593 | ||
1659 | d.WorldSetQuickStepNumIterations(world, curphysiteractions); | 1594 | // d.WorldSetQuickStepNumIterations(world, curphysiteractions); |
1660 | 1595 | ||
1661 | int loopstartMS = Util.EnvironmentTickCount(); | 1596 | int loopstartMS = Util.EnvironmentTickCount(); |
1662 | int looptimeMS = 0; | 1597 | int looptimeMS = 0; |
1663 | 1598 | ||
1664 | 1599 | ||
1665 | while (step_time > HalfOdeStep) | 1600 | while (step_time > HalfOdeStep) |
1666 | { | 1601 | { |
@@ -1763,6 +1698,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1763 | 1698 | ||
1764 | // do a ode simulation step | 1699 | // do a ode simulation step |
1765 | d.WorldQuickStep(world, ODE_STEPSIZE); | 1700 | d.WorldQuickStep(world, ODE_STEPSIZE); |
1701 | // d.WorldStep(world, ODE_STEPSIZE); | ||
1766 | d.JointGroupEmpty(contactgroup); | 1702 | d.JointGroupEmpty(contactgroup); |
1767 | 1703 | ||
1768 | // update managed ideia of physical data and do updates to core | 1704 | // update managed ideia of physical data and do updates to core |
@@ -1789,7 +1725,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1789 | { | 1725 | { |
1790 | if (actor.IsPhysical) | 1726 | if (actor.IsPhysical) |
1791 | { | 1727 | { |
1792 | actor.UpdatePositionAndVelocity(); | 1728 | actor.UpdatePositionAndVelocity(framecount); |
1793 | } | 1729 | } |
1794 | } | 1730 | } |
1795 | } | 1731 | } |