aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
diff options
context:
space:
mode:
authorKittoFlora2009-10-27 22:42:55 +0100
committerKittoFlora2009-10-27 22:42:55 +0100
commit1113b3b6ebba3e358326a7be90b338d8c95af688 (patch)
treed923340600e5a2699ceaceeb52fd6c45994f334a /OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
parentllRotLookAt Pt 2 (diff)
parentMerge branch 'master' into vehicles (diff)
downloadopensim-SC-1113b3b6ebba3e358326a7be90b338d8c95af688.zip
opensim-SC-1113b3b6ebba3e358326a7be90b338d8c95af688.tar.gz
opensim-SC-1113b3b6ebba3e358326a7be90b338d8c95af688.tar.bz2
opensim-SC-1113b3b6ebba3e358326a7be90b338d8c95af688.tar.xz
Merge branch 'vehicles' into tests
Conflicts: OpenSim/Region/Physics/Manager/PhysicsActor.cs OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/ODECharacter.cs')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODECharacter.cs113
1 files changed, 52 insertions, 61 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 8272083..e344f97 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -68,15 +68,15 @@ namespace OpenSim.Region.Physics.OdePlugin
68 { 68 {
69 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 69 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
70 70
71 private PhysicsVector _position; 71 private Vector3 _position;
72 private d.Vector3 _zeroPosition; 72 private d.Vector3 _zeroPosition;
73 // private d.Matrix3 m_StandUpRotation; 73 // private d.Matrix3 m_StandUpRotation;
74 private bool _zeroFlag = false; 74 private bool _zeroFlag = false;
75 private bool m_lastUpdateSent = false; 75 private bool m_lastUpdateSent = false;
76 private PhysicsVector _velocity; 76 private Vector3 _velocity;
77 private PhysicsVector _target_velocity; 77 private Vector3 _target_velocity;
78 private PhysicsVector _acceleration; 78 private Vector3 _acceleration;
79 private PhysicsVector m_rotationalVelocity; 79 private Vector3 m_rotationalVelocity;
80 private float m_mass = 80f; 80 private float m_mass = 80f;
81 public float m_density = 60f; 81 public float m_density = 60f;
82 private bool m_pidControllerActive = true; 82 private bool m_pidControllerActive = true;
@@ -99,7 +99,7 @@ namespace OpenSim.Region.Physics.OdePlugin
99 private bool m_hackSentFall = false; 99 private bool m_hackSentFall = false;
100 private bool m_hackSentFly = false; 100 private bool m_hackSentFly = false;
101 private int m_requestedUpdateFrequency = 0; 101 private int m_requestedUpdateFrequency = 0;
102 private PhysicsVector m_taintPosition = new PhysicsVector(0, 0, 0); 102 private Vector3 m_taintPosition = Vector3.Zero;
103 public uint m_localID = 0; 103 public uint m_localID = 0;
104 public bool m_returnCollisions = false; 104 public bool m_returnCollisions = false;
105 // taints and their non-tainted counterparts 105 // taints and their non-tainted counterparts
@@ -143,22 +143,17 @@ namespace OpenSim.Region.Physics.OdePlugin
143 public UUID m_uuid; 143 public UUID m_uuid;
144 public bool bad = false; 144 public bool bad = false;
145 145
146 public OdeCharacter(String avName, OdeScene parent_scene, PhysicsVector pos, CollisionLocker dode, PhysicsVector size, float pid_d, float pid_p, float capsule_radius, float tensor, float density, float height_fudge_factor, float walk_divisor, float rundivisor) 146 public OdeCharacter(String avName, OdeScene parent_scene, Vector3 pos, CollisionLocker dode, Vector3 size, float pid_d, float pid_p, float capsule_radius, float tensor, float density, float height_fudge_factor, float walk_divisor, float rundivisor)
147 { 147 {
148 m_uuid = UUID.Random(); 148 m_uuid = UUID.Random();
149 149
150 // ode = dode; 150 if (pos.IsFinite())
151 _velocity = new PhysicsVector();
152 _target_velocity = new PhysicsVector();
153
154
155 if (PhysicsVector.isFinite(pos))
156 { 151 {
157 if (pos.Z > 9999999) 152 if (pos.Z > 9999999f)
158 { 153 {
159 pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5; 154 pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
160 } 155 }
161 if (pos.Z < -90000) 156 if (pos.Z < -90000f)
162 { 157 {
163 pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5; 158 pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
164 } 159 }
@@ -169,15 +164,13 @@ namespace OpenSim.Region.Physics.OdePlugin
169 } 164 }
170 else 165 else
171 { 166 {
172 _position = new PhysicsVector(((int)_parent_scene.WorldExtents.X * 0.5f), ((int)_parent_scene.WorldExtents.Y * 0.5f), parent_scene.GetTerrainHeightAtXY(128, 128) + 10); 167 _position = new Vector3(((float)_parent_scene.WorldExtents.X * 0.5f), ((float)_parent_scene.WorldExtents.Y * 0.5f), parent_scene.GetTerrainHeightAtXY(128f, 128f) + 10f);
173 m_taintPosition.X = _position.X; 168 m_taintPosition.X = _position.X;
174 m_taintPosition.Y = _position.Y; 169 m_taintPosition.Y = _position.Y;
175 m_taintPosition.Z = _position.Z; 170 m_taintPosition.Z = _position.Z;
176 m_log.Warn("[PHYSICS]: Got NaN Position on Character Create"); 171 m_log.Warn("[PHYSICS]: Got NaN Position on Character Create");
177 } 172 }
178 173
179
180 _acceleration = new PhysicsVector();
181 _parent_scene = parent_scene; 174 _parent_scene = parent_scene;
182 175
183 PID_D = pid_d; 176 PID_D = pid_d;
@@ -189,7 +182,6 @@ namespace OpenSim.Region.Physics.OdePlugin
189 walkDivisor = walk_divisor; 182 walkDivisor = walk_divisor;
190 runDivisor = rundivisor; 183 runDivisor = rundivisor;
191 184
192
193 // m_StandUpRotation = 185 // m_StandUpRotation =
194 // new d.Matrix3(0.5f, 0.7071068f, 0.5f, -0.7071068f, 0f, 0.7071068f, 0.5f, -0.7071068f, 186 // new d.Matrix3(0.5f, 0.7071068f, 0.5f, -0.7071068f, 0f, 0.7071068f, 0.5f, -0.7071068f,
195 // 0.5f); 187 // 0.5f);
@@ -205,7 +197,6 @@ namespace OpenSim.Region.Physics.OdePlugin
205 m_isPhysical = false; // current status: no ODE information exists 197 m_isPhysical = false; // current status: no ODE information exists
206 m_tainted_isPhysical = true; // new tainted status: need to create ODE information 198 m_tainted_isPhysical = true; // new tainted status: need to create ODE information
207 199
208
209 _parent_scene.AddPhysicsActorTaint(this); 200 _parent_scene.AddPhysicsActorTaint(this);
210 201
211 m_name = avName; 202 m_name = avName;
@@ -412,20 +403,20 @@ namespace OpenSim.Region.Physics.OdePlugin
412 /// Not really a good choice unless you 'know' it's a good 403 /// Not really a good choice unless you 'know' it's a good
413 /// spot otherwise you're likely to orbit the avatar. 404 /// spot otherwise you're likely to orbit the avatar.
414 /// </summary> 405 /// </summary>
415 public override PhysicsVector Position 406 public override Vector3 Position
416 { 407 {
417 get { return _position; } 408 get { return _position; }
418 set 409 set
419 { 410 {
420 if (Body == IntPtr.Zero || Shell == IntPtr.Zero) 411 if (Body == IntPtr.Zero || Shell == IntPtr.Zero)
421 { 412 {
422 if (PhysicsVector.isFinite(value)) 413 if (value.IsFinite())
423 { 414 {
424 if (value.Z > 9999999) 415 if (value.Z > 9999999f)
425 { 416 {
426 value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5; 417 value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
427 } 418 }
428 if (value.Z < -90000) 419 if (value.Z < -90000f)
429 { 420 {
430 value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5; 421 value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
431 } 422 }
@@ -447,7 +438,7 @@ namespace OpenSim.Region.Physics.OdePlugin
447 } 438 }
448 } 439 }
449 440
450 public override PhysicsVector RotationalVelocity 441 public override Vector3 RotationalVelocity
451 { 442 {
452 get { return m_rotationalVelocity; } 443 get { return m_rotationalVelocity; }
453 set { m_rotationalVelocity = value; } 444 set { m_rotationalVelocity = value; }
@@ -457,20 +448,20 @@ namespace OpenSim.Region.Physics.OdePlugin
457 /// This property sets the height of the avatar only. We use the height to make sure the avatar stands up straight 448 /// This property sets the height of the avatar only. We use the height to make sure the avatar stands up straight
458 /// and use it to offset landings properly 449 /// and use it to offset landings properly
459 /// </summary> 450 /// </summary>
460 public override PhysicsVector Size 451 public override Vector3 Size
461 { 452 {
462 get { return new PhysicsVector(CAPSULE_RADIUS*2, CAPSULE_RADIUS*2, CAPSULE_LENGTH); } 453 get { return new Vector3(CAPSULE_RADIUS * 2, CAPSULE_RADIUS * 2, CAPSULE_LENGTH); }
463 set 454 set
464 { 455 {
465 if (PhysicsVector.isFinite(value)) 456 if (value.IsFinite())
466 { 457 {
467 m_pidControllerActive = true; 458 m_pidControllerActive = true;
468 459
469 PhysicsVector SetSize = value; 460 Vector3 SetSize = value;
470 m_tainted_CAPSULE_LENGTH = (SetSize.Z*1.15f) - CAPSULE_RADIUS*2.0f; 461 m_tainted_CAPSULE_LENGTH = (SetSize.Z*1.15f) - CAPSULE_RADIUS*2.0f;
471 //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString()); 462 //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString());
472 463
473 Velocity = new PhysicsVector(0f, 0f, 0f); 464 Velocity = Vector3.Zero;
474 465
475 _parent_scene.AddPhysicsActorTaint(this); 466 _parent_scene.AddPhysicsActorTaint(this);
476 } 467 }
@@ -481,7 +472,7 @@ namespace OpenSim.Region.Physics.OdePlugin
481 } 472 }
482 } 473 }
483 474
484 private void AlignAvatarTiltWithCurrentDirectionOfMovement(PhysicsVector movementVector) 475 private void AlignAvatarTiltWithCurrentDirectionOfMovement(Vector3 movementVector)
485 { 476 {
486 movementVector.Z = 0f; 477 movementVector.Z = 0f;
487 float magnitude = (float)Math.Sqrt((double)(movementVector.X * movementVector.X + movementVector.Y * movementVector.Y)); 478 float magnitude = (float)Math.Sqrt((double)(movementVector.X * movementVector.X + movementVector.Y * movementVector.Y));
@@ -643,7 +634,7 @@ namespace OpenSim.Region.Physics.OdePlugin
643 // (with -0..0 motor stops) falls into the terrain for reasons yet 634 // (with -0..0 motor stops) falls into the terrain for reasons yet
644 // to be comprehended in their entirety. 635 // to be comprehended in their entirety.
645 #endregion 636 #endregion
646 AlignAvatarTiltWithCurrentDirectionOfMovement(new PhysicsVector(0,0,0)); 637 AlignAvatarTiltWithCurrentDirectionOfMovement(Vector3.Zero);
647 d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f); 638 d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f);
648 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f); 639 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f);
649 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f); 640 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f);
@@ -688,7 +679,7 @@ namespace OpenSim.Region.Physics.OdePlugin
688 679
689 } 680 }
690 681
691 public override void LockAngularMotion(PhysicsVector axis) 682 public override void LockAngularMotion(Vector3 axis)
692 { 683 {
693 684
694 } 685 }
@@ -716,9 +707,9 @@ namespace OpenSim.Region.Physics.OdePlugin
716// //m_log.Info("[PHYSICSAV]: Rotation: " + bodyrotation.M00 + " : " + bodyrotation.M01 + " : " + bodyrotation.M02 + " : " + bodyrotation.M10 + " : " + bodyrotation.M11 + " : " + bodyrotation.M12 + " : " + bodyrotation.M20 + " : " + bodyrotation.M21 + " : " + bodyrotation.M22); 707// //m_log.Info("[PHYSICSAV]: Rotation: " + bodyrotation.M00 + " : " + bodyrotation.M01 + " : " + bodyrotation.M02 + " : " + bodyrotation.M10 + " : " + bodyrotation.M11 + " : " + bodyrotation.M12 + " : " + bodyrotation.M20 + " : " + bodyrotation.M21 + " : " + bodyrotation.M22);
717// } 708// }
718 709
719 public override PhysicsVector Force 710 public override Vector3 Force
720 { 711 {
721 get { return new PhysicsVector(_target_velocity.X, _target_velocity.Y, _target_velocity.Z); } 712 get { return _target_velocity; }
722 set { return; } 713 set { return; }
723 } 714 }
724 715
@@ -733,7 +724,7 @@ namespace OpenSim.Region.Physics.OdePlugin
733 724
734 } 725 }
735 726
736 public override void VehicleVectorParam(int param, PhysicsVector value) 727 public override void VehicleVectorParam(int param, Vector3 value)
737 { 728 {
738 729
739 } 730 }
@@ -748,14 +739,14 @@ namespace OpenSim.Region.Physics.OdePlugin
748 739
749 } 740 }
750 741
751 public override PhysicsVector CenterOfMass 742 public override Vector3 CenterOfMass
752 { 743 {
753 get { return PhysicsVector.Zero; } 744 get { return Vector3.Zero; }
754 } 745 }
755 746
756 public override PhysicsVector GeometricCenter 747 public override Vector3 GeometricCenter
757 { 748 {
758 get { return PhysicsVector.Zero; } 749 get { return Vector3.Zero; }
759 } 750 }
760 751
761 public override PrimitiveBaseShape Shape 752 public override PrimitiveBaseShape Shape
@@ -763,18 +754,18 @@ namespace OpenSim.Region.Physics.OdePlugin
763 set { return; } 754 set { return; }
764 } 755 }
765 756
766 public override PhysicsVector Velocity 757 public override Vector3 Velocity
767 { 758 {
768 get { 759 get {
769 // There's a problem with PhysicsVector.Zero! Don't Use it Here! 760 // There's a problem with Vector3.Zero! Don't Use it Here!
770 if (_zeroFlag) 761 if (_zeroFlag)
771 return new PhysicsVector(0f, 0f, 0f); 762 return Vector3.Zero;
772 m_lastUpdateSent = false; 763 m_lastUpdateSent = false;
773 return _velocity; 764 return _velocity;
774 } 765 }
775 set 766 set
776 { 767 {
777 if (PhysicsVector.isFinite(value)) 768 if (value.IsFinite())
778 { 769 {
779 m_pidControllerActive = true; 770 m_pidControllerActive = true;
780 _target_velocity = value; 771 _target_velocity = value;
@@ -786,9 +777,9 @@ namespace OpenSim.Region.Physics.OdePlugin
786 } 777 }
787 } 778 }
788 779
789 public override PhysicsVector Torque 780 public override Vector3 Torque
790 { 781 {
791 get { return PhysicsVector.Zero; } 782 get { return Vector3.Zero; }
792 set { return; } 783 set { return; }
793 } 784 }
794 785
@@ -814,12 +805,12 @@ namespace OpenSim.Region.Physics.OdePlugin
814 } 805 }
815 } 806 }
816 807
817 public override PhysicsVector Acceleration 808 public override Vector3 Acceleration
818 { 809 {
819 get { return _acceleration; } 810 get { return _acceleration; }
820 } 811 }
821 812
822 public void SetAcceleration(PhysicsVector accel) 813 public void SetAcceleration(Vector3 accel)
823 { 814 {
824 m_pidControllerActive = true; 815 m_pidControllerActive = true;
825 _acceleration = accel; 816 _acceleration = accel;
@@ -830,9 +821,9 @@ namespace OpenSim.Region.Physics.OdePlugin
830 /// The PID controller takes this target velocity and tries to make it a reality 821 /// The PID controller takes this target velocity and tries to make it a reality
831 /// </summary> 822 /// </summary>
832 /// <param name="force"></param> 823 /// <param name="force"></param>
833 public override void AddForce(PhysicsVector force, bool pushforce) 824 public override void AddForce(Vector3 force, bool pushforce)
834 { 825 {
835 if (PhysicsVector.isFinite(force)) 826 if (force.IsFinite())
836 { 827 {
837 if (pushforce) 828 if (pushforce)
838 { 829 {
@@ -861,7 +852,7 @@ namespace OpenSim.Region.Physics.OdePlugin
861 //m_lastUpdateSent = false; 852 //m_lastUpdateSent = false;
862 } 853 }
863 854
864 public override void AddAngularForce(PhysicsVector force, bool pushforce) 855 public override void AddAngularForce(Vector3 force, bool pushforce)
865 { 856 {
866 857
867 } 858 }
@@ -870,7 +861,7 @@ namespace OpenSim.Region.Physics.OdePlugin
870 /// After all of the forces add up with 'add force' we apply them with doForce 861 /// After all of the forces add up with 'add force' we apply them with doForce
871 /// </summary> 862 /// </summary>
872 /// <param name="force"></param> 863 /// <param name="force"></param>
873 public void doForce(PhysicsVector force) 864 public void doForce(Vector3 force)
874 { 865 {
875 if (!collidelock) 866 if (!collidelock)
876 { 867 {
@@ -881,7 +872,7 @@ namespace OpenSim.Region.Physics.OdePlugin
881 } 872 }
882 } 873 }
883 874
884 public override void SetMomentum(PhysicsVector momentum) 875 public override void SetMomentum(Vector3 momentum)
885 { 876 {
886 } 877 }
887 878
@@ -908,9 +899,9 @@ namespace OpenSim.Region.Physics.OdePlugin
908 //PidStatus = true; 899 //PidStatus = true;
909 900
910 d.Vector3 localpos = d.BodyGetPosition(Body); 901 d.Vector3 localpos = d.BodyGetPosition(Body);
911 PhysicsVector localPos = new PhysicsVector(localpos.X, localpos.Y, localpos.Z); 902 Vector3 localPos = new Vector3(localpos.X, localpos.Y, localpos.Z);
912 903
913 if (!PhysicsVector.isFinite(localPos)) 904 if (!localPos.IsFinite())
914 { 905 {
915 906
916 m_log.Warn("[PHYSICS]: Avatar Position is non-finite!"); 907 m_log.Warn("[PHYSICS]: Avatar Position is non-finite!");
@@ -946,7 +937,7 @@ namespace OpenSim.Region.Physics.OdePlugin
946 return; 937 return;
947 } 938 }
948 939
949 PhysicsVector vec = new PhysicsVector(); 940 Vector3 vec = Vector3.Zero;
950 d.Vector3 vel = d.BodyGetLinearVel(Body); 941 d.Vector3 vel = d.BodyGetLinearVel(Body);
951 942
952 float movementdivisor = 1f; 943 float movementdivisor = 1f;
@@ -1059,12 +1050,12 @@ namespace OpenSim.Region.Physics.OdePlugin
1059 } 1050 }
1060 // end add Kitto Flora 1051 // end add Kitto Flora
1061 } 1052 }
1062 if (PhysicsVector.isFinite(vec)) 1053 if (vec.IsFinite())
1063 { 1054 {
1064 doForce(vec); 1055 doForce(vec);
1065 if (!_zeroFlag) 1056 if (!_zeroFlag)
1066 { 1057 {
1067 AlignAvatarTiltWithCurrentDirectionOfMovement(new PhysicsVector(vec.X, vec.Y, vec.Z)); 1058 AlignAvatarTiltWithCurrentDirectionOfMovement(vec);
1068 } 1059 }
1069 } 1060 }
1070 else 1061 else
@@ -1197,7 +1188,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1197 { 1188 {
1198 } 1189 }
1199 1190
1200 public override PhysicsVector PIDTarget { set { return; } } 1191 public override Vector3 PIDTarget { set { return; } }
1201 public override bool PIDActive { set { return; } } 1192 public override bool PIDActive { set { return; } }
1202 public override float PIDTau { set { return; } } 1193 public override float PIDTau { set { return; } }
1203 1194
@@ -1333,7 +1324,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1333 d.GeomDestroy(Shell); 1324 d.GeomDestroy(Shell);
1334 AvatarGeomAndBodyCreation(_position.X, _position.Y, 1325 AvatarGeomAndBodyCreation(_position.X, _position.Y,
1335 _position.Z + (Math.Abs(CAPSULE_LENGTH - prevCapsule) * 2), m_tensor); 1326 _position.Z + (Math.Abs(CAPSULE_LENGTH - prevCapsule) * 2), m_tensor);
1336 Velocity = new PhysicsVector(0f, 0f, 0f); 1327 Velocity = Vector3.Zero;
1337 1328
1338 _parent_scene.geom_name_map[Shell] = m_name; 1329 _parent_scene.geom_name_map[Shell] = m_name;
1339 _parent_scene.actor_name_map[Shell] = (PhysicsActor)this; 1330 _parent_scene.actor_name_map[Shell] = (PhysicsActor)this;
@@ -1347,7 +1338,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1347 } 1338 }
1348 } 1339 }
1349 1340
1350 if (!m_taintPosition.IsIdentical(_position, 0.05f)) 1341 if (!m_taintPosition.ApproxEquals(_position, 0.05f))
1351 { 1342 {
1352 if (Body != IntPtr.Zero) 1343 if (Body != IntPtr.Zero)
1353 { 1344 {