diff options
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs')
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | 126 |
1 files changed, 76 insertions, 50 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index 3fc2de3..1a6907d 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | |||
@@ -160,8 +160,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
160 | private Random fluidRandomizer = new Random(Environment.TickCount); | 160 | private Random fluidRandomizer = new Random(Environment.TickCount); |
161 | 161 | ||
162 | const d.ContactFlags comumContactFlags = d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM |d.ContactFlags.Approx1 | d.ContactFlags.Bounce; | 162 | const d.ContactFlags comumContactFlags = d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM |d.ContactFlags.Approx1 | d.ContactFlags.Bounce; |
163 | const float comumContactERP = 0.6f; | 163 | const float MaxERP = 0.8f; |
164 | const float comumSoftContactERP = 0.1f; | 164 | const float minERP = 0.1f; |
165 | const float comumContactCFM = 0.0001f; | 165 | const float comumContactCFM = 0.0001f; |
166 | 166 | ||
167 | float frictionMovementMult = 0.3f; | 167 | float frictionMovementMult = 0.3f; |
@@ -527,7 +527,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
527 | 527 | ||
528 | // sets a global contact for a joint for contactgeom , and base contact description) | 528 | // sets a global contact for a joint for contactgeom , and base contact description) |
529 | 529 | ||
530 | private IntPtr CreateContacJoint(ref d.ContactGeom contactGeom, float mu, float bounce, bool softerp) | 530 | private IntPtr CreateContacJoint(ref d.ContactGeom contactGeom, float mu, float bounce,float cfm,float erp) |
531 | { | 531 | { |
532 | if (GlobalContactsArray == IntPtr.Zero || m_global_contactcount >= maxContactsbeforedeath) | 532 | if (GlobalContactsArray == IntPtr.Zero || m_global_contactcount >= maxContactsbeforedeath) |
533 | return IntPtr.Zero; | 533 | return IntPtr.Zero; |
@@ -545,11 +545,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
545 | newcontact.surface.mode = comumContactFlags; | 545 | newcontact.surface.mode = comumContactFlags; |
546 | newcontact.surface.mu = mu; | 546 | newcontact.surface.mu = mu; |
547 | newcontact.surface.bounce = bounce; | 547 | newcontact.surface.bounce = bounce; |
548 | newcontact.surface.soft_cfm = comumContactCFM; | 548 | newcontact.surface.soft_cfm = cfm; |
549 | if (softerp) | 549 | newcontact.surface.soft_erp = erp; |
550 | newcontact.surface.soft_erp = comumSoftContactERP; | ||
551 | else | ||
552 | newcontact.surface.soft_erp = comumContactERP; | ||
553 | 550 | ||
554 | IntPtr contact = new IntPtr(GlobalContactsArray.ToInt64() + (Int64)(m_global_contactcount * d.Contact.unmanagedSizeOf)); | 551 | IntPtr contact = new IntPtr(GlobalContactsArray.ToInt64() + (Int64)(m_global_contactcount * d.Contact.unmanagedSizeOf)); |
555 | Marshal.StructureToPtr(newcontact, contact, true); | 552 | Marshal.StructureToPtr(newcontact, contact, true); |
@@ -693,9 +690,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
693 | // big messy collision analises | 690 | // big messy collision analises |
694 | float mu = 0; | 691 | float mu = 0; |
695 | float bounce = 0; | 692 | float bounce = 0; |
693 | float cfm = 0.0001f; | ||
694 | float erp = 0.1f; | ||
695 | |||
696 | ContactData contactdata1 = new ContactData(0, 0, false); | 696 | ContactData contactdata1 = new ContactData(0, 0, false); |
697 | ContactData contactdata2 = new ContactData(0, 0, false); | 697 | ContactData contactdata2 = new ContactData(0, 0, false); |
698 | bool erpSoft = false; | ||
699 | 698 | ||
700 | String name = null; | 699 | String name = null; |
701 | bool dop1foot = false; | 700 | bool dop1foot = false; |
@@ -705,61 +704,65 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
705 | switch (p1.PhysicsActorType) | 704 | switch (p1.PhysicsActorType) |
706 | { | 705 | { |
707 | case (int)ActorTypes.Agent: | 706 | case (int)ActorTypes.Agent: |
708 | switch (p2.PhysicsActorType) | ||
709 | { | 707 | { |
710 | case (int)ActorTypes.Agent: | 708 | bounce = 0; |
711 | p1.getContactData(ref contactdata1); | 709 | mu = 0; |
712 | p2.getContactData(ref contactdata2); | 710 | cfm = 0.0001f; |
713 | 711 | ||
714 | bounce = 0; | 712 | switch (p2.PhysicsActorType) |
715 | 713 | { | |
716 | mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); | 714 | case (int)ActorTypes.Agent: |
715 | /* | ||
716 | p1.getContactData(ref contactdata1); | ||
717 | p2.getContactData(ref contactdata2); | ||
717 | 718 | ||
718 | if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f)) | 719 | mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); |
719 | mu *= frictionMovementMult; | ||
720 | 720 | ||
721 | erpSoft = contactdata1.softcolide | contactdata2.softcolide; | 721 | if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f)) |
722 | p1.CollidingObj = true; | 722 | mu *= frictionMovementMult; |
723 | p2.CollidingObj = true; | 723 | */ |
724 | break; | 724 | p1.CollidingObj = true; |
725 | case (int)ActorTypes.Prim: | 725 | p2.CollidingObj = true; |
726 | p1.getContactData(ref contactdata1); | 726 | break; |
727 | p2.getContactData(ref contactdata2); | 727 | case (int)ActorTypes.Prim: |
728 | /* | ||
729 | p1.getContactData(ref contactdata1); | ||
730 | p2.getContactData(ref contactdata2); | ||
728 | 731 | ||
729 | bounce = 0; | ||
730 | |||
731 | mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); | ||
732 | 732 | ||
733 | if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f)) | 733 | mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); |
734 | mu *= frictionMovementMult; | ||
735 | if (p2.Velocity.LengthSquared() > 0.0f) | ||
736 | p2.CollidingObj = true; | ||
737 | 734 | ||
738 | erpSoft = contactdata1.softcolide | contactdata2.softcolide; | 735 | if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f)) |
736 | mu *= frictionMovementMult; | ||
737 | */ | ||
738 | if (p2.Velocity.LengthSquared() > 0.0f) | ||
739 | p2.CollidingObj = true; | ||
739 | 740 | ||
740 | dop1foot = true; | 741 | dop1foot = true; |
741 | break; | 742 | break; |
742 | default: | 743 | default: |
743 | ignore=true; // avatar to terrain and water ignored | 744 | ignore = true; // avatar to terrain and water ignored |
744 | break; | 745 | break; |
746 | } | ||
747 | break; | ||
745 | } | 748 | } |
746 | break; | ||
747 | 749 | ||
748 | case (int)ActorTypes.Prim: | 750 | case (int)ActorTypes.Prim: |
749 | switch (p2.PhysicsActorType) | 751 | switch (p2.PhysicsActorType) |
750 | { | 752 | { |
751 | case (int)ActorTypes.Agent: | 753 | case (int)ActorTypes.Agent: |
752 | p1.getContactData(ref contactdata1); | 754 | // p1.getContactData(ref contactdata1); |
753 | p2.getContactData(ref contactdata2); | 755 | // p2.getContactData(ref contactdata2); |
754 | 756 | ||
755 | bounce = 0; | 757 | bounce = 0; |
756 | 758 | mu = 0; | |
759 | cfm = 0.0001f; | ||
760 | /* | ||
757 | mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); | 761 | mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); |
758 | 762 | ||
759 | if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f)) | 763 | if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f)) |
760 | mu *= frictionMovementMult; | 764 | mu *= frictionMovementMult; |
761 | 765 | */ | |
762 | erpSoft = contactdata1.softcolide | contactdata2.softcolide; | ||
763 | dop2foot = true; | 766 | dop2foot = true; |
764 | if (p1.Velocity.LengthSquared() > 0.0f) | 767 | if (p1.Velocity.LengthSquared() > 0.0f) |
765 | p1.CollidingObj = true; | 768 | p1.CollidingObj = true; |
@@ -773,9 +776,16 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
773 | p1.getContactData(ref contactdata1); | 776 | p1.getContactData(ref contactdata1); |
774 | p2.getContactData(ref contactdata2); | 777 | p2.getContactData(ref contactdata2); |
775 | bounce = contactdata1.bounce * contactdata2.bounce; | 778 | bounce = contactdata1.bounce * contactdata2.bounce; |
776 | erpSoft = contactdata1.softcolide | contactdata2.softcolide; | ||
777 | mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); | 779 | mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu); |
778 | 780 | ||
781 | cfm = p1.Mass; | ||
782 | if (cfm > p2.Mass) | ||
783 | cfm = p2.Mass; | ||
784 | cfm = (float)Math.Sqrt(cfm); | ||
785 | cfm *= 0.0001f; | ||
786 | if (cfm > 0.8f) | ||
787 | cfm = 0.8f; | ||
788 | |||
779 | if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f)) | 789 | if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f)) |
780 | mu *= frictionMovementMult; | 790 | mu *= frictionMovementMult; |
781 | 791 | ||
@@ -790,12 +800,17 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
790 | mu = (float)Math.Sqrt(contactdata1.mu * TerrainFriction); | 800 | mu = (float)Math.Sqrt(contactdata1.mu * TerrainFriction); |
791 | if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f) | 801 | if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f) |
792 | mu *= frictionMovementMult; | 802 | mu *= frictionMovementMult; |
793 | erpSoft = contactdata1.softcolide; | ||
794 | p1.CollidingGround = true; | 803 | p1.CollidingGround = true; |
804 | cfm = p1.Mass; | ||
805 | cfm = (float)Math.Sqrt(cfm); | ||
806 | cfm *= 0.0001f; | ||
807 | if (cfm > 0.8f) | ||
808 | cfm = 0.8f; | ||
809 | |||
795 | } | 810 | } |
796 | else if (name == "Water") | 811 | else if (name == "Water") |
797 | { | 812 | { |
798 | erpSoft = true; | 813 | ignore = true; |
799 | } | 814 | } |
800 | } | 815 | } |
801 | else | 816 | else |
@@ -815,7 +830,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
815 | p2.getContactData(ref contactdata2); | 830 | p2.getContactData(ref contactdata2); |
816 | bounce = contactdata2.bounce * TerrainBounce; | 831 | bounce = contactdata2.bounce * TerrainBounce; |
817 | mu = (float)Math.Sqrt(contactdata2.mu * TerrainFriction); | 832 | mu = (float)Math.Sqrt(contactdata2.mu * TerrainFriction); |
818 | erpSoft = contactdata2.softcolide; | 833 | cfm = p2.Mass; |
834 | cfm = (float)Math.Sqrt(cfm); | ||
835 | cfm *= 0.0001f; | ||
836 | if (cfm > 0.8f) | ||
837 | cfm = 0.8f; | ||
819 | 838 | ||
820 | if (Math.Abs(p2.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y) > 0.1f) | 839 | if (Math.Abs(p2.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y) > 0.1f) |
821 | mu *= frictionMovementMult; | 840 | mu *= frictionMovementMult; |
@@ -827,7 +846,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
827 | else if (name == "Water" && | 846 | else if (name == "Water" && |
828 | (p2.PhysicsActorType == (int)ActorTypes.Prim || p2.PhysicsActorType == (int)ActorTypes.Agent)) | 847 | (p2.PhysicsActorType == (int)ActorTypes.Prim || p2.PhysicsActorType == (int)ActorTypes.Agent)) |
829 | { | 848 | { |
830 | erpSoft = true; | 849 | ignore = true; |
831 | } | 850 | } |
832 | } | 851 | } |
833 | else | 852 | else |
@@ -848,7 +867,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
848 | if (dop2foot && (p2.Position.Z - curContact.pos.Z) > (p2.Size.Z - avCapRadius) * 0.5f) | 867 | if (dop2foot && (p2.Position.Z - curContact.pos.Z) > (p2.Size.Z - avCapRadius) * 0.5f) |
849 | p2.IsColliding = true; | 868 | p2.IsColliding = true; |
850 | 869 | ||
851 | Joint = CreateContacJoint(ref curContact, mu, bounce, erpSoft); | 870 | |
871 | erp = curContact.depth; | ||
872 | if (erp < minERP) | ||
873 | erp = minERP; | ||
874 | else if (erp > MaxERP) | ||
875 | erp = MaxERP; | ||
876 | |||
877 | Joint = CreateContacJoint(ref curContact, mu, bounce,cfm,erp); | ||
852 | d.JointAttach(Joint, b1, b2); | 878 | d.JointAttach(Joint, b1, b2); |
853 | 879 | ||
854 | if (++m_global_contactcount >= maxContactsbeforedeath) | 880 | if (++m_global_contactcount >= maxContactsbeforedeath) |