diff options
author | UbitUmarov | 2012-04-17 15:50:14 +0100 |
---|---|---|
committer | UbitUmarov | 2012-04-17 15:50:14 +0100 |
commit | 9132c9e49963c656e303815e5cb9e0c4341f0821 (patch) | |
tree | 7e79a34ea797353e35878100b5bca4c57f1fd2a2 | |
parent | ubitODE: - made avatar/ground collision pid servo a bit softer since seems a ... (diff) | |
download | opensim-SC_OLD-9132c9e49963c656e303815e5cb9e0c4341f0821.zip opensim-SC_OLD-9132c9e49963c656e303815e5cb9e0c4341f0821.tar.gz opensim-SC_OLD-9132c9e49963c656e303815e5cb9e0c4341f0821.tar.bz2 opensim-SC_OLD-9132c9e49963c656e303815e5cb9e0c4341f0821.tar.xz |
ubitODE: - character managed ode was only getting position etc from unmanaged at heartbeat rate like core ode. Now do it at ODE rate in move(..). UpdatePositionAndVelocity() called once per heartbeat is now empty.
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs | 162 | ||||
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | 5 |
2 files changed, 48 insertions, 119 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs index 1c8de56..b9ec6b5 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs | |||
@@ -771,16 +771,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
771 | /// <param name="timeStep"></param> | 771 | /// <param name="timeStep"></param> |
772 | public void Move(float timeStep, List<OdeCharacter> defects) | 772 | public void Move(float timeStep, List<OdeCharacter> defects) |
773 | { | 773 | { |
774 | // no lock; for now it's only called from within Simulate() | ||
775 | |||
776 | // If the PID Controller isn't active then we set our force | ||
777 | // calculating base velocity to the current position | ||
778 | |||
779 | if (Body == IntPtr.Zero) | 774 | if (Body == IntPtr.Zero) |
780 | return; | 775 | return; |
781 | 776 | ||
782 | d.Vector3 dtmp; | 777 | d.Vector3 dtmp = d.BodyGetPosition(Body); |
783 | d.BodyCopyPosition(Body, out dtmp); | ||
784 | Vector3 localpos = new Vector3(dtmp.X, dtmp.Y, dtmp.Z); | 778 | Vector3 localpos = new Vector3(dtmp.X, dtmp.Y, dtmp.Z); |
785 | 779 | ||
786 | // the Amotor still lets avatar rotation to drift during colisions | 780 | // the Amotor still lets avatar rotation to drift during colisions |
@@ -797,22 +791,43 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
797 | { | 791 | { |
798 | _zeroPosition = localpos; | 792 | _zeroPosition = localpos; |
799 | } | 793 | } |
800 | //PidStatus = true; | ||
801 | |||
802 | 794 | ||
803 | if (!localpos.IsFinite()) | 795 | if (!localpos.IsFinite()) |
804 | { | 796 | { |
805 | |||
806 | m_log.Warn("[PHYSICS]: Avatar Position is non-finite!"); | 797 | m_log.Warn("[PHYSICS]: Avatar Position is non-finite!"); |
807 | defects.Add(this); | 798 | defects.Add(this); |
808 | // _parent_scene.RemoveCharacter(this); | 799 | // _parent_scene.RemoveCharacter(this); |
809 | 800 | ||
810 | // destroy avatar capsule and related ODE data | 801 | // destroy avatar capsule and related ODE data |
811 | AvatarGeomAndBodyDestroy(); | 802 | AvatarGeomAndBodyDestroy(); |
812 | |||
813 | return; | 803 | return; |
814 | } | 804 | } |
815 | 805 | ||
806 | // check outbounds forcing to be in world | ||
807 | bool fixbody = false; | ||
808 | if (localpos.X < 0.0f) | ||
809 | { | ||
810 | fixbody = true; | ||
811 | localpos.X = 0.1f; | ||
812 | } | ||
813 | else if (localpos.X > _parent_scene.WorldExtents.X - 0.1f) | ||
814 | { | ||
815 | fixbody = true; | ||
816 | localpos.X = _parent_scene.WorldExtents.X - 0.1f; | ||
817 | } | ||
818 | if (localpos.Y < 0.0f) | ||
819 | { | ||
820 | fixbody = true; | ||
821 | localpos.Y = 0.1f; | ||
822 | } | ||
823 | else if (localpos.Y > _parent_scene.WorldExtents.Y - 0.1) | ||
824 | { | ||
825 | fixbody = true; | ||
826 | localpos.Y = _parent_scene.WorldExtents.Y - 0.1f; | ||
827 | } | ||
828 | if (fixbody) | ||
829 | d.BodySetPosition(Body, localpos.X, localpos.Y, localpos.Z); | ||
830 | |||
816 | Vector3 vec = Vector3.Zero; | 831 | Vector3 vec = Vector3.Zero; |
817 | dtmp = d.BodyGetLinearVel(Body); | 832 | dtmp = d.BodyGetLinearVel(Body); |
818 | Vector3 vel = new Vector3(dtmp.X, dtmp.Y, dtmp.Z); | 833 | Vector3 vel = new Vector3(dtmp.X, dtmp.Y, dtmp.Z); |
@@ -820,16 +835,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
820 | float movementdivisor = 1f; | 835 | float movementdivisor = 1f; |
821 | //Ubit change divisions into multiplications below | 836 | //Ubit change divisions into multiplications below |
822 | if (!m_alwaysRun) | 837 | if (!m_alwaysRun) |
823 | { | ||
824 | movementdivisor = 1 / walkDivisor; | 838 | movementdivisor = 1 / walkDivisor; |
825 | } | ||
826 | else | 839 | else |
827 | { | ||
828 | movementdivisor = 1 / runDivisor; | 840 | movementdivisor = 1 / runDivisor; |
829 | } | ||
830 | 841 | ||
842 | //****************************************** | ||
831 | // colide with land | 843 | // colide with land |
832 | |||
833 | d.AABB aabb; | 844 | d.AABB aabb; |
834 | d.GeomGetAABB(Shell, out aabb); | 845 | d.GeomGetAABB(Shell, out aabb); |
835 | float chrminZ = aabb.MinZ; | 846 | float chrminZ = aabb.MinZ; |
@@ -856,26 +867,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
856 | else | 867 | else |
857 | vec.Z = depth * PID_P * 30; | 868 | vec.Z = depth * PID_P * 30; |
858 | 869 | ||
859 | /* | ||
860 | Vector3 vtmp; | ||
861 | vtmp.X = _target_velocity.X * timeStep; | ||
862 | vtmp.Y = _target_velocity.Y * timeStep; | ||
863 | // fake and avoid squares | ||
864 | float k = (Math.Abs(vtmp.X) + Math.Abs(vtmp.Y)); | ||
865 | if (k > 0) | ||
866 | { | ||
867 | posch.X += vtmp.X; | ||
868 | posch.Y += vtmp.Y; | ||
869 | terrainheight -= _parent_scene.GetTerrainHeightAtXY(posch.X, posch.Y); | ||
870 | k = 1 + Math.Abs(terrainheight) / k; | ||
871 | movementdivisor /= k; | ||
872 | |||
873 | if (k < 1) | ||
874 | k = 1; | ||
875 | } | ||
876 | */ | ||
877 | |||
878 | |||
879 | if (depth < 0.1f) | 870 | if (depth < 0.1f) |
880 | { | 871 | { |
881 | m_iscolliding = true; | 872 | m_iscolliding = true; |
@@ -901,6 +892,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
901 | else | 892 | else |
902 | m_iscollidingGround = false; | 893 | m_iscollidingGround = false; |
903 | 894 | ||
895 | //****************************************** | ||
904 | 896 | ||
905 | // if velocity is zero, use position control; otherwise, velocity control | 897 | // if velocity is zero, use position control; otherwise, velocity control |
906 | if (_target_velocity.X == 0.0f && _target_velocity.Y == 0.0f && _target_velocity.Z == 0.0f | 898 | if (_target_velocity.X == 0.0f && _target_velocity.Y == 0.0f && _target_velocity.Z == 0.0f |
@@ -1012,97 +1004,31 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1012 | // _parent_scene.RemoveCharacter(this); | 1004 | // _parent_scene.RemoveCharacter(this); |
1013 | // destroy avatar capsule and related ODE data | 1005 | // destroy avatar capsule and related ODE data |
1014 | AvatarGeomAndBodyDestroy(); | 1006 | AvatarGeomAndBodyDestroy(); |
1007 | return; | ||
1015 | } | 1008 | } |
1009 | |||
1010 | // update our local ideia of position velocity and aceleration | ||
1011 | _position = localpos; | ||
1012 | _acceleration = _velocity; // previus velocity | ||
1013 | _velocity = vel; | ||
1014 | _acceleration = (vel - _acceleration) / timeStep; | ||
1015 | |||
1016 | } | 1016 | } |
1017 | 1017 | ||
1018 | /// <summary> | 1018 | /// <summary> |
1019 | /// Updates the reported position and velocity. This essentially sends the data up to ScenePresence. | 1019 | /// Updates the reported position and velocity. |
1020 | /// Used to copy variables from unmanaged space at heartbeat rate and also trigger scene updates acording | ||
1021 | /// also outbounds checking | ||
1022 | /// copy and outbounds now done in move(..) at ode rate | ||
1023 | /// | ||
1020 | /// </summary> | 1024 | /// </summary> |
1021 | public void UpdatePositionAndVelocity() | 1025 | public void UpdatePositionAndVelocity() |
1022 | { | 1026 | { |
1023 | // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! | 1027 | return; |
1024 | if (Body == IntPtr.Zero) | ||
1025 | return; | ||
1026 | 1028 | ||
1027 | d.Vector3 vec; | 1029 | // if (Body == IntPtr.Zero) |
1028 | try | 1030 | // return; |
1029 | { | ||
1030 | d.BodyCopyPosition(Body, out vec); | ||
1031 | } | ||
1032 | catch (NullReferenceException) | ||
1033 | { | ||
1034 | bad = true; | ||
1035 | _parent_scene.BadCharacter(this); | ||
1036 | vec = new d.Vector3(_position.X, _position.Y, _position.Z); | ||
1037 | base.RaiseOutOfBounds(_position); // Tells ScenePresence that there's a problem! | ||
1038 | m_log.WarnFormat("[ODEPLUGIN]: Avatar Null reference for Avatar {0}, physical actor {1}", m_name, m_uuid); | ||
1039 | } | ||
1040 | |||
1041 | _position.X = vec.X; | ||
1042 | _position.Y = vec.Y; | ||
1043 | _position.Z = vec.Z; | ||
1044 | |||
1045 | bool fixbody = false; | ||
1046 | |||
1047 | if (_position.X < 0.0f) | ||
1048 | { | ||
1049 | fixbody = true; | ||
1050 | _position.X = 0.1f; | ||
1051 | } | ||
1052 | else if (_position.X > (int)_parent_scene.WorldExtents.X - 0.1f) | ||
1053 | { | ||
1054 | fixbody = true; | ||
1055 | _position.X = (int)_parent_scene.WorldExtents.X - 0.1f; | ||
1056 | } | ||
1057 | |||
1058 | if (_position.Y < 0.0f) | ||
1059 | { | ||
1060 | fixbody = true; | ||
1061 | _position.Y = 0.1f; | ||
1062 | } | ||
1063 | else if (_position.Y > (int)_parent_scene.WorldExtents.Y - 0.1) | ||
1064 | { | ||
1065 | fixbody = true; | ||
1066 | _position.Y = (int)_parent_scene.WorldExtents.Y - 0.1f; | ||
1067 | } | ||
1068 | 1031 | ||
1069 | if (fixbody) | ||
1070 | d.BodySetPosition(Body, _position.X, _position.Y, _position.Z); | ||
1071 | |||
1072 | // Did we move last? = zeroflag | ||
1073 | // This helps keep us from sliding all over | ||
1074 | /* | ||
1075 | if (_zeroFlag) | ||
1076 | { | ||
1077 | _velocity.X = 0.0f; | ||
1078 | _velocity.Y = 0.0f; | ||
1079 | _velocity.Z = 0.0f; | ||
1080 | |||
1081 | // Did we send out the 'stopped' message? | ||
1082 | if (!m_lastUpdateSent) | ||
1083 | { | ||
1084 | m_lastUpdateSent = true; | ||
1085 | base.RequestPhysicsterseUpdate(); | ||
1086 | } | ||
1087 | } | ||
1088 | else | ||
1089 | { | ||
1090 | m_lastUpdateSent = false; | ||
1091 | */ | ||
1092 | try | ||
1093 | { | ||
1094 | vec = d.BodyGetLinearVel(Body); | ||
1095 | } | ||
1096 | catch (NullReferenceException) | ||
1097 | { | ||
1098 | vec.X = _velocity.X; | ||
1099 | vec.Y = _velocity.Y; | ||
1100 | vec.Z = _velocity.Z; | ||
1101 | } | ||
1102 | _velocity.X = (vec.X); | ||
1103 | _velocity.Y = (vec.Y); | ||
1104 | _velocity.Z = (vec.Z); | ||
1105 | // } | ||
1106 | } | 1032 | } |
1107 | 1033 | ||
1108 | /// <summary> | 1034 | /// <summary> |
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index 837eae3..9ca2d3f 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | |||
@@ -1861,6 +1861,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1861 | 1861 | ||
1862 | statstart = Util.EnvironmentTickCount(); | 1862 | statstart = Util.EnvironmentTickCount(); |
1863 | 1863 | ||
1864 | /* | ||
1865 | // now included in characters move() and done at ode rate | ||
1866 | // maybe be needed later if we need to do any extra work at hearbeat rate | ||
1864 | lock (_characters) | 1867 | lock (_characters) |
1865 | { | 1868 | { |
1866 | foreach (OdeCharacter actor in _characters) | 1869 | foreach (OdeCharacter actor in _characters) |
@@ -1874,7 +1877,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1874 | } | 1877 | } |
1875 | } | 1878 | } |
1876 | } | 1879 | } |
1877 | 1880 | */ | |
1878 | lock (_badCharacter) | 1881 | lock (_badCharacter) |
1879 | { | 1882 | { |
1880 | if (_badCharacter.Count > 0) | 1883 | if (_badCharacter.Count > 0) |