diff options
author | Teravus Ovares | 2007-11-08 15:22:36 +0000 |
---|---|---|
committer | Teravus Ovares | 2007-11-08 15:22:36 +0000 |
commit | fcc276a68da1da15fac802725a116b3e8d7f7197 (patch) | |
tree | b69d28ba9ef087154aa7480b6be89cee8d1b2389 /OpenSim | |
parent | reformatted OpenSimAssetSet.xml (whitespace only) (diff) | |
download | opensim-SC_OLD-fcc276a68da1da15fac802725a116b3e8d7f7197.zip opensim-SC_OLD-fcc276a68da1da15fac802725a116b3e8d7f7197.tar.gz opensim-SC_OLD-fcc276a68da1da15fac802725a116b3e8d7f7197.tar.bz2 opensim-SC_OLD-fcc276a68da1da15fac802725a116b3e8d7f7197.tar.xz |
* Fixed occasional character drift caused by sim not sending the avatar's final resting velocity.
* Added Smooth moving prim
* Added event to PhysicsActor RequestPhysicsterseUpdate to allow physics plugins to be able to schedule a terse update.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/SceneObjectPart.cs | 12 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Scenes/ScenePresence.cs | 2 | ||||
-rw-r--r-- | OpenSim/Region/Physics/Manager/PhysicsActor.cs | 20 | ||||
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 93 |
4 files changed, 111 insertions, 16 deletions
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index 0e2b186..f54b52f 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs | |||
@@ -782,10 +782,15 @@ namespace OpenSim.Region.Environment.Scenes | |||
782 | if (UsePhysics) | 782 | if (UsePhysics) |
783 | { | 783 | { |
784 | AddFlag(LLObject.ObjectFlags.Physics); | 784 | AddFlag(LLObject.ObjectFlags.Physics); |
785 | if (PhysActor != null) | ||
786 | PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate; | ||
787 | |||
785 | } | 788 | } |
786 | else | 789 | else |
787 | { | 790 | { |
788 | RemFlag(LLObject.ObjectFlags.Physics); | 791 | RemFlag(LLObject.ObjectFlags.Physics); |
792 | if (PhysActor != null) | ||
793 | PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate; | ||
789 | } | 794 | } |
790 | 795 | ||
791 | if (IsPhantom) | 796 | if (IsPhantom) |
@@ -1067,6 +1072,13 @@ namespace OpenSim.Region.Environment.Scenes | |||
1067 | public virtual void UpdateMovement() | 1072 | public virtual void UpdateMovement() |
1068 | { | 1073 | { |
1069 | } | 1074 | } |
1075 | #region Events | ||
1076 | public void PhysicsRequestingTerseUpdate() | ||
1077 | { | ||
1078 | SendTerseUpdateToAllClients(); | ||
1079 | } | ||
1080 | #endregion | ||
1081 | |||
1070 | 1082 | ||
1071 | public virtual void OnGrab(LLVector3 offsetPos, IClientAPI remoteClient) | 1083 | public virtual void OnGrab(LLVector3 offsetPos, IClientAPI remoteClient) |
1072 | { | 1084 | { |
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index 789bd68..608efc3 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs | |||
@@ -386,6 +386,7 @@ namespace OpenSim.Region.Environment.Scenes | |||
386 | if (PhysicsActor != null) | 386 | if (PhysicsActor != null) |
387 | { | 387 | { |
388 | m_scene.PhysScene.RemoveAvatar(PhysicsActor); | 388 | m_scene.PhysScene.RemoveAvatar(PhysicsActor); |
389 | m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; | ||
389 | PhysicsActor = null; | 390 | PhysicsActor = null; |
390 | } | 391 | } |
391 | } | 392 | } |
@@ -1092,6 +1093,7 @@ namespace OpenSim.Region.Environment.Scenes | |||
1092 | AbsolutePosition.Z); | 1093 | AbsolutePosition.Z); |
1093 | 1094 | ||
1094 | m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec); | 1095 | m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec); |
1096 | m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; | ||
1095 | } | 1097 | } |
1096 | 1098 | ||
1097 | internal void Close() | 1099 | internal void Close() |
diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs index 2d8eb9a..049da96 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs | |||
@@ -36,14 +36,19 @@ namespace OpenSim.Region.Physics.Manager | |||
36 | 36 | ||
37 | public delegate void OrientationUpdate(Quaternion orientation); | 37 | public delegate void OrientationUpdate(Quaternion orientation); |
38 | 38 | ||
39 | |||
40 | |||
39 | 41 | ||
40 | 42 | ||
41 | public abstract class PhysicsActor | 43 | public abstract class PhysicsActor |
42 | { | 44 | { |
45 | public delegate void RequestTerseUpdate(); | ||
46 | |||
43 | #pragma warning disable 67 | 47 | #pragma warning disable 67 |
44 | public event PositionUpdate OnPositionUpdate; | 48 | public event PositionUpdate OnPositionUpdate; |
45 | public event VelocityUpdate OnVelocityUpdate; | 49 | public event VelocityUpdate OnVelocityUpdate; |
46 | public event OrientationUpdate OnOrientationUpdate; | 50 | public event OrientationUpdate OnOrientationUpdate; |
51 | public event RequestTerseUpdate OnRequestTerseUpdate; | ||
47 | #pragma warning restore 67 | 52 | #pragma warning restore 67 |
48 | 53 | ||
49 | public static PhysicsActor Null | 54 | public static PhysicsActor Null |
@@ -57,6 +62,19 @@ namespace OpenSim.Region.Physics.Manager | |||
57 | { | 62 | { |
58 | set; | 63 | set; |
59 | } | 64 | } |
65 | public virtual void RequestPhysicsterseUpdate() | ||
66 | { | ||
67 | // Make a temporary copy of the event to avoid possibility of | ||
68 | // a race condition if the last subscriber unsubscribes | ||
69 | // immediately after the null check and before the event is raised. | ||
70 | RequestTerseUpdate handler = OnRequestTerseUpdate; | ||
71 | if (handler != null) | ||
72 | { | ||
73 | OnRequestTerseUpdate(); | ||
74 | } | ||
75 | |||
76 | } | ||
77 | |||
60 | 78 | ||
61 | public abstract PhysicsVector Position { get; set; } | 79 | public abstract PhysicsVector Position { get; set; } |
62 | 80 | ||
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 512b96e..b6c63af 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | |||
@@ -217,21 +217,18 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
217 | 217 | ||
218 | private void collision_optimized(float timeStep) | 218 | private void collision_optimized(float timeStep) |
219 | { | 219 | { |
220 | foreach (OdeCharacter chr in _characters) | 220 | |
221 | { | ||
222 | chr.IsColliding = false; | ||
223 | } | ||
224 | foreach (OdeCharacter chr in _characters) | 221 | foreach (OdeCharacter chr in _characters) |
225 | { | 222 | { |
226 | 223 | ||
227 | 224 | ||
228 | 225 | chr.IsColliding = false; | |
229 | d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); | 226 | d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); |
230 | foreach (OdeCharacter ch2 in _characters) | 227 | foreach (OdeCharacter ch2 in _characters) |
231 | /// should be a separate space -- lots of avatars will be N**2 slow | 228 | /// should be a separate space -- lots of avatars will be N**2 slow |
232 | { | 229 | { |
233 | 230 | ||
234 | 231 | ||
235 | d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback); | 232 | d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback); |
236 | } | 233 | } |
237 | 234 | ||
@@ -614,6 +611,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
614 | private PhysicsVector _position; | 611 | private PhysicsVector _position; |
615 | private d.Vector3 _zeroPosition; | 612 | private d.Vector3 _zeroPosition; |
616 | private bool _zeroFlag = false; | 613 | private bool _zeroFlag = false; |
614 | private bool m_lastUpdateSent = false; | ||
617 | private PhysicsVector _velocity; | 615 | private PhysicsVector _velocity; |
618 | private PhysicsVector _target_velocity; | 616 | private PhysicsVector _target_velocity; |
619 | private PhysicsVector _acceleration; | 617 | private PhysicsVector _acceleration; |
@@ -624,7 +622,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
624 | public static float CAPSULE_RADIUS = 0.5f; | 622 | public static float CAPSULE_RADIUS = 0.5f; |
625 | public static float CAPSULE_LENGTH = 0.79f; | 623 | public static float CAPSULE_LENGTH = 0.79f; |
626 | private bool flying = false; | 624 | private bool flying = false; |
627 | private bool iscolliding = false; | 625 | private bool m_iscolliding = false; |
626 | |||
627 | private bool[] m_colliderarr = new bool[10]; | ||
628 | |||
628 | private bool jumping = false; | 629 | private bool jumping = false; |
629 | //private float gravityAccel; | 630 | //private float gravityAccel; |
630 | public IntPtr Body; | 631 | public IntPtr Body; |
@@ -640,6 +641,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
640 | _position = pos; | 641 | _position = pos; |
641 | _acceleration = new PhysicsVector(); | 642 | _acceleration = new PhysicsVector(); |
642 | _parent_scene = parent_scene; | 643 | _parent_scene = parent_scene; |
644 | |||
645 | for (int i = 0; i < 10; i++) | ||
646 | { | ||
647 | m_colliderarr[i] = false; | ||
648 | } | ||
649 | |||
643 | lock (OdeScene.OdeLock) | 650 | lock (OdeScene.OdeLock) |
644 | { | 651 | { |
645 | 652 | ||
@@ -667,11 +674,48 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
667 | } | 674 | } |
668 | public override bool IsColliding | 675 | public override bool IsColliding |
669 | { | 676 | { |
670 | get { return iscolliding; } | 677 | |
678 | get { return m_iscolliding; } | ||
671 | set | 679 | set |
672 | {iscolliding = value;} | 680 | { |
681 | int i; | ||
682 | int truecount=0; | ||
683 | int falsecount=0; | ||
684 | |||
685 | if (m_colliderarr.Length >= 6) | ||
686 | { | ||
687 | for (i = 0; i < 6; i++) | ||
688 | { | ||
689 | m_colliderarr[i] = m_colliderarr[i + 1]; | ||
690 | } | ||
691 | } | ||
692 | m_colliderarr[6] = value; | ||
693 | |||
694 | for (i = 0; i < 7; i++) | ||
695 | { | ||
696 | if (m_colliderarr[i]) | ||
697 | { | ||
698 | truecount++; | ||
699 | } | ||
700 | else | ||
701 | { | ||
702 | falsecount++; | ||
703 | } | ||
704 | } | ||
705 | |||
706 | // Equal truecounts and false counts means we're colliding with something. | ||
707 | |||
708 | if (falsecount > truecount) | ||
709 | { | ||
710 | m_iscolliding = false; | ||
711 | } | ||
712 | else | ||
713 | { | ||
714 | m_iscolliding = true; | ||
715 | } | ||
716 | } | ||
673 | } | 717 | } |
674 | public override PhysicsVector Position | 718 | public override PhysicsVector Position |
675 | { | 719 | { |
676 | get { return _position; } | 720 | get { return _position; } |
677 | set | 721 | set |
@@ -737,7 +781,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
737 | _target_velocity.Y += force.Y; | 781 | _target_velocity.Y += force.Y; |
738 | _target_velocity.Z += force.Z; | 782 | _target_velocity.Z += force.Z; |
739 | 783 | ||
740 | 784 | //m_lastUpdateSent = false; | |
741 | } | 785 | } |
742 | public void doForce(PhysicsVector force) | 786 | public void doForce(PhysicsVector force) |
743 | { | 787 | { |
@@ -756,6 +800,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
756 | float servo = (2.5f - posture) * POSTURE_SERVO; | 800 | float servo = (2.5f - posture) * POSTURE_SERVO; |
757 | d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, servo, 0.0f, 0.0f, 1.0f); | 801 | d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, servo, 0.0f, 0.0f, 1.0f); |
758 | d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f); | 802 | d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f); |
803 | //m_lastUpdateSent = false; | ||
804 | |||
759 | } | 805 | } |
760 | 806 | ||
761 | } | 807 | } |
@@ -771,7 +817,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
771 | d.Vector3 vel = d.BodyGetLinearVel(Body); | 817 | d.Vector3 vel = d.BodyGetLinearVel(Body); |
772 | 818 | ||
773 | // if velocity is zero, use position control; otherwise, velocity control | 819 | // if velocity is zero, use position control; otherwise, velocity control |
774 | if (_target_velocity.X == 0.0f && _target_velocity.Y == 0.0f && _target_velocity.Z == 0.0f && iscolliding) | 820 | if (_target_velocity.X == 0.0f && _target_velocity.Y == 0.0f && _target_velocity.Z == 0.0f && m_iscolliding) |
775 | { | 821 | { |
776 | // keep track of where we stopped. No more slippin' & slidin' | 822 | // keep track of where we stopped. No more slippin' & slidin' |
777 | if (!_zeroFlag) | 823 | if (!_zeroFlag) |
@@ -791,12 +837,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
791 | { | 837 | { |
792 | 838 | ||
793 | _zeroFlag = false; | 839 | _zeroFlag = false; |
794 | if (iscolliding || flying) | 840 | if (m_iscolliding || flying) |
795 | { | 841 | { |
796 | vec.X = (_target_velocity.X - vel.X) * PID_D; | 842 | vec.X = (_target_velocity.X - vel.X) * PID_D; |
797 | vec.Y = (_target_velocity.Y - vel.Y) * PID_D; | 843 | vec.Y = (_target_velocity.Y - vel.Y) * PID_D; |
798 | } | 844 | } |
799 | if (iscolliding && !flying && _target_velocity.Z > 0.0f) | 845 | if (m_iscolliding && !flying && _target_velocity.Z > 0.0f) |
800 | { | 846 | { |
801 | d.Vector3 pos = d.BodyGetPosition(Body); | 847 | d.Vector3 pos = d.BodyGetPosition(Body); |
802 | vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P; | 848 | vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P; |
@@ -836,9 +882,16 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
836 | _velocity.X = 0.0f; | 882 | _velocity.X = 0.0f; |
837 | _velocity.Y = 0.0f; | 883 | _velocity.Y = 0.0f; |
838 | _velocity.Z = 0.0f; | 884 | _velocity.Z = 0.0f; |
885 | if (!m_lastUpdateSent) | ||
886 | { | ||
887 | m_lastUpdateSent = true; | ||
888 | base.RequestPhysicsterseUpdate(); | ||
889 | |||
890 | } | ||
839 | } | 891 | } |
840 | else | 892 | else |
841 | { | 893 | { |
894 | m_lastUpdateSent = false; | ||
842 | vec = d.BodyGetLinearVel(Body); | 895 | vec = d.BodyGetLinearVel(Body); |
843 | _velocity.X = (vec.X); | 896 | _velocity.X = (vec.X); |
844 | _velocity.Y = (vec.Y); | 897 | _velocity.Y = (vec.Y); |
@@ -875,7 +928,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
875 | public IntPtr _triMeshData; | 928 | public IntPtr _triMeshData; |
876 | private bool iscolliding = false; | 929 | private bool iscolliding = false; |
877 | private bool m_isphysical = false; | 930 | private bool m_isphysical = false; |
931 | |||
878 | public bool _zeroFlag = false; | 932 | public bool _zeroFlag = false; |
933 | private bool m_lastUpdateSent = false; | ||
934 | |||
879 | public IntPtr Body = (IntPtr) 0; | 935 | public IntPtr Body = (IntPtr) 0; |
880 | private String m_primName; | 936 | private String m_primName; |
881 | private PhysicsVector _target_velocity; | 937 | private PhysicsVector _target_velocity; |
@@ -1281,6 +1337,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1281 | 1337 | ||
1282 | } | 1338 | } |
1283 | } | 1339 | } |
1340 | |||
1284 | IsPhysical = false; | 1341 | IsPhysical = false; |
1285 | _velocity.X = 0; | 1342 | _velocity.X = 0; |
1286 | _velocity.Y = 0; | 1343 | _velocity.Y = 0; |
@@ -1288,15 +1345,20 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1288 | m_rotationalVelocity.X = 0; | 1345 | m_rotationalVelocity.X = 0; |
1289 | m_rotationalVelocity.Y = 0; | 1346 | m_rotationalVelocity.Y = 0; |
1290 | m_rotationalVelocity.Z = 0; | 1347 | m_rotationalVelocity.Z = 0; |
1348 | base.RequestPhysicsterseUpdate(); | ||
1291 | _zeroFlag = true; | 1349 | _zeroFlag = true; |
1292 | } | 1350 | } |
1293 | 1351 | ||
1294 | if (m_lastposition == l_position) | 1352 | if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02) |
1353 | && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02) | ||
1354 | && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02 )) | ||
1295 | { | 1355 | { |
1356 | |||
1296 | _zeroFlag = true; | 1357 | _zeroFlag = true; |
1297 | } | 1358 | } |
1298 | else | 1359 | else |
1299 | { | 1360 | { |
1361 | System.Console.WriteLine(Math.Abs(m_lastposition.X - l_position.X).ToString()); | ||
1300 | _zeroFlag = false; | 1362 | _zeroFlag = false; |
1301 | } | 1363 | } |
1302 | m_lastposition = l_position; | 1364 | m_lastposition = l_position; |
@@ -1337,6 +1399,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1337 | _orientation.x = ori.X; | 1399 | _orientation.x = ori.X; |
1338 | _orientation.y = ori.Y; | 1400 | _orientation.y = ori.Y; |
1339 | _orientation.z = ori.Z; | 1401 | _orientation.z = ori.Z; |
1402 | base.RequestPhysicsterseUpdate(); | ||
1340 | } | 1403 | } |
1341 | 1404 | ||
1342 | } | 1405 | } |