aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs93
1 files changed, 78 insertions, 15 deletions
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 }