aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs318
1 files changed, 161 insertions, 157 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index f59f0ae..5ff9d32 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -1,18 +1,5 @@
1/* 1/* Copyright (c) Contributors, http://opensimulator.org/
2 * Revised August 26 2009 by Kitto Flora. ODEDynamics.cs replaces
3 * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
4 * ODEPrim.cs contains methods dealing with Prim editing, Prim
5 * characteristics and Kinetic motion.
6 * ODEDynamics.cs contains methods dealing with Prim Physical motion
7 * (dynamics) and the associated settings. Old Linear and angular
8 * motors for dynamic motion have been replace with MoveLinear()
9 * and MoveAngular(); 'Physical' is used only to switch ODE dynamic
10 * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
11 * switch between 'VEHICLE' parameter use and general dynamics
12 * settings use.
13 * Copyright (c) Contributors, http://opensimulator.org/
14 * See CONTRIBUTORS.TXT for a full list of copyright holders. 2 * See CONTRIBUTORS.TXT for a full list of copyright holders.
15 *
16 * Redistribution and use in source and binary forms, with or without 3 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions are met: 4 * modification, are permitted provided that the following conditions are met:
18 * * Redistributions of source code must retain the above copyright 5 * * Redistributions of source code must retain the above copyright
@@ -35,6 +22,20 @@
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */ 24 */
25
26/*
27 * Revised August 26 2009 by Kitto Flora. ODEDynamics.cs replaces
28 * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
29 * ODEPrim.cs contains methods dealing with Prim editing, Prim
30 * characteristics and Kinetic motion.
31 * ODEDynamics.cs contains methods dealing with Prim Physical motion
32 * (dynamics) and the associated settings. Old Linear and angular
33 * motors for dynamic motion have been replace with MoveLinear()
34 * and MoveAngular(); 'Physical' is used only to switch ODE dynamic
35 * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
36 * switch between 'VEHICLE' parameter use and general dynamics
37 * settings use.
38 */
38using System; 39using System;
39using System.Collections.Generic; 40using System.Collections.Generic;
40using System.Reflection; 41using System.Reflection;
@@ -56,44 +57,43 @@ namespace OpenSim.Region.Physics.OdePlugin
56 { 57 {
57 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 58 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
58 59
59 private PhysicsVector _position; 60 private Vector3 _position;
60 private PhysicsVector _velocity; 61 private Vector3 _velocity;
61 private PhysicsVector _torque = new PhysicsVector(0,0,0); 62 private Vector3 _torque;
62 private PhysicsVector m_lastVelocity = new PhysicsVector(0.0f, 0.0f, 0.0f); 63 private Vector3 m_lastVelocity;
63 private PhysicsVector m_lastposition = new PhysicsVector(0.0f, 0.0f, 0.0f); 64 private Vector3 m_lastposition;
64 private Quaternion m_lastorientation = new Quaternion(); 65 private Quaternion m_lastorientation = new Quaternion();
65 private PhysicsVector m_rotationalVelocity; 66 private Vector3 m_rotationalVelocity;
66 private PhysicsVector _size; 67 private Vector3 _size;
67 private PhysicsVector _acceleration; 68 private Vector3 _acceleration;
68 // private d.Vector3 _zeroPosition = new d.Vector3(0.0f, 0.0f, 0.0f); 69 // private d.Vector3 _zeroPosition = new d.Vector3(0.0f, 0.0f, 0.0f);
69 private Quaternion _orientation; 70 private Quaternion _orientation;
70 private PhysicsVector m_taintposition; 71 private Vector3 m_taintposition;
71 private PhysicsVector m_taintsize; 72 private Vector3 m_taintsize;
72 private PhysicsVector m_taintVelocity = new PhysicsVector(0, 0, 0); 73 private Vector3 m_taintVelocity;
73 private PhysicsVector m_taintTorque = new PhysicsVector(0, 0, 0); 74 private Vector3 m_taintTorque;
74 private Quaternion m_taintrot; 75 private Quaternion m_taintrot;
75 private PhysicsVector m_angularlock = new PhysicsVector(1f, 1f, 1f); 76 private Vector3 m_angularlock = Vector3.One;
76 private PhysicsVector m_taintAngularLock = new PhysicsVector(1f, 1f, 1f); 77 private Vector3 m_taintAngularLock = Vector3.One;
77 private IntPtr Amotor = IntPtr.Zero; 78 private IntPtr Amotor = IntPtr.Zero;
78 79
79 private PhysicsVector m_PIDTarget = new PhysicsVector(0, 0, 0); 80 private Vector3 m_PIDTarget;
80 // private PhysicsVector m_taintPIDTarget = new PhysicsVector(0, 0, 0); 81 private float m_PIDTau;
81 private float m_PIDTau = 0f;
82 private float PID_D = 35f; 82 private float PID_D = 35f;
83 private float PID_G = 25f; 83 private float PID_G = 25f;
84 private bool m_usePID = false; 84 private bool m_usePID;
85 85
86 // KF: These next 7 params apply to llSetHoverHeight(float height, integer water, float tau), 86 // KF: These next 7 params apply to llSetHoverHeight(float height, integer water, float tau),
87 // and are for non-VEHICLES only. 87 // and are for non-VEHICLES only.
88 88
89 private float m_PIDHoverHeight = 0f; 89 private float m_PIDHoverHeight;
90 private float m_PIDHoverTau = 0f; 90 private float m_PIDHoverTau;
91 private bool m_useHoverPID = false; 91 private bool m_useHoverPID;
92 private PIDHoverType m_PIDHoverType = PIDHoverType.Ground; 92 private PIDHoverType m_PIDHoverType = PIDHoverType.Ground;
93 private float m_targetHoverHeight = 0f; 93 private float m_targetHoverHeight;
94 private float m_groundHeight = 0f; 94 private float m_groundHeight;
95 private float m_waterHeight = 0f; 95 private float m_waterHeight;
96 private float m_buoyancy = 0f; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle. 96 private float m_buoyancy; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle.
97 97
98 // private float m_tensor = 5f; 98 // private float m_tensor = 5f;
99 private int body_autodisable_frames = 20; 99 private int body_autodisable_frames = 20;
@@ -104,11 +104,11 @@ namespace OpenSim.Region.Physics.OdePlugin
104 | CollisionCategories.Body 104 | CollisionCategories.Body
105 | CollisionCategories.Character 105 | CollisionCategories.Character
106 ); 106 );
107 private bool m_taintshape = false; 107 private bool m_taintshape;
108 private bool m_taintPhysics = false; 108 private bool m_taintPhysics;
109 private bool m_collidesLand = true; 109 private bool m_collidesLand = true;
110 private bool m_collidesWater = false; 110 private bool m_collidesWater;
111 public bool m_returnCollisions = false; 111 public bool m_returnCollisions;
112 112
113 // Default we're a Geometry 113 // Default we're a Geometry
114 private CollisionCategories m_collisionCategories = (CollisionCategories.Geom); 114 private CollisionCategories m_collisionCategories = (CollisionCategories.Geom);
@@ -116,85 +116,83 @@ namespace OpenSim.Region.Physics.OdePlugin
116 // Default, Collide with Other Geometries, spaces and Bodies 116 // Default, Collide with Other Geometries, spaces and Bodies
117 private CollisionCategories m_collisionFlags = m_default_collisionFlags; 117 private CollisionCategories m_collisionFlags = m_default_collisionFlags;
118 118
119 public bool m_taintremove = false; 119 public bool m_taintremove;
120 public bool m_taintdisable = false; 120 public bool m_taintdisable;
121 public bool m_disabled = false; 121 public bool m_disabled;
122 public bool m_taintadd = false; 122 public bool m_taintadd;
123 public bool m_taintselected = false; 123 public bool m_taintselected;
124 public bool m_taintCollidesWater = false; 124 public bool m_taintCollidesWater;
125 125
126 public uint m_localID = 0; 126 public uint m_localID;
127 127
128 //public GCHandle gc; 128 //public GCHandle gc;
129 private CollisionLocker ode; 129 private CollisionLocker ode;
130 130
131 private bool m_taintforce = false; 131 private bool m_taintforce = false;
132 private bool m_taintaddangularforce = false; 132 private bool m_taintaddangularforce = false;
133 private PhysicsVector m_force = new PhysicsVector(0.0f, 0.0f, 0.0f); 133 private Vector3 m_force;
134 private List<PhysicsVector> m_forcelist = new List<PhysicsVector>(); 134 private List<Vector3> m_forcelist = new List<Vector3>();
135 private List<PhysicsVector> m_angularforcelist = new List<PhysicsVector>(); 135 private List<Vector3> m_angularforcelist = new List<Vector3>();
136 136
137 private IMesh _mesh; 137 private IMesh _mesh;
138 private PrimitiveBaseShape _pbs; 138 private PrimitiveBaseShape _pbs;
139 private OdeScene _parent_scene; 139 private OdeScene _parent_scene;
140 public IntPtr m_targetSpace = (IntPtr) 0; 140 public IntPtr m_targetSpace = IntPtr.Zero;
141 public IntPtr prim_geom; 141 public IntPtr prim_geom;
142 public IntPtr prev_geom; 142 public IntPtr prev_geom;
143 public IntPtr _triMeshData; 143 public IntPtr _triMeshData;
144 144
145 private IntPtr _linkJointGroup = (IntPtr)0; 145 private IntPtr _linkJointGroup = IntPtr.Zero;
146 private PhysicsActor _parent = null; 146 private PhysicsActor _parent;
147 private PhysicsActor m_taintparent = null; 147 private PhysicsActor m_taintparent;
148 148
149 private List<OdePrim> childrenPrim = new List<OdePrim>(); 149 private List<OdePrim> childrenPrim = new List<OdePrim>();
150 150
151 private bool iscolliding = false; 151 private bool iscolliding;
152 private bool m_isphysical = false; 152 private bool m_isphysical;
153 private bool m_isSelected = false; 153 private bool m_isSelected;
154 154
155 internal bool m_isVolumeDetect = false; // If true, this prim only detects collisions but doesn't collide actively 155 internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively
156 156
157 private bool m_throttleUpdates = false; 157 private bool m_throttleUpdates;
158 private int throttleCounter = 0; 158 private int throttleCounter;
159 public int m_interpenetrationcount = 0; 159 public int m_interpenetrationcount;
160 public float m_collisionscore = 0; 160 public float m_collisionscore;
161 public int m_roundsUnderMotionThreshold = 0; 161 public int m_roundsUnderMotionThreshold;
162 private int m_crossingfailures = 0; 162 private int m_crossingfailures;
163 163
164 public bool outofBounds = false; 164 public bool outofBounds;
165 private float m_density = 10.000006836f; // Aluminum g/cm3; 165 private float m_density = 10.000006836f; // Aluminum g/cm3;
166 166
167 public bool _zeroFlag = false; 167 public bool _zeroFlag;
168 private bool m_lastUpdateSent = false; 168 private bool m_lastUpdateSent;
169 169
170 public IntPtr Body = (IntPtr) 0; 170 public IntPtr Body = IntPtr.Zero;
171 public String m_primName; 171 public String m_primName;
172// private String m_primName; 172 private Vector3 _target_velocity;
173 private PhysicsVector _target_velocity;
174 public d.Mass pMass; 173 public d.Mass pMass;
175 174
176 public int m_eventsubscription = 0; 175 public int m_eventsubscription;
177 private CollisionEventUpdate CollisionEventsThisFrame = null; 176 private CollisionEventUpdate CollisionEventsThisFrame;
178 177
179 private IntPtr m_linkJoint = (IntPtr)0; 178 private IntPtr m_linkJoint = IntPtr.Zero;
180 179
181 public volatile bool childPrim = false; 180 public volatile bool childPrim;
182 181
183 private ODEDynamics m_vehicle; 182 private ODEDynamics m_vehicle;
184 183
185 internal int m_material = (int)Material.Wood; 184 internal int m_material = (int)Material.Wood;
186 185
187 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, 186 public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size,
188 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) 187 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode)
189 { 188 {
190 _target_velocity = new PhysicsVector(0, 0, 0);
191 m_vehicle = new ODEDynamics(); 189 m_vehicle = new ODEDynamics();
192 //gc = GCHandle.Alloc(prim_geom, GCHandleType.Pinned); 190 //gc = GCHandle.Alloc(prim_geom, GCHandleType.Pinned);
193 ode = dode; 191 ode = dode;
194 _velocity = new PhysicsVector(); 192 if (!pos.IsFinite())
195 if (!PhysicsVector.isFinite(pos))
196 { 193 {
197 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); 194 pos = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f),
195 parent_scene.GetTerrainHeightAtXY(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f)) + 0.5f);
198 m_log.Warn("[PHYSICS]: Got nonFinite Object create Position"); 196 m_log.Warn("[PHYSICS]: Got nonFinite Object create Position");
199 } 197 }
200 _position = pos; 198 _position = pos;
@@ -209,9 +207,9 @@ namespace OpenSim.Region.Physics.OdePlugin
209 prim_geom = IntPtr.Zero; 207 prim_geom = IntPtr.Zero;
210 prev_geom = IntPtr.Zero; 208 prev_geom = IntPtr.Zero;
211 209
212 if (!PhysicsVector.isFinite(pos)) 210 if (!pos.IsFinite())
213 { 211 {
214 size = new PhysicsVector(0.5f, 0.5f, 0.5f); 212 size = new Vector3(0.5f, 0.5f, 0.5f);
215 m_log.Warn("[PHYSICS]: Got nonFinite Object create Size"); 213 m_log.Warn("[PHYSICS]: Got nonFinite Object create Size");
216 } 214 }
217 215
@@ -221,8 +219,6 @@ namespace OpenSim.Region.Physics.OdePlugin
221 219
222 _size = size; 220 _size = size;
223 m_taintsize = _size; 221 m_taintsize = _size;
224 _acceleration = new PhysicsVector();
225 m_rotationalVelocity = PhysicsVector.Zero;
226 222
227 if (!QuaternionIsFinite(rotation)) 223 if (!QuaternionIsFinite(rotation))
228 { 224 {
@@ -387,7 +383,7 @@ namespace OpenSim.Region.Physics.OdePlugin
387 m_disabled = false; 383 m_disabled = false;
388 384
389 // The body doesn't already have a finite rotation mode set here 385 // The body doesn't already have a finite rotation mode set here
390 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null) 386 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0.0f)) && _parent == null)
391 { 387 {
392 createAMotor(m_angularlock); 388 createAMotor(m_angularlock);
393 } 389 }
@@ -800,6 +796,8 @@ namespace OpenSim.Region.Physics.OdePlugin
800 m_collisionscore = 0; 796 m_collisionscore = 0;
801 } 797 }
802 798
799 private static Dictionary<IMesh, IntPtr> m_MeshToTriMeshMap = new Dictionary<IMesh, IntPtr>();
800
803 public void setMesh(OdeScene parent_scene, IMesh mesh) 801 public void setMesh(OdeScene parent_scene, IMesh mesh)
804 { 802 {
805 // This sleeper is there to moderate how long it takes between 803 // This sleeper is there to moderate how long it takes between
@@ -831,19 +829,24 @@ namespace OpenSim.Region.Physics.OdePlugin
831 mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage 829 mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage
832 830
833 mesh.releaseSourceMeshData(); // free up the original mesh data to save memory 831 mesh.releaseSourceMeshData(); // free up the original mesh data to save memory
832 if (m_MeshToTriMeshMap.ContainsKey(mesh))
833 {
834 _triMeshData = m_MeshToTriMeshMap[mesh];
835 }
836 else
837 {
838 _triMeshData = d.GeomTriMeshDataCreate();
834 839
835 _triMeshData = d.GeomTriMeshDataCreate(); 840 d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
836 841 d.GeomTriMeshDataPreprocess(_triMeshData);
837 d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride); 842 m_MeshToTriMeshMap[mesh] = _triMeshData;
838 d.GeomTriMeshDataPreprocess(_triMeshData); 843 }
839 844
840 _parent_scene.waitForSpaceUnlock(m_targetSpace); 845 _parent_scene.waitForSpaceUnlock(m_targetSpace);
841
842 try 846 try
843 { 847 {
844 if (prim_geom == IntPtr.Zero) 848 if (prim_geom == IntPtr.Zero)
845 { 849 {
846//Console.WriteLine(" setMesh 1");
847 SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null)); 850 SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null));
848 } 851 }
849 } 852 }
@@ -853,6 +856,7 @@ namespace OpenSim.Region.Physics.OdePlugin
853 return; 856 return;
854 } 857 }
855 858
859
856 // if (IsPhysical && Body == (IntPtr) 0) 860 // if (IsPhysical && Body == (IntPtr) 0)
857 // { 861 // {
858 // Recreate the body 862 // Recreate the body
@@ -873,7 +877,7 @@ namespace OpenSim.Region.Physics.OdePlugin
873 877
874 if (prim_geom != IntPtr.Zero) 878 if (prim_geom != IntPtr.Zero)
875 { 879 {
876 if (!_position.IsIdentical(m_taintposition,0f)) 880 if (!_position.ApproxEquals(m_taintposition, 0f))
877 changemove(timestep); 881 changemove(timestep);
878 882
879 if (m_taintrot != _orientation) 883 if (m_taintrot != _orientation)
@@ -898,7 +902,7 @@ namespace OpenSim.Region.Physics.OdePlugin
898 changePhysicsStatus(timestep); 902 changePhysicsStatus(timestep);
899 // 903 //
900 904
901 if (!_size.IsIdentical(m_taintsize,0)) 905 if (!_size.ApproxEquals(m_taintsize,0f))
902 changesize(timestep); 906 changesize(timestep);
903 // 907 //
904 908
@@ -912,7 +916,7 @@ namespace OpenSim.Region.Physics.OdePlugin
912 if (m_taintaddangularforce) 916 if (m_taintaddangularforce)
913 changeAddAngularForce(timestep); 917 changeAddAngularForce(timestep);
914 918
915 if (!m_taintTorque.IsIdentical(PhysicsVector.Zero, 0.001f)) 919 if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f))
916 changeSetTorque(timestep); 920 changeSetTorque(timestep);
917 921
918 if (m_taintdisable) 922 if (m_taintdisable)
@@ -921,7 +925,7 @@ namespace OpenSim.Region.Physics.OdePlugin
921 if (m_taintselected != m_isSelected) 925 if (m_taintselected != m_isSelected)
922 changeSelectedStatus(timestep); 926 changeSelectedStatus(timestep);
923 927
924 if (!m_taintVelocity.IsIdentical(PhysicsVector.Zero, 0.001f)) 928 if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f))
925 changevelocity(timestep); 929 changevelocity(timestep);
926 930
927 if (m_taintparent != _parent) 931 if (m_taintparent != _parent)
@@ -930,7 +934,7 @@ namespace OpenSim.Region.Physics.OdePlugin
930 if (m_taintCollidesWater != m_collidesWater) 934 if (m_taintCollidesWater != m_collidesWater)
931 changefloatonwater(timestep); 935 changefloatonwater(timestep);
932 936
933 if (!m_angularlock.IsIdentical(m_taintAngularLock,0)) 937 if (!m_angularlock.ApproxEquals(m_taintAngularLock,0f))
934 changeAngularLock(timestep); 938 changeAngularLock(timestep);
935 939
936 } 940 }
@@ -950,7 +954,7 @@ namespace OpenSim.Region.Physics.OdePlugin
950 //If we have a parent then we're not authorative here 954 //If we have a parent then we're not authorative here
951 if (_parent == null) 955 if (_parent == null)
952 { 956 {
953 if (!m_taintAngularLock.IsIdentical(new PhysicsVector(1f,1f,1f), 0)) 957 if (!m_taintAngularLock.ApproxEquals(Vector3.One, 0f))
954 { 958 {
955 //d.BodySetFiniteRotationMode(Body, 0); 959 //d.BodySetFiniteRotationMode(Body, 0);
956 //d.BodySetFiniteRotationAxis(Body,m_taintAngularLock.X,m_taintAngularLock.Y,m_taintAngularLock.Z); 960 //d.BodySetFiniteRotationAxis(Body,m_taintAngularLock.X,m_taintAngularLock.Y,m_taintAngularLock.Z);
@@ -967,7 +971,7 @@ namespace OpenSim.Region.Physics.OdePlugin
967 } 971 }
968 } 972 }
969 // Store this for later in case we get turned into a separate body 973 // Store this for later in case we get turned into a separate body
970 m_angularlock = new PhysicsVector(m_taintAngularLock.X, m_taintAngularLock.Y, m_taintAngularLock.Z); 974 m_angularlock = m_taintAngularLock;
971 975
972 } 976 }
973 977
@@ -1111,7 +1115,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1111 prm.m_disabled = false; 1115 prm.m_disabled = false;
1112 1116
1113 // The body doesn't already have a finite rotation mode set here 1117 // The body doesn't already have a finite rotation mode set here
1114 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null) 1118 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
1115 { 1119 {
1116 prm.createAMotor(m_angularlock); 1120 prm.createAMotor(m_angularlock);
1117 } 1121 }
@@ -1154,7 +1158,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1154 m_disabled = false; 1158 m_disabled = false;
1155 1159
1156 // The body doesn't already have a finite rotation mode set here 1160 // The body doesn't already have a finite rotation mode set here
1157 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null) 1161 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
1158 { 1162 {
1159 createAMotor(m_angularlock); 1163 createAMotor(m_angularlock);
1160 } 1164 }
@@ -1338,7 +1342,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1338 m_taintshape = false; 1342 m_taintshape = false;
1339 m_taintforce = false; 1343 m_taintforce = false;
1340 m_taintdisable = false; 1344 m_taintdisable = false;
1341 m_taintVelocity = PhysicsVector.Zero; 1345 m_taintVelocity = Vector3.Zero;
1342 } 1346 }
1343 1347
1344 public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh) 1348 public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh)
@@ -1567,7 +1571,7 @@ Console.WriteLine(" JointCreateFixed");
1567//Console.WriteLine("Move " + m_primName); 1571//Console.WriteLine("Move " + m_primName);
1568 if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body); // KF add 161009 1572 if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body); // KF add 161009
1569 // NON-'VEHICLES' are dealt with here 1573 // NON-'VEHICLES' are dealt with here
1570 if (d.BodyIsEnabled(Body) && !m_angularlock.IsIdentical(PhysicsVector.Zero, 0.003f)) 1574 if (d.BodyIsEnabled(Body) && !m_angularlock.ApproxEquals(Vector3.Zero, 0.003f))
1571 { 1575 {
1572 d.Vector3 avel2 = d.BodyGetAngularVel(Body); 1576 d.Vector3 avel2 = d.BodyGetAngularVel(Body);
1573 if (m_angularlock.X == 1) 1577 if (m_angularlock.X == 1)
@@ -1624,7 +1628,7 @@ Console.WriteLine(" JointCreateFixed");
1624 1628
1625 d.Vector3 pos = d.BodyGetPosition(Body); 1629 d.Vector3 pos = d.BodyGetPosition(Body);
1626 _target_velocity = 1630 _target_velocity =
1627 new PhysicsVector( 1631 new Vector3(
1628 (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep), 1632 (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep),
1629 (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep), 1633 (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep),
1630 (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep) 1634 (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep)
@@ -1632,7 +1636,7 @@ Console.WriteLine(" JointCreateFixed");
1632 1636
1633 // if velocity is zero, use position control; otherwise, velocity control 1637 // if velocity is zero, use position control; otherwise, velocity control
1634 1638
1635 if (_target_velocity.IsIdentical(PhysicsVector.Zero,0.1f)) 1639 if (_target_velocity.ApproxEquals(Vector3.Zero,0.1f))
1636 { 1640 {
1637 // keep track of where we stopped. No more slippin' & slidin' 1641 // keep track of where we stopped. No more slippin' & slidin'
1638 1642
@@ -1717,13 +1721,13 @@ Console.WriteLine(" JointCreateFixed");
1717 1721
1718 1722
1719 _target_velocity = 1723 _target_velocity =
1720 new PhysicsVector(0.0f, 0.0f, 1724 new Vector3(0.0f, 0.0f,
1721 (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep) 1725 (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep)
1722 ); 1726 );
1723 1727
1724 // if velocity is zero, use position control; otherwise, velocity control 1728 // if velocity is zero, use position control; otherwise, velocity control
1725 1729
1726 if (_target_velocity.IsIdentical(PhysicsVector.Zero, 0.1f)) 1730 if (_target_velocity.ApproxEquals(Vector3.Zero, 0.1f))
1727 { 1731 {
1728 // keep track of where we stopped. No more slippin' & slidin' 1732 // keep track of where we stopped. No more slippin' & slidin'
1729 1733
@@ -1812,7 +1816,7 @@ Console.WriteLine(" JointCreateFixed");
1812 d.BodySetQuaternion(Body, ref myrot); 1816 d.BodySetQuaternion(Body, ref myrot);
1813 if (m_isphysical) 1817 if (m_isphysical)
1814 { 1818 {
1815 if (!m_angularlock.IsIdentical(new PhysicsVector(1, 1, 1), 0)) 1819 if (!m_angularlock.ApproxEquals(Vector3.One, 0f))
1816 createAMotor(m_angularlock); 1820 createAMotor(m_angularlock);
1817 } 1821 }
1818 } 1822 }
@@ -2121,7 +2125,7 @@ Console.WriteLine(" JointCreateFixed");
2121 //m_log.Info("[PHYSICS]: dequeing forcelist"); 2125 //m_log.Info("[PHYSICS]: dequeing forcelist");
2122 if (IsPhysical) 2126 if (IsPhysical)
2123 { 2127 {
2124 PhysicsVector iforce = new PhysicsVector(); 2128 Vector3 iforce = Vector3.Zero;
2125 for (int i = 0; i < m_forcelist.Count; i++) 2129 for (int i = 0; i < m_forcelist.Count; i++)
2126 { 2130 {
2127 iforce = iforce + (m_forcelist[i] * 100); 2131 iforce = iforce + (m_forcelist[i] * 100);
@@ -2151,8 +2155,8 @@ Console.WriteLine(" JointCreateFixed");
2151 d.BodySetTorque(Body, m_taintTorque.X, m_taintTorque.Y, m_taintTorque.Z); 2155 d.BodySetTorque(Body, m_taintTorque.X, m_taintTorque.Y, m_taintTorque.Z);
2152 } 2156 }
2153 } 2157 }
2154 2158
2155 m_taintTorque = new PhysicsVector(0, 0, 0); 2159 m_taintTorque = Vector3.Zero;
2156 } 2160 }
2157 2161
2158 public void changeAddAngularForce(float timestamp) 2162 public void changeAddAngularForce(float timestamp)
@@ -2164,7 +2168,7 @@ Console.WriteLine(" JointCreateFixed");
2164 //m_log.Info("[PHYSICS]: dequeing forcelist"); 2168 //m_log.Info("[PHYSICS]: dequeing forcelist");
2165 if (IsPhysical) 2169 if (IsPhysical)
2166 { 2170 {
2167 PhysicsVector iforce = new PhysicsVector(); 2171 Vector3 iforce = Vector3.Zero;
2168 for (int i = 0; i < m_angularforcelist.Count; i++) 2172 for (int i = 0; i < m_angularforcelist.Count; i++)
2169 { 2173 {
2170 iforce = iforce + (m_angularforcelist[i] * 100); 2174 iforce = iforce + (m_angularforcelist[i] * 100);
@@ -2198,7 +2202,7 @@ Console.WriteLine(" JointCreateFixed");
2198 2202
2199 //resetCollisionAccounting(); 2203 //resetCollisionAccounting();
2200 } 2204 }
2201 m_taintVelocity = PhysicsVector.Zero; 2205 m_taintVelocity = Vector3.Zero;
2202 } 2206 }
2203 2207
2204 public override bool IsPhysical 2208 public override bool IsPhysical
@@ -2207,7 +2211,7 @@ Console.WriteLine(" JointCreateFixed");
2207 set { 2211 set {
2208 m_isphysical = value; 2212 m_isphysical = value;
2209 if (!m_isphysical) // Zero the remembered last velocity 2213 if (!m_isphysical) // Zero the remembered last velocity
2210 m_lastVelocity = new PhysicsVector(0.0f, 0.0f, 0.0f); 2214 m_lastVelocity = Vector3.Zero;
2211 } 2215 }
2212 } 2216 }
2213 2217
@@ -2252,7 +2256,7 @@ Console.WriteLine(" JointCreateFixed");
2252 get { return _zeroFlag; } 2256 get { return _zeroFlag; }
2253 } 2257 }
2254 2258
2255 public override PhysicsVector Position 2259 public override Vector3 Position
2256 { 2260 {
2257 get { return _position; } 2261 get { return _position; }
2258 2262
@@ -2261,12 +2265,12 @@ Console.WriteLine(" JointCreateFixed");
2261 } 2265 }
2262 } 2266 }
2263 2267
2264 public override PhysicsVector Size 2268 public override Vector3 Size
2265 { 2269 {
2266 get { return _size; } 2270 get { return _size; }
2267 set 2271 set
2268 { 2272 {
2269 if (PhysicsVector.isFinite(value)) 2273 if (value.IsFinite())
2270 { 2274 {
2271 _size = value; 2275 _size = value;
2272 } 2276 }
@@ -2282,13 +2286,13 @@ Console.WriteLine(" JointCreateFixed");
2282 get { return CalculateMass(); } 2286 get { return CalculateMass(); }
2283 } 2287 }
2284 2288
2285 public override PhysicsVector Force 2289 public override Vector3 Force
2286 { 2290 {
2287 //get { return PhysicsVector.Zero; } 2291 //get { return Vector3.Zero; }
2288 get { return m_force; } 2292 get { return m_force; }
2289 set 2293 set
2290 { 2294 {
2291 if (PhysicsVector.isFinite(value)) 2295 if (value.IsFinite())
2292 { 2296 {
2293 m_force = value; 2297 m_force = value;
2294 } 2298 }
@@ -2310,7 +2314,7 @@ Console.WriteLine(" JointCreateFixed");
2310 m_vehicle.ProcessFloatVehicleParam((Vehicle) param, value); 2314 m_vehicle.ProcessFloatVehicleParam((Vehicle) param, value);
2311 } 2315 }
2312 2316
2313 public override void VehicleVectorParam(int param, PhysicsVector value) 2317 public override void VehicleVectorParam(int param, Vector3 value)
2314 { 2318 {
2315 m_vehicle.ProcessVectorVehicleParam((Vehicle) param, value); 2319 m_vehicle.ProcessVectorVehicleParam((Vehicle) param, value);
2316 } 2320 }
@@ -2328,14 +2332,14 @@ Console.WriteLine(" JointCreateFixed");
2328 } 2332 }
2329 } 2333 }
2330 2334
2331 public override PhysicsVector CenterOfMass 2335 public override Vector3 CenterOfMass
2332 { 2336 {
2333 get { return PhysicsVector.Zero; } 2337 get { return Vector3.Zero; }
2334 } 2338 }
2335 2339
2336 public override PhysicsVector GeometricCenter 2340 public override Vector3 GeometricCenter
2337 { 2341 {
2338 get { return PhysicsVector.Zero; } 2342 get { return Vector3.Zero; }
2339 } 2343 }
2340 2344
2341 public override PrimitiveBaseShape Shape 2345 public override PrimitiveBaseShape Shape
@@ -2347,13 +2351,13 @@ Console.WriteLine(" JointCreateFixed");
2347 } 2351 }
2348 } 2352 }
2349 2353
2350 public override PhysicsVector Velocity 2354 public override Vector3 Velocity
2351 { 2355 {
2352 get 2356 get
2353 { 2357 {
2354 // Averate previous velocity with the new one so 2358 // Averate previous velocity with the new one so
2355 // client object interpolation works a 'little' better 2359 // client object interpolation works a 'little' better
2356 PhysicsVector returnVelocity = new PhysicsVector(); 2360 Vector3 returnVelocity = Vector3.Zero;
2357 returnVelocity.X = (m_lastVelocity.X + _velocity.X)/2; 2361 returnVelocity.X = (m_lastVelocity.X + _velocity.X)/2;
2358 returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y)/2; 2362 returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y)/2;
2359 returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z)/2; 2363 returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z)/2;
@@ -2361,7 +2365,7 @@ Console.WriteLine(" JointCreateFixed");
2361 } 2365 }
2362 set 2366 set
2363 { 2367 {
2364 if (PhysicsVector.isFinite(value)) 2368 if (value.IsFinite())
2365 { 2369 {
2366 _velocity = value; 2370 _velocity = value;
2367 2371
@@ -2376,19 +2380,19 @@ Console.WriteLine(" JointCreateFixed");
2376 } 2380 }
2377 } 2381 }
2378 2382
2379 public override PhysicsVector Torque 2383 public override Vector3 Torque
2380 { 2384 {
2381 get 2385 get
2382 { 2386 {
2383 if (!m_isphysical || Body == IntPtr.Zero) 2387 if (!m_isphysical || Body == IntPtr.Zero)
2384 return new PhysicsVector(0,0,0); 2388 return Vector3.Zero;
2385 2389
2386 return _torque; 2390 return _torque;
2387 } 2391 }
2388 2392
2389 set 2393 set
2390 { 2394 {
2391 if (PhysicsVector.isFinite(value)) 2395 if (value.IsFinite())
2392 { 2396 {
2393 m_taintTorque = value; 2397 m_taintTorque = value;
2394 _parent_scene.AddPhysicsActorTaint(this); 2398 _parent_scene.AddPhysicsActorTaint(this);
@@ -2440,20 +2444,20 @@ Console.WriteLine(" JointCreateFixed");
2440 return true; 2444 return true;
2441 } 2445 }
2442 2446
2443 public override PhysicsVector Acceleration 2447 public override Vector3 Acceleration
2444 { 2448 {
2445 get { return _acceleration; } 2449 get { return _acceleration; }
2446 } 2450 }
2447 2451
2448 2452
2449 public void SetAcceleration(PhysicsVector accel) 2453 public void SetAcceleration(Vector3 accel)
2450 { 2454 {
2451 _acceleration = accel; 2455 _acceleration = accel;
2452 } 2456 }
2453 2457
2454 public override void AddForce(PhysicsVector force, bool pushforce) 2458 public override void AddForce(Vector3 force, bool pushforce)
2455 { 2459 {
2456 if (PhysicsVector.isFinite(force)) 2460 if (force.IsFinite())
2457 { 2461 {
2458 m_forcelist.Add(force); 2462 m_forcelist.Add(force);
2459 m_taintforce = true; 2463 m_taintforce = true;
@@ -2465,9 +2469,9 @@ Console.WriteLine(" JointCreateFixed");
2465 //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString()); 2469 //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString());
2466 } 2470 }
2467 2471
2468 public override void AddAngularForce(PhysicsVector force, bool pushforce) 2472 public override void AddAngularForce(Vector3 force, bool pushforce)
2469 { 2473 {
2470 if (PhysicsVector.isFinite(force)) 2474 if (force.IsFinite())
2471 { 2475 {
2472 m_angularforcelist.Add(force); 2476 m_angularforcelist.Add(force);
2473 m_taintaddangularforce = true; 2477 m_taintaddangularforce = true;
@@ -2478,23 +2482,23 @@ Console.WriteLine(" JointCreateFixed");
2478 } 2482 }
2479 } 2483 }
2480 2484
2481 public override PhysicsVector RotationalVelocity 2485 public override Vector3 RotationalVelocity
2482 { 2486 {
2483 get 2487 get
2484 { 2488 {
2485 PhysicsVector pv = new PhysicsVector(0, 0, 0); 2489 Vector3 pv = Vector3.Zero;
2486 if (_zeroFlag) 2490 if (_zeroFlag)
2487 return pv; 2491 return pv;
2488 m_lastUpdateSent = false; 2492 m_lastUpdateSent = false;
2489 2493
2490 if (m_rotationalVelocity.IsIdentical(pv, 0.2f)) 2494 if (m_rotationalVelocity.ApproxEquals(pv, 0.2f))
2491 return pv; 2495 return pv;
2492 2496
2493 return m_rotationalVelocity; 2497 return m_rotationalVelocity;
2494 } 2498 }
2495 set 2499 set
2496 { 2500 {
2497 if (PhysicsVector.isFinite(value)) 2501 if (value.IsFinite())
2498 { 2502 {
2499 m_rotationalVelocity = value; 2503 m_rotationalVelocity = value;
2500 } 2504 }
@@ -2535,16 +2539,16 @@ Console.WriteLine(" JointCreateFixed");
2535 m_taintparent = null; 2539 m_taintparent = null;
2536 } 2540 }
2537 2541
2538 public override void LockAngularMotion(PhysicsVector axis) 2542 public override void LockAngularMotion(Vector3 axis)
2539 { 2543 {
2540 // reverse the zero/non zero values for ODE. 2544 // reverse the zero/non zero values for ODE.
2541 if (PhysicsVector.isFinite(axis)) 2545 if (axis.IsFinite())
2542 { 2546 {
2543 axis.X = (axis.X > 0) ? 1f : 0f; 2547 axis.X = (axis.X > 0) ? 1f : 0f;
2544 axis.Y = (axis.Y > 0) ? 1f : 0f; 2548 axis.Y = (axis.Y > 0) ? 1f : 0f;
2545 axis.Z = (axis.Z > 0) ? 1f : 0f; 2549 axis.Z = (axis.Z > 0) ? 1f : 0f;
2546 m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z); 2550 m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z);
2547 m_taintAngularLock = new PhysicsVector(axis.X, axis.Y, axis.Z); 2551 m_taintAngularLock = axis;
2548 } 2552 }
2549 else 2553 else
2550 { 2554 {
@@ -2557,7 +2561,7 @@ Console.WriteLine(" JointCreateFixed");
2557 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! 2561 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
2558 if (_parent == null) 2562 if (_parent == null)
2559 { 2563 {
2560 PhysicsVector pv = new PhysicsVector(0, 0, 0); 2564 Vector3 pv = Vector3.Zero;
2561 bool lastZeroFlag = _zeroFlag; 2565 bool lastZeroFlag = _zeroFlag;
2562 if (Body != (IntPtr)0) // FIXME -> or if it is a joint 2566 if (Body != (IntPtr)0) // FIXME -> or if it is a joint
2563 { 2567 {
@@ -2566,9 +2570,9 @@ Console.WriteLine(" JointCreateFixed");
2566 d.Vector3 vel = d.BodyGetLinearVel(Body); 2570 d.Vector3 vel = d.BodyGetLinearVel(Body);
2567 d.Vector3 rotvel = d.BodyGetAngularVel(Body); 2571 d.Vector3 rotvel = d.BodyGetAngularVel(Body);
2568 d.Vector3 torque = d.BodyGetTorque(Body); 2572 d.Vector3 torque = d.BodyGetTorque(Body);
2569 _torque.setValues(torque.X, torque.Y, torque.Z); 2573 _torque = new Vector3(torque.X, torque.Y, torque.Z);
2570 PhysicsVector l_position = new PhysicsVector(); 2574 Vector3 l_position = Vector3.Zero;
2571 Quaternion l_orientation = new Quaternion(); 2575 Quaternion l_orientation = Quaternion.Identity;
2572 2576
2573 // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) 2577 // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!)
2574 //if (vec.X < 0.0f) { vec.X = 0.0f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); } 2578 //if (vec.X < 0.0f) { vec.X = 0.0f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); }
@@ -2703,16 +2707,16 @@ Console.WriteLine(" JointCreateFixed");
2703 _velocity.Z = vel.Z; 2707 _velocity.Z = vel.Z;
2704 2708
2705 _acceleration = ((_velocity - m_lastVelocity) / 0.1f); 2709 _acceleration = ((_velocity - m_lastVelocity) / 0.1f);
2706 _acceleration = new PhysicsVector(_velocity.X - m_lastVelocity.X / 0.1f, _velocity.Y - m_lastVelocity.Y / 0.1f, _velocity.Z - m_lastVelocity.Z / 0.1f); 2710 _acceleration = new Vector3(_velocity.X - m_lastVelocity.X / 0.1f, _velocity.Y - m_lastVelocity.Y / 0.1f, _velocity.Z - m_lastVelocity.Z / 0.1f);
2707 //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString()); 2711 //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString());
2708 2712
2709 if (_velocity.IsIdentical(pv, 0.5f)) 2713 if (_velocity.ApproxEquals(pv, 0.5f))
2710 { 2714 {
2711 m_rotationalVelocity = pv; 2715 m_rotationalVelocity = pv;
2712 } 2716 }
2713 else 2717 else
2714 { 2718 {
2715 m_rotationalVelocity.setValues(rotvel.X, rotvel.Y, rotvel.Z); 2719 m_rotationalVelocity = new Vector3(rotvel.X, rotvel.Y, rotvel.Z);
2716 } 2720 }
2717 2721
2718 //m_log.Debug("ODE: " + m_rotationalVelocity.ToString()); 2722 //m_log.Debug("ODE: " + m_rotationalVelocity.ToString());
@@ -2760,15 +2764,15 @@ Console.WriteLine(" JointCreateFixed");
2760 } 2764 }
2761 } 2765 }
2762 2766
2763 public override void SetMomentum(PhysicsVector momentum) 2767 public override void SetMomentum(Vector3 momentum)
2764 { 2768 {
2765 } 2769 }
2766 2770
2767 public override PhysicsVector PIDTarget 2771 public override Vector3 PIDTarget
2768 { 2772 {
2769 set 2773 set
2770 { 2774 {
2771 if (PhysicsVector.isFinite(value)) 2775 if (value.IsFinite())
2772 { 2776 {
2773 m_PIDTarget = value; 2777 m_PIDTarget = value;
2774 } 2778 }
@@ -2784,7 +2788,7 @@ Console.WriteLine(" JointCreateFixed");
2784 public override PIDHoverType PIDHoverType { set { m_PIDHoverType = value; } } 2788 public override PIDHoverType PIDHoverType { set { m_PIDHoverType = value; } }
2785 public override float PIDHoverTau { set { m_PIDHoverTau = value; } } 2789 public override float PIDHoverTau { set { m_PIDHoverTau = value; } }
2786 2790
2787 private void createAMotor(PhysicsVector axis) 2791 private void createAMotor(Vector3 axis)
2788 { 2792 {
2789 if (Body == IntPtr.Zero) 2793 if (Body == IntPtr.Zero)
2790 return; 2794 return;