aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODECharacter.cs113
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEDynamics.cs15
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs304
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs67
-rw-r--r--OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs4
5 files changed, 264 insertions, 239 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 {
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEDynamics.cs b/OpenSim/Region/Physics/OdePlugin/ODEDynamics.cs
index 0c168c6..345112d 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEDynamics.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEDynamics.cs
@@ -38,6 +38,19 @@
38 * 38 *
39 */ 39 */
40 40
41/* Revised Aug, Sept 2009 by Kitto Flora. ODEDynamics.cs replaces
42 * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
43 * ODEPrim.cs contains methods dealing with Prim editing, Prim
44 * characteristics and Kinetic motion.
45 * ODEDynamics.cs contains methods dealing with Prim Physical motion
46 * (dynamics) and the associated settings. Old Linear and angular
47 * motors for dynamic motion have been replace with MoveLinear()
48 * and MoveAngular(); 'Physical' is used only to switch ODE dynamic
49 * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
50 * switch between 'VEHICLE' parameter use and general dynamics
51 * settings use.
52 */
53
41using System; 54using System;
42using System.Collections.Generic; 55using System.Collections.Generic;
43using System.Reflection; 56using System.Reflection;
@@ -232,7 +245,7 @@ namespace OpenSim.Region.Physics.OdePlugin
232 245
233 }//end ProcessFloatVehicleParam 246 }//end ProcessFloatVehicleParam
234 247
235 internal void ProcessVectorVehicleParam(Vehicle pParam, PhysicsVector pValue) 248 internal void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue)
236 { 249 {
237 switch (pParam) 250 switch (pParam)
238 { 251 {
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 93c9a44..62c5c81 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -1,7 +1,5 @@
1/* 1/* Copyright (c) Contributors, http://opensimulator.org/
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 2 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without 3 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 4 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 5 * * Redistributions of source code must retain the above copyright
@@ -36,6 +34,20 @@
36 * switch between 'VEHICLE' parameter use and general dynamics 34 * switch between 'VEHICLE' parameter use and general dynamics
37 * settings use. 35 * settings use.
38 */ 36 */
37
38/*
39 * Revised August 26 2009 by Kitto Flora. ODEDynamics.cs replaces
40 * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
41 * ODEPrim.cs contains methods dealing with Prim editing, Prim
42 * characteristics and Kinetic motion.
43 * ODEDynamics.cs contains methods dealing with Prim Physical motion
44 * (dynamics) and the associated settings. Old Linear and angular
45 * motors for dynamic motion have been replace with MoveLinear()
46 * and MoveAngular(); 'Physical' is used only to switch ODE dynamic
47 * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
48 * switch between 'VEHICLE' parameter use and general dynamics
49 * settings use.
50 */
39using System; 51using System;
40using System.Collections.Generic; 52using System.Collections.Generic;
41using System.Reflection; 53using System.Reflection;
@@ -57,29 +69,28 @@ namespace OpenSim.Region.Physics.OdePlugin
57 { 69 {
58 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 70 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
59 71
60 private PhysicsVector _position; 72 private Vector3 _position;
61 private PhysicsVector _velocity; 73 private Vector3 _velocity;
62 private PhysicsVector _torque = new PhysicsVector(0,0,0); 74 private Vector3 _torque;
63 private PhysicsVector m_lastVelocity = new PhysicsVector(0.0f, 0.0f, 0.0f); 75 private Vector3 m_lastVelocity;
64 private PhysicsVector m_lastposition = new PhysicsVector(0.0f, 0.0f, 0.0f); 76 private Vector3 m_lastposition;
65 private Quaternion m_lastorientation = new Quaternion(); 77 private Quaternion m_lastorientation = new Quaternion();
66 private PhysicsVector m_rotationalVelocity; 78 private Vector3 m_rotationalVelocity;
67 private PhysicsVector _size; 79 private Vector3 _size;
68 private PhysicsVector _acceleration; 80 private Vector3 _acceleration;
69 // private d.Vector3 _zeroPosition = new d.Vector3(0.0f, 0.0f, 0.0f); 81 // private d.Vector3 _zeroPosition = new d.Vector3(0.0f, 0.0f, 0.0f);
70 private Quaternion _orientation; 82 private Quaternion _orientation;
71 private PhysicsVector m_taintposition; 83 private Vector3 m_taintposition;
72 private PhysicsVector m_taintsize; 84 private Vector3 m_taintsize;
73 private PhysicsVector m_taintVelocity = new PhysicsVector(0, 0, 0); 85 private Vector3 m_taintVelocity;
74 private PhysicsVector m_taintTorque = new PhysicsVector(0, 0, 0); 86 private Vector3 m_taintTorque;
75 private Quaternion m_taintrot; 87 private Quaternion m_taintrot;
76 private PhysicsVector m_angularlock = new PhysicsVector(1f, 1f, 1f); 88 private Vector3 m_angularlock = Vector3.One;
77 private PhysicsVector m_taintAngularLock = new PhysicsVector(1f, 1f, 1f); 89 private Vector3 m_taintAngularLock = Vector3.One;
78 private IntPtr Amotor = IntPtr.Zero; 90 private IntPtr Amotor = IntPtr.Zero;
79 91
80 private PhysicsVector m_PIDTarget = new PhysicsVector(0, 0, 0); 92 private Vector3 m_PIDTarget;
81 // private PhysicsVector m_taintPIDTarget = new PhysicsVector(0, 0, 0); 93 private float m_PIDTau;
82 private float m_PIDTau = 0f;
83 private float PID_D = 35f; 94 private float PID_D = 35f;
84 private float PID_G = 25f; 95 private float PID_G = 25f;
85 private bool m_usePID = false; 96 private bool m_usePID = false;
@@ -91,15 +102,22 @@ namespace OpenSim.Region.Physics.OdePlugin
91 102
92 // KF: These next 7 params apply to llSetHoverHeight(float height, integer water, float tau), 103 // KF: These next 7 params apply to llSetHoverHeight(float height, integer water, float tau),
93 // and are for non-VEHICLES only. 104 // and are for non-VEHICLES only.
94 105
95 private float m_PIDHoverHeight = 0f; 106 private float m_PIDHoverHeight;
96 private float m_PIDHoverTau = 0f; 107 private float m_PIDHoverTau;
97 private bool m_useHoverPID = false; 108 private bool m_useHoverPID;
98 private PIDHoverType m_PIDHoverType = PIDHoverType.Ground; 109 private PIDHoverType m_PIDHoverType = PIDHoverType.Ground;
110<<<<<<< HEAD:OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
99 private float m_targetHoverHeight = 0f; 111 private float m_targetHoverHeight = 0f;
100 private float m_groundHeight = 0f; 112 private float m_groundHeight = 0f;
101 private float m_waterHeight = 0f; 113 private float m_waterHeight = 0f;
102 private float m_buoyancy = 0f; //Set by llSetBuoyancy(), for non-vehicles. 114 private float m_buoyancy = 0f; //Set by llSetBuoyancy(), for non-vehicles.
115=======
116 private float m_targetHoverHeight;
117 private float m_groundHeight;
118 private float m_waterHeight;
119 private float m_buoyancy; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle.
120>>>>>>> vehicles:OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
103 121
104 // private float m_tensor = 5f; 122 // private float m_tensor = 5f;
105 private int body_autodisable_frames = 20; 123 private int body_autodisable_frames = 20;
@@ -110,11 +128,11 @@ namespace OpenSim.Region.Physics.OdePlugin
110 | CollisionCategories.Body 128 | CollisionCategories.Body
111 | CollisionCategories.Character 129 | CollisionCategories.Character
112 ); 130 );
113 private bool m_taintshape = false; 131 private bool m_taintshape;
114 private bool m_taintPhysics = false; 132 private bool m_taintPhysics;
115 private bool m_collidesLand = true; 133 private bool m_collidesLand = true;
116 private bool m_collidesWater = false; 134 private bool m_collidesWater;
117 public bool m_returnCollisions = false; 135 public bool m_returnCollisions;
118 136
119 // Default we're a Geometry 137 // Default we're a Geometry
120 private CollisionCategories m_collisionCategories = (CollisionCategories.Geom); 138 private CollisionCategories m_collisionCategories = (CollisionCategories.Geom);
@@ -122,69 +140,68 @@ namespace OpenSim.Region.Physics.OdePlugin
122 // Default, Collide with Other Geometries, spaces and Bodies 140 // Default, Collide with Other Geometries, spaces and Bodies
123 private CollisionCategories m_collisionFlags = m_default_collisionFlags; 141 private CollisionCategories m_collisionFlags = m_default_collisionFlags;
124 142
125 public bool m_taintremove = false; 143 public bool m_taintremove;
126 public bool m_taintdisable = false; 144 public bool m_taintdisable;
127 public bool m_disabled = false; 145 public bool m_disabled;
128 public bool m_taintadd = false; 146 public bool m_taintadd;
129 public bool m_taintselected = false; 147 public bool m_taintselected;
130 public bool m_taintCollidesWater = false; 148 public bool m_taintCollidesWater;
131 149
132 public uint m_localID = 0; 150 public uint m_localID;
133 151
134 //public GCHandle gc; 152 //public GCHandle gc;
135 private CollisionLocker ode; 153 private CollisionLocker ode;
136 154
137 private bool m_taintforce = false; 155 private bool m_taintforce = false;
138 private bool m_taintaddangularforce = false; 156 private bool m_taintaddangularforce = false;
139 private PhysicsVector m_force = new PhysicsVector(0.0f, 0.0f, 0.0f); 157 private Vector3 m_force;
140 private List<PhysicsVector> m_forcelist = new List<PhysicsVector>(); 158 private List<Vector3> m_forcelist = new List<Vector3>();
141 private List<PhysicsVector> m_angularforcelist = new List<PhysicsVector>(); 159 private List<Vector3> m_angularforcelist = new List<Vector3>();
142 160
143 private IMesh _mesh; 161 private IMesh _mesh;
144 private PrimitiveBaseShape _pbs; 162 private PrimitiveBaseShape _pbs;
145 private OdeScene _parent_scene; 163 private OdeScene _parent_scene;
146 public IntPtr m_targetSpace = (IntPtr) 0; 164 public IntPtr m_targetSpace = IntPtr.Zero;
147 public IntPtr prim_geom; 165 public IntPtr prim_geom;
148 public IntPtr prev_geom; 166 public IntPtr prev_geom;
149 public IntPtr _triMeshData; 167 public IntPtr _triMeshData;
150 168
151 private IntPtr _linkJointGroup = (IntPtr)0; 169 private IntPtr _linkJointGroup = IntPtr.Zero;
152 private PhysicsActor _parent = null; 170 private PhysicsActor _parent;
153 private PhysicsActor m_taintparent = null; 171 private PhysicsActor m_taintparent;
154 172
155 private List<OdePrim> childrenPrim = new List<OdePrim>(); 173 private List<OdePrim> childrenPrim = new List<OdePrim>();
156 174
157 private bool iscolliding = false; 175 private bool iscolliding;
158 private bool m_isphysical = false; 176 private bool m_isphysical;
159 private bool m_isSelected = false; 177 private bool m_isSelected;
160 178
161 internal bool m_isVolumeDetect = false; // If true, this prim only detects collisions but doesn't collide actively 179 internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively
162 180
163 private bool m_throttleUpdates = false; 181 private bool m_throttleUpdates;
164 private int throttleCounter = 0; 182 private int throttleCounter;
165 public int m_interpenetrationcount = 0; 183 public int m_interpenetrationcount;
166 public float m_collisionscore = 0; 184 public float m_collisionscore;
167 public int m_roundsUnderMotionThreshold = 0; 185 public int m_roundsUnderMotionThreshold;
168 private int m_crossingfailures = 0; 186 private int m_crossingfailures;
169 187
170 public bool outofBounds = false; 188 public bool outofBounds;
171 private float m_density = 10.000006836f; // Aluminum g/cm3; 189 private float m_density = 10.000006836f; // Aluminum g/cm3;
172 190
173 public bool _zeroFlag = false; 191 public bool _zeroFlag;
174 private bool m_lastUpdateSent = false; 192 private bool m_lastUpdateSent;
175 193
176 public IntPtr Body = (IntPtr) 0; 194 public IntPtr Body = IntPtr.Zero;
177 public String m_primName; 195 public String m_primName;
178// private String m_primName; 196 private Vector3 _target_velocity;
179 private PhysicsVector _target_velocity;
180 public d.Mass pMass; 197 public d.Mass pMass;
181 198
182 public int m_eventsubscription = 0; 199 public int m_eventsubscription;
183 private CollisionEventUpdate CollisionEventsThisFrame = null; 200 private CollisionEventUpdate CollisionEventsThisFrame;
184 201
185 private IntPtr m_linkJoint = (IntPtr)0; 202 private IntPtr m_linkJoint = IntPtr.Zero;
186 203
187 public volatile bool childPrim = false; 204 public volatile bool childPrim;
188 205
189 private ODEDynamics m_vehicle; 206 private ODEDynamics m_vehicle;
190 207
@@ -193,17 +210,16 @@ namespace OpenSim.Region.Physics.OdePlugin
193 private int frcount = 0; // Used to limit dynamics debug output to 210 private int frcount = 0; // Used to limit dynamics debug output to
194 211
195 212
196 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, 213 public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size,
197 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) 214 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode)
198 { 215 {
199 _target_velocity = new PhysicsVector(0, 0, 0);
200 m_vehicle = new ODEDynamics(); 216 m_vehicle = new ODEDynamics();
201 //gc = GCHandle.Alloc(prim_geom, GCHandleType.Pinned); 217 //gc = GCHandle.Alloc(prim_geom, GCHandleType.Pinned);
202 ode = dode; 218 ode = dode;
203 _velocity = new PhysicsVector(); 219 if (!pos.IsFinite())
204 if (!PhysicsVector.isFinite(pos))
205 { 220 {
206 pos = new PhysicsVector(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), parent_scene.GetTerrainHeightAtXY(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f)) + 0.5f); 221 pos = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f),
222 parent_scene.GetTerrainHeightAtXY(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f)) + 0.5f);
207 m_log.Warn("[PHYSICS]: Got nonFinite Object create Position"); 223 m_log.Warn("[PHYSICS]: Got nonFinite Object create Position");
208 } 224 }
209 _position = pos; 225 _position = pos;
@@ -218,9 +234,9 @@ namespace OpenSim.Region.Physics.OdePlugin
218 prim_geom = IntPtr.Zero; 234 prim_geom = IntPtr.Zero;
219 prev_geom = IntPtr.Zero; 235 prev_geom = IntPtr.Zero;
220 236
221 if (!PhysicsVector.isFinite(pos)) 237 if (!pos.IsFinite())
222 { 238 {
223 size = new PhysicsVector(0.5f, 0.5f, 0.5f); 239 size = new Vector3(0.5f, 0.5f, 0.5f);
224 m_log.Warn("[PHYSICS]: Got nonFinite Object create Size"); 240 m_log.Warn("[PHYSICS]: Got nonFinite Object create Size");
225 } 241 }
226 242
@@ -230,8 +246,6 @@ namespace OpenSim.Region.Physics.OdePlugin
230 246
231 _size = size; 247 _size = size;
232 m_taintsize = _size; 248 m_taintsize = _size;
233 _acceleration = new PhysicsVector();
234 m_rotationalVelocity = PhysicsVector.Zero;
235 249
236 if (!QuaternionIsFinite(rotation)) 250 if (!QuaternionIsFinite(rotation))
237 { 251 {
@@ -396,7 +410,7 @@ namespace OpenSim.Region.Physics.OdePlugin
396 m_disabled = false; 410 m_disabled = false;
397 411
398 // The body doesn't already have a finite rotation mode set here 412 // The body doesn't already have a finite rotation mode set here
399 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null) 413 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0.0f)) && _parent == null)
400 { 414 {
401 createAMotor(m_angularlock); 415 createAMotor(m_angularlock);
402 } 416 }
@@ -809,6 +823,8 @@ namespace OpenSim.Region.Physics.OdePlugin
809 m_collisionscore = 0; 823 m_collisionscore = 0;
810 } 824 }
811 825
826 private static Dictionary<IMesh, IntPtr> m_MeshToTriMeshMap = new Dictionary<IMesh, IntPtr>();
827
812 public void setMesh(OdeScene parent_scene, IMesh mesh) 828 public void setMesh(OdeScene parent_scene, IMesh mesh)
813 { 829 {
814 // This sleeper is there to moderate how long it takes between 830 // This sleeper is there to moderate how long it takes between
@@ -840,19 +856,24 @@ namespace OpenSim.Region.Physics.OdePlugin
840 mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage 856 mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage
841 857
842 mesh.releaseSourceMeshData(); // free up the original mesh data to save memory 858 mesh.releaseSourceMeshData(); // free up the original mesh data to save memory
859 if (m_MeshToTriMeshMap.ContainsKey(mesh))
860 {
861 _triMeshData = m_MeshToTriMeshMap[mesh];
862 }
863 else
864 {
865 _triMeshData = d.GeomTriMeshDataCreate();
843 866
844 _triMeshData = d.GeomTriMeshDataCreate(); 867 d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
845 868 d.GeomTriMeshDataPreprocess(_triMeshData);
846 d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride); 869 m_MeshToTriMeshMap[mesh] = _triMeshData;
847 d.GeomTriMeshDataPreprocess(_triMeshData); 870 }
848 871
849 _parent_scene.waitForSpaceUnlock(m_targetSpace); 872 _parent_scene.waitForSpaceUnlock(m_targetSpace);
850
851 try 873 try
852 { 874 {
853 if (prim_geom == IntPtr.Zero) 875 if (prim_geom == IntPtr.Zero)
854 { 876 {
855//Console.WriteLine(" setMesh 1");
856 SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null)); 877 SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null));
857 } 878 }
858 } 879 }
@@ -862,6 +883,7 @@ namespace OpenSim.Region.Physics.OdePlugin
862 return; 883 return;
863 } 884 }
864 885
886
865 // if (IsPhysical && Body == (IntPtr) 0) 887 // if (IsPhysical && Body == (IntPtr) 0)
866 // { 888 // {
867 // Recreate the body 889 // Recreate the body
@@ -882,7 +904,7 @@ namespace OpenSim.Region.Physics.OdePlugin
882 904
883 if (prim_geom != IntPtr.Zero) 905 if (prim_geom != IntPtr.Zero)
884 { 906 {
885 if (!_position.IsIdentical(m_taintposition,0f)) 907 if (!_position.ApproxEquals(m_taintposition, 0f))
886 changemove(timestep); 908 changemove(timestep);
887 909
888 if (m_taintrot != _orientation) 910 if (m_taintrot != _orientation)
@@ -907,7 +929,7 @@ namespace OpenSim.Region.Physics.OdePlugin
907 changePhysicsStatus(timestep); 929 changePhysicsStatus(timestep);
908 // 930 //
909 931
910 if (!_size.IsIdentical(m_taintsize,0)) 932 if (!_size.ApproxEquals(m_taintsize,0f))
911 changesize(timestep); 933 changesize(timestep);
912 // 934 //
913 935
@@ -921,7 +943,7 @@ namespace OpenSim.Region.Physics.OdePlugin
921 if (m_taintaddangularforce) 943 if (m_taintaddangularforce)
922 changeAddAngularForce(timestep); 944 changeAddAngularForce(timestep);
923 945
924 if (!m_taintTorque.IsIdentical(PhysicsVector.Zero, 0.001f)) 946 if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f))
925 changeSetTorque(timestep); 947 changeSetTorque(timestep);
926 948
927 if (m_taintdisable) 949 if (m_taintdisable)
@@ -930,7 +952,7 @@ namespace OpenSim.Region.Physics.OdePlugin
930 if (m_taintselected != m_isSelected) 952 if (m_taintselected != m_isSelected)
931 changeSelectedStatus(timestep); 953 changeSelectedStatus(timestep);
932 954
933 if (!m_taintVelocity.IsIdentical(PhysicsVector.Zero, 0.001f)) 955 if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f))
934 changevelocity(timestep); 956 changevelocity(timestep);
935 957
936 if (m_taintparent != _parent) 958 if (m_taintparent != _parent)
@@ -939,7 +961,7 @@ namespace OpenSim.Region.Physics.OdePlugin
939 if (m_taintCollidesWater != m_collidesWater) 961 if (m_taintCollidesWater != m_collidesWater)
940 changefloatonwater(timestep); 962 changefloatonwater(timestep);
941 963
942 if (!m_angularlock.IsIdentical(m_taintAngularLock,0)) 964 if (!m_angularlock.ApproxEquals(m_taintAngularLock,0f))
943 changeAngularLock(timestep); 965 changeAngularLock(timestep);
944 966
945 } 967 }
@@ -959,7 +981,7 @@ namespace OpenSim.Region.Physics.OdePlugin
959 //If we have a parent then we're not authorative here 981 //If we have a parent then we're not authorative here
960 if (_parent == null) 982 if (_parent == null)
961 { 983 {
962 if (!m_taintAngularLock.IsIdentical(new PhysicsVector(1f,1f,1f), 0)) 984 if (!m_taintAngularLock.ApproxEquals(Vector3.One, 0f))
963 { 985 {
964 //d.BodySetFiniteRotationMode(Body, 0); 986 //d.BodySetFiniteRotationMode(Body, 0);
965 //d.BodySetFiniteRotationAxis(Body,m_taintAngularLock.X,m_taintAngularLock.Y,m_taintAngularLock.Z); 987 //d.BodySetFiniteRotationAxis(Body,m_taintAngularLock.X,m_taintAngularLock.Y,m_taintAngularLock.Z);
@@ -976,7 +998,7 @@ namespace OpenSim.Region.Physics.OdePlugin
976 } 998 }
977 } 999 }
978 // Store this for later in case we get turned into a separate body 1000 // Store this for later in case we get turned into a separate body
979 m_angularlock = new PhysicsVector(m_taintAngularLock.X, m_taintAngularLock.Y, m_taintAngularLock.Z); 1001 m_angularlock = m_taintAngularLock;
980 1002
981 } 1003 }
982 1004
@@ -1120,7 +1142,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1120 prm.m_disabled = false; 1142 prm.m_disabled = false;
1121 1143
1122 // The body doesn't already have a finite rotation mode set here 1144 // The body doesn't already have a finite rotation mode set here
1123 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null) 1145 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
1124 { 1146 {
1125 prm.createAMotor(m_angularlock); 1147 prm.createAMotor(m_angularlock);
1126 } 1148 }
@@ -1163,7 +1185,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1163 m_disabled = false; 1185 m_disabled = false;
1164 1186
1165 // The body doesn't already have a finite rotation mode set here 1187 // The body doesn't already have a finite rotation mode set here
1166 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null) 1188 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
1167 { 1189 {
1168 createAMotor(m_angularlock); 1190 createAMotor(m_angularlock);
1169 } 1191 }
@@ -1347,7 +1369,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1347 m_taintshape = false; 1369 m_taintshape = false;
1348 m_taintforce = false; 1370 m_taintforce = false;
1349 m_taintdisable = false; 1371 m_taintdisable = false;
1350 m_taintVelocity = PhysicsVector.Zero; 1372 m_taintVelocity = Vector3.Zero;
1351 } 1373 }
1352 1374
1353 public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh) 1375 public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh)
@@ -1580,7 +1602,7 @@ if(frcount == 0) Console.WriteLine("Move " + m_primName + " VTyp " + m_vehicle
1580 { 1602 {
1581 if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body); // KF add 161009 1603 if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body); // KF add 161009
1582 // NON-'VEHICLES' are dealt with here 1604 // NON-'VEHICLES' are dealt with here
1583 if (d.BodyIsEnabled(Body) && !m_angularlock.IsIdentical(PhysicsVector.Zero, 0.003f)) 1605 if (d.BodyIsEnabled(Body) && !m_angularlock.ApproxEquals(Vector3.Zero, 0.003f))
1584 { 1606 {
1585 d.Vector3 avel2 = d.BodyGetAngularVel(Body); 1607 d.Vector3 avel2 = d.BodyGetAngularVel(Body);
1586 if (m_angularlock.X == 1) 1608 if (m_angularlock.X == 1)
@@ -1634,7 +1656,7 @@ if(frcount == 0) Console.WriteLine("Move " + m_primName + " VTyp " + m_vehicle
1634 1656
1635 d.Vector3 pos = d.BodyGetPosition(Body); 1657 d.Vector3 pos = d.BodyGetPosition(Body);
1636 _target_velocity = 1658 _target_velocity =
1637 new PhysicsVector( 1659 new Vector3(
1638 (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep), 1660 (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep),
1639 (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep), 1661 (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep),
1640 (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep) 1662 (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep)
@@ -1642,7 +1664,7 @@ if(frcount == 0) Console.WriteLine("Move " + m_primName + " VTyp " + m_vehicle
1642 1664
1643 // if velocity is zero, use position control; otherwise, velocity control 1665 // if velocity is zero, use position control; otherwise, velocity control
1644 1666
1645 if (_target_velocity.IsIdentical(PhysicsVector.Zero,0.1f)) 1667 if (_target_velocity.ApproxEquals(Vector3.Zero,0.1f))
1646 { 1668 {
1647 // keep track of where we stopped. No more slippin' & slidin' 1669 // keep track of where we stopped. No more slippin' & slidin'
1648 1670
@@ -1727,13 +1749,13 @@ if(frcount == 0) Console.WriteLine("Move " + m_primName + " VTyp " + m_vehicle
1727 1749
1728 1750
1729 _target_velocity = 1751 _target_velocity =
1730 new PhysicsVector(0.0f, 0.0f, 1752 new Vector3(0.0f, 0.0f,
1731 (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep) 1753 (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep)
1732 ); 1754 );
1733 1755
1734 // if velocity is zero, use position control; otherwise, velocity control 1756 // if velocity is zero, use position control; otherwise, velocity control
1735 1757
1736 if (_target_velocity.IsIdentical(PhysicsVector.Zero, 0.1f)) 1758 if (_target_velocity.ApproxEquals(Vector3.Zero, 0.1f))
1737 { 1759 {
1738 // keep track of where we stopped. No more slippin' & slidin' 1760 // keep track of where we stopped. No more slippin' & slidin'
1739 1761
@@ -1860,7 +1882,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
1860 d.BodySetQuaternion(Body, ref myrot); 1882 d.BodySetQuaternion(Body, ref myrot);
1861 if (m_isphysical) 1883 if (m_isphysical)
1862 { 1884 {
1863 if (!m_angularlock.IsIdentical(new PhysicsVector(1, 1, 1), 0)) 1885 if (!m_angularlock.ApproxEquals(Vector3.One, 0f))
1864 createAMotor(m_angularlock); 1886 createAMotor(m_angularlock);
1865 } 1887 }
1866 } 1888 }
@@ -2169,7 +2191,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2169 //m_log.Info("[PHYSICS]: dequeing forcelist"); 2191 //m_log.Info("[PHYSICS]: dequeing forcelist");
2170 if (IsPhysical) 2192 if (IsPhysical)
2171 { 2193 {
2172 PhysicsVector iforce = new PhysicsVector(); 2194 Vector3 iforce = Vector3.Zero;
2173 for (int i = 0; i < m_forcelist.Count; i++) 2195 for (int i = 0; i < m_forcelist.Count; i++)
2174 { 2196 {
2175 iforce = iforce + (m_forcelist[i] * 100); 2197 iforce = iforce + (m_forcelist[i] * 100);
@@ -2199,8 +2221,8 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2199 d.BodySetTorque(Body, m_taintTorque.X, m_taintTorque.Y, m_taintTorque.Z); 2221 d.BodySetTorque(Body, m_taintTorque.X, m_taintTorque.Y, m_taintTorque.Z);
2200 } 2222 }
2201 } 2223 }
2202 2224
2203 m_taintTorque = new PhysicsVector(0, 0, 0); 2225 m_taintTorque = Vector3.Zero;
2204 } 2226 }
2205 2227
2206 public void changeAddAngularForce(float timestamp) 2228 public void changeAddAngularForce(float timestamp)
@@ -2212,7 +2234,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2212 //m_log.Info("[PHYSICS]: dequeing forcelist"); 2234 //m_log.Info("[PHYSICS]: dequeing forcelist");
2213 if (IsPhysical) 2235 if (IsPhysical)
2214 { 2236 {
2215 PhysicsVector iforce = new PhysicsVector(); 2237 Vector3 iforce = Vector3.Zero;
2216 for (int i = 0; i < m_angularforcelist.Count; i++) 2238 for (int i = 0; i < m_angularforcelist.Count; i++)
2217 { 2239 {
2218 iforce = iforce + (m_angularforcelist[i] * 100); 2240 iforce = iforce + (m_angularforcelist[i] * 100);
@@ -2246,7 +2268,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2246 2268
2247 //resetCollisionAccounting(); 2269 //resetCollisionAccounting();
2248 } 2270 }
2249 m_taintVelocity = PhysicsVector.Zero; 2271 m_taintVelocity = Vector3.Zero;
2250 } 2272 }
2251 2273
2252 public override bool IsPhysical 2274 public override bool IsPhysical
@@ -2255,7 +2277,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2255 set { 2277 set {
2256 m_isphysical = value; 2278 m_isphysical = value;
2257 if (!m_isphysical) // Zero the remembered last velocity 2279 if (!m_isphysical) // Zero the remembered last velocity
2258 m_lastVelocity = new PhysicsVector(0.0f, 0.0f, 0.0f); 2280 m_lastVelocity = Vector3.Zero;
2259 } 2281 }
2260 } 2282 }
2261 2283
@@ -2300,7 +2322,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2300 get { return _zeroFlag; } 2322 get { return _zeroFlag; }
2301 } 2323 }
2302 2324
2303 public override PhysicsVector Position 2325 public override Vector3 Position
2304 { 2326 {
2305 get { return _position; } 2327 get { return _position; }
2306 2328
@@ -2309,12 +2331,12 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2309 } 2331 }
2310 } 2332 }
2311 2333
2312 public override PhysicsVector Size 2334 public override Vector3 Size
2313 { 2335 {
2314 get { return _size; } 2336 get { return _size; }
2315 set 2337 set
2316 { 2338 {
2317 if (PhysicsVector.isFinite(value)) 2339 if (value.IsFinite())
2318 { 2340 {
2319 _size = value; 2341 _size = value;
2320 } 2342 }
@@ -2330,13 +2352,13 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2330 get { return CalculateMass(); } 2352 get { return CalculateMass(); }
2331 } 2353 }
2332 2354
2333 public override PhysicsVector Force 2355 public override Vector3 Force
2334 { 2356 {
2335 //get { return PhysicsVector.Zero; } 2357 //get { return Vector3.Zero; }
2336 get { return m_force; } 2358 get { return m_force; }
2337 set 2359 set
2338 { 2360 {
2339 if (PhysicsVector.isFinite(value)) 2361 if (value.IsFinite())
2340 { 2362 {
2341 m_force = value; 2363 m_force = value;
2342 } 2364 }
@@ -2358,7 +2380,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2358 m_vehicle.ProcessFloatVehicleParam((Vehicle) param, value); 2380 m_vehicle.ProcessFloatVehicleParam((Vehicle) param, value);
2359 } 2381 }
2360 2382
2361 public override void VehicleVectorParam(int param, PhysicsVector value) 2383 public override void VehicleVectorParam(int param, Vector3 value)
2362 { 2384 {
2363 m_vehicle.ProcessVectorVehicleParam((Vehicle) param, value); 2385 m_vehicle.ProcessVectorVehicleParam((Vehicle) param, value);
2364 } 2386 }
@@ -2376,14 +2398,14 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2376 } 2398 }
2377 } 2399 }
2378 2400
2379 public override PhysicsVector CenterOfMass 2401 public override Vector3 CenterOfMass
2380 { 2402 {
2381 get { return PhysicsVector.Zero; } 2403 get { return Vector3.Zero; }
2382 } 2404 }
2383 2405
2384 public override PhysicsVector GeometricCenter 2406 public override Vector3 GeometricCenter
2385 { 2407 {
2386 get { return PhysicsVector.Zero; } 2408 get { return Vector3.Zero; }
2387 } 2409 }
2388 2410
2389 public override PrimitiveBaseShape Shape 2411 public override PrimitiveBaseShape Shape
@@ -2395,13 +2417,13 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2395 } 2417 }
2396 } 2418 }
2397 2419
2398 public override PhysicsVector Velocity 2420 public override Vector3 Velocity
2399 { 2421 {
2400 get 2422 get
2401 { 2423 {
2402 // Averate previous velocity with the new one so 2424 // Averate previous velocity with the new one so
2403 // client object interpolation works a 'little' better 2425 // client object interpolation works a 'little' better
2404 PhysicsVector returnVelocity = new PhysicsVector(); 2426 Vector3 returnVelocity = Vector3.Zero;
2405 returnVelocity.X = (m_lastVelocity.X + _velocity.X)/2; 2427 returnVelocity.X = (m_lastVelocity.X + _velocity.X)/2;
2406 returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y)/2; 2428 returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y)/2;
2407 returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z)/2; 2429 returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z)/2;
@@ -2409,7 +2431,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2409 } 2431 }
2410 set 2432 set
2411 { 2433 {
2412 if (PhysicsVector.isFinite(value)) 2434 if (value.IsFinite())
2413 { 2435 {
2414 _velocity = value; 2436 _velocity = value;
2415 2437
@@ -2424,19 +2446,19 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2424 } 2446 }
2425 } 2447 }
2426 2448
2427 public override PhysicsVector Torque 2449 public override Vector3 Torque
2428 { 2450 {
2429 get 2451 get
2430 { 2452 {
2431 if (!m_isphysical || Body == IntPtr.Zero) 2453 if (!m_isphysical || Body == IntPtr.Zero)
2432 return new PhysicsVector(0,0,0); 2454 return Vector3.Zero;
2433 2455
2434 return _torque; 2456 return _torque;
2435 } 2457 }
2436 2458
2437 set 2459 set
2438 { 2460 {
2439 if (PhysicsVector.isFinite(value)) 2461 if (value.IsFinite())
2440 { 2462 {
2441 m_taintTorque = value; 2463 m_taintTorque = value;
2442 _parent_scene.AddPhysicsActorTaint(this); 2464 _parent_scene.AddPhysicsActorTaint(this);
@@ -2488,20 +2510,20 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2488 return true; 2510 return true;
2489 } 2511 }
2490 2512
2491 public override PhysicsVector Acceleration 2513 public override Vector3 Acceleration
2492 { 2514 {
2493 get { return _acceleration; } 2515 get { return _acceleration; }
2494 } 2516 }
2495 2517
2496 2518
2497 public void SetAcceleration(PhysicsVector accel) 2519 public void SetAcceleration(Vector3 accel)
2498 { 2520 {
2499 _acceleration = accel; 2521 _acceleration = accel;
2500 } 2522 }
2501 2523
2502 public override void AddForce(PhysicsVector force, bool pushforce) 2524 public override void AddForce(Vector3 force, bool pushforce)
2503 { 2525 {
2504 if (PhysicsVector.isFinite(force)) 2526 if (force.IsFinite())
2505 { 2527 {
2506 m_forcelist.Add(force); 2528 m_forcelist.Add(force);
2507 m_taintforce = true; 2529 m_taintforce = true;
@@ -2513,9 +2535,9 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2513 //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString()); 2535 //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString());
2514 } 2536 }
2515 2537
2516 public override void AddAngularForce(PhysicsVector force, bool pushforce) 2538 public override void AddAngularForce(Vector3 force, bool pushforce)
2517 { 2539 {
2518 if (PhysicsVector.isFinite(force)) 2540 if (force.IsFinite())
2519 { 2541 {
2520 m_angularforcelist.Add(force); 2542 m_angularforcelist.Add(force);
2521 m_taintaddangularforce = true; 2543 m_taintaddangularforce = true;
@@ -2526,23 +2548,23 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2526 } 2548 }
2527 } 2549 }
2528 2550
2529 public override PhysicsVector RotationalVelocity 2551 public override Vector3 RotationalVelocity
2530 { 2552 {
2531 get 2553 get
2532 { 2554 {
2533 PhysicsVector pv = new PhysicsVector(0, 0, 0); 2555 Vector3 pv = Vector3.Zero;
2534 if (_zeroFlag) 2556 if (_zeroFlag)
2535 return pv; 2557 return pv;
2536 m_lastUpdateSent = false; 2558 m_lastUpdateSent = false;
2537 2559
2538 if (m_rotationalVelocity.IsIdentical(pv, 0.2f)) 2560 if (m_rotationalVelocity.ApproxEquals(pv, 0.2f))
2539 return pv; 2561 return pv;
2540 2562
2541 return m_rotationalVelocity; 2563 return m_rotationalVelocity;
2542 } 2564 }
2543 set 2565 set
2544 { 2566 {
2545 if (PhysicsVector.isFinite(value)) 2567 if (value.IsFinite())
2546 { 2568 {
2547 m_rotationalVelocity = value; 2569 m_rotationalVelocity = value;
2548 } 2570 }
@@ -2583,16 +2605,16 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2583 m_taintparent = null; 2605 m_taintparent = null;
2584 } 2606 }
2585 2607
2586 public override void LockAngularMotion(PhysicsVector axis) 2608 public override void LockAngularMotion(Vector3 axis)
2587 { 2609 {
2588 // reverse the zero/non zero values for ODE. 2610 // reverse the zero/non zero values for ODE.
2589 if (PhysicsVector.isFinite(axis)) 2611 if (axis.IsFinite())
2590 { 2612 {
2591 axis.X = (axis.X > 0) ? 1f : 0f; 2613 axis.X = (axis.X > 0) ? 1f : 0f;
2592 axis.Y = (axis.Y > 0) ? 1f : 0f; 2614 axis.Y = (axis.Y > 0) ? 1f : 0f;
2593 axis.Z = (axis.Z > 0) ? 1f : 0f; 2615 axis.Z = (axis.Z > 0) ? 1f : 0f;
2594 m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z); 2616 m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z);
2595 m_taintAngularLock = new PhysicsVector(axis.X, axis.Y, axis.Z); 2617 m_taintAngularLock = axis;
2596 } 2618 }
2597 else 2619 else
2598 { 2620 {
@@ -2605,7 +2627,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2605 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! 2627 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
2606 if (_parent == null) 2628 if (_parent == null)
2607 { 2629 {
2608 PhysicsVector pv = new PhysicsVector(0, 0, 0); 2630 Vector3 pv = Vector3.Zero;
2609 bool lastZeroFlag = _zeroFlag; 2631 bool lastZeroFlag = _zeroFlag;
2610 if (Body != (IntPtr)0) // FIXME -> or if it is a joint 2632 if (Body != (IntPtr)0) // FIXME -> or if it is a joint
2611 { 2633 {
@@ -2614,9 +2636,9 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2614 d.Vector3 vel = d.BodyGetLinearVel(Body); 2636 d.Vector3 vel = d.BodyGetLinearVel(Body);
2615 d.Vector3 rotvel = d.BodyGetAngularVel(Body); 2637 d.Vector3 rotvel = d.BodyGetAngularVel(Body);
2616 d.Vector3 torque = d.BodyGetTorque(Body); 2638 d.Vector3 torque = d.BodyGetTorque(Body);
2617 _torque.setValues(torque.X, torque.Y, torque.Z); 2639 _torque = new Vector3(torque.X, torque.Y, torque.Z);
2618 PhysicsVector l_position = new PhysicsVector(); 2640 Vector3 l_position = Vector3.Zero;
2619 Quaternion l_orientation = new Quaternion(); 2641 Quaternion l_orientation = Quaternion.Identity;
2620 2642
2621 // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) 2643 // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!)
2622 //if (vec.X < 0.0f) { vec.X = 0.0f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); } 2644 //if (vec.X < 0.0f) { vec.X = 0.0f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); }
@@ -2751,16 +2773,16 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2751 _velocity.Z = vel.Z; 2773 _velocity.Z = vel.Z;
2752 2774
2753 _acceleration = ((_velocity - m_lastVelocity) / 0.1f); 2775 _acceleration = ((_velocity - m_lastVelocity) / 0.1f);
2754 _acceleration = new PhysicsVector(_velocity.X - m_lastVelocity.X / 0.1f, _velocity.Y - m_lastVelocity.Y / 0.1f, _velocity.Z - m_lastVelocity.Z / 0.1f); 2776 _acceleration = new Vector3(_velocity.X - m_lastVelocity.X / 0.1f, _velocity.Y - m_lastVelocity.Y / 0.1f, _velocity.Z - m_lastVelocity.Z / 0.1f);
2755 //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString()); 2777 //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString());
2756 2778
2757 if (_velocity.IsIdentical(pv, 0.5f)) 2779 if (_velocity.ApproxEquals(pv, 0.5f))
2758 { 2780 {
2759 m_rotationalVelocity = pv; 2781 m_rotationalVelocity = pv;
2760 } 2782 }
2761 else 2783 else
2762 { 2784 {
2763 m_rotationalVelocity.setValues(rotvel.X, rotvel.Y, rotvel.Z); 2785 m_rotationalVelocity = new Vector3(rotvel.X, rotvel.Y, rotvel.Z);
2764 } 2786 }
2765 2787
2766 //m_log.Debug("ODE: " + m_rotationalVelocity.ToString()); 2788 //m_log.Debug("ODE: " + m_rotationalVelocity.ToString());
@@ -2808,15 +2830,15 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2808 } 2830 }
2809 } 2831 }
2810 2832
2811 public override void SetMomentum(PhysicsVector momentum) 2833 public override void SetMomentum(Vector3 momentum)
2812 { 2834 {
2813 } 2835 }
2814 2836
2815 public override PhysicsVector PIDTarget 2837 public override Vector3 PIDTarget
2816 { 2838 {
2817 set 2839 set
2818 { 2840 {
2819 if (PhysicsVector.isFinite(value)) 2841 if (value.IsFinite())
2820 { 2842 {
2821 m_PIDTarget = value; 2843 m_PIDTarget = value;
2822 } 2844 }
@@ -2838,7 +2860,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo +
2838 public override PIDHoverType PIDHoverType { set { m_PIDHoverType = value; } } 2860 public override PIDHoverType PIDHoverType { set { m_PIDHoverType = value; } }
2839 public override float PIDHoverTau { set { m_PIDHoverTau = value; } } 2861 public override float PIDHoverTau { set { m_PIDHoverTau = value; } }
2840 2862
2841 private void createAMotor(PhysicsVector axis) 2863 private void createAMotor(Vector3 axis)
2842 { 2864 {
2843 if (Body == IntPtr.Zero) 2865 if (Body == IntPtr.Zero)
2844 return; 2866 return;
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 0a065be..2f42646 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -239,6 +239,7 @@ namespace OpenSim.Region.Physics.OdePlugin
239 private readonly HashSet<OdePrim> _prims = new HashSet<OdePrim>(); 239 private readonly HashSet<OdePrim> _prims = new HashSet<OdePrim>();
240 private readonly HashSet<OdePrim> _activeprims = new HashSet<OdePrim>(); 240 private readonly HashSet<OdePrim> _activeprims = new HashSet<OdePrim>();
241 private readonly HashSet<OdePrim> _taintedPrimH = new HashSet<OdePrim>(); 241 private readonly HashSet<OdePrim> _taintedPrimH = new HashSet<OdePrim>();
242 private readonly Object _taintedPrimLock = new Object();
242 private readonly List<OdePrim> _taintedPrimL = new List<OdePrim>(); 243 private readonly List<OdePrim> _taintedPrimL = new List<OdePrim>();
243 private readonly HashSet<OdeCharacter> _taintedActors = new HashSet<OdeCharacter>(); 244 private readonly HashSet<OdeCharacter> _taintedActors = new HashSet<OdeCharacter>();
244 private readonly List<d.ContactGeom> _perloopContact = new List<d.ContactGeom>(); 245 private readonly List<d.ContactGeom> _perloopContact = new List<d.ContactGeom>();
@@ -683,7 +684,7 @@ namespace OpenSim.Region.Physics.OdePlugin
683 /// </summary> 684 /// </summary>
684 /// <param name="pos"></param> 685 /// <param name="pos"></param>
685 /// <returns>Returns which split up space the given position is in.</returns> 686 /// <returns>Returns which split up space the given position is in.</returns>
686 public string whichspaceamIin(PhysicsVector pos) 687 public string whichspaceamIin(Vector3 pos)
687 { 688 {
688 return calculateSpaceForGeom(pos).ToString(); 689 return calculateSpaceForGeom(pos).ToString();
689 } 690 }
@@ -962,7 +963,7 @@ namespace OpenSim.Region.Physics.OdePlugin
962 963
963 //p2.CollidingObj = true; 964 //p2.CollidingObj = true;
964 contacts[i].depth = 0.00000003f; 965 contacts[i].depth = 0.00000003f;
965 p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f); 966 p2.Velocity = p2.Velocity + new Vector3(0f, 0f, 0.5f);
966 contacts[i].pos = 967 contacts[i].pos =
967 new d.Vector3(contacts[i].pos.X + (p1.Size.X/2), 968 new d.Vector3(contacts[i].pos.X + (p1.Size.X/2),
968 contacts[i].pos.Y + (p1.Size.Y/2), 969 contacts[i].pos.Y + (p1.Size.Y/2),
@@ -980,7 +981,7 @@ namespace OpenSim.Region.Physics.OdePlugin
980 981
981 //p2.CollidingObj = true; 982 //p2.CollidingObj = true;
982 contacts[i].depth = 0.00000003f; 983 contacts[i].depth = 0.00000003f;
983 p1.Velocity = p1.Velocity + new PhysicsVector(0, 0, 0.5f); 984 p1.Velocity = p1.Velocity + new Vector3(0f, 0f, 0.5f);
984 contacts[i].pos = 985 contacts[i].pos =
985 new d.Vector3(contacts[i].pos.X + (p1.Size.X/2), 986 new d.Vector3(contacts[i].pos.X + (p1.Size.X/2),
986 contacts[i].pos.Y + (p1.Size.Y/2), 987 contacts[i].pos.Y + (p1.Size.Y/2),
@@ -1645,9 +1646,9 @@ namespace OpenSim.Region.Physics.OdePlugin
1645 1646
1646 #region Add/Remove Entities 1647 #region Add/Remove Entities
1647 1648
1648 public override PhysicsActor AddAvatar(string avName, PhysicsVector position, PhysicsVector size, bool isFlying) 1649 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
1649 { 1650 {
1650 PhysicsVector pos = new PhysicsVector(); 1651 Vector3 pos;
1651 pos.X = position.X; 1652 pos.X = position.X;
1652 pos.Y = position.Y; 1653 pos.Y = position.Y;
1653 pos.Z = position.Z; 1654 pos.Z = position.Z;
@@ -1697,18 +1698,12 @@ namespace OpenSim.Region.Physics.OdePlugin
1697 1698
1698 } 1699 }
1699 1700
1700 private PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation, 1701 private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation,
1701 IMesh mesh, PrimitiveBaseShape pbs, bool isphysical) 1702 IMesh mesh, PrimitiveBaseShape pbs, bool isphysical)
1702 { 1703 {
1703 1704
1704 PhysicsVector pos = new PhysicsVector(position.X, position.Y, position.Z); 1705 Vector3 pos = position;
1705 //pos.X = position.X; 1706 Vector3 siz = size;
1706 //pos.Y = position.Y;
1707 //pos.Z = position.Z;
1708 PhysicsVector siz = new PhysicsVector();
1709 siz.X = size.X;
1710 siz.Y = size.Y;
1711 siz.Z = size.Z;
1712 Quaternion rot = rotation; 1707 Quaternion rot = rotation;
1713 1708
1714 OdePrim newPrim; 1709 OdePrim newPrim;
@@ -1735,14 +1730,14 @@ namespace OpenSim.Region.Physics.OdePlugin
1735 } 1730 }
1736 } 1731 }
1737 1732
1738 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, 1733 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1739 PhysicsVector size, Quaternion rotation) //To be removed 1734 Vector3 size, Quaternion rotation) //To be removed
1740 { 1735 {
1741 return AddPrimShape(primName, pbs, position, size, rotation, false); 1736 return AddPrimShape(primName, pbs, position, size, rotation, false);
1742 } 1737 }
1743 1738
1744 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, 1739 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1745 PhysicsVector size, Quaternion rotation, bool isPhysical) 1740 Vector3 size, Quaternion rotation, bool isPhysical)
1746 { 1741 {
1747 PhysicsActor result; 1742 PhysicsActor result;
1748 IMesh mesh = null; 1743 IMesh mesh = null;
@@ -1975,7 +1970,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1975 // this joint will just be added to a waiting list that is NOT processed during the main 1970 // this joint will just be added to a waiting list that is NOT processed during the main
1976 // Simulate() loop (to avoid deadlocks). After Simulate() is finished, we handle unprocessed joint requests. 1971 // Simulate() loop (to avoid deadlocks). After Simulate() is finished, we handle unprocessed joint requests.
1977 1972
1978 public override PhysicsJoint RequestJointCreation(string objectNameInScene, PhysicsJointType jointType, PhysicsVector position, 1973 public override PhysicsJoint RequestJointCreation(string objectNameInScene, PhysicsJointType jointType, Vector3 position,
1979 Quaternion rotation, string parms, List<string> bodyNames, string trackedBodyName, Quaternion localRotation) 1974 Quaternion rotation, string parms, List<string> bodyNames, string trackedBodyName, Quaternion localRotation)
1980 1975
1981 { 1976 {
@@ -1983,7 +1978,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1983 OdePhysicsJoint joint = new OdePhysicsJoint(); 1978 OdePhysicsJoint joint = new OdePhysicsJoint();
1984 joint.ObjectNameInScene = objectNameInScene; 1979 joint.ObjectNameInScene = objectNameInScene;
1985 joint.Type = jointType; 1980 joint.Type = jointType;
1986 joint.Position = new PhysicsVector(position.X, position.Y, position.Z); 1981 joint.Position = position;
1987 joint.Rotation = rotation; 1982 joint.Rotation = rotation;
1988 joint.RawParams = parms; 1983 joint.RawParams = parms;
1989 joint.BodyNames = new List<string>(bodyNames); 1984 joint.BodyNames = new List<string>(bodyNames);
@@ -2035,7 +2030,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2035 } 2030 }
2036 2031
2037 // normally called from within OnJointMoved, which is called from within a lock (OdeLock) 2032 // normally called from within OnJointMoved, which is called from within a lock (OdeLock)
2038 public override PhysicsVector GetJointAnchor(PhysicsJoint joint) 2033 public override Vector3 GetJointAnchor(PhysicsJoint joint)
2039 { 2034 {
2040 Debug.Assert(joint.IsInPhysicsEngine); 2035 Debug.Assert(joint.IsInPhysicsEngine);
2041 d.Vector3 pos = new d.Vector3(); 2036 d.Vector3 pos = new d.Vector3();
@@ -2057,14 +2052,14 @@ namespace OpenSim.Region.Physics.OdePlugin
2057 break; 2052 break;
2058 } 2053 }
2059 } 2054 }
2060 return new PhysicsVector(pos.X, pos.Y, pos.Z); 2055 return new Vector3(pos.X, pos.Y, pos.Z);
2061 } 2056 }
2062 2057
2063 // normally called from within OnJointMoved, which is called from within a lock (OdeLock) 2058 // normally called from within OnJointMoved, which is called from within a lock (OdeLock)
2064 // WARNING: ODE sometimes returns <0,0,0> as the joint axis! Therefore this function 2059 // WARNING: ODE sometimes returns <0,0,0> as the joint axis! Therefore this function
2065 // appears to be unreliable. Fortunately we can compute the joint axis ourselves by 2060 // appears to be unreliable. Fortunately we can compute the joint axis ourselves by
2066 // keeping track of the joint's original orientation relative to one of the involved bodies. 2061 // keeping track of the joint's original orientation relative to one of the involved bodies.
2067 public override PhysicsVector GetJointAxis(PhysicsJoint joint) 2062 public override Vector3 GetJointAxis(PhysicsJoint joint)
2068 { 2063 {
2069 Debug.Assert(joint.IsInPhysicsEngine); 2064 Debug.Assert(joint.IsInPhysicsEngine);
2070 d.Vector3 axis = new d.Vector3(); 2065 d.Vector3 axis = new d.Vector3();
@@ -2086,7 +2081,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2086 break; 2081 break;
2087 } 2082 }
2088 } 2083 }
2089 return new PhysicsVector(axis.X, axis.Y, axis.Z); 2084 return new Vector3(axis.X, axis.Y, axis.Z);
2090 } 2085 }
2091 2086
2092 2087
@@ -2254,7 +2249,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2254 /// <param name="pos">the position that the geom moved to</param> 2249 /// <param name="pos">the position that the geom moved to</param>
2255 /// <param name="currentspace">a pointer to the space it was in before it was moved.</param> 2250 /// <param name="currentspace">a pointer to the space it was in before it was moved.</param>
2256 /// <returns>a pointer to the new space it's in</returns> 2251 /// <returns>a pointer to the new space it's in</returns>
2257 public IntPtr recalculateSpaceForGeom(IntPtr geom, PhysicsVector pos, IntPtr currentspace) 2252 public IntPtr recalculateSpaceForGeom(IntPtr geom, Vector3 pos, IntPtr currentspace)
2258 { 2253 {
2259 // Called from setting the Position and Size of an ODEPrim so 2254 // Called from setting the Position and Size of an ODEPrim so
2260 // it's already in locked space. 2255 // it's already in locked space.
@@ -2401,7 +2396,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2401 /// </summary> 2396 /// </summary>
2402 /// <param name="pos"></param> 2397 /// <param name="pos"></param>
2403 /// <returns>a pointer to the space. This could be a new space or reused space.</returns> 2398 /// <returns>a pointer to the space. This could be a new space or reused space.</returns>
2404 public IntPtr calculateSpaceForGeom(PhysicsVector pos) 2399 public IntPtr calculateSpaceForGeom(Vector3 pos)
2405 { 2400 {
2406 int[] xyspace = calculateSpaceArrayItemFromPos(pos); 2401 int[] xyspace = calculateSpaceArrayItemFromPos(pos);
2407 //m_log.Info("[Physics]: Attempting to use arrayItem: " + xyspace[0].ToString() + "," + xyspace[1].ToString()); 2402 //m_log.Info("[Physics]: Attempting to use arrayItem: " + xyspace[0].ToString() + "," + xyspace[1].ToString());
@@ -2413,7 +2408,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2413 /// </summary> 2408 /// </summary>
2414 /// <param name="pos"></param> 2409 /// <param name="pos"></param>
2415 /// <returns>an array item based on the position</returns> 2410 /// <returns>an array item based on the position</returns>
2416 public int[] calculateSpaceArrayItemFromPos(PhysicsVector pos) 2411 public int[] calculateSpaceArrayItemFromPos(Vector3 pos)
2417 { 2412 {
2418 int[] returnint = new int[2]; 2413 int[] returnint = new int[2];
2419 2414
@@ -2572,7 +2567,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2572 if (prim is OdePrim) 2567 if (prim is OdePrim)
2573 { 2568 {
2574 OdePrim taintedprim = ((OdePrim) prim); 2569 OdePrim taintedprim = ((OdePrim) prim);
2575 lock (_taintedPrimH) 2570 lock (_taintedPrimLock)
2576 { 2571 {
2577 if (!(_taintedPrimH.Contains(taintedprim))) 2572 if (!(_taintedPrimH.Contains(taintedprim)))
2578 { 2573 {
@@ -2700,24 +2695,28 @@ namespace OpenSim.Region.Physics.OdePlugin
2700 // Modify other objects in the scene. 2695 // Modify other objects in the scene.
2701 processedtaints = false; 2696 processedtaints = false;
2702 2697
2703 lock (_taintedPrimL) 2698 lock (_taintedPrimLock)
2704 { 2699 {
2705 foreach (OdePrim prim in _taintedPrimL) 2700 foreach (OdePrim prim in _taintedPrimL)
2706 { 2701 {
2707
2708
2709 if (prim.m_taintremove) 2702 if (prim.m_taintremove)
2710 { 2703 {
2711//Console.WriteLine("Simulate calls RemovePrimThreadLocked"); 2704 //Console.WriteLine("Simulate calls RemovePrimThreadLocked");
2712 RemovePrimThreadLocked(prim); 2705 RemovePrimThreadLocked(prim);
2713 } 2706 }
2714 else 2707 else
2715 { 2708 {
2716//Console.WriteLine("Simulate calls ProcessTaints"); 2709 //Console.WriteLine("Simulate calls ProcessTaints");
2717 prim.ProcessTaints(timeStep); 2710 prim.ProcessTaints(timeStep);
2718 } 2711 }
2719 processedtaints = true; 2712 processedtaints = true;
2720 prim.m_collisionscore = 0; 2713 prim.m_collisionscore = 0;
2714
2715 // This loop can block up the Heartbeat for a very long time on large regions.
2716 // We need to let the Watchdog know that the Heartbeat is not dead
2717 // NOTE: This is currently commented out, but if things like OAR loading are
2718 // timing the heartbeat out we will need to uncomment it
2719 //Watchdog.UpdateThread();
2721 } 2720 }
2722 2721
2723 if (SupportsNINJAJoints) 2722 if (SupportsNINJAJoints)
diff --git a/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs b/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs
index cdd38c4..69e2d03 100644
--- a/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs
@@ -76,8 +76,8 @@ namespace OpenSim.Region.Physics.OdePlugin
76 public void CreateAndDropPhysicalCube() 76 public void CreateAndDropPhysicalCube()
77 { 77 {
78 PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox(); 78 PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox();
79 PhysicsVector position = new PhysicsVector(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128); 79 Vector3 position = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 128f);
80 PhysicsVector size = new PhysicsVector(0.5f, 0.5f, 0.5f); 80 Vector3 size = new Vector3(0.5f, 0.5f, 0.5f);
81 Quaternion rot = Quaternion.Identity; 81 Quaternion rot = Quaternion.Identity;
82 PhysicsActor prim = ps.AddPrimShape("CoolShape", newcube, position, size, rot, true); 82 PhysicsActor prim = ps.AddPrimShape("CoolShape", newcube, position, size, rot, true);
83 OdePrim oprim = (OdePrim)prim; 83 OdePrim oprim = (OdePrim)prim;