diff options
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/ODEPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 594 |
1 files changed, 323 insertions, 271 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 032b5df..86ed3bd 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | |||
@@ -1,4 +1,15 @@ | |||
1 | /* | 1 | /* |
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. | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 13 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 14 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 15 | * |
@@ -72,6 +83,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
72 | private float PID_G = 25f; | 83 | private float PID_G = 25f; |
73 | private bool m_usePID = false; | 84 | private bool m_usePID = false; |
74 | 85 | ||
86 | // KF: These next 7 params apply to llSetHoverHeight(float height, integer water, float tau), | ||
87 | // and are for non-VEHICLES only. | ||
88 | |||
75 | private float m_PIDHoverHeight = 0f; | 89 | private float m_PIDHoverHeight = 0f; |
76 | private float m_PIDHoverTau = 0f; | 90 | private float m_PIDHoverTau = 0f; |
77 | private bool m_useHoverPID = false; | 91 | private bool m_useHoverPID = false; |
@@ -79,6 +93,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
79 | private float m_targetHoverHeight = 0f; | 93 | private float m_targetHoverHeight = 0f; |
80 | private float m_groundHeight = 0f; | 94 | private float m_groundHeight = 0f; |
81 | private float m_waterHeight = 0f; | 95 | private float m_waterHeight = 0f; |
96 | private float m_buoyancy = 0f; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle. | ||
82 | 97 | ||
83 | // private float m_tensor = 5f; | 98 | // private float m_tensor = 5f; |
84 | private int body_autodisable_frames = 20; | 99 | private int body_autodisable_frames = 20; |
@@ -146,8 +161,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
146 | public int m_roundsUnderMotionThreshold = 0; | 161 | public int m_roundsUnderMotionThreshold = 0; |
147 | private int m_crossingfailures = 0; | 162 | private int m_crossingfailures = 0; |
148 | 163 | ||
149 | public float m_buoyancy = 0f; | ||
150 | |||
151 | public bool outofBounds = false; | 164 | public bool outofBounds = false; |
152 | private float m_density = 10.000006836f; // Aluminum g/cm3; | 165 | private float m_density = 10.000006836f; // Aluminum g/cm3; |
153 | 166 | ||
@@ -155,7 +168,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
155 | private bool m_lastUpdateSent = false; | 168 | private bool m_lastUpdateSent = false; |
156 | 169 | ||
157 | public IntPtr Body = (IntPtr) 0; | 170 | public IntPtr Body = (IntPtr) 0; |
158 | private String m_primName; | 171 | public String m_primName; |
172 | // private String m_primName; | ||
159 | private PhysicsVector _target_velocity; | 173 | private PhysicsVector _target_velocity; |
160 | public d.Mass pMass; | 174 | public d.Mass pMass; |
161 | 175 | ||
@@ -166,7 +180,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
166 | 180 | ||
167 | public volatile bool childPrim = false; | 181 | public volatile bool childPrim = false; |
168 | 182 | ||
169 | private ODEVehicleSettings m_vehicle; | 183 | private ODEDynamics m_vehicle; |
170 | 184 | ||
171 | internal int m_material = (int)Material.Wood; | 185 | internal int m_material = (int)Material.Wood; |
172 | 186 | ||
@@ -174,7 +188,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
174 | Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) | 188 | Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) |
175 | { | 189 | { |
176 | _target_velocity = new PhysicsVector(0, 0, 0); | 190 | _target_velocity = new PhysicsVector(0, 0, 0); |
177 | m_vehicle = new ODEVehicleSettings(); | 191 | m_vehicle = new ODEDynamics(); |
178 | //gc = GCHandle.Alloc(prim_geom, GCHandleType.Pinned); | 192 | //gc = GCHandle.Alloc(prim_geom, GCHandleType.Pinned); |
179 | ode = dode; | 193 | ode = dode; |
180 | _velocity = new PhysicsVector(); | 194 | _velocity = new PhysicsVector(); |
@@ -259,11 +273,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
259 | m_localID = value; } | 273 | m_localID = value; } |
260 | } | 274 | } |
261 | 275 | ||
262 | public override int GetHashCode() | ||
263 | { | ||
264 | return (int)m_localID; | ||
265 | } | ||
266 | |||
267 | public override bool Grabbed | 276 | public override bool Grabbed |
268 | { | 277 | { |
269 | set { return; } | 278 | set { return; } |
@@ -272,6 +281,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
272 | public override bool Selected | 281 | public override bool Selected |
273 | { | 282 | { |
274 | set { | 283 | set { |
284 | |||
285 | |||
275 | // This only makes the object not collidable if the object | 286 | // This only makes the object not collidable if the object |
276 | // is physical or the object is modified somehow *IN THE FUTURE* | 287 | // is physical or the object is modified somehow *IN THE FUTURE* |
277 | // without this, if an avatar selects prim, they can walk right | 288 | // without this, if an avatar selects prim, they can walk right |
@@ -287,6 +298,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
287 | m_taintselected = value; | 298 | m_taintselected = value; |
288 | m_isSelected = value; | 299 | m_isSelected = value; |
289 | } | 300 | } |
301 | if(m_isSelected) disableBodySoft(); | ||
290 | } | 302 | } |
291 | } | 303 | } |
292 | 304 | ||
@@ -294,6 +306,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
294 | { | 306 | { |
295 | prev_geom = prim_geom; | 307 | prev_geom = prim_geom; |
296 | prim_geom = geom; | 308 | prim_geom = geom; |
309 | //Console.WriteLine("SetGeom to " + prim_geom + " for " + m_primName); | ||
297 | if (prim_geom != IntPtr.Zero) | 310 | if (prim_geom != IntPtr.Zero) |
298 | { | 311 | { |
299 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); | 312 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); |
@@ -305,6 +318,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
305 | if (_parent != null && _parent is OdePrim) | 318 | if (_parent != null && _parent is OdePrim) |
306 | { | 319 | { |
307 | OdePrim parent = (OdePrim)_parent; | 320 | OdePrim parent = (OdePrim)_parent; |
321 | //Console.WriteLine("SetGeom calls ChildSetGeom"); | ||
308 | parent.ChildSetGeom(this); | 322 | parent.ChildSetGeom(this); |
309 | } | 323 | } |
310 | } | 324 | } |
@@ -320,7 +334,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
320 | if (m_isphysical && Body != IntPtr.Zero) | 334 | if (m_isphysical && Body != IntPtr.Zero) |
321 | { | 335 | { |
322 | d.BodyEnable(Body); | 336 | d.BodyEnable(Body); |
323 | m_vehicle.Enable(Body, _parent_scene); | 337 | if (m_vehicle.Type != Vehicle.TYPE_NONE) |
338 | m_vehicle.Enable(Body, _parent_scene); | ||
324 | } | 339 | } |
325 | 340 | ||
326 | m_disabled = false; | 341 | m_disabled = false; |
@@ -334,7 +349,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
334 | if (m_isphysical && Body != IntPtr.Zero) | 349 | if (m_isphysical && Body != IntPtr.Zero) |
335 | { | 350 | { |
336 | d.BodyDisable(Body); | 351 | d.BodyDisable(Body); |
337 | m_vehicle.Disable(); | ||
338 | } | 352 | } |
339 | } | 353 | } |
340 | 354 | ||
@@ -364,6 +378,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
364 | 378 | ||
365 | d.BodySetAutoDisableFlag(Body, true); | 379 | d.BodySetAutoDisableFlag(Body, true); |
366 | d.BodySetAutoDisableSteps(Body, body_autodisable_frames); | 380 | d.BodySetAutoDisableSteps(Body, body_autodisable_frames); |
381 | |||
382 | // disconnect from world gravity so we can apply buoyancy | ||
383 | d.BodySetGravityMode (Body, false); | ||
367 | 384 | ||
368 | m_interpenetrationcount = 0; | 385 | m_interpenetrationcount = 0; |
369 | m_collisionscore = 0; | 386 | m_collisionscore = 0; |
@@ -710,13 +727,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
710 | break; | 727 | break; |
711 | } | 728 | } |
712 | } | 729 | } |
713 | |||
714 | |||
715 | |||
716 | |||
717 | |||
718 | return returnMass; | 730 | return returnMass; |
719 | } | 731 | }// end CalculateMass |
720 | 732 | ||
721 | #endregion | 733 | #endregion |
722 | 734 | ||
@@ -742,7 +754,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
742 | if (Body != IntPtr.Zero) | 754 | if (Body != IntPtr.Zero) |
743 | { | 755 | { |
744 | _parent_scene.remActivePrim(this); | 756 | _parent_scene.remActivePrim(this); |
745 | m_vehicle.Destroy(); | ||
746 | m_collisionCategories &= ~CollisionCategories.Body; | 757 | m_collisionCategories &= ~CollisionCategories.Body; |
747 | m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); | 758 | m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); |
748 | 759 | ||
@@ -833,6 +844,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
833 | { | 844 | { |
834 | if (prim_geom == IntPtr.Zero) | 845 | if (prim_geom == IntPtr.Zero) |
835 | { | 846 | { |
847 | //Console.WriteLine(" setMesh 1"); | ||
836 | SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null)); | 848 | SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null)); |
837 | } | 849 | } |
838 | } | 850 | } |
@@ -854,19 +866,35 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
854 | 866 | ||
855 | public void ProcessTaints(float timestep) | 867 | public void ProcessTaints(float timestep) |
856 | { | 868 | { |
869 | //Console.WriteLine("ProcessTaints for " + m_primName ); | ||
857 | if (m_taintadd) | 870 | if (m_taintadd) |
858 | { | 871 | { |
859 | changeadd(timestep); | 872 | changeadd(timestep); |
860 | } | 873 | } |
874 | |||
861 | if (prim_geom != IntPtr.Zero) | 875 | if (prim_geom != IntPtr.Zero) |
862 | { | 876 | { |
863 | if (!_position.IsIdentical(m_taintposition,0f)) | 877 | if (!_position.IsIdentical(m_taintposition,0f)) |
864 | changemove(timestep); | 878 | changemove(timestep); |
865 | 879 | ||
866 | if (m_taintrot != _orientation) | 880 | if (m_taintrot != _orientation) |
867 | rotate(timestep); | 881 | { |
882 | if(childPrim && IsPhysical) // For physical child prim... | ||
883 | { | ||
884 | rotate(timestep); | ||
885 | // KF: ODE will also rotate the parent prim! | ||
886 | // so rotate the root back to where it was | ||
887 | OdePrim parent = (OdePrim)_parent; | ||
888 | parent.rotate(timestep); | ||
889 | } | ||
890 | else | ||
891 | { | ||
892 | //Just rotate the prim | ||
893 | rotate(timestep); | ||
894 | } | ||
895 | } | ||
868 | // | 896 | // |
869 | 897 | ||
870 | if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent)) | 898 | if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent)) |
871 | changePhysicsStatus(timestep); | 899 | changePhysicsStatus(timestep); |
872 | // | 900 | // |
@@ -905,8 +933,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
905 | 933 | ||
906 | if (!m_angularlock.IsIdentical(m_taintAngularLock,0)) | 934 | if (!m_angularlock.IsIdentical(m_taintAngularLock,0)) |
907 | changeAngularLock(timestep); | 935 | changeAngularLock(timestep); |
908 | 936 | ||
909 | |||
910 | } | 937 | } |
911 | else | 938 | else |
912 | { | 939 | { |
@@ -938,11 +965,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
938 | Amotor = IntPtr.Zero; | 965 | Amotor = IntPtr.Zero; |
939 | } | 966 | } |
940 | } | 967 | } |
941 | |||
942 | if (m_vehicle.Type != Vehicle.TYPE_NONE) | ||
943 | { | ||
944 | m_vehicle.Reset(); | ||
945 | } | ||
946 | } | 968 | } |
947 | } | 969 | } |
948 | // Store this for later in case we get turned into a separate body | 970 | // Store this for later in case we get turned into a separate body |
@@ -960,7 +982,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
960 | { | 982 | { |
961 | OdePrim obj = (OdePrim)m_taintparent; | 983 | OdePrim obj = (OdePrim)m_taintparent; |
962 | //obj.disableBody(); | 984 | //obj.disableBody(); |
963 | 985 | //Console.WriteLine("changelink calls ParentPrim"); | |
964 | obj.ParentPrim(this); | 986 | obj.ParentPrim(this); |
965 | 987 | ||
966 | /* | 988 | /* |
@@ -978,6 +1000,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
978 | // destroy link | 1000 | // destroy link |
979 | else if (_parent != null && m_taintparent == null) | 1001 | else if (_parent != null && m_taintparent == null) |
980 | { | 1002 | { |
1003 | //Console.WriteLine(" changelink B"); | ||
1004 | |||
981 | if (_parent is OdePrim) | 1005 | if (_parent is OdePrim) |
982 | { | 1006 | { |
983 | OdePrim obj = (OdePrim)_parent; | 1007 | OdePrim obj = (OdePrim)_parent; |
@@ -994,7 +1018,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
994 | m_linkJoint = (IntPtr)0; | 1018 | m_linkJoint = (IntPtr)0; |
995 | */ | 1019 | */ |
996 | } | 1020 | } |
997 | 1021 | ||
998 | _parent = m_taintparent; | 1022 | _parent = m_taintparent; |
999 | m_taintPhysics = m_isphysical; | 1023 | m_taintPhysics = m_isphysical; |
1000 | } | 1024 | } |
@@ -1003,6 +1027,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1003 | // prim is the child | 1027 | // prim is the child |
1004 | public void ParentPrim(OdePrim prim) | 1028 | public void ParentPrim(OdePrim prim) |
1005 | { | 1029 | { |
1030 | //Console.WriteLine("ParentPrim " + m_primName); | ||
1006 | if (this.m_localID != prim.m_localID) | 1031 | if (this.m_localID != prim.m_localID) |
1007 | { | 1032 | { |
1008 | if (Body == IntPtr.Zero) | 1033 | if (Body == IntPtr.Zero) |
@@ -1016,6 +1041,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1016 | { | 1041 | { |
1017 | if (!childrenPrim.Contains(prim)) | 1042 | if (!childrenPrim.Contains(prim)) |
1018 | { | 1043 | { |
1044 | //Console.WriteLine("childrenPrim.Add " + prim); | ||
1019 | childrenPrim.Add(prim); | 1045 | childrenPrim.Add(prim); |
1020 | 1046 | ||
1021 | foreach (OdePrim prm in childrenPrim) | 1047 | foreach (OdePrim prm in childrenPrim) |
@@ -1039,6 +1065,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1039 | } | 1065 | } |
1040 | foreach (OdePrim prm in childrenPrim) | 1066 | foreach (OdePrim prm in childrenPrim) |
1041 | { | 1067 | { |
1068 | |||
1042 | prm.m_collisionCategories |= CollisionCategories.Body; | 1069 | prm.m_collisionCategories |= CollisionCategories.Body; |
1043 | prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); | 1070 | prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); |
1044 | 1071 | ||
@@ -1047,7 +1074,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1047 | m_log.Warn("[PHYSICS]: Unable to link one of the linkset elements. No geom yet"); | 1074 | m_log.Warn("[PHYSICS]: Unable to link one of the linkset elements. No geom yet"); |
1048 | continue; | 1075 | continue; |
1049 | } | 1076 | } |
1050 | 1077 | //Console.WriteLine(" GeomSetCategoryBits 1: " + prm.prim_geom + " - " + (int)prm.m_collisionCategories + " for " + m_primName); | |
1051 | d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories); | 1078 | d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories); |
1052 | d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); | 1079 | d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); |
1053 | 1080 | ||
@@ -1092,11 +1119,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1092 | prm.Body = Body; | 1119 | prm.Body = Body; |
1093 | _parent_scene.addActivePrim(prm); | 1120 | _parent_scene.addActivePrim(prm); |
1094 | } | 1121 | } |
1095 | |||
1096 | m_collisionCategories |= CollisionCategories.Body; | 1122 | m_collisionCategories |= CollisionCategories.Body; |
1097 | m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); | 1123 | m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); |
1098 | 1124 | ||
1125 | //Console.WriteLine("GeomSetCategoryBits 2: " + prim_geom + " - " + (int)m_collisionCategories + " for " + m_primName); | ||
1099 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); | 1126 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); |
1127 | //Console.WriteLine(" Post GeomSetCategoryBits 2"); | ||
1100 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); | 1128 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); |
1101 | 1129 | ||
1102 | 1130 | ||
@@ -1132,7 +1160,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1132 | createAMotor(m_angularlock); | 1160 | createAMotor(m_angularlock); |
1133 | } | 1161 | } |
1134 | d.BodySetPosition(Body, Position.X, Position.Y, Position.Z); | 1162 | d.BodySetPosition(Body, Position.X, Position.Y, Position.Z); |
1135 | m_vehicle.Enable(Body, _parent_scene); | 1163 | if (m_vehicle.Type != Vehicle.TYPE_NONE) m_vehicle.Enable(Body, _parent_scene); |
1136 | _parent_scene.addActivePrim(this); | 1164 | _parent_scene.addActivePrim(this); |
1137 | } | 1165 | } |
1138 | } | 1166 | } |
@@ -1169,6 +1197,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1169 | { | 1197 | { |
1170 | foreach (OdePrim prm in childrenPrim) | 1198 | foreach (OdePrim prm in childrenPrim) |
1171 | { | 1199 | { |
1200 | //Console.WriteLine("ChildSetGeom calls ParentPrim"); | ||
1172 | ParentPrim(prm); | 1201 | ParentPrim(prm); |
1173 | } | 1202 | } |
1174 | } | 1203 | } |
@@ -1195,6 +1224,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1195 | 1224 | ||
1196 | lock (childrenPrim) | 1225 | lock (childrenPrim) |
1197 | { | 1226 | { |
1227 | //Console.WriteLine("childrenPrim.Remove " + odePrim); | ||
1198 | childrenPrim.Remove(odePrim); | 1228 | childrenPrim.Remove(odePrim); |
1199 | } | 1229 | } |
1200 | 1230 | ||
@@ -1212,6 +1242,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1212 | { | 1242 | { |
1213 | foreach (OdePrim prm in childrenPrim) | 1243 | foreach (OdePrim prm in childrenPrim) |
1214 | { | 1244 | { |
1245 | //Console.WriteLine("ChildDelink calls ParentPrim"); | ||
1215 | ParentPrim(prm); | 1246 | ParentPrim(prm); |
1216 | } | 1247 | } |
1217 | } | 1248 | } |
@@ -1296,7 +1327,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1296 | 1327 | ||
1297 | resetCollisionAccounting(); | 1328 | resetCollisionAccounting(); |
1298 | m_isSelected = m_taintselected; | 1329 | m_isSelected = m_taintselected; |
1299 | } | 1330 | }//end changeSelectedStatus |
1300 | 1331 | ||
1301 | public void ResetTaints() | 1332 | public void ResetTaints() |
1302 | { | 1333 | { |
@@ -1313,6 +1344,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1313 | 1344 | ||
1314 | public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh) | 1345 | public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh) |
1315 | { | 1346 | { |
1347 | //Console.WriteLine("CreateGeom:"); | ||
1316 | if (_mesh != null) | 1348 | if (_mesh != null) |
1317 | { | 1349 | { |
1318 | setMesh(_parent_scene, _mesh); | 1350 | setMesh(_parent_scene, _mesh); |
@@ -1328,6 +1360,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1328 | _parent_scene.waitForSpaceUnlock(m_targetSpace); | 1360 | _parent_scene.waitForSpaceUnlock(m_targetSpace); |
1329 | try | 1361 | try |
1330 | { | 1362 | { |
1363 | //Console.WriteLine(" CreateGeom 1"); | ||
1331 | SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2)); | 1364 | SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2)); |
1332 | } | 1365 | } |
1333 | catch (AccessViolationException) | 1366 | catch (AccessViolationException) |
@@ -1342,6 +1375,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1342 | _parent_scene.waitForSpaceUnlock(m_targetSpace); | 1375 | _parent_scene.waitForSpaceUnlock(m_targetSpace); |
1343 | try | 1376 | try |
1344 | { | 1377 | { |
1378 | //Console.WriteLine(" CreateGeom 2"); | ||
1345 | SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z)); | 1379 | SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z)); |
1346 | } | 1380 | } |
1347 | catch (AccessViolationException) | 1381 | catch (AccessViolationException) |
@@ -1357,6 +1391,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1357 | _parent_scene.waitForSpaceUnlock(m_targetSpace); | 1391 | _parent_scene.waitForSpaceUnlock(m_targetSpace); |
1358 | try | 1392 | try |
1359 | { | 1393 | { |
1394 | //Console.WriteLine(" CreateGeom 3"); | ||
1360 | SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z)); | 1395 | SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z)); |
1361 | } | 1396 | } |
1362 | catch (AccessViolationException) | 1397 | catch (AccessViolationException) |
@@ -1373,6 +1408,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1373 | _parent_scene.waitForSpaceUnlock(m_targetSpace); | 1408 | _parent_scene.waitForSpaceUnlock(m_targetSpace); |
1374 | try | 1409 | try |
1375 | { | 1410 | { |
1411 | //Console.WriteLine(" CreateGeom 4"); | ||
1376 | SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z)); | 1412 | SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z)); |
1377 | } | 1413 | } |
1378 | catch (AccessViolationException) | 1414 | catch (AccessViolationException) |
@@ -1409,6 +1445,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1409 | 1445 | ||
1410 | lock (_parent_scene.OdeLock) | 1446 | lock (_parent_scene.OdeLock) |
1411 | { | 1447 | { |
1448 | //Console.WriteLine("changeadd 1"); | ||
1412 | CreateGeom(m_targetSpace, _mesh); | 1449 | CreateGeom(m_targetSpace, _mesh); |
1413 | 1450 | ||
1414 | if (prim_geom != IntPtr.Zero) | 1451 | if (prim_geom != IntPtr.Zero) |
@@ -1464,6 +1501,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1464 | OdePrim odParent = (OdePrim)_parent; | 1501 | OdePrim odParent = (OdePrim)_parent; |
1465 | if (Body != (IntPtr)0 && odParent.Body != (IntPtr)0 && Body != odParent.Body) | 1502 | if (Body != (IntPtr)0 && odParent.Body != (IntPtr)0 && Body != odParent.Body) |
1466 | { | 1503 | { |
1504 | // KF: Fixed Joints were removed? Anyway - this Console.WriteLine does not show up, so routine is not used?? | ||
1505 | Console.WriteLine(" JointCreateFixed"); | ||
1467 | m_linkJoint = d.JointCreateFixed(_parent_scene.world, _linkJointGroup); | 1506 | m_linkJoint = d.JointCreateFixed(_parent_scene.world, _linkJointGroup); |
1468 | d.JointAttach(m_linkJoint, Body, odParent.Body); | 1507 | d.JointAttach(m_linkJoint, Body, odParent.Body); |
1469 | d.JointSetFixed(m_linkJoint); | 1508 | d.JointSetFixed(m_linkJoint); |
@@ -1517,239 +1556,236 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1517 | float fz = 0; | 1556 | float fz = 0; |
1518 | 1557 | ||
1519 | 1558 | ||
1520 | if (IsPhysical && Body != IntPtr.Zero && !m_isSelected) | 1559 | if (IsPhysical && (Body != IntPtr.Zero) && !m_isSelected && !childPrim) // KF: Only move root prims. |
1521 | { | 1560 | { |
1522 | if (d.BodyIsEnabled(Body) && !m_angularlock.IsIdentical(PhysicsVector.Zero, 0.003f)) | 1561 | if (m_vehicle.Type != Vehicle.TYPE_NONE) |
1523 | { | 1562 | { |
1524 | d.Vector3 avel2 = d.BodyGetAngularVel(Body); | 1563 | // 'VEHICLES' are dealt with in ODEDynamics.cs |
1525 | if (m_angularlock.X == 1) | 1564 | m_vehicle.Step(timestep, _parent_scene); |
1526 | avel2.X = 0; | 1565 | } |
1527 | if (m_angularlock.Y == 1) | 1566 | else |
1528 | avel2.Y = 0; | 1567 | { |
1529 | if (m_angularlock.Z == 1) | 1568 | // NON-'VEHICLES' are dealt with here |
1530 | avel2.Z = 0; | 1569 | if (d.BodyIsEnabled(Body) && !m_angularlock.IsIdentical(PhysicsVector.Zero, 0.003f)) |
1531 | d.BodySetAngularVel(Body, avel2.X, avel2.Y, avel2.Z); | 1570 | { |
1532 | } | 1571 | d.Vector3 avel2 = d.BodyGetAngularVel(Body); |
1533 | //float PID_P = 900.0f; | 1572 | if (m_angularlock.X == 1) |
1534 | 1573 | avel2.X = 0; | |
1535 | float m_mass = CalculateMass(); | 1574 | if (m_angularlock.Y == 1) |
1536 | 1575 | avel2.Y = 0; | |
1537 | fz = 0f; | 1576 | if (m_angularlock.Z == 1) |
1577 | avel2.Z = 0; | ||
1578 | d.BodySetAngularVel(Body, avel2.X, avel2.Y, avel2.Z); | ||
1579 | } | ||
1580 | //float PID_P = 900.0f; | ||
1581 | |||
1582 | float m_mass = CalculateMass(); | ||
1583 | |||
1584 | // fz = 0f; | ||
1538 | //m_log.Info(m_collisionFlags.ToString()); | 1585 | //m_log.Info(m_collisionFlags.ToString()); |
1539 | 1586 | ||
1540 | if (m_buoyancy != 0) | 1587 | |
1541 | { | 1588 | //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle. |
1542 | if (m_buoyancy > 0) | 1589 | // would come from SceneObjectPart.cs, public void SetBuoyancy(float fvalue) , PhysActor.Buoyancy = fvalue; ?? |
1543 | { | 1590 | // m_buoyancy: (unlimited value) <0=Falls fast; 0=1g; 1=0g; >1 = floats up |
1544 | fz = (((-1 * _parent_scene.gravityz) * m_buoyancy) * m_mass); | 1591 | // gravityz multiplier = 1 - m_buoyancy |
1545 | 1592 | fz = _parent_scene.gravityz * (1.0f - m_buoyancy) * m_mass; | |
1546 | //d.Vector3 l_velocity = d.BodyGetLinearVel(Body); | 1593 | |
1547 | //m_log.Info("Using Buoyancy: " + buoyancy + " G: " + (_parent_scene.gravityz * m_buoyancy) + "mass:" + m_mass + " Pos: " + Position.ToString()); | 1594 | if (m_usePID) |
1548 | } | 1595 | { |
1549 | else | 1596 | // KF - this is for object move? eg. llSetPos() ? |
1550 | { | 1597 | //if (!d.BodyIsEnabled(Body)) |
1551 | fz = (-1 * (((-1 * _parent_scene.gravityz) * (-1 * m_buoyancy)) * m_mass)); | 1598 | //d.BodySetForce(Body, 0f, 0f, 0f); |
1552 | } | 1599 | // If we're using the PID controller, then we have no gravity |
1553 | } | 1600 | //fz = (-1 * _parent_scene.gravityz) * m_mass; //KF: ?? Prims have no global gravity,so simply... |
1554 | 1601 | fz = 0f; | |
1555 | if (m_usePID) | 1602 | |
1556 | { | 1603 | // no lock; for now it's only called from within Simulate() |
1604 | |||
1605 | // If the PID Controller isn't active then we set our force | ||
1606 | // calculating base velocity to the current position | ||
1607 | |||
1608 | if ((m_PIDTau < 1) && (m_PIDTau != 0)) | ||
1609 | { | ||
1610 | //PID_G = PID_G / m_PIDTau; | ||
1611 | m_PIDTau = 1; | ||
1612 | } | ||
1613 | |||
1614 | if ((PID_G - m_PIDTau) <= 0) | ||
1615 | { | ||
1616 | PID_G = m_PIDTau + 1; | ||
1617 | } | ||
1618 | //PidStatus = true; | ||
1619 | |||
1620 | // PhysicsVector vec = new PhysicsVector(); | ||
1621 | d.Vector3 vel = d.BodyGetLinearVel(Body); | ||
1622 | |||
1623 | d.Vector3 pos = d.BodyGetPosition(Body); | ||
1624 | _target_velocity = | ||
1625 | new PhysicsVector( | ||
1626 | (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep), | ||
1627 | (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep), | ||
1628 | (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep) | ||
1629 | ); | ||
1630 | |||
1631 | // if velocity is zero, use position control; otherwise, velocity control | ||
1632 | |||
1633 | if (_target_velocity.IsIdentical(PhysicsVector.Zero,0.1f)) | ||
1634 | { | ||
1635 | // keep track of where we stopped. No more slippin' & slidin' | ||
1636 | |||
1637 | // We only want to deactivate the PID Controller if we think we want to have our surrogate | ||
1638 | // react to the physics scene by moving it's position. | ||
1639 | // Avatar to Avatar collisions | ||
1640 | // Prim to avatar collisions | ||
1641 | |||
1642 | //fx = (_target_velocity.X - vel.X) * (PID_D) + (_zeroPosition.X - pos.X) * (PID_P * 2); | ||
1643 | //fy = (_target_velocity.Y - vel.Y) * (PID_D) + (_zeroPosition.Y - pos.Y) * (PID_P * 2); | ||
1644 | //fz = fz + (_target_velocity.Z - vel.Z) * (PID_D) + (_zeroPosition.Z - pos.Z) * PID_P; | ||
1645 | d.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z); | ||
1646 | d.BodySetLinearVel(Body, 0, 0, 0); | ||
1647 | d.BodyAddForce(Body, 0, 0, fz); | ||
1648 | return; | ||
1649 | } | ||
1650 | else | ||
1651 | { | ||
1652 | _zeroFlag = false; | ||
1653 | |||
1654 | // We're flying and colliding with something | ||
1655 | fx = ((_target_velocity.X) - vel.X) * (PID_D); | ||
1656 | fy = ((_target_velocity.Y) - vel.Y) * (PID_D); | ||
1657 | |||
1658 | // vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P; | ||
1659 | |||
1660 | fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass); | ||
1661 | } | ||
1662 | } // end if (m_usePID) | ||
1663 | |||
1664 | // Hover PID Controller needs to be mutually exlusive to MoveTo PID controller | ||
1665 | if (m_useHoverPID && !m_usePID) | ||
1666 | { | ||
1667 | // If we're using the PID controller, then we have no gravity | ||
1668 | fz = (-1 * _parent_scene.gravityz) * m_mass; | ||
1669 | |||
1670 | // no lock; for now it's only called from within Simulate() | ||
1671 | |||
1672 | // If the PID Controller isn't active then we set our force | ||
1673 | // calculating base velocity to the current position | ||
1674 | |||
1675 | if ((m_PIDTau < 1)) | ||
1676 | { | ||
1677 | PID_G = PID_G / m_PIDTau; | ||
1678 | } | ||
1679 | |||
1680 | if ((PID_G - m_PIDTau) <= 0) | ||
1681 | { | ||
1682 | PID_G = m_PIDTau + 1; | ||
1683 | } | ||
1557 | 1684 | ||
1558 | //if (!d.BodyIsEnabled(Body)) | ||
1559 | //d.BodySetForce(Body, 0f, 0f, 0f); | ||
1560 | // If we're using the PID controller, then we have no gravity | ||
1561 | fz = (-1 * _parent_scene.gravityz) * m_mass; | ||
1562 | 1685 | ||
1563 | // no lock; for now it's only called from within Simulate() | 1686 | // Where are we, and where are we headed? |
1687 | d.Vector3 pos = d.BodyGetPosition(Body); | ||
1688 | d.Vector3 vel = d.BodyGetLinearVel(Body); | ||
1689 | |||
1690 | |||
1691 | // Non-Vehicles have a limited set of Hover options. | ||
1692 | // determine what our target height really is based on HoverType | ||
1693 | switch (m_PIDHoverType) | ||
1694 | { | ||
1695 | case PIDHoverType.Ground: | ||
1696 | m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y); | ||
1697 | m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight; | ||
1698 | break; | ||
1699 | case PIDHoverType.GroundAndWater: | ||
1700 | m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y); | ||
1701 | m_waterHeight = _parent_scene.GetWaterLevel(); | ||
1702 | if (m_groundHeight > m_waterHeight) | ||
1703 | { | ||
1704 | m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight; | ||
1705 | } | ||
1706 | else | ||
1707 | { | ||
1708 | m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight; | ||
1709 | } | ||
1710 | break; | ||
1711 | |||
1712 | } // end switch (m_PIDHoverType) | ||
1713 | |||
1714 | |||
1715 | _target_velocity = | ||
1716 | new PhysicsVector(0.0f, 0.0f, | ||
1717 | (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep) | ||
1718 | ); | ||
1719 | |||
1720 | // if velocity is zero, use position control; otherwise, velocity control | ||
1721 | |||
1722 | if (_target_velocity.IsIdentical(PhysicsVector.Zero, 0.1f)) | ||
1723 | { | ||
1724 | // keep track of where we stopped. No more slippin' & slidin' | ||
1725 | |||
1726 | // We only want to deactivate the PID Controller if we think we want to have our surrogate | ||
1727 | // react to the physics scene by moving it's position. | ||
1728 | // Avatar to Avatar collisions | ||
1729 | // Prim to avatar collisions | ||
1730 | |||
1731 | d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight); | ||
1732 | d.BodySetLinearVel(Body, vel.X, vel.Y, 0); | ||
1733 | d.BodyAddForce(Body, 0, 0, fz); | ||
1734 | return; | ||
1735 | } | ||
1736 | else | ||
1737 | { | ||
1738 | _zeroFlag = false; | ||
1739 | |||
1740 | // We're flying and colliding with something | ||
1741 | fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass); | ||
1742 | } | ||
1743 | } | ||
1744 | |||
1745 | fx *= m_mass; | ||
1746 | fy *= m_mass; | ||
1747 | //fz *= m_mass; | ||
1748 | |||
1749 | fx += m_force.X; | ||
1750 | fy += m_force.Y; | ||
1751 | fz += m_force.Z; | ||
1752 | |||
1753 | //m_log.Info("[OBJPID]: X:" + fx.ToString() + " Y:" + fy.ToString() + " Z:" + fz.ToString()); | ||
1754 | if (fx != 0 || fy != 0 || fz != 0) | ||
1755 | { | ||
1756 | //m_taintdisable = true; | ||
1757 | //base.RaiseOutOfBounds(Position); | ||
1758 | //d.BodySetLinearVel(Body, fx, fy, 0f); | ||
1759 | if (!d.BodyIsEnabled(Body)) | ||
1760 | { | ||
1761 | // A physical body at rest on a surface will auto-disable after a while, | ||
1762 | // this appears to re-enable it incase the surface it is upon vanishes, | ||
1763 | // and the body should fall again. | ||
1764 | d.BodySetLinearVel(Body, 0f, 0f, 0f); | ||
1765 | d.BodySetForce(Body, 0, 0, 0); | ||
1766 | enableBodySoft(); | ||
1767 | } | ||
1768 | |||
1769 | // 35x10 = 350n times the mass per second applied maximum. | ||
1770 | float nmax = 35f * m_mass; | ||
1771 | float nmin = -35f * m_mass; | ||
1564 | 1772 | ||
1565 | // If the PID Controller isn't active then we set our force | ||
1566 | // calculating base velocity to the current position | ||
1567 | |||
1568 | if ((m_PIDTau < 1) && (m_PIDTau != 0)) | ||
1569 | { | ||
1570 | //PID_G = PID_G / m_PIDTau; | ||
1571 | m_PIDTau = 1; | ||
1572 | } | ||
1573 | |||
1574 | if ((PID_G - m_PIDTau) <= 0) | ||
1575 | { | ||
1576 | PID_G = m_PIDTau + 1; | ||
1577 | } | ||
1578 | //PidStatus = true; | ||
1579 | |||
1580 | // PhysicsVector vec = new PhysicsVector(); | ||
1581 | d.Vector3 vel = d.BodyGetLinearVel(Body); | ||
1582 | |||
1583 | d.Vector3 pos = d.BodyGetPosition(Body); | ||
1584 | _target_velocity = | ||
1585 | new PhysicsVector( | ||
1586 | (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep), | ||
1587 | (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep), | ||
1588 | (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep) | ||
1589 | ); | ||
1590 | |||
1591 | // if velocity is zero, use position control; otherwise, velocity control | ||
1592 | |||
1593 | if (_target_velocity.IsIdentical(PhysicsVector.Zero,0.1f)) | ||
1594 | { | ||
1595 | // keep track of where we stopped. No more slippin' & slidin' | ||
1596 | |||
1597 | // We only want to deactivate the PID Controller if we think we want to have our surrogate | ||
1598 | // react to the physics scene by moving it's position. | ||
1599 | // Avatar to Avatar collisions | ||
1600 | // Prim to avatar collisions | ||
1601 | |||
1602 | //fx = (_target_velocity.X - vel.X) * (PID_D) + (_zeroPosition.X - pos.X) * (PID_P * 2); | ||
1603 | //fy = (_target_velocity.Y - vel.Y) * (PID_D) + (_zeroPosition.Y - pos.Y) * (PID_P * 2); | ||
1604 | //fz = fz + (_target_velocity.Z - vel.Z) * (PID_D) + (_zeroPosition.Z - pos.Z) * PID_P; | ||
1605 | d.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z); | ||
1606 | d.BodySetLinearVel(Body, 0, 0, 0); | ||
1607 | d.BodyAddForce(Body, 0, 0, fz); | ||
1608 | return; | ||
1609 | } | ||
1610 | else | ||
1611 | { | ||
1612 | _zeroFlag = false; | ||
1613 | |||
1614 | // We're flying and colliding with something | ||
1615 | fx = ((_target_velocity.X) - vel.X) * (PID_D); | ||
1616 | fy = ((_target_velocity.Y) - vel.Y) * (PID_D); | ||
1617 | |||
1618 | // vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P; | ||
1619 | |||
1620 | fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass); | ||
1621 | } | ||
1622 | } | ||
1623 | |||
1624 | // Hover PID Controller needs to be mutually exlusive to MoveTo PID controller | ||
1625 | if (m_useHoverPID && !m_usePID) | ||
1626 | { | ||
1627 | // If we're using the PID controller, then we have no gravity | ||
1628 | fz = (-1 * _parent_scene.gravityz) * m_mass; | ||
1629 | |||
1630 | // no lock; for now it's only called from within Simulate() | ||
1631 | |||
1632 | // If the PID Controller isn't active then we set our force | ||
1633 | // calculating base velocity to the current position | ||
1634 | |||
1635 | if ((m_PIDTau < 1)) | ||
1636 | { | ||
1637 | PID_G = PID_G / m_PIDTau; | ||
1638 | } | ||
1639 | |||
1640 | if ((PID_G - m_PIDTau) <= 0) | ||
1641 | { | ||
1642 | PID_G = m_PIDTau + 1; | ||
1643 | } | ||
1644 | 1773 | ||
1645 | 1774 | if (fx > nmax) | |
1646 | // Where are we, and where are we headed? | 1775 | fx = nmax; |
1647 | d.Vector3 pos = d.BodyGetPosition(Body); | 1776 | if (fx < nmin) |
1648 | d.Vector3 vel = d.BodyGetLinearVel(Body); | 1777 | fx = nmin; |
1649 | 1778 | if (fy > nmax) | |
1650 | // determine what our target height really is based on HoverType | 1779 | fy = nmax; |
1651 | switch (m_PIDHoverType) | 1780 | if (fy < nmin) |
1652 | { | 1781 | fy = nmin; |
1653 | case PIDHoverType.Absolute: | 1782 | d.BodyAddForce(Body, fx, fy, fz); |
1654 | m_targetHoverHeight = m_PIDHoverHeight; | 1783 | } |
1655 | break; | 1784 | } |
1656 | case PIDHoverType.Ground: | ||
1657 | m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y); | ||
1658 | m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight; | ||
1659 | break; | ||
1660 | case PIDHoverType.GroundAndWater: | ||
1661 | m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y); | ||
1662 | m_waterHeight = _parent_scene.GetWaterLevel(); | ||
1663 | if (m_groundHeight > m_waterHeight) | ||
1664 | { | ||
1665 | m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight; | ||
1666 | } | ||
1667 | else | ||
1668 | { | ||
1669 | m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight; | ||
1670 | } | ||
1671 | break; | ||
1672 | case PIDHoverType.Water: | ||
1673 | m_waterHeight = _parent_scene.GetWaterLevel(); | ||
1674 | m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight; | ||
1675 | break; | ||
1676 | } | ||
1677 | |||
1678 | |||
1679 | _target_velocity = | ||
1680 | new PhysicsVector(0.0f, 0.0f, | ||
1681 | (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep) | ||
1682 | ); | ||
1683 | |||
1684 | // if velocity is zero, use position control; otherwise, velocity control | ||
1685 | |||
1686 | if (_target_velocity.IsIdentical(PhysicsVector.Zero, 0.1f)) | ||
1687 | { | ||
1688 | // keep track of where we stopped. No more slippin' & slidin' | ||
1689 | |||
1690 | // We only want to deactivate the PID Controller if we think we want to have our surrogate | ||
1691 | // react to the physics scene by moving it's position. | ||
1692 | // Avatar to Avatar collisions | ||
1693 | // Prim to avatar collisions | ||
1694 | |||
1695 | d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight); | ||
1696 | d.BodySetLinearVel(Body, vel.X, vel.Y, 0); | ||
1697 | d.BodyAddForce(Body, 0, 0, fz); | ||
1698 | return; | ||
1699 | } | ||
1700 | else | ||
1701 | { | ||
1702 | _zeroFlag = false; | ||
1703 | |||
1704 | // We're flying and colliding with something | ||
1705 | fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass); | ||
1706 | } | ||
1707 | } | ||
1708 | |||
1709 | fx *= m_mass; | ||
1710 | fy *= m_mass; | ||
1711 | //fz *= m_mass; | ||
1712 | |||
1713 | fx += m_force.X; | ||
1714 | fy += m_force.Y; | ||
1715 | fz += m_force.Z; | ||
1716 | |||
1717 | //m_log.Info("[OBJPID]: X:" + fx.ToString() + " Y:" + fy.ToString() + " Z:" + fz.ToString()); | ||
1718 | if (fx != 0 || fy != 0 || fz != 0) | ||
1719 | { | ||
1720 | //m_taintdisable = true; | ||
1721 | //base.RaiseOutOfBounds(Position); | ||
1722 | //d.BodySetLinearVel(Body, fx, fy, 0f); | ||
1723 | if (!d.BodyIsEnabled(Body)) | ||
1724 | { | ||
1725 | d.BodySetLinearVel(Body, 0f, 0f, 0f); | ||
1726 | d.BodySetForce(Body, 0, 0, 0); | ||
1727 | enableBodySoft(); | ||
1728 | } | ||
1729 | |||
1730 | // 35x10 = 350n times the mass per second applied maximum. | ||
1731 | float nmax = 35f * m_mass; | ||
1732 | float nmin = -35f * m_mass; | ||
1733 | |||
1734 | |||
1735 | if (fx > nmax) | ||
1736 | fx = nmax; | ||
1737 | if (fx < nmin) | ||
1738 | fx = nmin; | ||
1739 | if (fy > nmax) | ||
1740 | fy = nmax; | ||
1741 | if (fy < nmin) | ||
1742 | fy = nmin; | ||
1743 | d.BodyAddForce(Body, fx, fy, fz); | ||
1744 | } | ||
1745 | if (m_vehicle.Body == IntPtr.Zero && m_vehicle.Type != Vehicle.TYPE_NONE) | ||
1746 | m_vehicle.Enable(Body, _parent_scene); | ||
1747 | |||
1748 | m_vehicle.Step(timestep); | ||
1749 | } | 1785 | } |
1750 | else | 1786 | else |
1751 | { | 1787 | { // is not physical, or is not a body or is selected |
1752 | // _zeroPosition = d.BodyGetPosition(Body); | 1788 | // _zeroPosition = d.BodyGetPosition(Body); |
1753 | return; | 1789 | return; |
1754 | } | 1790 | } |
1755 | } | 1791 | } |
@@ -1763,14 +1799,22 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1763 | myrot.Y = _orientation.Y; | 1799 | myrot.Y = _orientation.Y; |
1764 | myrot.Z = _orientation.Z; | 1800 | myrot.Z = _orientation.Z; |
1765 | myrot.W = _orientation.W; | 1801 | myrot.W = _orientation.W; |
1766 | d.GeomSetQuaternion(prim_geom, ref myrot); | 1802 | if (Body != IntPtr.Zero) |
1767 | if (m_isphysical && Body != IntPtr.Zero) | ||
1768 | { | 1803 | { |
1804 | // KF: If this is a root prim do BodySet | ||
1769 | d.BodySetQuaternion(Body, ref myrot); | 1805 | d.BodySetQuaternion(Body, ref myrot); |
1770 | if (!m_angularlock.IsIdentical(new PhysicsVector(1, 1, 1), 0)) | 1806 | if (m_isphysical) |
1771 | createAMotor(m_angularlock); | 1807 | { |
1808 | if (!m_angularlock.IsIdentical(new PhysicsVector(1, 1, 1), 0)) | ||
1809 | createAMotor(m_angularlock); | ||
1810 | } | ||
1811 | } | ||
1812 | else | ||
1813 | { | ||
1814 | // daughter prim, do Geom set | ||
1815 | d.GeomSetQuaternion(prim_geom, ref myrot); | ||
1772 | } | 1816 | } |
1773 | 1817 | ||
1774 | resetCollisionAccounting(); | 1818 | resetCollisionAccounting(); |
1775 | m_taintrot = _orientation; | 1819 | m_taintrot = _orientation; |
1776 | } | 1820 | } |
@@ -1832,7 +1876,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1832 | m_log.Error("[PHYSICS]: PrimGeom dead"); | 1876 | m_log.Error("[PHYSICS]: PrimGeom dead"); |
1833 | } | 1877 | } |
1834 | } | 1878 | } |
1835 | 1879 | //Console.WriteLine("changePhysicsStatus for " + m_primName ); | |
1836 | changeadd(2f); | 1880 | changeadd(2f); |
1837 | } | 1881 | } |
1838 | if (childPrim) | 1882 | if (childPrim) |
@@ -1910,7 +1954,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1910 | mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); | 1954 | mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); |
1911 | 1955 | ||
1912 | //IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); | 1956 | //IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); |
1913 | 1957 | //Console.WriteLine("changesize 1"); | |
1914 | CreateGeom(m_targetSpace, mesh); | 1958 | CreateGeom(m_targetSpace, mesh); |
1915 | 1959 | ||
1916 | 1960 | ||
@@ -1918,6 +1962,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1918 | else | 1962 | else |
1919 | { | 1963 | { |
1920 | _mesh = null; | 1964 | _mesh = null; |
1965 | //Console.WriteLine("changesize 2"); | ||
1921 | CreateGeom(m_targetSpace, _mesh); | 1966 | CreateGeom(m_targetSpace, _mesh); |
1922 | } | 1967 | } |
1923 | 1968 | ||
@@ -2024,6 +2069,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2024 | else | 2069 | else |
2025 | { | 2070 | { |
2026 | _mesh = null; | 2071 | _mesh = null; |
2072 | //Console.WriteLine("changeshape"); | ||
2027 | CreateGeom(m_targetSpace, null); | 2073 | CreateGeom(m_targetSpace, null); |
2028 | } | 2074 | } |
2029 | 2075 | ||
@@ -2365,7 +2411,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2365 | set | 2411 | set |
2366 | { | 2412 | { |
2367 | if (QuaternionIsFinite(value)) | 2413 | if (QuaternionIsFinite(value)) |
2414 | { | ||
2368 | _orientation = value; | 2415 | _orientation = value; |
2416 | } | ||
2369 | else | 2417 | else |
2370 | m_log.Warn("[PHYSICS]: Got NaN quaternion Orientation from Scene in Object"); | 2418 | m_log.Warn("[PHYSICS]: Got NaN quaternion Orientation from Scene in Object"); |
2371 | 2419 | ||
@@ -2584,12 +2632,16 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2584 | //outofBounds = true; | 2632 | //outofBounds = true; |
2585 | } | 2633 | } |
2586 | 2634 | ||
2635 | float Adiff = 1.0f - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)); | ||
2636 | //Console.WriteLine("Adiff " + m_primName + " = " + Adiff); | ||
2587 | if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02) | 2637 | if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02) |
2588 | && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02) | 2638 | && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02) |
2589 | && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02) | 2639 | && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02) |
2590 | && (1.0 - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)) < 0.01)) | 2640 | // && (1.0 - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)) < 0.01)) |
2641 | && (1.0 - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)) < 0.0001)) // KF 0.01 is far to large | ||
2591 | { | 2642 | { |
2592 | _zeroFlag = true; | 2643 | _zeroFlag = true; |
2644 | //Console.WriteLine("ZFT 2"); | ||
2593 | m_throttleUpdates = false; | 2645 | m_throttleUpdates = false; |
2594 | } | 2646 | } |
2595 | else | 2647 | else |