diff options
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin')
6 files changed, 238 insertions, 509 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs index e912997..ecd5474 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs | |||
@@ -95,10 +95,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
95 | 95 | ||
96 | private float m_feetOffset = 0; | 96 | private float m_feetOffset = 0; |
97 | private float feetOff = 0; | 97 | private float feetOff = 0; |
98 | private float feetSZ = 0.5f; | ||
99 | const float feetScale = 0.8f; | ||
100 | private float boneOff = 0; | 98 | private float boneOff = 0; |
101 | private float m_lastVelocitySqr = 0; | ||
102 | 99 | ||
103 | public float walkDivisor = 1.3f; | 100 | public float walkDivisor = 1.3f; |
104 | public float runDivisor = 0.8f; | 101 | public float runDivisor = 0.8f; |
@@ -110,7 +107,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
110 | 107 | ||
111 | private bool _zeroFlag = false; | 108 | private bool _zeroFlag = false; |
112 | 109 | ||
113 | private int m_requestedUpdateFrequency = 0; | ||
114 | private uint m_localID = 0; | 110 | private uint m_localID = 0; |
115 | public bool m_returnCollisions = false; | 111 | public bool m_returnCollisions = false; |
116 | // taints and their non-tainted counterparts | 112 | // taints and their non-tainted counterparts |
@@ -127,7 +123,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
127 | int m_colliderfilter = 0; | 123 | int m_colliderfilter = 0; |
128 | int m_colliderGroundfilter = 0; | 124 | int m_colliderGroundfilter = 0; |
129 | int m_colliderObjectfilter = 0; | 125 | int m_colliderObjectfilter = 0; |
130 | bool m_collisionException = false; | ||
131 | 126 | ||
132 | // Default we're a Character | 127 | // Default we're a Character |
133 | private CollisionCategories m_collisionCategories = (CollisionCategories.Character); | 128 | private CollisionCategories m_collisionCategories = (CollisionCategories.Character); |
@@ -140,9 +135,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
140 | // we do land collisions not ode | CollisionCategories.Land); | 135 | // we do land collisions not ode | CollisionCategories.Land); |
141 | public IntPtr Body = IntPtr.Zero; | 136 | public IntPtr Body = IntPtr.Zero; |
142 | private OdeScene _parent_scene; | 137 | private OdeScene _parent_scene; |
143 | private IntPtr topbox = IntPtr.Zero; | 138 | private IntPtr capsule = IntPtr.Zero; |
144 | private IntPtr midbox = IntPtr.Zero; | ||
145 | private IntPtr feetbox = IntPtr.Zero; | ||
146 | private IntPtr bbox = IntPtr.Zero; | 139 | private IntPtr bbox = IntPtr.Zero; |
147 | public IntPtr collider = IntPtr.Zero; | 140 | public IntPtr collider = IntPtr.Zero; |
148 | 141 | ||
@@ -150,9 +143,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
150 | 143 | ||
151 | public d.Mass ShellMass; | 144 | public d.Mass ShellMass; |
152 | 145 | ||
153 | |||
154 | |||
155 | |||
156 | public int m_eventsubscription = 0; | 146 | public int m_eventsubscription = 0; |
157 | private int m_cureventsubscription = 0; | 147 | private int m_cureventsubscription = 0; |
158 | private CollisionEventUpdate CollisionEventsThisFrame = null; | 148 | private CollisionEventUpdate CollisionEventsThisFrame = null; |
@@ -214,8 +204,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
214 | // force lower density for testing | 204 | // force lower density for testing |
215 | m_density = 3.0f; | 205 | m_density = 3.0f; |
216 | 206 | ||
217 | m_density *= 1.4f; // scale to have mass similar to capsule | ||
218 | |||
219 | mu = parent_scene.AvatarFriction; | 207 | mu = parent_scene.AvatarFriction; |
220 | 208 | ||
221 | walkDivisor = walk_divisor; | 209 | walkDivisor = walk_divisor; |
@@ -704,58 +692,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
704 | AddChange(changes.Momentum, momentum); | 692 | AddChange(changes.Momentum, momentum); |
705 | } | 693 | } |
706 | 694 | ||
707 | private void ajustCollider() | ||
708 | { | ||
709 | float vq = _velocity.LengthSquared(); | ||
710 | if (m_lastVelocitySqr != vq) | ||
711 | { | ||
712 | m_lastVelocitySqr = vq; | ||
713 | if (vq > 100.0f) | ||
714 | { | ||
715 | Vector3 off = _velocity; | ||
716 | float t = 0.5f * timeStep; | ||
717 | off = off * t; | ||
718 | d.Quaternion qtmp; | ||
719 | d.GeomCopyQuaternion(bbox, out qtmp); | ||
720 | Quaternion q; | ||
721 | q.X = qtmp.X; | ||
722 | q.Y = qtmp.Y; | ||
723 | q.Z = qtmp.Z; | ||
724 | q.W = qtmp.W; | ||
725 | off *= Quaternion.Conjugate(q); | ||
726 | |||
727 | d.GeomSetOffsetPosition(bbox, off.X, off.Y, off.Z); | ||
728 | |||
729 | off.X = 2.0f * (m_size.X + Math.Abs(off.X)); | ||
730 | off.Y = 2.0f * (m_size.Y + Math.Abs(off.Y)); | ||
731 | off.Z = m_size.Z + 2.0f * Math.Abs(off.Z); | ||
732 | d.GeomBoxSetLengths(bbox, off.X, off.Y, off.Z); | ||
733 | |||
734 | d.GeomSetCategoryBits(bbox, (uint)m_collisionCategories); | ||
735 | d.GeomSetCollideBits(bbox, (uint)m_collisionFlags); | ||
736 | d.GeomSetCategoryBits(topbox, 0); | ||
737 | d.GeomSetCollideBits(topbox, 0); | ||
738 | d.GeomSetCategoryBits(midbox, 0); | ||
739 | d.GeomSetCollideBits(midbox, 0); | ||
740 | d.GeomSetCategoryBits(feetbox, 0); | ||
741 | d.GeomSetCollideBits(feetbox, 0); | ||
742 | } | ||
743 | else | ||
744 | { | ||
745 | d.GeomSetCategoryBits(bbox, 0); | ||
746 | d.GeomSetCollideBits(bbox, 0); | ||
747 | d.GeomSetCategoryBits(topbox, (uint)m_collisionCategories); | ||
748 | d.GeomSetCollideBits(topbox, (uint)m_collisionFlags); | ||
749 | d.GeomSetCategoryBits(midbox, (uint)m_collisionCategories); | ||
750 | d.GeomSetCollideBits(midbox, (uint)m_collisionFlags); | ||
751 | d.GeomSetCategoryBits(feetbox, (uint)m_collisionCategories); | ||
752 | d.GeomSetCollideBits(feetbox, (uint)m_collisionFlags); | ||
753 | } | ||
754 | uint cat1 = d.GeomGetCategoryBits(bbox); | ||
755 | uint col1 = d.GeomGetCollideBits(bbox); | ||
756 | |||
757 | } | ||
758 | } | ||
759 | 695 | ||
760 | private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ) | 696 | private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ) |
761 | { | 697 | { |
@@ -764,37 +700,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
764 | float sy = m_size.Y; | 700 | float sy = m_size.Y; |
765 | float sz = m_size.Z; | 701 | float sz = m_size.Z; |
766 | 702 | ||
767 | float topsx = sx * 0.9f; | 703 | float bot = -sz * 0.5f + m_feetOffset; |
768 | float midsx = sx; | 704 | boneOff = bot + 0.3f; |
769 | float feetsx = sx * feetScale; | ||
770 | float bonesx = sx * 0.2f; | ||
771 | |||
772 | float topsy = sy * 0.4f; | ||
773 | float midsy = sy; | ||
774 | float feetsy = sy * feetScale * 0.8f; | ||
775 | float bonesy = feetsy * 0.2f; | ||
776 | 705 | ||
777 | float topsz = sz * 0.15f; | ||
778 | float feetsz = sz * 0.45f; | 706 | float feetsz = sz * 0.45f; |
779 | if (feetsz > 0.6f) | 707 | if (feetsz > 0.6f) |
780 | feetsz = 0.6f; | 708 | feetsz = 0.6f; |
781 | 709 | ||
782 | float midsz = sz - topsz - feetsz; | 710 | feetOff = bot + feetsz; |
783 | float bonesz = sz; | ||
784 | |||
785 | float bot = -sz * 0.5f + m_feetOffset; | ||
786 | |||
787 | boneOff = bot + 0.3f; | ||
788 | |||
789 | float feetz = bot + feetsz * 0.5f; | ||
790 | bot += feetsz; | ||
791 | |||
792 | feetOff = bot; | ||
793 | feetSZ = feetsz; | ||
794 | |||
795 | float midz = bot + midsz * 0.5f; | ||
796 | bot += midsz; | ||
797 | float topz = bot + topsz * 0.5f; | ||
798 | 711 | ||
799 | _parent_scene.waitForSpaceUnlock(_parent_scene.CharsSpace); | 712 | _parent_scene.waitForSpaceUnlock(_parent_scene.CharsSpace); |
800 | 713 | ||
@@ -805,9 +718,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
805 | d.GeomSetCategoryBits(collider, (uint)m_collisionCategories); | 718 | d.GeomSetCategoryBits(collider, (uint)m_collisionCategories); |
806 | d.GeomSetCollideBits(collider, (uint)m_collisionFlags); | 719 | d.GeomSetCollideBits(collider, (uint)m_collisionFlags); |
807 | 720 | ||
808 | feetbox = d.CreateBox(collider, feetsx, feetsy, feetsz); | 721 | float r = m_size.X; |
809 | midbox = d.CreateBox(collider, midsx, midsy, midsz); | 722 | if (m_size.Y > r) |
810 | topbox = d.CreateBox(collider, topsx, topsy, topsz); | 723 | r = m_size.Y; |
724 | float l = m_size.Z - r; | ||
725 | r *= 0.5f; | ||
726 | capsule = d.CreateCapsule(collider, r, l); | ||
727 | |||
811 | bbox = d.CreateBox(collider, m_size.X, m_size.Y, m_size.Z); | 728 | bbox = d.CreateBox(collider, m_size.X, m_size.Y, m_size.Z); |
812 | 729 | ||
813 | m_mass = m_density * m_size.X * m_size.Y * m_size.Z; // update mass | 730 | m_mass = m_density * m_size.X * m_size.Y * m_size.Z; // update mass |
@@ -820,12 +737,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
820 | Body = d.BodyCreate(_parent_scene.world); | 737 | Body = d.BodyCreate(_parent_scene.world); |
821 | 738 | ||
822 | _zeroFlag = false; | 739 | _zeroFlag = false; |
823 | m_collisionException = false; | ||
824 | m_pidControllerActive = true; | 740 | m_pidControllerActive = true; |
825 | m_freemove = false; | 741 | m_freemove = false; |
826 | 742 | ||
827 | _velocity = Vector3.Zero; | 743 | _velocity = Vector3.Zero; |
828 | m_lastVelocitySqr = 0; | ||
829 | 744 | ||
830 | d.BodySetAutoDisableFlag(Body, false); | 745 | d.BodySetAutoDisableFlag(Body, false); |
831 | d.BodySetPosition(Body, npositionX, npositionY, npositionZ); | 746 | d.BodySetPosition(Body, npositionX, npositionY, npositionZ); |
@@ -835,17 +750,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
835 | _position.Z = npositionZ; | 750 | _position.Z = npositionZ; |
836 | 751 | ||
837 | d.BodySetMass(Body, ref ShellMass); | 752 | d.BodySetMass(Body, ref ShellMass); |
838 | d.GeomSetBody(feetbox, Body); | ||
839 | d.GeomSetBody(midbox, Body); | ||
840 | d.GeomSetBody(topbox, Body); | ||
841 | d.GeomSetBody(bbox, Body); | ||
842 | |||
843 | d.GeomSetOffsetPosition(feetbox, 0, 0, feetz); | ||
844 | d.GeomSetOffsetPosition(midbox, 0, 0, midz); | ||
845 | d.GeomSetOffsetPosition(topbox, 0, 0, topz); | ||
846 | |||
847 | ajustCollider(); | ||
848 | 753 | ||
754 | d.GeomSetBody(bbox, Body); | ||
755 | d.GeomSetBody(capsule, Body); | ||
849 | 756 | ||
850 | // The purpose of the AMotor here is to keep the avatar's physical | 757 | // The purpose of the AMotor here is to keep the avatar's physical |
851 | // surrogate from rotating while moving | 758 | // surrogate from rotating while moving |
@@ -906,26 +813,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
906 | } | 813 | } |
907 | 814 | ||
908 | //kill the Geoms | 815 | //kill the Geoms |
909 | if (topbox != IntPtr.Zero) | 816 | if (capsule != IntPtr.Zero) |
910 | { | 817 | { |
911 | _parent_scene.actor_name_map.Remove(topbox); | 818 | _parent_scene.actor_name_map.Remove(capsule); |
912 | _parent_scene.waitForSpaceUnlock(collider); | 819 | _parent_scene.waitForSpaceUnlock(collider); |
913 | d.GeomDestroy(topbox); | 820 | d.GeomDestroy(capsule); |
914 | topbox = IntPtr.Zero; | 821 | capsule = IntPtr.Zero; |
915 | } | ||
916 | if (midbox != IntPtr.Zero) | ||
917 | { | ||
918 | _parent_scene.actor_name_map.Remove(midbox); | ||
919 | _parent_scene.waitForSpaceUnlock(collider); | ||
920 | d.GeomDestroy(midbox); | ||
921 | midbox = IntPtr.Zero; | ||
922 | } | ||
923 | if (feetbox != IntPtr.Zero) | ||
924 | { | ||
925 | _parent_scene.actor_name_map.Remove(feetbox); | ||
926 | _parent_scene.waitForSpaceUnlock(collider); | ||
927 | d.GeomDestroy(feetbox); | ||
928 | feetbox = IntPtr.Zero; | ||
929 | } | 822 | } |
930 | 823 | ||
931 | if (bbox != IntPtr.Zero) | 824 | if (bbox != IntPtr.Zero) |
@@ -981,163 +874,21 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
981 | public bool Collide(IntPtr me, bool reverse, ref d.ContactGeom contact, ref bool feetcollision) | 874 | public bool Collide(IntPtr me, bool reverse, ref d.ContactGeom contact, ref bool feetcollision) |
982 | { | 875 | { |
983 | feetcollision = false; | 876 | feetcollision = false; |
984 | if (m_collisionException) | ||
985 | return false; | ||
986 | 877 | ||
987 | Vector3 offset; | 878 | Vector3 offset; |
988 | 879 | ||
989 | if (me == bbox) // if moving fast | ||
990 | { | ||
991 | // force a full inelastic collision | ||
992 | m_collisionException = true; | ||
993 | |||
994 | offset = m_size * m_orientation2D; | ||
995 | |||
996 | offset.X = (float)Math.Abs(offset.X) * 0.5f + contact.depth; | ||
997 | offset.Y = (float)Math.Abs(offset.Y) * 0.5f + contact.depth; | ||
998 | offset.Z = (float)Math.Abs(offset.Z) * 0.5f + contact.depth; | ||
999 | |||
1000 | if (reverse) | ||
1001 | { | ||
1002 | offset.X *= -contact.normal.X; | ||
1003 | offset.Y *= -contact.normal.Y; | ||
1004 | offset.Z *= -contact.normal.Z; | ||
1005 | } | ||
1006 | else | ||
1007 | { | ||
1008 | offset.X *= contact.normal.X; | ||
1009 | offset.Y *= contact.normal.Y; | ||
1010 | offset.Z *= contact.normal.Z; | ||
1011 | } | ||
1012 | |||
1013 | offset.X += contact.pos.X; | ||
1014 | offset.Y += contact.pos.Y; | ||
1015 | offset.Z += contact.pos.Z; | ||
1016 | |||
1017 | //_position = offset; | ||
1018 | //return false; | ||
1019 | } | ||
1020 | |||
1021 | offset.X = contact.pos.X - _position.X; | 880 | offset.X = contact.pos.X - _position.X; |
1022 | offset.Y = contact.pos.Y - _position.Y; | 881 | offset.Y = contact.pos.Y - _position.Y; |
1023 | 882 | ||
1024 | if (me == topbox) | 883 | if (me == capsule) |
1025 | { | ||
1026 | offset.Z = contact.pos.Z - _position.Z; | ||
1027 | |||
1028 | offset.Normalize(); | ||
1029 | |||
1030 | if (reverse) | ||
1031 | { | ||
1032 | contact.normal.X = offset.X; | ||
1033 | contact.normal.Y = offset.Y; | ||
1034 | contact.normal.Z = offset.Z; | ||
1035 | } | ||
1036 | else | ||
1037 | { | ||
1038 | contact.normal.X = -offset.X; | ||
1039 | contact.normal.Y = -offset.Y; | ||
1040 | contact.normal.Z = -offset.Z; | ||
1041 | } | ||
1042 | return true; | ||
1043 | } | ||
1044 | |||
1045 | if (me == midbox) | ||
1046 | { | ||
1047 | if (Math.Abs(contact.normal.Z) > 0.95f) | ||
1048 | { | ||
1049 | offset.Z = contact.pos.Z - _position.Z; | ||
1050 | offset.X = (float)Math.Abs(offset.X) * 0.5f + contact.depth; | ||
1051 | offset.Y = (float)Math.Abs(offset.Y) * 0.5f + contact.depth; | ||
1052 | offset.Z = (float)Math.Abs(offset.Z) * 0.5f + contact.depth; | ||
1053 | |||
1054 | if (reverse) | ||
1055 | { | ||
1056 | offset.X *= -contact.normal.X; | ||
1057 | offset.Y *= -contact.normal.Y; | ||
1058 | offset.Z *= -contact.normal.Z; | ||
1059 | } | ||
1060 | else | ||
1061 | { | ||
1062 | offset.X *= contact.normal.X; | ||
1063 | offset.Y *= contact.normal.Y; | ||
1064 | offset.Z *= contact.normal.Z; | ||
1065 | } | ||
1066 | |||
1067 | offset.X += contact.pos.X; | ||
1068 | offset.Y += contact.pos.Y; | ||
1069 | offset.Z += contact.pos.Z; | ||
1070 | _position = offset; | ||
1071 | return true; | ||
1072 | } | ||
1073 | else | ||
1074 | offset.Z = contact.normal.Z; | ||
1075 | |||
1076 | offset.Normalize(); | ||
1077 | |||
1078 | /* | ||
1079 | if (reverse) | ||
1080 | { | ||
1081 | contact.normal.X = offset.X; | ||
1082 | contact.normal.Y = offset.Y; | ||
1083 | contact.normal.Z = offset.Z; | ||
1084 | } | ||
1085 | else | ||
1086 | { | ||
1087 | contact.normal.X = -offset.X; | ||
1088 | contact.normal.Y = -offset.Y; | ||
1089 | contact.normal.Z = -offset.Z; | ||
1090 | } | ||
1091 | */ | ||
1092 | //_position.Z = offset.Z; | ||
1093 | return true; | ||
1094 | } | ||
1095 | |||
1096 | else if (me == feetbox) | ||
1097 | { | 884 | { |
1098 | float h = contact.pos.Z - _position.Z; | 885 | float h = contact.pos.Z - _position.Z; |
1099 | 886 | offset.Z = h - feetOff; | |
1100 | // Only do this if the normal is sufficiently pointing in the 'up' direction | ||
1101 | if (Math.Abs(contact.normal.Z) > 0.95f) | ||
1102 | { | ||
1103 | // We Only want to do this if we're sunk into the object a bit and we're stuck and we're trying to move and feetcollision is false | ||
1104 | if ((contact.depth > 0.0010f && _velocity.X == 0f && _velocity.Y == 0 && _velocity.Z == 0) | ||
1105 | && (_target_velocity.X > 0 || _target_velocity.Y > 0 || _target_velocity.Z > 0) | ||
1106 | && (!feetcollision) ) | ||
1107 | { | ||
1108 | m_collisionException = true; // Stop looping, do this only once not X times Contacts | ||
1109 | _position.Z += contact.depth + 0.01f; // Move us Up the amount that we sank in, and add 0.01 meters to gently lift avatar up. | ||
1110 | |||
1111 | return true; | ||
1112 | } | ||
1113 | |||
1114 | if (contact.normal.Z > 0) | ||
1115 | contact.normal.Z = 1.0f; | ||
1116 | else | ||
1117 | contact.normal.Z = -1.0f; | ||
1118 | contact.normal.X = 0.0f; | ||
1119 | contact.normal.Y = 0.0f; | ||
1120 | feetcollision = true; | ||
1121 | if (h < boneOff) | ||
1122 | IsColliding = true; | ||
1123 | return true; | ||
1124 | } | ||
1125 | |||
1126 | offset.Z = h - feetOff; // distance from top of feetbox | ||
1127 | 887 | ||
1128 | if (offset.Z > 0) | 888 | if (offset.Z > 0) |
1129 | return false; | 889 | return true; |
1130 | 890 | ||
1131 | if (offset.Z > -0.01) | 891 | offset.Normalize(); |
1132 | { | ||
1133 | offset.X = 0; | ||
1134 | offset.Y = 0; | ||
1135 | offset.Z = -1.0f; | ||
1136 | } | ||
1137 | else | ||
1138 | { | ||
1139 | offset.Normalize(); | ||
1140 | } | ||
1141 | 892 | ||
1142 | if (reverse) | 893 | if (reverse) |
1143 | { | 894 | { |
@@ -1171,23 +922,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1171 | if (Body == IntPtr.Zero) | 922 | if (Body == IntPtr.Zero) |
1172 | return; | 923 | return; |
1173 | 924 | ||
1174 | if (m_collisionException) | ||
1175 | { | ||
1176 | d.BodySetPosition(Body,_position.X, _position.Y, _position.Z); | ||
1177 | d.BodySetLinearVel(Body, 0, 0, 0); | ||
1178 | |||
1179 | float v = _velocity.Length(); | ||
1180 | if (v != 0) | ||
1181 | { | ||
1182 | v = 5.0f / v; | ||
1183 | _velocity = _velocity * v; | ||
1184 | d.BodySetLinearVel(Body, _velocity.X, _velocity.Y, _velocity.Z); | ||
1185 | } | ||
1186 | ajustCollider(); | ||
1187 | m_collisionException = false; | ||
1188 | return; | ||
1189 | } | ||
1190 | |||
1191 | d.Vector3 dtmp = d.BodyGetPosition(Body); | 925 | d.Vector3 dtmp = d.BodyGetPosition(Body); |
1192 | Vector3 localpos = new Vector3(dtmp.X, dtmp.Y, dtmp.Z); | 926 | Vector3 localpos = new Vector3(dtmp.X, dtmp.Y, dtmp.Z); |
1193 | 927 | ||
@@ -1263,7 +997,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1263 | // colide with land | 997 | // colide with land |
1264 | 998 | ||
1265 | d.AABB aabb; | 999 | d.AABB aabb; |
1266 | d.GeomGetAABB(feetbox, out aabb); | 1000 | // d.GeomGetAABB(feetbox, out aabb); |
1001 | d.GeomGetAABB(capsule, out aabb); | ||
1267 | float chrminZ = aabb.MinZ; ; // move up a bit | 1002 | float chrminZ = aabb.MinZ; ; // move up a bit |
1268 | Vector3 posch = localpos; | 1003 | Vector3 posch = localpos; |
1269 | 1004 | ||
@@ -1489,7 +1224,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1489 | m_rotationalVelocity.Z = dtmp.Z; | 1224 | m_rotationalVelocity.Z = dtmp.Z; |
1490 | Math.Round(m_rotationalVelocity.Z,3); | 1225 | Math.Round(m_rotationalVelocity.Z,3); |
1491 | } | 1226 | } |
1492 | ajustCollider(); | ||
1493 | } | 1227 | } |
1494 | 1228 | ||
1495 | public void round(ref Vector3 v, int digits) | 1229 | public void round(ref Vector3 v, int digits) |
@@ -1655,10 +1389,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1655 | AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z); | 1389 | AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z); |
1656 | 1390 | ||
1657 | _parent_scene.actor_name_map[collider] = (PhysicsActor)this; | 1391 | _parent_scene.actor_name_map[collider] = (PhysicsActor)this; |
1658 | _parent_scene.actor_name_map[feetbox] = (PhysicsActor)this; | 1392 | // _parent_scene.actor_name_map[feetbox] = (PhysicsActor)this; |
1659 | _parent_scene.actor_name_map[midbox] = (PhysicsActor)this; | 1393 | // _parent_scene.actor_name_map[midbox] = (PhysicsActor)this; |
1660 | _parent_scene.actor_name_map[topbox] = (PhysicsActor)this; | 1394 | // _parent_scene.actor_name_map[topbox] = (PhysicsActor)this; |
1661 | _parent_scene.actor_name_map[bbox] = (PhysicsActor)this; | 1395 | _parent_scene.actor_name_map[bbox] = (PhysicsActor)this; |
1396 | _parent_scene.actor_name_map[capsule] = (PhysicsActor)this; | ||
1662 | _parent_scene.AddCharacter(this); | 1397 | _parent_scene.AddCharacter(this); |
1663 | } | 1398 | } |
1664 | else | 1399 | else |
@@ -1714,13 +1449,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1714 | 1449 | ||
1715 | 1450 | ||
1716 | _parent_scene.actor_name_map[collider] = (PhysicsActor)this; | 1451 | _parent_scene.actor_name_map[collider] = (PhysicsActor)this; |
1717 | _parent_scene.actor_name_map[feetbox] = (PhysicsActor)this; | ||
1718 | _parent_scene.actor_name_map[midbox] = (PhysicsActor)this; | ||
1719 | _parent_scene.actor_name_map[topbox] = (PhysicsActor)this; | ||
1720 | _parent_scene.actor_name_map[bbox] = (PhysicsActor)this; | 1452 | _parent_scene.actor_name_map[bbox] = (PhysicsActor)this; |
1453 | _parent_scene.actor_name_map[capsule] = (PhysicsActor)this; | ||
1721 | } | 1454 | } |
1722 | m_freemove = false; | 1455 | m_freemove = false; |
1723 | m_collisionException = false; | ||
1724 | m_pidControllerActive = true; | 1456 | m_pidControllerActive = true; |
1725 | } | 1457 | } |
1726 | else | 1458 | else |
@@ -1851,7 +1583,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1851 | 1583 | ||
1852 | if (Body != IntPtr.Zero) | 1584 | if (Body != IntPtr.Zero) |
1853 | d.BodySetLinearVel(Body, newmomentum.X, newmomentum.Y, newmomentum.Z); | 1585 | d.BodySetLinearVel(Body, newmomentum.X, newmomentum.Y, newmomentum.Z); |
1854 | ajustCollider(); | ||
1855 | } | 1586 | } |
1856 | 1587 | ||
1857 | private void donullchange() | 1588 | private void donullchange() |
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs index a7dda7a..3c952ae 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs | |||
@@ -137,6 +137,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
137 | float m_amdampY; | 137 | float m_amdampY; |
138 | float m_amdampZ; | 138 | float m_amdampZ; |
139 | 139 | ||
140 | float m_gravmod; | ||
140 | 141 | ||
141 | public float FrictionFactor | 142 | public float FrictionFactor |
142 | { | 143 | { |
@@ -146,6 +147,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
146 | } | 147 | } |
147 | } | 148 | } |
148 | 149 | ||
150 | public float GravMod | ||
151 | { | ||
152 | set | ||
153 | { | ||
154 | m_gravmod = value; | ||
155 | } | ||
156 | } | ||
157 | |||
149 | 158 | ||
150 | public ODEDynamics(OdePrim rootp) | 159 | public ODEDynamics(OdePrim rootp) |
151 | { | 160 | { |
@@ -153,6 +162,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
153 | _pParentScene = rootPrim._parent_scene; | 162 | _pParentScene = rootPrim._parent_scene; |
154 | m_timestep = _pParentScene.ODE_STEPSIZE; | 163 | m_timestep = _pParentScene.ODE_STEPSIZE; |
155 | m_invtimestep = 1.0f / m_timestep; | 164 | m_invtimestep = 1.0f / m_timestep; |
165 | m_gravmod = rootPrim.GravModifier; | ||
156 | } | 166 | } |
157 | 167 | ||
158 | public void DoSetVehicle(VehicleData vd) | 168 | public void DoSetVehicle(VehicleData vd) |
@@ -816,7 +826,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
816 | m_lmEfect = 0; | 826 | m_lmEfect = 0; |
817 | m_ffactor = 1f; | 827 | m_ffactor = 1f; |
818 | } | 828 | } |
819 | 829 | ||
820 | // hover | 830 | // hover |
821 | if (m_VhoverTimescale < 300 && rootPrim.prim_geom != IntPtr.Zero) | 831 | if (m_VhoverTimescale < 300 && rootPrim.prim_geom != IntPtr.Zero) |
822 | { | 832 | { |
@@ -862,7 +872,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
862 | force.Z += perr; | 872 | force.Z += perr; |
863 | ldampZ *= -curVel.Z; | 873 | ldampZ *= -curVel.Z; |
864 | 874 | ||
865 | force.Z += _pParentScene.gravityz * (1f - m_VehicleBuoyancy); | 875 | force.Z += _pParentScene.gravityz * m_gravmod * (1f - m_VehicleBuoyancy); |
866 | } | 876 | } |
867 | else // no buoyancy | 877 | else // no buoyancy |
868 | force.Z += _pParentScene.gravityz; | 878 | force.Z += _pParentScene.gravityz; |
@@ -870,7 +880,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
870 | else | 880 | else |
871 | { | 881 | { |
872 | // default gravity and Buoyancy | 882 | // default gravity and Buoyancy |
873 | force.Z += _pParentScene.gravityz * (1f - m_VehicleBuoyancy); | 883 | force.Z += _pParentScene.gravityz * m_gravmod * (1f - m_VehicleBuoyancy); |
874 | } | 884 | } |
875 | 885 | ||
876 | // linear deflection | 886 | // linear deflection |
@@ -1063,8 +1073,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1063 | torque.Y -= curLocalAngVel.Y * m_amdampY; | 1073 | torque.Y -= curLocalAngVel.Y * m_amdampY; |
1064 | torque.Z -= curLocalAngVel.Z * m_amdampZ; | 1074 | torque.Z -= curLocalAngVel.Z * m_amdampZ; |
1065 | } | 1075 | } |
1066 | 1076 | ||
1067 | |||
1068 | 1077 | ||
1069 | if (force.X != 0 || force.Y != 0 || force.Z != 0) | 1078 | if (force.X != 0 || force.Y != 0 || force.Z != 0) |
1070 | { | 1079 | { |
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs index 0df71eb..5030cec 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs | |||
@@ -448,7 +448,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
448 | else | 448 | else |
449 | { | 449 | { |
450 | repData.meshState = MeshState.needMesh; | 450 | repData.meshState = MeshState.needMesh; |
451 | mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, false, convex, true); | 451 | mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex, true); |
452 | if (mesh == null) | 452 | if (mesh == null) |
453 | { | 453 | { |
454 | repData.meshState = MeshState.MeshFailed; | 454 | repData.meshState = MeshState.MeshFailed; |
@@ -513,7 +513,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
513 | clod = (int)LevelOfDetail.Low; | 513 | clod = (int)LevelOfDetail.Low; |
514 | } | 514 | } |
515 | 515 | ||
516 | mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, false, convex, true); | 516 | mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex, true); |
517 | 517 | ||
518 | if (mesh == null) | 518 | if (mesh == null) |
519 | { | 519 | { |
@@ -929,4 +929,4 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
929 | repData.actor.Name); | 929 | repData.actor.Name); |
930 | } | 930 | } |
931 | } | 931 | } |
932 | } | 932 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs index faa9488..4cac0aa 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | |||
@@ -25,7 +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 by Ubit Umarov | 28 | /* Revision 2011/12/13 by Ubit Umarov |
29 | * | 29 | * |
30 | * | 30 | * |
31 | */ | 31 | */ |
@@ -115,7 +115,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
115 | 115 | ||
116 | private int body_autodisable_frames; | 116 | private int body_autodisable_frames; |
117 | public int bodydisablecontrol; | 117 | public int bodydisablecontrol; |
118 | 118 | private float m_gravmod = 1.0f; | |
119 | 119 | ||
120 | // Default we're a Geometry | 120 | // Default we're a Geometry |
121 | private CollisionCategories m_collisionCategories = (CollisionCategories.Geom); | 121 | private CollisionCategories m_collisionCategories = (CollisionCategories.Geom); |
@@ -914,6 +914,55 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
914 | bounce = _parent_scene.m_materialContactsData[pMaterial].bounce; | 914 | bounce = _parent_scene.m_materialContactsData[pMaterial].bounce; |
915 | } | 915 | } |
916 | 916 | ||
917 | public override float Density | ||
918 | { | ||
919 | get | ||
920 | { | ||
921 | return m_density * 100f; | ||
922 | } | ||
923 | set | ||
924 | { | ||
925 | m_density = value / 100f; | ||
926 | // for not prim mass is not updated since this implies full rebuild of body inertia TODO | ||
927 | } | ||
928 | } | ||
929 | public override float GravModifier | ||
930 | { | ||
931 | get | ||
932 | { | ||
933 | return m_gravmod; | ||
934 | } | ||
935 | set | ||
936 | { | ||
937 | m_gravmod = value; | ||
938 | if (m_vehicle != null) | ||
939 | m_vehicle.GravMod = m_gravmod; | ||
940 | } | ||
941 | } | ||
942 | public override float Friction | ||
943 | { | ||
944 | get | ||
945 | { | ||
946 | return mu; | ||
947 | } | ||
948 | set | ||
949 | { | ||
950 | mu = value; | ||
951 | } | ||
952 | } | ||
953 | |||
954 | public override float Restitution | ||
955 | { | ||
956 | get | ||
957 | { | ||
958 | return bounce; | ||
959 | } | ||
960 | set | ||
961 | { | ||
962 | bounce = value; | ||
963 | } | ||
964 | } | ||
965 | |||
917 | public void setPrimForRemoval() | 966 | public void setPrimForRemoval() |
918 | { | 967 | { |
919 | AddChange(changes.Remove, null); | 968 | AddChange(changes.Remove, null); |
@@ -1736,7 +1785,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1736 | 1785 | ||
1737 | d.BodySetAutoDisableFlag(Body, true); | 1786 | d.BodySetAutoDisableFlag(Body, true); |
1738 | d.BodySetAutoDisableSteps(Body, body_autodisable_frames); | 1787 | d.BodySetAutoDisableSteps(Body, body_autodisable_frames); |
1739 | d.BodySetDamping(Body, .005f, .005f); | 1788 | d.BodySetAutoDisableAngularThreshold(Body, 0.01f); |
1789 | d.BodySetAutoDisableLinearThreshold(Body, 0.01f); | ||
1790 | d.BodySetDamping(Body, .005f, .001f); | ||
1740 | 1791 | ||
1741 | if (m_targetSpace != IntPtr.Zero) | 1792 | if (m_targetSpace != IntPtr.Zero) |
1742 | { | 1793 | { |
@@ -2144,7 +2195,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2144 | 2195 | ||
2145 | _mass = primMass; // just in case | 2196 | _mass = primMass; // just in case |
2146 | 2197 | ||
2147 | d.MassSetBoxTotal(out primdMass, primMass, m_OBB.X, m_OBB.Y, m_OBB.Z); | 2198 | d.MassSetBoxTotal(out primdMass, primMass, 2.0f * m_OBB.X, 2.0f * m_OBB.Y, 2.0f * m_OBB.Z); |
2148 | 2199 | ||
2149 | d.MassTranslate(ref primdMass, | 2200 | d.MassTranslate(ref primdMass, |
2150 | m_OBBOffset.X, | 2201 | m_OBBOffset.X, |
@@ -2362,6 +2413,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2362 | MakeBody(); | 2413 | MakeBody(); |
2363 | } | 2414 | } |
2364 | 2415 | ||
2416 | |||
2365 | #region changes | 2417 | #region changes |
2366 | 2418 | ||
2367 | private void changeadd() | 2419 | private void changeadd() |
@@ -3213,7 +3265,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3213 | 3265 | ||
3214 | if (++bodydisablecontrol < 20) | 3266 | if (++bodydisablecontrol < 20) |
3215 | return; | 3267 | return; |
3216 | |||
3217 | 3268 | ||
3218 | d.BodyEnable(Body); | 3269 | d.BodyEnable(Body); |
3219 | } | 3270 | } |
@@ -3334,7 +3385,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3334 | } | 3385 | } |
3335 | else | 3386 | else |
3336 | { | 3387 | { |
3337 | float b = (1.0f - m_buoyancy); | 3388 | float b = (1.0f - m_buoyancy) * m_gravmod; |
3338 | fx = _parent_scene.gravityx * b; | 3389 | fx = _parent_scene.gravityx * b; |
3339 | fy = _parent_scene.gravityy * b; | 3390 | fy = _parent_scene.gravityy * b; |
3340 | fz = _parent_scene.gravityz * b; | 3391 | fz = _parent_scene.gravityz * b; |
@@ -3381,11 +3432,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3381 | } | 3432 | } |
3382 | } | 3433 | } |
3383 | 3434 | ||
3384 | public void UpdatePositionAndVelocity() | 3435 | public void UpdatePositionAndVelocity(int frame) |
3385 | { | 3436 | { |
3386 | if (_parent == null && !m_disabled && !m_building && !m_outbounds && Body != IntPtr.Zero) | 3437 | if (_parent == null && !m_disabled && !m_building && !m_outbounds && Body != IntPtr.Zero) |
3387 | { | 3438 | { |
3388 | if (d.BodyIsEnabled(Body) || !_zeroFlag) | 3439 | bool bodyenabled = d.BodyIsEnabled(Body); |
3440 | if (bodyenabled || !_zeroFlag) | ||
3389 | { | 3441 | { |
3390 | bool lastZeroFlag = _zeroFlag; | 3442 | bool lastZeroFlag = _zeroFlag; |
3391 | 3443 | ||
@@ -3478,13 +3530,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3478 | // tolerance values depende a lot on simulation noise... | 3530 | // tolerance values depende a lot on simulation noise... |
3479 | // use simple math.abs since we dont need to be exact | 3531 | // use simple math.abs since we dont need to be exact |
3480 | 3532 | ||
3481 | if ( | 3533 | if (!bodyenabled || |
3482 | (Math.Abs(_position.X - lpos.X) < 0.001f) | 3534 | (Math.Abs(_position.X - lpos.X) < 0.005f) |
3483 | && (Math.Abs(_position.Y - lpos.Y) < 0.001f) | 3535 | && (Math.Abs(_position.Y - lpos.Y) < 0.005f) |
3484 | && (Math.Abs(_position.Z - lpos.Z) < 0.001f) | 3536 | && (Math.Abs(_position.Z - lpos.Z) < 0.005f) |
3485 | && (Math.Abs(_orientation.X - ori.X) < 0.0001f) | 3537 | && (Math.Abs(_orientation.X - ori.X) < 0.0005f) |
3486 | && (Math.Abs(_orientation.Y - ori.Y) < 0.0001f) | 3538 | && (Math.Abs(_orientation.Y - ori.Y) < 0.0005f) |
3487 | && (Math.Abs(_orientation.Z - ori.Z) < 0.0001f) // ignore W | 3539 | && (Math.Abs(_orientation.Z - ori.Z) < 0.0005f) // ignore W |
3488 | ) | 3540 | ) |
3489 | { | 3541 | { |
3490 | _zeroFlag = true; | 3542 | _zeroFlag = true; |
@@ -3499,9 +3551,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3499 | 3551 | ||
3500 | _acceleration = _velocity; | 3552 | _acceleration = _velocity; |
3501 | 3553 | ||
3502 | if ((Math.Abs(vel.X) < 0.001f) && | 3554 | if ((Math.Abs(vel.X) < 0.005f) && |
3503 | (Math.Abs(vel.Y) < 0.001f) && | 3555 | (Math.Abs(vel.Y) < 0.005f) && |
3504 | (Math.Abs(vel.Z) < 0.001f)) | 3556 | (Math.Abs(vel.Z) < 0.005f)) |
3505 | { | 3557 | { |
3506 | _velocity = Vector3.Zero; | 3558 | _velocity = Vector3.Zero; |
3507 | float t = -m_invTimeStep; | 3559 | float t = -m_invTimeStep; |
@@ -3538,6 +3590,15 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3538 | } | 3590 | } |
3539 | } | 3591 | } |
3540 | 3592 | ||
3593 | _position.X = lpos.X; | ||
3594 | _position.Y = lpos.Y; | ||
3595 | _position.Z = lpos.Z; | ||
3596 | |||
3597 | _orientation.X = ori.X; | ||
3598 | _orientation.Y = ori.Y; | ||
3599 | _orientation.Z = ori.Z; | ||
3600 | _orientation.W = ori.W; | ||
3601 | |||
3541 | if (_zeroFlag) | 3602 | if (_zeroFlag) |
3542 | { | 3603 | { |
3543 | if (lastZeroFlag) | 3604 | if (lastZeroFlag) |
@@ -3556,14 +3617,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3556 | return; | 3617 | return; |
3557 | } | 3618 | } |
3558 | 3619 | ||
3559 | _position.X = lpos.X; | ||
3560 | _position.Y = lpos.Y; | ||
3561 | _position.Z = lpos.Z; | ||
3562 | |||
3563 | _orientation.X = ori.X; | ||
3564 | _orientation.Y = ori.Y; | ||
3565 | _orientation.Z = ori.Z; | ||
3566 | _orientation.W = ori.W; | ||
3567 | base.RequestPhysicsterseUpdate(); | 3620 | base.RequestPhysicsterseUpdate(); |
3568 | m_lastUpdateSent = false; | 3621 | m_lastUpdateSent = false; |
3569 | } | 3622 | } |
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs index 2923ccf..73ababa 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs | |||
@@ -680,4 +680,4 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
680 | public RayFilterFlags filter; | 680 | public RayFilterFlags filter; |
681 | public Quaternion orientation; | 681 | public Quaternion orientation; |
682 | } | 682 | } |
683 | } | 683 | } \ No newline at end of file |
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 | } |