aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
diff options
context:
space:
mode:
authorUbitUmarov2018-01-14 01:40:49 +0000
committerUbitUmarov2018-01-14 01:40:49 +0000
commit3d87e37d99b0db26847e079f5b1da3ac82412ddc (patch)
tree18919f5348ea877ab3befb7946fb58ef65403e39 /OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
parentmake ubOde PInvoke follow ms coding rules (diff)
downloadopensim-SC-3d87e37d99b0db26847e079f5b1da3ac82412ddc.zip
opensim-SC-3d87e37d99b0db26847e079f5b1da3ac82412ddc.tar.gz
opensim-SC-3d87e37d99b0db26847e079f5b1da3ac82412ddc.tar.bz2
opensim-SC-3d87e37d99b0db26847e079f5b1da3ac82412ddc.tar.xz
make old Ode PInvoke follow ms coding rules
Diffstat (limited to 'OpenSim/Region/PhysicsModules/Ode/OdeScene.cs')
-rw-r--r--OpenSim/Region/PhysicsModules/Ode/OdeScene.cs281
1 files changed, 139 insertions, 142 deletions
diff --git a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
index d15568e..e760fa2 100644
--- a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
+++ b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
@@ -336,9 +336,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
336 336
337 private bool m_filterCollisions = true; 337 private bool m_filterCollisions = true;
338 338
339 private d.NearCallback nearCallback; 339 private SafeNativeMethods.NearCallback nearCallback;
340 public d.TriCallback triCallback;
341 public d.TriArrayCallback triArrayCallback;
342 340
343 /// <summary> 341 /// <summary>
344 /// Avatars in the physics scene. 342 /// Avatars in the physics scene.
@@ -368,7 +366,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
368 /// <summary> 366 /// <summary>
369 /// Keep record of contacts in the physics loop so that we can remove duplicates. 367 /// Keep record of contacts in the physics loop so that we can remove duplicates.
370 /// </summary> 368 /// </summary>
371 private readonly List<d.ContactGeom> _perloopContact = new List<d.ContactGeom>(); 369 private readonly List<SafeNativeMethods.ContactGeom> _perloopContact = new List<SafeNativeMethods.ContactGeom>();
372 370
373 /// <summary> 371 /// <summary>
374 /// A dictionary of actors that should receive collision events. 372 /// A dictionary of actors that should receive collision events.
@@ -409,7 +407,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
409 private bool m_NINJA_physics_joints_enabled = false; 407 private bool m_NINJA_physics_joints_enabled = false;
410 //private Dictionary<String, IntPtr> jointpart_name_map = new Dictionary<String,IntPtr>(); 408 //private Dictionary<String, IntPtr> jointpart_name_map = new Dictionary<String,IntPtr>();
411 private readonly Dictionary<String, List<PhysicsJoint>> joints_connecting_actor = new Dictionary<String, List<PhysicsJoint>>(); 409 private readonly Dictionary<String, List<PhysicsJoint>> joints_connecting_actor = new Dictionary<String, List<PhysicsJoint>>();
412 private d.ContactGeom[] contacts; 410 private SafeNativeMethods.ContactGeom[] contacts;
413 411
414 /// <summary> 412 /// <summary>
415 /// Lock only briefly. accessed by external code (to request new joints) and by OdeScene.Simulate() to move those joints into pending/active 413 /// Lock only briefly. accessed by external code (to request new joints) and by OdeScene.Simulate() to move those joints into pending/active
@@ -437,12 +435,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
437 private readonly DoubleDictionary<Vector3, IntPtr, IntPtr> RegionTerrain = new DoubleDictionary<Vector3, IntPtr, IntPtr>(); 435 private readonly DoubleDictionary<Vector3, IntPtr, IntPtr> RegionTerrain = new DoubleDictionary<Vector3, IntPtr, IntPtr>();
438 private readonly Dictionary<IntPtr,float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>(); 436 private readonly Dictionary<IntPtr,float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>();
439 437
440 private d.Contact contact; 438 private SafeNativeMethods.Contact contact;
441 private d.Contact TerrainContact; 439 private SafeNativeMethods.Contact TerrainContact;
442 private d.Contact AvatarMovementprimContact; 440 private SafeNativeMethods.Contact AvatarMovementprimContact;
443 private d.Contact AvatarMovementTerrainContact; 441 private SafeNativeMethods.Contact AvatarMovementTerrainContact;
444 private d.Contact WaterContact; 442 private SafeNativeMethods.Contact WaterContact;
445 private d.Contact[,] m_materialContacts; 443 private SafeNativeMethods.Contact[,] m_materialContacts;
446 444
447 private int m_physicsiterations = 10; 445 private int m_physicsiterations = 10;
448 private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag 446 private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag
@@ -480,8 +478,8 @@ namespace OpenSim.Region.PhysicsModule.ODE
480 private bool avplanted = false; 478 private bool avplanted = false;
481 private bool av_av_collisions_off = false; 479 private bool av_av_collisions_off = false;
482 480
483 public d.Vector3 xyz = new d.Vector3(128.1640f, 128.3079f, 25.7600f); 481 internal SafeNativeMethods.Vector3 xyz = new SafeNativeMethods.Vector3(128.1640f, 128.3079f, 25.7600f);
484 public d.Vector3 hpr = new d.Vector3(125.5000f, -17.0000f, 0.0000f); 482 internal SafeNativeMethods.Vector3 hpr = new SafeNativeMethods.Vector3(125.5000f, -17.0000f, 0.0000f);
485 483
486 private volatile int m_global_contactcount = 0; 484 private volatile int m_global_contactcount = 0;
487 485
@@ -544,12 +542,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
544 m_rayCastManager = new ODERayCastRequestManager(this); 542 m_rayCastManager = new ODERayCastRequestManager(this);
545 543
546 // Create the world and the first space 544 // Create the world and the first space
547 world = d.WorldCreate(); 545 world = SafeNativeMethods.WorldCreate();
548 space = d.HashSpaceCreate(IntPtr.Zero); 546 space = SafeNativeMethods.HashSpaceCreate(IntPtr.Zero);
547 contactgroup = SafeNativeMethods.JointGroupCreate(0);
549 548
550 contactgroup = d.JointGroupCreate(0); 549 SafeNativeMethods.WorldSetAutoDisableFlag(world, false);
551
552 d.WorldSetAutoDisableFlag(world, false);
553 } 550 }
554 551
555 // Initialize from configs 552 // Initialize from configs
@@ -651,7 +648,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
651 } 648 }
652 } 649 }
653 650
654 contacts = new d.ContactGeom[contactsPerCollision]; 651 contacts = new SafeNativeMethods.ContactGeom[contactsPerCollision];
655 652
656 spacesPerMeterX = 1.0f / metersInSpace; 653 spacesPerMeterX = 1.0f / metersInSpace;
657 spacesPerMeterY = 1.0f / metersInSpace; 654 spacesPerMeterY = 1.0f / metersInSpace;
@@ -680,7 +677,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
680 // Centeral contact friction and bounce 677 // Centeral contact friction and bounce
681 // ckrinke 11/10/08 Enabling soft_erp but not soft_cfm until I figure out why 678 // ckrinke 11/10/08 Enabling soft_erp but not soft_cfm until I figure out why
682 // an avatar falls through in Z but not in X or Y when walking on a prim. 679 // an avatar falls through in Z but not in X or Y when walking on a prim.
683 contact.surface.mode |= d.ContactFlags.SoftERP; 680 contact.surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
684 contact.surface.mu = nmAvatarObjectContactFriction; 681 contact.surface.mu = nmAvatarObjectContactFriction;
685 contact.surface.bounce = nmAvatarObjectContactBounce; 682 contact.surface.bounce = nmAvatarObjectContactBounce;
686 contact.surface.soft_cfm = 0.010f; 683 contact.surface.soft_cfm = 0.010f;
@@ -689,12 +686,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
689 // Terrain contact friction and Bounce 686 // Terrain contact friction and Bounce
690 // This is the *non* moving version. Use this when an avatar 687 // This is the *non* moving version. Use this when an avatar
691 // isn't moving to keep it in place better 688 // isn't moving to keep it in place better
692 TerrainContact.surface.mode |= d.ContactFlags.SoftERP; 689 TerrainContact.surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
693 TerrainContact.surface.mu = nmTerrainContactFriction; 690 TerrainContact.surface.mu = nmTerrainContactFriction;
694 TerrainContact.surface.bounce = nmTerrainContactBounce; 691 TerrainContact.surface.bounce = nmTerrainContactBounce;
695 TerrainContact.surface.soft_erp = nmTerrainContactERP; 692 TerrainContact.surface.soft_erp = nmTerrainContactERP;
696 693
697 WaterContact.surface.mode |= (d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM); 694 WaterContact.surface.mode |= (SafeNativeMethods.ContactFlags.SoftERP | SafeNativeMethods.ContactFlags.SoftCFM);
698 WaterContact.surface.mu = 0f; // No friction 695 WaterContact.surface.mu = 0f; // No friction
699 WaterContact.surface.bounce = 0.0f; // No bounce 696 WaterContact.surface.bounce = 0.0f; // No bounce
700 WaterContact.surface.soft_cfm = 0.010f; 697 WaterContact.surface.soft_cfm = 0.010f;
@@ -709,7 +706,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
709 706
710 // Terrain contact friction bounce and various error correcting calculations 707 // Terrain contact friction bounce and various error correcting calculations
711 // Use this when an avatar is in contact with the terrain and moving. 708 // Use this when an avatar is in contact with the terrain and moving.
712 AvatarMovementTerrainContact.surface.mode |= d.ContactFlags.SoftERP; 709 AvatarMovementTerrainContact.surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
713 AvatarMovementTerrainContact.surface.mu = mTerrainContactFriction; 710 AvatarMovementTerrainContact.surface.mu = mTerrainContactFriction;
714 AvatarMovementTerrainContact.surface.bounce = mTerrainContactBounce; 711 AvatarMovementTerrainContact.surface.bounce = mTerrainContactBounce;
715 AvatarMovementTerrainContact.surface.soft_erp = mTerrainContactERP; 712 AvatarMovementTerrainContact.surface.soft_erp = mTerrainContactERP;
@@ -731,38 +728,38 @@ namespace OpenSim.Region.PhysicsModule.ODE
731 Rubber = 6 728 Rubber = 6
732 */ 729 */
733 730
734 m_materialContacts = new d.Contact[7,2]; 731 m_materialContacts = new SafeNativeMethods.Contact[7,2];
735 732
736 m_materialContacts[(int)Material.Stone, 0] = new d.Contact(); 733 m_materialContacts[(int)Material.Stone, 0] = new SafeNativeMethods.Contact();
737 m_materialContacts[(int)Material.Stone, 0].surface.mode |= d.ContactFlags.SoftERP; 734 m_materialContacts[(int)Material.Stone, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
738 m_materialContacts[(int)Material.Stone, 0].surface.mu = nmAvatarObjectContactFriction; 735 m_materialContacts[(int)Material.Stone, 0].surface.mu = nmAvatarObjectContactFriction;
739 m_materialContacts[(int)Material.Stone, 0].surface.bounce = nmAvatarObjectContactBounce; 736 m_materialContacts[(int)Material.Stone, 0].surface.bounce = nmAvatarObjectContactBounce;
740 m_materialContacts[(int)Material.Stone, 0].surface.soft_cfm = 0.010f; 737 m_materialContacts[(int)Material.Stone, 0].surface.soft_cfm = 0.010f;
741 m_materialContacts[(int)Material.Stone, 0].surface.soft_erp = 0.010f; 738 m_materialContacts[(int)Material.Stone, 0].surface.soft_erp = 0.010f;
742 739
743 m_materialContacts[(int)Material.Stone, 1] = new d.Contact(); 740 m_materialContacts[(int)Material.Stone, 1] = new SafeNativeMethods.Contact();
744 m_materialContacts[(int)Material.Stone, 1].surface.mode |= d.ContactFlags.SoftERP; 741 m_materialContacts[(int)Material.Stone, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
745 m_materialContacts[(int)Material.Stone, 1].surface.mu = mAvatarObjectContactFriction; 742 m_materialContacts[(int)Material.Stone, 1].surface.mu = mAvatarObjectContactFriction;
746 m_materialContacts[(int)Material.Stone, 1].surface.bounce = mAvatarObjectContactBounce; 743 m_materialContacts[(int)Material.Stone, 1].surface.bounce = mAvatarObjectContactBounce;
747 m_materialContacts[(int)Material.Stone, 1].surface.soft_cfm = 0.010f; 744 m_materialContacts[(int)Material.Stone, 1].surface.soft_cfm = 0.010f;
748 m_materialContacts[(int)Material.Stone, 1].surface.soft_erp = 0.010f; 745 m_materialContacts[(int)Material.Stone, 1].surface.soft_erp = 0.010f;
749 746
750 m_materialContacts[(int)Material.Metal, 0] = new d.Contact(); 747 m_materialContacts[(int)Material.Metal, 0] = new SafeNativeMethods.Contact();
751 m_materialContacts[(int)Material.Metal, 0].surface.mode |= d.ContactFlags.SoftERP; 748 m_materialContacts[(int)Material.Metal, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
752 m_materialContacts[(int)Material.Metal, 0].surface.mu = nmAvatarObjectContactFriction; 749 m_materialContacts[(int)Material.Metal, 0].surface.mu = nmAvatarObjectContactFriction;
753 m_materialContacts[(int)Material.Metal, 0].surface.bounce = nmAvatarObjectContactBounce; 750 m_materialContacts[(int)Material.Metal, 0].surface.bounce = nmAvatarObjectContactBounce;
754 m_materialContacts[(int)Material.Metal, 0].surface.soft_cfm = 0.010f; 751 m_materialContacts[(int)Material.Metal, 0].surface.soft_cfm = 0.010f;
755 m_materialContacts[(int)Material.Metal, 0].surface.soft_erp = 0.010f; 752 m_materialContacts[(int)Material.Metal, 0].surface.soft_erp = 0.010f;
756 753
757 m_materialContacts[(int)Material.Metal, 1] = new d.Contact(); 754 m_materialContacts[(int)Material.Metal, 1] = new SafeNativeMethods.Contact();
758 m_materialContacts[(int)Material.Metal, 1].surface.mode |= d.ContactFlags.SoftERP; 755 m_materialContacts[(int)Material.Metal, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
759 m_materialContacts[(int)Material.Metal, 1].surface.mu = mAvatarObjectContactFriction; 756 m_materialContacts[(int)Material.Metal, 1].surface.mu = mAvatarObjectContactFriction;
760 m_materialContacts[(int)Material.Metal, 1].surface.bounce = mAvatarObjectContactBounce; 757 m_materialContacts[(int)Material.Metal, 1].surface.bounce = mAvatarObjectContactBounce;
761 m_materialContacts[(int)Material.Metal, 1].surface.soft_cfm = 0.010f; 758 m_materialContacts[(int)Material.Metal, 1].surface.soft_cfm = 0.010f;
762 m_materialContacts[(int)Material.Metal, 1].surface.soft_erp = 0.010f; 759 m_materialContacts[(int)Material.Metal, 1].surface.soft_erp = 0.010f;
763 760
764 m_materialContacts[(int)Material.Glass, 0] = new d.Contact(); 761 m_materialContacts[(int)Material.Glass, 0] = new SafeNativeMethods.Contact();
765 m_materialContacts[(int)Material.Glass, 0].surface.mode |= d.ContactFlags.SoftERP; 762 m_materialContacts[(int)Material.Glass, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
766 m_materialContacts[(int)Material.Glass, 0].surface.mu = 1f; 763 m_materialContacts[(int)Material.Glass, 0].surface.mu = 1f;
767 m_materialContacts[(int)Material.Glass, 0].surface.bounce = 0.5f; 764 m_materialContacts[(int)Material.Glass, 0].surface.bounce = 0.5f;
768 m_materialContacts[(int)Material.Glass, 0].surface.soft_cfm = 0.010f; 765 m_materialContacts[(int)Material.Glass, 0].surface.soft_cfm = 0.010f;
@@ -775,83 +772,83 @@ namespace OpenSim.Region.PhysicsModule.ODE
775 private float mAvatarObjectContactFriction = 75f; 772 private float mAvatarObjectContactFriction = 75f;
776 private float mAvatarObjectContactBounce = 0.1f; 773 private float mAvatarObjectContactBounce = 0.1f;
777 */ 774 */
778 m_materialContacts[(int)Material.Glass, 1] = new d.Contact(); 775 m_materialContacts[(int)Material.Glass, 1] = new SafeNativeMethods.Contact();
779 m_materialContacts[(int)Material.Glass, 1].surface.mode |= d.ContactFlags.SoftERP; 776 m_materialContacts[(int)Material.Glass, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
780 m_materialContacts[(int)Material.Glass, 1].surface.mu = 1f; 777 m_materialContacts[(int)Material.Glass, 1].surface.mu = 1f;
781 m_materialContacts[(int)Material.Glass, 1].surface.bounce = 0.5f; 778 m_materialContacts[(int)Material.Glass, 1].surface.bounce = 0.5f;
782 m_materialContacts[(int)Material.Glass, 1].surface.soft_cfm = 0.010f; 779 m_materialContacts[(int)Material.Glass, 1].surface.soft_cfm = 0.010f;
783 m_materialContacts[(int)Material.Glass, 1].surface.soft_erp = 0.010f; 780 m_materialContacts[(int)Material.Glass, 1].surface.soft_erp = 0.010f;
784 781
785 m_materialContacts[(int)Material.Wood, 0] = new d.Contact(); 782 m_materialContacts[(int)Material.Wood, 0] = new SafeNativeMethods.Contact();
786 m_materialContacts[(int)Material.Wood, 0].surface.mode |= d.ContactFlags.SoftERP; 783 m_materialContacts[(int)Material.Wood, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
787 m_materialContacts[(int)Material.Wood, 0].surface.mu = nmAvatarObjectContactFriction; 784 m_materialContacts[(int)Material.Wood, 0].surface.mu = nmAvatarObjectContactFriction;
788 m_materialContacts[(int)Material.Wood, 0].surface.bounce = nmAvatarObjectContactBounce; 785 m_materialContacts[(int)Material.Wood, 0].surface.bounce = nmAvatarObjectContactBounce;
789 m_materialContacts[(int)Material.Wood, 0].surface.soft_cfm = 0.010f; 786 m_materialContacts[(int)Material.Wood, 0].surface.soft_cfm = 0.010f;
790 m_materialContacts[(int)Material.Wood, 0].surface.soft_erp = 0.010f; 787 m_materialContacts[(int)Material.Wood, 0].surface.soft_erp = 0.010f;
791 788
792 m_materialContacts[(int)Material.Wood, 1] = new d.Contact(); 789 m_materialContacts[(int)Material.Wood, 1] = new SafeNativeMethods.Contact();
793 m_materialContacts[(int)Material.Wood, 1].surface.mode |= d.ContactFlags.SoftERP; 790 m_materialContacts[(int)Material.Wood, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
794 m_materialContacts[(int)Material.Wood, 1].surface.mu = mAvatarObjectContactFriction; 791 m_materialContacts[(int)Material.Wood, 1].surface.mu = mAvatarObjectContactFriction;
795 m_materialContacts[(int)Material.Wood, 1].surface.bounce = mAvatarObjectContactBounce; 792 m_materialContacts[(int)Material.Wood, 1].surface.bounce = mAvatarObjectContactBounce;
796 m_materialContacts[(int)Material.Wood, 1].surface.soft_cfm = 0.010f; 793 m_materialContacts[(int)Material.Wood, 1].surface.soft_cfm = 0.010f;
797 m_materialContacts[(int)Material.Wood, 1].surface.soft_erp = 0.010f; 794 m_materialContacts[(int)Material.Wood, 1].surface.soft_erp = 0.010f;
798 795
799 m_materialContacts[(int)Material.Flesh, 0] = new d.Contact(); 796 m_materialContacts[(int)Material.Flesh, 0] = new SafeNativeMethods.Contact();
800 m_materialContacts[(int)Material.Flesh, 0].surface.mode |= d.ContactFlags.SoftERP; 797 m_materialContacts[(int)Material.Flesh, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
801 m_materialContacts[(int)Material.Flesh, 0].surface.mu = nmAvatarObjectContactFriction; 798 m_materialContacts[(int)Material.Flesh, 0].surface.mu = nmAvatarObjectContactFriction;
802 m_materialContacts[(int)Material.Flesh, 0].surface.bounce = nmAvatarObjectContactBounce; 799 m_materialContacts[(int)Material.Flesh, 0].surface.bounce = nmAvatarObjectContactBounce;
803 m_materialContacts[(int)Material.Flesh, 0].surface.soft_cfm = 0.010f; 800 m_materialContacts[(int)Material.Flesh, 0].surface.soft_cfm = 0.010f;
804 m_materialContacts[(int)Material.Flesh, 0].surface.soft_erp = 0.010f; 801 m_materialContacts[(int)Material.Flesh, 0].surface.soft_erp = 0.010f;
805 802
806 m_materialContacts[(int)Material.Flesh, 1] = new d.Contact(); 803 m_materialContacts[(int)Material.Flesh, 1] = new SafeNativeMethods.Contact();
807 m_materialContacts[(int)Material.Flesh, 1].surface.mode |= d.ContactFlags.SoftERP; 804 m_materialContacts[(int)Material.Flesh, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
808 m_materialContacts[(int)Material.Flesh, 1].surface.mu = mAvatarObjectContactFriction; 805 m_materialContacts[(int)Material.Flesh, 1].surface.mu = mAvatarObjectContactFriction;
809 m_materialContacts[(int)Material.Flesh, 1].surface.bounce = mAvatarObjectContactBounce; 806 m_materialContacts[(int)Material.Flesh, 1].surface.bounce = mAvatarObjectContactBounce;
810 m_materialContacts[(int)Material.Flesh, 1].surface.soft_cfm = 0.010f; 807 m_materialContacts[(int)Material.Flesh, 1].surface.soft_cfm = 0.010f;
811 m_materialContacts[(int)Material.Flesh, 1].surface.soft_erp = 0.010f; 808 m_materialContacts[(int)Material.Flesh, 1].surface.soft_erp = 0.010f;
812 809
813 m_materialContacts[(int)Material.Plastic, 0] = new d.Contact(); 810 m_materialContacts[(int)Material.Plastic, 0] = new SafeNativeMethods.Contact();
814 m_materialContacts[(int)Material.Plastic, 0].surface.mode |= d.ContactFlags.SoftERP; 811 m_materialContacts[(int)Material.Plastic, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
815 m_materialContacts[(int)Material.Plastic, 0].surface.mu = nmAvatarObjectContactFriction; 812 m_materialContacts[(int)Material.Plastic, 0].surface.mu = nmAvatarObjectContactFriction;
816 m_materialContacts[(int)Material.Plastic, 0].surface.bounce = nmAvatarObjectContactBounce; 813 m_materialContacts[(int)Material.Plastic, 0].surface.bounce = nmAvatarObjectContactBounce;
817 m_materialContacts[(int)Material.Plastic, 0].surface.soft_cfm = 0.010f; 814 m_materialContacts[(int)Material.Plastic, 0].surface.soft_cfm = 0.010f;
818 m_materialContacts[(int)Material.Plastic, 0].surface.soft_erp = 0.010f; 815 m_materialContacts[(int)Material.Plastic, 0].surface.soft_erp = 0.010f;
819 816
820 m_materialContacts[(int)Material.Plastic, 1] = new d.Contact(); 817 m_materialContacts[(int)Material.Plastic, 1] = new SafeNativeMethods.Contact();
821 m_materialContacts[(int)Material.Plastic, 1].surface.mode |= d.ContactFlags.SoftERP; 818 m_materialContacts[(int)Material.Plastic, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
822 m_materialContacts[(int)Material.Plastic, 1].surface.mu = mAvatarObjectContactFriction; 819 m_materialContacts[(int)Material.Plastic, 1].surface.mu = mAvatarObjectContactFriction;
823 m_materialContacts[(int)Material.Plastic, 1].surface.bounce = mAvatarObjectContactBounce; 820 m_materialContacts[(int)Material.Plastic, 1].surface.bounce = mAvatarObjectContactBounce;
824 m_materialContacts[(int)Material.Plastic, 1].surface.soft_cfm = 0.010f; 821 m_materialContacts[(int)Material.Plastic, 1].surface.soft_cfm = 0.010f;
825 m_materialContacts[(int)Material.Plastic, 1].surface.soft_erp = 0.010f; 822 m_materialContacts[(int)Material.Plastic, 1].surface.soft_erp = 0.010f;
826 823
827 m_materialContacts[(int)Material.Rubber, 0] = new d.Contact(); 824 m_materialContacts[(int)Material.Rubber, 0] = new SafeNativeMethods.Contact();
828 m_materialContacts[(int)Material.Rubber, 0].surface.mode |= d.ContactFlags.SoftERP; 825 m_materialContacts[(int)Material.Rubber, 0].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
829 m_materialContacts[(int)Material.Rubber, 0].surface.mu = nmAvatarObjectContactFriction; 826 m_materialContacts[(int)Material.Rubber, 0].surface.mu = nmAvatarObjectContactFriction;
830 m_materialContacts[(int)Material.Rubber, 0].surface.bounce = nmAvatarObjectContactBounce; 827 m_materialContacts[(int)Material.Rubber, 0].surface.bounce = nmAvatarObjectContactBounce;
831 m_materialContacts[(int)Material.Rubber, 0].surface.soft_cfm = 0.010f; 828 m_materialContacts[(int)Material.Rubber, 0].surface.soft_cfm = 0.010f;
832 m_materialContacts[(int)Material.Rubber, 0].surface.soft_erp = 0.010f; 829 m_materialContacts[(int)Material.Rubber, 0].surface.soft_erp = 0.010f;
833 830
834 m_materialContacts[(int)Material.Rubber, 1] = new d.Contact(); 831 m_materialContacts[(int)Material.Rubber, 1] = new SafeNativeMethods.Contact();
835 m_materialContacts[(int)Material.Rubber, 1].surface.mode |= d.ContactFlags.SoftERP; 832 m_materialContacts[(int)Material.Rubber, 1].surface.mode |= SafeNativeMethods.ContactFlags.SoftERP;
836 m_materialContacts[(int)Material.Rubber, 1].surface.mu = mAvatarObjectContactFriction; 833 m_materialContacts[(int)Material.Rubber, 1].surface.mu = mAvatarObjectContactFriction;
837 m_materialContacts[(int)Material.Rubber, 1].surface.bounce = mAvatarObjectContactBounce; 834 m_materialContacts[(int)Material.Rubber, 1].surface.bounce = mAvatarObjectContactBounce;
838 m_materialContacts[(int)Material.Rubber, 1].surface.soft_cfm = 0.010f; 835 m_materialContacts[(int)Material.Rubber, 1].surface.soft_cfm = 0.010f;
839 m_materialContacts[(int)Material.Rubber, 1].surface.soft_erp = 0.010f; 836 m_materialContacts[(int)Material.Rubber, 1].surface.soft_erp = 0.010f;
840 837
841 d.HashSpaceSetLevels(space, HashspaceLow, HashspaceHigh); 838 SafeNativeMethods.HashSpaceSetLevels(space, HashspaceLow, HashspaceHigh);
842 839
843 // Set the gravity,, don't disable things automatically (we set it explicitly on some things) 840 // Set the gravity,, don't disable things automatically (we set it explicitly on some things)
844 841
845 d.WorldSetGravity(world, gravityx, gravityy, gravityz); 842 SafeNativeMethods.WorldSetGravity(world, gravityx, gravityy, gravityz);
846 d.WorldSetContactSurfaceLayer(world, contactsurfacelayer); 843 SafeNativeMethods.WorldSetContactSurfaceLayer(world, contactsurfacelayer);
847 844
848 d.WorldSetLinearDamping(world, 256f); 845 SafeNativeMethods.WorldSetLinearDamping(world, 256f);
849 d.WorldSetAngularDamping(world, 256f); 846 SafeNativeMethods.WorldSetAngularDamping(world, 256f);
850 d.WorldSetAngularDampingThreshold(world, 256f); 847 SafeNativeMethods.WorldSetAngularDampingThreshold(world, 256f);
851 d.WorldSetLinearDampingThreshold(world, 256f); 848 SafeNativeMethods.WorldSetLinearDampingThreshold(world, 256f);
852 d.WorldSetMaxAngularSpeed(world, 256f); 849 SafeNativeMethods.WorldSetMaxAngularSpeed(world, 256f);
853 850
854 d.WorldSetQuickStepNumIterations(world, m_physicsiterations); 851 SafeNativeMethods.WorldSetQuickStepNumIterations(world, m_physicsiterations);
855 //d.WorldSetContactMaxCorrectingVel(world, 1000.0f); 852 //d.WorldSetContactMaxCorrectingVel(world, 1000.0f);
856 853
857 for (int i = 0; i < staticPrimspace.GetLength(0); i++) 854 for (int i = 0; i < staticPrimspace.GetLength(0); i++)
@@ -877,7 +874,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
877 /// <param name='contactsArray'></param> 874 /// <param name='contactsArray'></param>
878 /// <param name='contactGeomSize'></param> 875 /// <param name='contactGeomSize'></param>
879 private int CollideGeoms( 876 private int CollideGeoms(
880 IntPtr geom1, IntPtr geom2, int maxContacts, d.ContactGeom[] contactsArray, int contactGeomSize) 877 IntPtr geom1, IntPtr geom2, int maxContacts, SafeNativeMethods.ContactGeom[] contactsArray, int contactGeomSize)
881 { 878 {
882 int count; 879 int count;
883 880
@@ -887,7 +884,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
887 if (CollectStats) 884 if (CollectStats)
888 m_nativeCollisionStartTick = Util.EnvironmentTickCount(); 885 m_nativeCollisionStartTick = Util.EnvironmentTickCount();
889 886
890 count = d.Collide(geom1, geom2, maxContacts, contactsArray, contactGeomSize); 887 count = SafeNativeMethods.Collide(geom1, geom2, maxContacts, contactsArray, contactGeomSize);
891 } 888 }
892 889
893 // We do this outside the lock so that any waiting threads aren't held up, though the effect is probably 890 // We do this outside the lock so that any waiting threads aren't held up, though the effect is probably
@@ -913,7 +910,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
913 m_nativeCollisionStartTick = Util.EnvironmentTickCount(); 910 m_nativeCollisionStartTick = Util.EnvironmentTickCount();
914 } 911 }
915 912
916 d.SpaceCollide2(space1, space2, data, nearCallback); 913 SafeNativeMethods.SpaceCollide2(space1, space2, data, nearCallback);
917 914
918 if (CollectStats && m_inCollisionTiming) 915 if (CollectStats && m_inCollisionTiming)
919 { 916 {
@@ -944,7 +941,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
944 // Test if we're colliding a geom with a space. 941 // Test if we're colliding a geom with a space.
945 // If so we have to drill down into the space recursively 942 // If so we have to drill down into the space recursively
946 943
947 if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2)) 944 if (SafeNativeMethods.GeomIsSpace(g1) || SafeNativeMethods.GeomIsSpace(g2))
948 { 945 {
949 if (g1 == IntPtr.Zero || g2 == IntPtr.Zero) 946 if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
950 return; 947 return;
@@ -973,8 +970,8 @@ namespace OpenSim.Region.PhysicsModule.ODE
973 if (g1 == IntPtr.Zero || g2 == IntPtr.Zero) 970 if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
974 return; 971 return;
975 972
976 IntPtr b1 = d.GeomGetBody(g1); 973 IntPtr b1 = SafeNativeMethods.GeomGetBody(g1);
977 IntPtr b2 = d.GeomGetBody(g2); 974 IntPtr b2 = SafeNativeMethods.GeomGetBody(g2);
978 975
979 // d.GeomClassID id = d.GeomGetClass(g1); 976 // d.GeomClassID id = d.GeomGetClass(g1);
980 977
@@ -1001,10 +998,10 @@ namespace OpenSim.Region.PhysicsModule.ODE
1001 if (g1 == g2) 998 if (g1 == g2)
1002 return; // Can't collide with yourself 999 return; // Can't collide with yourself
1003 1000
1004 if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) 1001 if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && SafeNativeMethods.AreConnectedExcluding(b1, b2, SafeNativeMethods.JointType.Contact))
1005 return; 1002 return;
1006 1003
1007 count = CollideGeoms(g1, g2, contacts.Length, contacts, d.ContactGeom.unmanagedSizeOf); 1004 count = CollideGeoms(g1, g2, contacts.Length, contacts, SafeNativeMethods.ContactGeom.unmanagedSizeOf);
1008 1005
1009 // All code after this is only relevant if we have any collisions 1006 // All code after this is only relevant if we have any collisions
1010 if (count <= 0) 1007 if (count <= 0)
@@ -1052,7 +1049,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1052 1049
1053 for (int i = 0; i < count; i++) 1050 for (int i = 0; i < count; i++)
1054 { 1051 {
1055 d.ContactGeom curContact = contacts[i]; 1052 SafeNativeMethods.ContactGeom curContact = contacts[i];
1056 1053
1057 if (curContact.depth > maxDepthContact.PenetrationDepth) 1054 if (curContact.depth > maxDepthContact.PenetrationDepth)
1058 { 1055 {
@@ -1129,7 +1126,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1129 curContact.depth = 0.00000003f; 1126 curContact.depth = 0.00000003f;
1130 p2.Velocity = p2.Velocity + new Vector3(0f, 0f, 0.5f); 1127 p2.Velocity = p2.Velocity + new Vector3(0f, 0f, 0.5f);
1131 curContact.pos = 1128 curContact.pos =
1132 new d.Vector3(curContact.pos.X + (p1.Size.X/2), 1129 new SafeNativeMethods.Vector3(curContact.pos.X + (p1.Size.X/2),
1133 curContact.pos.Y + (p1.Size.Y/2), 1130 curContact.pos.Y + (p1.Size.Y/2),
1134 curContact.pos.Z + (p1.Size.Z/2)); 1131 curContact.pos.Z + (p1.Size.Z/2));
1135 character.SetPidStatus(true); 1132 character.SetPidStatus(true);
@@ -1146,7 +1143,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1146 curContact.depth = 0.00000003f; 1143 curContact.depth = 0.00000003f;
1147 p1.Velocity = p1.Velocity + new Vector3(0f, 0f, 0.5f); 1144 p1.Velocity = p1.Velocity + new Vector3(0f, 0f, 0.5f);
1148 curContact.pos = 1145 curContact.pos =
1149 new d.Vector3(curContact.pos.X + (p1.Size.X/2), 1146 new SafeNativeMethods.Vector3(curContact.pos.X + (p1.Size.X/2),
1150 curContact.pos.Y + (p1.Size.Y/2), 1147 curContact.pos.Y + (p1.Size.Y/2),
1151 curContact.pos.Z + (p1.Size.Z/2)); 1148 curContact.pos.Z + (p1.Size.Z/2));
1152 character.SetPidStatus(true); 1149 character.SetPidStatus(true);
@@ -1198,7 +1195,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1198 1195
1199 if (m_global_contactcount < maxContactsbeforedeath) 1196 if (m_global_contactcount < maxContactsbeforedeath)
1200 { 1197 {
1201 joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementTerrainContact); 1198 joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref AvatarMovementTerrainContact);
1202 m_global_contactcount++; 1199 m_global_contactcount++;
1203 } 1200 }
1204 } 1201 }
@@ -1212,7 +1209,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1212 1209
1213 if (m_global_contactcount < maxContactsbeforedeath) 1210 if (m_global_contactcount < maxContactsbeforedeath)
1214 { 1211 {
1215 joint = d.JointCreateContact(world, contactgroup, ref TerrainContact); 1212 joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref TerrainContact);
1216 m_global_contactcount++; 1213 m_global_contactcount++;
1217 } 1214 }
1218 } 1215 }
@@ -1247,7 +1244,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1247 1244
1248 if (m_global_contactcount < maxContactsbeforedeath) 1245 if (m_global_contactcount < maxContactsbeforedeath)
1249 { 1246 {
1250 joint = d.JointCreateContact(world, contactgroup, ref m_materialContacts[material, movintYN]); 1247 joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref m_materialContacts[material, movintYN]);
1251 m_global_contactcount++; 1248 m_global_contactcount++;
1252 } 1249 }
1253 } 1250 }
@@ -1273,7 +1270,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1273 1270
1274 if (m_global_contactcount < maxContactsbeforedeath) 1271 if (m_global_contactcount < maxContactsbeforedeath)
1275 { 1272 {
1276 joint = d.JointCreateContact(world, contactgroup, ref m_materialContacts[material, movintYN]); 1273 joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref m_materialContacts[material, movintYN]);
1277 m_global_contactcount++; 1274 m_global_contactcount++;
1278 } 1275 }
1279 } 1276 }
@@ -1307,7 +1304,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1307 1304
1308 if (m_global_contactcount < maxContactsbeforedeath) 1305 if (m_global_contactcount < maxContactsbeforedeath)
1309 { 1306 {
1310 joint = d.JointCreateContact(world, contactgroup, ref WaterContact); 1307 joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref WaterContact);
1311 m_global_contactcount++; 1308 m_global_contactcount++;
1312 } 1309 }
1313 //m_log.Info("[PHYSICS]: Prim Water Contact" + contact.depth); 1310 //m_log.Info("[PHYSICS]: Prim Water Contact" + contact.depth);
@@ -1324,7 +1321,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1324 1321
1325 if (m_global_contactcount < maxContactsbeforedeath) 1322 if (m_global_contactcount < maxContactsbeforedeath)
1326 { 1323 {
1327 joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementprimContact); 1324 joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref AvatarMovementprimContact);
1328 m_global_contactcount++; 1325 m_global_contactcount++;
1329 } 1326 }
1330 } 1327 }
@@ -1335,7 +1332,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1335 1332
1336 if (m_global_contactcount < maxContactsbeforedeath) 1333 if (m_global_contactcount < maxContactsbeforedeath)
1337 { 1334 {
1338 joint = d.JointCreateContact(world, contactgroup, ref contact); 1335 joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref contact);
1339 m_global_contactcount++; 1336 m_global_contactcount++;
1340 } 1337 }
1341 } 1338 }
@@ -1356,7 +1353,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1356 1353
1357 if (m_global_contactcount < maxContactsbeforedeath) 1354 if (m_global_contactcount < maxContactsbeforedeath)
1358 { 1355 {
1359 joint = d.JointCreateContact(world, contactgroup, ref m_materialContacts[material, 0]); 1356 joint = SafeNativeMethods.JointCreateContact(world, contactgroup, ref m_materialContacts[material, 0]);
1360 m_global_contactcount++; 1357 m_global_contactcount++;
1361 } 1358 }
1362 } 1359 }
@@ -1364,7 +1361,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1364 1361
1365 if (m_global_contactcount < maxContactsbeforedeath && joint != IntPtr.Zero) // stack collide! 1362 if (m_global_contactcount < maxContactsbeforedeath && joint != IntPtr.Zero) // stack collide!
1366 { 1363 {
1367 d.JointAttach(joint, b1, b2); 1364 SafeNativeMethods.JointAttach(joint, b1, b2);
1368 m_global_contactcount++; 1365 m_global_contactcount++;
1369 } 1366 }
1370 } 1367 }
@@ -1384,7 +1381,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1384 } 1381 }
1385 } 1382 }
1386 1383
1387 private bool checkDupe(d.ContactGeom contactGeom, int atype) 1384 private bool checkDupe(SafeNativeMethods.ContactGeom contactGeom, int atype)
1388 { 1385 {
1389 if (!m_filterCollisions) 1386 if (!m_filterCollisions)
1390 return false; 1387 return false;
@@ -1393,7 +1390,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1393 1390
1394 ActorTypes at = (ActorTypes)atype; 1391 ActorTypes at = (ActorTypes)atype;
1395 1392
1396 foreach (d.ContactGeom contact in _perloopContact) 1393 foreach (SafeNativeMethods.ContactGeom contact in _perloopContact)
1397 { 1394 {
1398 //if ((contact.g1 == contactGeom.g1 && contact.g2 == contactGeom.g2)) 1395 //if ((contact.g1 == contactGeom.g1 && contact.g2 == contactGeom.g2))
1399 //{ 1396 //{
@@ -1580,7 +1577,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1580 List<OdePrim> removeprims = null; 1577 List<OdePrim> removeprims = null;
1581 foreach (OdePrim chr in _activeprims) 1578 foreach (OdePrim chr in _activeprims)
1582 { 1579 {
1583 if (chr.Body != IntPtr.Zero && d.BodyIsEnabled(chr.Body) && (!chr.m_disabled)) 1580 if (chr.Body != IntPtr.Zero && SafeNativeMethods.BodyIsEnabled(chr.Body) && (!chr.m_disabled))
1584 { 1581 {
1585 try 1582 try
1586 { 1583 {
@@ -1706,7 +1703,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1706 1703
1707 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying) 1704 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
1708 { 1705 {
1709 d.AllocateODEDataForThread(0); 1706 SafeNativeMethods.AllocateODEDataForThread(0);
1710 1707
1711 OdeCharacter newAv 1708 OdeCharacter newAv
1712 = new OdeCharacter( 1709 = new OdeCharacter(
@@ -1729,7 +1726,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1729 1726
1730 lock (OdeLock) 1727 lock (OdeLock)
1731 { 1728 {
1732 d.AllocateODEDataForThread(0); 1729 SafeNativeMethods.AllocateODEDataForThread(0);
1733 1730
1734 ((OdeCharacter) actor).Destroy(); 1731 ((OdeCharacter) actor).Destroy();
1735 } 1732 }
@@ -1786,7 +1783,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1786 OdePrim newPrim; 1783 OdePrim newPrim;
1787 lock (OdeLock) 1784 lock (OdeLock)
1788 { 1785 {
1789 d.AllocateODEDataForThread(0); 1786 SafeNativeMethods.AllocateODEDataForThread(0);
1790 newPrim = new OdePrim(name, this, pos, siz, rot, pbs, isphysical); 1787 newPrim = new OdePrim(name, this, pos, siz, rot, pbs, isphysical);
1791 1788
1792 lock (_prims) 1789 lock (_prims)
@@ -1950,7 +1947,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
1950 DoJointDeactivated(joint); 1947 DoJointDeactivated(joint);
1951 if (joint.jointID != IntPtr.Zero) 1948 if (joint.jointID != IntPtr.Zero)
1952 { 1949 {
1953 d.JointDestroy(joint.jointID); 1950 SafeNativeMethods.JointDestroy(joint.jointID);
1954 joint.jointID = IntPtr.Zero; 1951 joint.jointID = IntPtr.Zero;
1955 //DoJointErrorMessage(joint, "successfully destroyed joint " + jointName); 1952 //DoJointErrorMessage(joint, "successfully destroyed joint " + jointName);
1956 } 1953 }
@@ -2115,7 +2112,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
2115 public override Vector3 GetJointAnchor(PhysicsJoint joint) 2112 public override Vector3 GetJointAnchor(PhysicsJoint joint)
2116 { 2113 {
2117 Debug.Assert(joint.IsInPhysicsEngine); 2114 Debug.Assert(joint.IsInPhysicsEngine);
2118 d.Vector3 pos = new d.Vector3(); 2115 SafeNativeMethods.Vector3 pos = new SafeNativeMethods.Vector3();
2119 2116
2120 if (!(joint is OdePhysicsJoint)) 2117 if (!(joint is OdePhysicsJoint))
2121 { 2118 {
@@ -2127,10 +2124,10 @@ namespace OpenSim.Region.PhysicsModule.ODE
2127 switch (odeJoint.Type) 2124 switch (odeJoint.Type)
2128 { 2125 {
2129 case PhysicsJointType.Ball: 2126 case PhysicsJointType.Ball:
2130 d.JointGetBallAnchor(odeJoint.jointID, out pos); 2127 SafeNativeMethods.JointGetBallAnchor(odeJoint.jointID, out pos);
2131 break; 2128 break;
2132 case PhysicsJointType.Hinge: 2129 case PhysicsJointType.Hinge:
2133 d.JointGetHingeAnchor(odeJoint.jointID, out pos); 2130 SafeNativeMethods.JointGetHingeAnchor(odeJoint.jointID, out pos);
2134 break; 2131 break;
2135 } 2132 }
2136 } 2133 }
@@ -2151,7 +2148,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
2151 public override Vector3 GetJointAxis(PhysicsJoint joint) 2148 public override Vector3 GetJointAxis(PhysicsJoint joint)
2152 { 2149 {
2153 Debug.Assert(joint.IsInPhysicsEngine); 2150 Debug.Assert(joint.IsInPhysicsEngine);
2154 d.Vector3 axis = new d.Vector3(); 2151 SafeNativeMethods.Vector3 axis = new SafeNativeMethods.Vector3();
2155 2152
2156 if (!(joint is OdePhysicsJoint)) 2153 if (!(joint is OdePhysicsJoint))
2157 { 2154 {
@@ -2166,7 +2163,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
2166 DoJointErrorMessage(joint, "warning - axis requested for ball joint: " + joint.ObjectNameInScene); 2163 DoJointErrorMessage(joint, "warning - axis requested for ball joint: " + joint.ObjectNameInScene);
2167 break; 2164 break;
2168 case PhysicsJointType.Hinge: 2165 case PhysicsJointType.Hinge:
2169 d.JointGetHingeAxis(odeJoint.jointID, out axis); 2166 SafeNativeMethods.JointGetHingeAxis(odeJoint.jointID, out axis);
2170 break; 2167 break;
2171 } 2168 }
2172 } 2169 }
@@ -2299,12 +2296,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
2299 //{ 2296 //{
2300 //int adfadf = 0; 2297 //int adfadf = 0;
2301 //} 2298 //}
2302 if (d.SpaceQuery(currentspace, geom) && currentspace != IntPtr.Zero) 2299 if (SafeNativeMethods.SpaceQuery(currentspace, geom) && currentspace != IntPtr.Zero)
2303 { 2300 {
2304 if (d.GeomIsSpace(currentspace)) 2301 if (SafeNativeMethods.GeomIsSpace(currentspace))
2305 { 2302 {
2306// waitForSpaceUnlock(currentspace); 2303// waitForSpaceUnlock(currentspace);
2307 d.SpaceRemove(currentspace, geom); 2304 SafeNativeMethods.SpaceRemove(currentspace, geom);
2308 } 2305 }
2309 else 2306 else
2310 { 2307 {
@@ -2314,13 +2311,13 @@ namespace OpenSim.Region.PhysicsModule.ODE
2314 } 2311 }
2315 else 2312 else
2316 { 2313 {
2317 IntPtr sGeomIsIn = d.GeomGetSpace(geom); 2314 IntPtr sGeomIsIn = SafeNativeMethods.GeomGetSpace(geom);
2318 if (sGeomIsIn != IntPtr.Zero) 2315 if (sGeomIsIn != IntPtr.Zero)
2319 { 2316 {
2320 if (d.GeomIsSpace(currentspace)) 2317 if (SafeNativeMethods.GeomIsSpace(currentspace))
2321 { 2318 {
2322// waitForSpaceUnlock(sGeomIsIn); 2319// waitForSpaceUnlock(sGeomIsIn);
2323 d.SpaceRemove(sGeomIsIn, geom); 2320 SafeNativeMethods.SpaceRemove(sGeomIsIn, geom);
2324 } 2321 }
2325 else 2322 else
2326 { 2323 {
@@ -2331,13 +2328,13 @@ namespace OpenSim.Region.PhysicsModule.ODE
2331 } 2328 }
2332 2329
2333 //If there are no more geometries in the sub-space, we don't need it in the main space anymore 2330 //If there are no more geometries in the sub-space, we don't need it in the main space anymore
2334 if (d.SpaceGetNumGeoms(currentspace) == 0) 2331 if (SafeNativeMethods.SpaceGetNumGeoms(currentspace) == 0)
2335 { 2332 {
2336 if (currentspace != IntPtr.Zero) 2333 if (currentspace != IntPtr.Zero)
2337 { 2334 {
2338 if (d.GeomIsSpace(currentspace)) 2335 if (SafeNativeMethods.GeomIsSpace(currentspace))
2339 { 2336 {
2340 d.SpaceRemove(space, currentspace); 2337 SafeNativeMethods.SpaceRemove(space, currentspace);
2341 // free up memory used by the space. 2338 // free up memory used by the space.
2342 2339
2343 resetSpaceArrayItemToZero(currentspace); 2340 resetSpaceArrayItemToZero(currentspace);
@@ -2355,12 +2352,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
2355 // this is a physical object that got disabled. ;.; 2352 // this is a physical object that got disabled. ;.;
2356 if (currentspace != IntPtr.Zero && geom != IntPtr.Zero) 2353 if (currentspace != IntPtr.Zero && geom != IntPtr.Zero)
2357 { 2354 {
2358 if (d.SpaceQuery(currentspace, geom)) 2355 if (SafeNativeMethods.SpaceQuery(currentspace, geom))
2359 { 2356 {
2360 if (d.GeomIsSpace(currentspace)) 2357 if (SafeNativeMethods.GeomIsSpace(currentspace))
2361 { 2358 {
2362// waitForSpaceUnlock(currentspace); 2359// waitForSpaceUnlock(currentspace);
2363 d.SpaceRemove(currentspace, geom); 2360 SafeNativeMethods.SpaceRemove(currentspace, geom);
2364 } 2361 }
2365 else 2362 else
2366 { 2363 {
@@ -2370,13 +2367,13 @@ namespace OpenSim.Region.PhysicsModule.ODE
2370 } 2367 }
2371 else 2368 else
2372 { 2369 {
2373 IntPtr sGeomIsIn = d.GeomGetSpace(geom); 2370 IntPtr sGeomIsIn = SafeNativeMethods.GeomGetSpace(geom);
2374 if (sGeomIsIn != IntPtr.Zero) 2371 if (sGeomIsIn != IntPtr.Zero)
2375 { 2372 {
2376 if (d.GeomIsSpace(sGeomIsIn)) 2373 if (SafeNativeMethods.GeomIsSpace(sGeomIsIn))
2377 { 2374 {
2378// waitForSpaceUnlock(sGeomIsIn); 2375// waitForSpaceUnlock(sGeomIsIn);
2379 d.SpaceRemove(sGeomIsIn, geom); 2376 SafeNativeMethods.SpaceRemove(sGeomIsIn, geom);
2380 } 2377 }
2381 else 2378 else
2382 { 2379 {
@@ -2397,7 +2394,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
2397 if (newspace == IntPtr.Zero) 2394 if (newspace == IntPtr.Zero)
2398 { 2395 {
2399 newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]); 2396 newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]);
2400 d.HashSpaceSetLevels(newspace, HashspaceLow, HashspaceHigh); 2397 SafeNativeMethods.HashSpaceSetLevels(newspace, HashspaceLow, HashspaceHigh);
2401 } 2398 }
2402 2399
2403 return newspace; 2400 return newspace;
@@ -2412,11 +2409,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
2412 internal IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY) 2409 internal IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY)
2413 { 2410 {
2414 // creating a new space for prim and inserting it into main space. 2411 // creating a new space for prim and inserting it into main space.
2415 staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero); 2412 staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = SafeNativeMethods.HashSpaceCreate(IntPtr.Zero);
2416 d.GeomSetCategoryBits(staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY], (int)CollisionCategories.Space); 2413 SafeNativeMethods.GeomSetCategoryBits(staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY], (int)CollisionCategories.Space);
2417// waitForSpaceUnlock(space); 2414// waitForSpaceUnlock(space);
2418 d.SpaceSetSublevel(space, 1); 2415 SafeNativeMethods.SpaceSetSublevel(space, 1);
2419 d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]); 2416 SafeNativeMethods.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]);
2420 2417
2421 return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]; 2418 return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY];
2422 } 2419 }
@@ -2636,7 +2633,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
2636 m_log.InfoFormat("[Ode] start processing pending actor operations"); 2633 m_log.InfoFormat("[Ode] start processing pending actor operations");
2637 int tstart = Util.EnvironmentTickCount(); 2634 int tstart = Util.EnvironmentTickCount();
2638 2635
2639 d.AllocateODEDataForThread(0); 2636 SafeNativeMethods.AllocateODEDataForThread(0);
2640 2637
2641 lock (_taintedPrims) 2638 lock (_taintedPrims)
2642 { 2639 {
@@ -2719,7 +2716,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
2719 2716
2720 lock (OdeLock) 2717 lock (OdeLock)
2721 { 2718 {
2722 d.AllocateODEDataForThread(~0U); 2719 SafeNativeMethods.AllocateODEDataForThread(~0U);
2723 2720
2724 while (step_time > HalfOdeStep) 2721 while (step_time > HalfOdeStep)
2725 { 2722 {
@@ -2871,12 +2868,12 @@ namespace OpenSim.Region.PhysicsModule.ODE
2871 } 2868 }
2872 2869
2873 lock(SimulationLock) 2870 lock(SimulationLock)
2874 d.WorldQuickStep(world, ODE_STEPSIZE); 2871 SafeNativeMethods.WorldQuickStep(world, ODE_STEPSIZE);
2875 2872
2876 if (CollectStats) 2873 if (CollectStats)
2877 m_stats[ODENativeStepFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick); 2874 m_stats[ODENativeStepFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick);
2878 2875
2879 d.JointGroupEmpty(contactgroup); 2876 SafeNativeMethods.JointGroupEmpty(contactgroup);
2880 } 2877 }
2881 catch (Exception e) 2878 catch (Exception e)
2882 { 2879 {
@@ -2924,7 +2921,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
2924 2921
2925 foreach (OdePrim prim in _activeprims) 2922 foreach (OdePrim prim in _activeprims)
2926 { 2923 {
2927 if (prim.IsPhysical && (d.BodyIsEnabled(prim.Body) || !prim._zeroFlag)) 2924 if (prim.IsPhysical && (SafeNativeMethods.BodyIsEnabled(prim.Body) || !prim._zeroFlag))
2928 { 2925 {
2929 prim.UpdatePositionAndVelocity(); 2926 prim.UpdatePositionAndVelocity();
2930 2927
@@ -2954,7 +2951,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
2954 fwriter.Close(); 2951 fwriter.Close();
2955 } 2952 }
2956 2953
2957 d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); 2954 SafeNativeMethods.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix);
2958 } 2955 }
2959 2956
2960 latertickcount = Util.EnvironmentTickCountSubtract(tickCountFrameRun); 2957 latertickcount = Util.EnvironmentTickCountSubtract(tickCountFrameRun);
@@ -3069,11 +3066,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
3069 { 3066 {
3070 IntPtr odeJoint; 3067 IntPtr odeJoint;
3071 //DoJointErrorMessage(joint, "ODE creating ball joint "); 3068 //DoJointErrorMessage(joint, "ODE creating ball joint ");
3072 odeJoint = d.JointCreateBall(world, IntPtr.Zero); 3069 odeJoint = SafeNativeMethods.JointCreateBall(world, IntPtr.Zero);
3073 //DoJointErrorMessage(joint, "ODE attaching ball joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); 3070 //DoJointErrorMessage(joint, "ODE attaching ball joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]);
3074 d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); 3071 SafeNativeMethods.JointAttach(odeJoint, jointBodies[0], jointBodies[1]);
3075 //DoJointErrorMessage(joint, "ODE setting ball anchor: " + odeJoint + " to vec:" + joint.Position); 3072 //DoJointErrorMessage(joint, "ODE setting ball anchor: " + odeJoint + " to vec:" + joint.Position);
3076 d.JointSetBallAnchor(odeJoint, 3073 SafeNativeMethods.JointSetBallAnchor(odeJoint,
3077 joint.Position.X, 3074 joint.Position.X,
3078 joint.Position.Y, 3075 joint.Position.Y,
3079 joint.Position.Z); 3076 joint.Position.Z);
@@ -3097,11 +3094,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
3097 { 3094 {
3098 IntPtr odeJoint; 3095 IntPtr odeJoint;
3099 //DoJointErrorMessage(joint, "ODE creating hinge joint "); 3096 //DoJointErrorMessage(joint, "ODE creating hinge joint ");
3100 odeJoint = d.JointCreateHinge(world, IntPtr.Zero); 3097 odeJoint = SafeNativeMethods.JointCreateHinge(world, IntPtr.Zero);
3101 //DoJointErrorMessage(joint, "ODE attaching hinge joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); 3098 //DoJointErrorMessage(joint, "ODE attaching hinge joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]);
3102 d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); 3099 SafeNativeMethods.JointAttach(odeJoint, jointBodies[0], jointBodies[1]);
3103 //DoJointErrorMessage(joint, "ODE setting hinge anchor: " + odeJoint + " to vec:" + joint.Position); 3100 //DoJointErrorMessage(joint, "ODE setting hinge anchor: " + odeJoint + " to vec:" + joint.Position);
3104 d.JointSetHingeAnchor(odeJoint, 3101 SafeNativeMethods.JointSetHingeAnchor(odeJoint,
3105 joint.Position.X, 3102 joint.Position.X,
3106 joint.Position.Y, 3103 joint.Position.Y,
3107 joint.Position.Z); 3104 joint.Position.Z);
@@ -3137,7 +3134,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
3137 Vector3 jointAxis = Vector3.Transform(Vector3.UnitX, proxyFrame); 3134 Vector3 jointAxis = Vector3.Transform(Vector3.UnitX, proxyFrame);
3138 //m_log.Debug("PHY: making axis: hinge joint axis is " + jointAxis); 3135 //m_log.Debug("PHY: making axis: hinge joint axis is " + jointAxis);
3139 //DoJointErrorMessage(joint, "ODE setting hinge axis: " + odeJoint + " to vec:" + jointAxis); 3136 //DoJointErrorMessage(joint, "ODE setting hinge axis: " + odeJoint + " to vec:" + jointAxis);
3140 d.JointSetHingeAxis(odeJoint, 3137 SafeNativeMethods.JointSetHingeAxis(odeJoint,
3141 jointAxis.X, 3138 jointAxis.X,
3142 jointAxis.Y, 3139 jointAxis.Y,
3143 jointAxis.Z); 3140 jointAxis.Z);
@@ -3299,7 +3296,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
3299 3296
3300 lock (OdeLock) 3297 lock (OdeLock)
3301 { 3298 {
3302 d.AllocateODEDataForThread(~0U); 3299 SafeNativeMethods.AllocateODEDataForThread(~0U);
3303 3300
3304 IntPtr GroundGeom = IntPtr.Zero; 3301 IntPtr GroundGeom = IntPtr.Zero;
3305 if (RegionTerrain.TryGetValue(pOffset, out GroundGeom)) 3302 if (RegionTerrain.TryGetValue(pOffset, out GroundGeom))
@@ -3311,29 +3308,29 @@ namespace OpenSim.Region.PhysicsModule.ODE
3311 { 3308 {
3312 TerrainHeightFieldHeights.Remove(GroundGeom); 3309 TerrainHeightFieldHeights.Remove(GroundGeom);
3313 } 3310 }
3314 d.SpaceRemove(space, GroundGeom); 3311 SafeNativeMethods.SpaceRemove(space, GroundGeom);
3315 d.GeomDestroy(GroundGeom); 3312 SafeNativeMethods.GeomDestroy(GroundGeom);
3316 } 3313 }
3317 3314
3318 } 3315 }
3319 IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); 3316 IntPtr HeightmapData = SafeNativeMethods.GeomHeightfieldDataCreate();
3320 d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0, 3317 SafeNativeMethods.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0,
3321 heightmapWidth, heightmapHeight, 3318 heightmapWidth, heightmapHeight,
3322 (int)heightmapWidthSamples, 3319 (int)heightmapWidthSamples,
3323 (int)heightmapHeightSamples, 3320 (int)heightmapHeightSamples,
3324 scale, offset, thickness, wrap); 3321 scale, offset, thickness, wrap);
3325 3322
3326 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); 3323 SafeNativeMethods.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
3327 GroundGeom = d.CreateHeightfield(space, HeightmapData, 1); 3324 GroundGeom = SafeNativeMethods.CreateHeightfield(space, HeightmapData, 1);
3328 if (GroundGeom != IntPtr.Zero) 3325 if (GroundGeom != IntPtr.Zero)
3329 { 3326 {
3330 d.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land)); 3327 SafeNativeMethods.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land));
3331 d.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space)); 3328 SafeNativeMethods.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space));
3332 3329
3333 } 3330 }
3334 geom_name_map[GroundGeom] = "Terrain"; 3331 geom_name_map[GroundGeom] = "Terrain";
3335 3332
3336 d.Matrix3 R = new d.Matrix3(); 3333 SafeNativeMethods.Matrix3 R = new SafeNativeMethods.Matrix3();
3337 3334
3338 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f); 3335 Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
3339 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f); 3336 Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
@@ -3343,9 +3340,9 @@ namespace OpenSim.Region.PhysicsModule.ODE
3343 float angle; 3340 float angle;
3344 q1.GetAxisAngle(out v3, out angle); 3341 q1.GetAxisAngle(out v3, out angle);
3345 3342
3346 d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); 3343 SafeNativeMethods.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
3347 d.GeomSetRotation(GroundGeom, ref R); 3344 SafeNativeMethods.GeomSetRotation(GroundGeom, ref R);
3348 d.GeomSetPosition(GroundGeom, pOffset.X + regionsizeX * 0.5f, pOffset.Y + regionsizeY * 0.5f, 0.0f); 3345 SafeNativeMethods.GeomSetPosition(GroundGeom, pOffset.X + regionsizeX * 0.5f, pOffset.Y + regionsizeY * 0.5f, 0.0f);
3349 IntPtr testGround = IntPtr.Zero; 3346 IntPtr testGround = IntPtr.Zero;
3350 if (RegionTerrain.TryGetValue(pOffset, out testGround)) 3347 if (RegionTerrain.TryGetValue(pOffset, out testGround))
3351 { 3348 {
@@ -3384,7 +3381,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
3384 3381
3385 _worldInitialized = false; 3382 _worldInitialized = false;
3386 3383
3387 d.AllocateODEDataForThread(~0U); 3384 SafeNativeMethods.AllocateODEDataForThread(~0U);
3388 3385
3389 if (m_rayCastManager != null) 3386 if (m_rayCastManager != null)
3390 { 3387 {
@@ -3412,13 +3409,13 @@ namespace OpenSim.Region.PhysicsModule.ODE
3412 { 3409 {
3413 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom)) 3410 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
3414 TerrainHeightFieldHeights.Remove(GroundGeom); 3411 TerrainHeightFieldHeights.Remove(GroundGeom);
3415 d.GeomDestroy(GroundGeom); 3412 SafeNativeMethods.GeomDestroy(GroundGeom);
3416 } 3413 }
3417 } 3414 }
3418 3415
3419 try 3416 try
3420 { 3417 {
3421 d.WorldDestroy(world); 3418 SafeNativeMethods.WorldDestroy(world);
3422 world = IntPtr.Zero; 3419 world = IntPtr.Zero;
3423 } 3420 }
3424 catch (AccessViolationException e) 3421 catch (AccessViolationException e)