aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs321
1 files changed, 152 insertions, 169 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
index 3b7f562..0ccdbc0 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs
@@ -111,7 +111,7 @@ namespace OpenSim.Region.Physics.OdePlugin
111 | CollisionCategories.Body 111 | CollisionCategories.Body
112 | CollisionCategories.Character 112 | CollisionCategories.Character
113 ); 113 );
114 private bool m_collidesLand = true; 114// private bool m_collidesLand = true;
115 private bool m_collidesWater; 115 private bool m_collidesWater;
116 public bool m_returnCollisions; 116 public bool m_returnCollisions;
117 117
@@ -122,7 +122,7 @@ namespace OpenSim.Region.Physics.OdePlugin
122 private CollisionCategories m_collisionFlags = m_default_collisionFlags; 122 private CollisionCategories m_collisionFlags = m_default_collisionFlags;
123 123
124 public bool m_disabled; 124 public bool m_disabled;
125 public bool m_taintselected; 125
126 126
127 public uint m_localID; 127 public uint m_localID;
128 128
@@ -142,20 +142,19 @@ namespace OpenSim.Region.Physics.OdePlugin
142 private List<OdePrim> childrenPrim = new List<OdePrim>(); 142 private List<OdePrim> childrenPrim = new List<OdePrim>();
143 143
144 private bool m_iscolliding; 144 private bool m_iscolliding;
145 private bool m_wascolliding; 145
146 private bool m_isSelected; 146 public bool m_isSelected;
147 private bool m_delaySelect;
148 private bool m_lastdoneSelected;
149 public bool m_outbounds;
147 150
148 internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively 151 internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively
149 152
150 private bool m_throttleUpdates; 153 private bool m_throttleUpdates;
151 private int throttleCounter; 154 private int throttleCounter;
152 public int m_interpenetrationcount;
153 public float m_collisionscore; 155 public float m_collisionscore;
154 int m_colliderfilter = 0; 156 int m_colliderfilter = 0;
155 public int m_roundsUnderMotionThreshold;
156 private int m_crossingfailures;
157 157
158 public bool outofBounds;
159 private float m_density = 10.000006836f; // Aluminum g/cm3; 158 private float m_density = 10.000006836f; // Aluminum g/cm3;
160 159
161 public bool _zeroFlag; 160 public bool _zeroFlag;
@@ -166,12 +165,11 @@ namespace OpenSim.Region.Physics.OdePlugin
166 private Vector3 _target_velocity; 165 private Vector3 _target_velocity;
167 166
168 public Vector3 primOOBsize; // prim real dimensions from mesh 167 public Vector3 primOOBsize; // prim real dimensions from mesh
169 public Vector3 primOOBoffset; // is centroid out of mesh or rest aabb 168 public Vector3 primOOBoffset; // its centroid out of mesh or rest aabb
170 public float primOOBradiusSQ; 169 public float primOOBradiusSQ;
171 public d.Mass primdMass; // prim inertia information on it's own referencial 170 public d.Mass primdMass; // prim inertia information on it's own referencial
172 float primMass; // prim own mass 171 float primMass; // prim own mass
173 float _mass; // object mass acording to case 172 float _mass; // object mass acording to case
174 public d.Mass objectpMass; // object last computed inertia
175 private bool hasOOBoffsetFromMesh = false; // if true we did compute it form mesh centroid, else from aabb 173 private bool hasOOBoffsetFromMesh = false; // if true we did compute it form mesh centroid, else from aabb
176 174
177 public int givefakepos = 0; 175 public int givefakepos = 0;
@@ -182,9 +180,6 @@ namespace OpenSim.Region.Physics.OdePlugin
182 public int m_eventsubscription; 180 public int m_eventsubscription;
183 private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate(); 181 private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();
184 182
185 private IntPtr m_linkJoint = IntPtr.Zero;
186 private IntPtr _linkJointGroup = IntPtr.Zero;
187
188 public volatile bool childPrim; 183 public volatile bool childPrim;
189 184
190 public ODEDynamics m_vehicle; 185 public ODEDynamics m_vehicle;
@@ -264,7 +259,7 @@ namespace OpenSim.Region.Physics.OdePlugin
264 set 259 set
265 { 260 {
266 if (value) 261 if (value)
267 m_isSelected = value; 262 m_isSelected = value; // if true set imediatly to stop moves etc
268 AddChange(changes.Selected, value); 263 AddChange(changes.Selected, value);
269 } 264 }
270 } 265 }
@@ -298,13 +293,6 @@ namespace OpenSim.Region.Physics.OdePlugin
298 m_iscolliding = false; 293 m_iscolliding = false;
299 else 294 else
300 m_iscolliding = true; 295 m_iscolliding = true;
301
302 if (m_wascolliding != m_iscolliding)
303 {
304 if (m_wascolliding && !m_isSelected && Body != IntPtr.Zero)
305 d.BodyEnable(Body);
306 m_wascolliding = m_iscolliding;
307 }
308 } 296 }
309 } 297 }
310 298
@@ -665,19 +653,21 @@ namespace OpenSim.Region.Physics.OdePlugin
665 strVehicleQuatParam fp = new strVehicleQuatParam(); 653 strVehicleQuatParam fp = new strVehicleQuatParam();
666 fp.param = param; 654 fp.param = param;
667 fp.value = value; 655 fp.value = value;
668 AddChange(changes.VehicleVectorParam, fp); 656 AddChange(changes.VehicleRotationParam, fp);
669 } 657 }
670 658
671 public override void VehicleFlags(int param, bool value) 659 public override void VehicleFlags(int param, bool value)
672 { 660 {
673 if (m_vehicle == null)
674 return;
675 strVehicleBoolParam bp = new strVehicleBoolParam(); 661 strVehicleBoolParam bp = new strVehicleBoolParam();
676 bp.param = param; 662 bp.param = param;
677 bp.value = value; 663 bp.value = value;
678 AddChange(changes.VehicleFlags, bp); 664 AddChange(changes.VehicleFlags, bp);
679 } 665 }
680 666
667 public override void SetVehicle(object vdata)
668 {
669 AddChange(changes.SetVehicle, vdata);
670 }
681 public void SetAcceleration(Vector3 accel) 671 public void SetAcceleration(Vector3 accel)
682 { 672 {
683 _acceleration = accel; 673 _acceleration = accel;
@@ -710,8 +700,30 @@ namespace OpenSim.Region.Physics.OdePlugin
710 700
711 public override void CrossingFailure() 701 public override void CrossingFailure()
712 { 702 {
713 m_crossingfailures++; 703 if (m_outbounds)
714 changeDisable(false); 704 {
705 _position.X = Util.Clip(_position.X, 0.5f, _parent_scene.WorldExtents.X - 0.5f);
706 _position.Y = Util.Clip(_position.Y, 0.5f, _parent_scene.WorldExtents.Y - 0.5f);
707 _position.Z = Util.Clip(_position.Z + 0.2f, -100f, 50000f);
708
709 m_lastposition = _position;
710 _velocity.X = 0;
711 _velocity.Y = 0;
712 _velocity.Z = 0;
713
714 m_lastVelocity = _velocity;
715 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
716 m_vehicle.Stop();
717
718 if(Body != IntPtr.Zero)
719 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
720 if (prim_geom != IntPtr.Zero)
721 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
722
723 m_outbounds = false;
724 changeDisable(false);
725 base.RequestPhysicsterseUpdate();
726 }
715 } 727 }
716 728
717 public override void SetMomentum(Vector3 momentum) 729 public override void SetMomentum(Vector3 momentum)
@@ -865,12 +877,14 @@ namespace OpenSim.Region.Physics.OdePlugin
865 m_force = Vector3.Zero; 877 m_force = Vector3.Zero;
866 878
867 m_iscolliding = false; 879 m_iscolliding = false;
868 m_wascolliding = false;
869 m_colliderfilter = 0; 880 m_colliderfilter = 0;
870 881
871 hasOOBoffsetFromMesh = false; 882 hasOOBoffsetFromMesh = false;
872 _triMeshData = IntPtr.Zero; 883 _triMeshData = IntPtr.Zero;
873 884
885 m_lastdoneSelected = false;
886 m_isSelected = false;
887 m_delaySelect = false;
874 888
875 primContactData.mu = parent_scene.m_materialContactsData[(int)Material.Wood].mu; 889 primContactData.mu = parent_scene.m_materialContactsData[(int)Material.Wood].mu;
876 primContactData.bounce = parent_scene.m_materialContactsData[(int)Material.Wood].bounce; 890 primContactData.bounce = parent_scene.m_materialContactsData[(int)Material.Wood].bounce;
@@ -885,8 +899,6 @@ namespace OpenSim.Region.Physics.OdePlugin
885 private void resetCollisionAccounting() 899 private void resetCollisionAccounting()
886 { 900 {
887 m_collisionscore = 0; 901 m_collisionscore = 0;
888 m_interpenetrationcount = 0;
889 m_disabled = false;
890 } 902 }
891 903
892 private void createAMotor(Vector3 axis) 904 private void createAMotor(Vector3 axis)
@@ -926,9 +938,6 @@ namespace OpenSim.Region.Physics.OdePlugin
926 curr.W = dcur.W; 938 curr.W = dcur.W;
927 Vector3 ax; 939 Vector3 ax;
928 940
929 const int StopERP = 7;
930 const int StopCFM = 8;
931
932 int i = 0; 941 int i = 0;
933 int j = 0; 942 int j = 0;
934 if (axis.X == 0) 943 if (axis.X == 0)
@@ -943,10 +952,10 @@ namespace OpenSim.Region.Physics.OdePlugin
943 d.JointSetAMotorParam(Amotor, (int)d.JointParam.FudgeFactor, 0.0001f); 952 d.JointSetAMotorParam(Amotor, (int)d.JointParam.FudgeFactor, 0.0001f);
944 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Bounce, 0f); 953 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Bounce, 0f);
945 d.JointSetAMotorParam(Amotor, (int)d.JointParam.FMax, 5e8f); 954 d.JointSetAMotorParam(Amotor, (int)d.JointParam.FMax, 5e8f);
946 d.JointSetAMotorParam(Amotor, (int)StopCFM, 0f); 955 d.JointSetAMotorParam(Amotor, (int)d.JointParam.StopCFM, 0f);
947 d.JointSetAMotorParam(Amotor, (int)StopERP, 0.8f); 956 d.JointSetAMotorParam(Amotor, (int)d.JointParam.StopERP, 0.8f);
948 i++; 957 i++;
949 j = 256; // odeplugin.cs doesn't have all parameters so this moves to next axis set 958 j = 256; // move to next axis set
950 } 959 }
951 960
952 if (axis.Y == 0) 961 if (axis.Y == 0)
@@ -960,8 +969,8 @@ namespace OpenSim.Region.Physics.OdePlugin
960 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FudgeFactor, 0.0001f); 969 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FudgeFactor, 0.0001f);
961 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Bounce, 0f); 970 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Bounce, 0f);
962 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FMax, 5e8f); 971 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FMax, 5e8f);
963 d.JointSetAMotorParam(Amotor, j + (int)StopCFM, 0f); 972 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopCFM, 0f);
964 d.JointSetAMotorParam(Amotor, j + (int)StopERP, 0.8f); 973 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopERP, 0.8f);
965 i++; 974 i++;
966 j += 256; 975 j += 256;
967 } 976 }
@@ -977,8 +986,8 @@ namespace OpenSim.Region.Physics.OdePlugin
977 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FudgeFactor, 0.0001f); 986 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FudgeFactor, 0.0001f);
978 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Bounce, 0f); 987 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Bounce, 0f);
979 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FMax, 5e8f); 988 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FMax, 5e8f);
980 d.JointSetAMotorParam(Amotor, j + (int)StopCFM, 0f); 989 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopCFM, 0f);
981 d.JointSetAMotorParam(Amotor, j + (int)StopERP, 0.8f); 990 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopERP, 0.8f);
982 } 991 }
983 } 992 }
984 993
@@ -1186,24 +1195,10 @@ namespace OpenSim.Region.Physics.OdePlugin
1186 1195
1187 public void enableBodySoft() 1196 public void enableBodySoft()
1188 { 1197 {
1189 if (!childPrim) 1198 if (!childPrim && !m_isSelected)
1190 { 1199 {
1191 if (m_isphysical && Body != IntPtr.Zero && prim_geom != IntPtr.Zero) 1200 if (m_isphysical && Body != IntPtr.Zero && prim_geom != IntPtr.Zero)
1192 { 1201 {
1193 if (m_targetSpace != _parent_scene.ActiveSpace)
1194 {
1195 m_targetSpace = _parent_scene.ActiveSpace;
1196
1197 foreach (OdePrim prm in childrenPrim)
1198 {
1199 if (prm.prim_geom != IntPtr.Zero)
1200 {
1201 d.SpaceAdd(m_targetSpace, prm.prim_geom);
1202 prm.m_targetSpace = m_targetSpace;
1203 }
1204 }
1205 d.SpaceAdd(m_targetSpace, prim_geom);
1206 }
1207 d.GeomEnable(prim_geom); 1202 d.GeomEnable(prim_geom);
1208 foreach (OdePrim prm in childrenPrim) 1203 foreach (OdePrim prm in childrenPrim)
1209 d.GeomEnable(prm.prim_geom); 1204 d.GeomEnable(prm.prim_geom);
@@ -1211,6 +1206,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1211 d.BodyEnable(Body); 1206 d.BodyEnable(Body);
1212 } 1207 }
1213 } 1208 }
1209 m_disabled = false;
1214 resetCollisionAccounting(); // this sets m_disable to false 1210 resetCollisionAccounting(); // this sets m_disable to false
1215 } 1211 }
1216 1212
@@ -1221,19 +1217,6 @@ namespace OpenSim.Region.Physics.OdePlugin
1221 { 1217 {
1222 if (m_isphysical && Body != IntPtr.Zero && prim_geom != IntPtr.Zero) 1218 if (m_isphysical && Body != IntPtr.Zero && prim_geom != IntPtr.Zero)
1223 { 1219 {
1224 if (m_targetSpace == _parent_scene.ActiveSpace)
1225 {
1226 foreach (OdePrim prm in childrenPrim)
1227 {
1228 if (prm.m_targetSpace != IntPtr.Zero && prm.prim_geom != IntPtr.Zero)
1229 {
1230 d.SpaceRemove(prm.m_targetSpace, prm.prim_geom);
1231 prm.m_targetSpace = IntPtr.Zero;
1232 }
1233 }
1234 d.SpaceRemove(m_targetSpace, prim_geom);
1235 m_targetSpace = IntPtr.Zero;
1236 }
1237 d.GeomDisable(prim_geom); 1220 d.GeomDisable(prim_geom);
1238 foreach (OdePrim prm in childrenPrim) 1221 foreach (OdePrim prm in childrenPrim)
1239 d.GeomDisable(prm.prim_geom); 1222 d.GeomDisable(prm.prim_geom);
@@ -1369,9 +1352,6 @@ namespace OpenSim.Region.Physics.OdePlugin
1369 d.BodySetMass(Body, ref objdmass); 1352 d.BodySetMass(Body, ref objdmass);
1370 _mass = objdmass.mass; 1353 _mass = objdmass.mass;
1371 1354
1372 m_collisionCategories |= CollisionCategories.Body;
1373 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1374
1375 // disconnect from world gravity so we can apply buoyancy 1355 // disconnect from world gravity so we can apply buoyancy
1376 d.BodySetGravityMode(Body, false); 1356 d.BodySetGravityMode(Body, false);
1377 1357
@@ -1379,16 +1359,14 @@ namespace OpenSim.Region.Physics.OdePlugin
1379 d.BodySetAutoDisableSteps(Body, body_autodisable_frames); 1359 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1380 // d.BodySetLinearDampingThreshold(Body, 0.01f); 1360 // d.BodySetLinearDampingThreshold(Body, 0.01f);
1381 // d.BodySetAngularDampingThreshold(Body, 0.001f); 1361 // d.BodySetAngularDampingThreshold(Body, 0.001f);
1382 d.BodySetDamping(Body, .001f, .0002f); 1362 d.BodySetDamping(Body, .002f, .002f);
1383 1363
1364 m_collisionCategories |= CollisionCategories.Body;
1365 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1384 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 1366 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1385 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 1367 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1386
1387 m_interpenetrationcount = 0;
1388 m_collisionscore = 0; 1368 m_collisionscore = 0;
1389 1369
1390 m_disabled = false;
1391
1392 if (m_targetSpace != _parent_scene.ActiveSpace) 1370 if (m_targetSpace != _parent_scene.ActiveSpace)
1393 { 1371 {
1394 if (m_targetSpace != IntPtr.Zero) 1372 if (m_targetSpace != IntPtr.Zero)
@@ -1416,6 +1394,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1416 prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); 1394 prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1417 d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories); 1395 d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories);
1418 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); 1396 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
1397 prm.m_collisionscore = 0;
1419 1398
1420 if (prm.m_targetSpace != _parent_scene.ActiveSpace) 1399 if (prm.m_targetSpace != _parent_scene.ActiveSpace)
1421 { 1400 {
@@ -1428,10 +1407,11 @@ namespace OpenSim.Region.Physics.OdePlugin
1428 prm.m_targetSpace = _parent_scene.ActiveSpace; 1407 prm.m_targetSpace = _parent_scene.ActiveSpace;
1429 d.SpaceAdd(m_targetSpace, prm.prim_geom); 1408 d.SpaceAdd(m_targetSpace, prm.prim_geom);
1430 } 1409 }
1431 d.GeomEnable(prm.prim_geom); 1410
1411 if (m_isSelected || m_disabled)
1412 d.GeomDisable(prm.prim_geom);
1413
1432 prm.m_disabled = false; 1414 prm.m_disabled = false;
1433 prm.m_interpenetrationcount = 0;
1434 prm.m_collisionscore = 0;
1435 _parent_scene.addActivePrim(prm); 1415 _parent_scene.addActivePrim(prm);
1436 } 1416 }
1437 } 1417 }
@@ -1442,8 +1422,12 @@ namespace OpenSim.Region.Physics.OdePlugin
1442 createAMotor(m_angularlock); 1422 createAMotor(m_angularlock);
1443 } 1423 }
1444 1424
1445 d.GeomEnable(prim_geom); 1425 if (m_isSelected || m_disabled)
1446 m_disabled = false; 1426 {
1427 d.GeomDisable(prim_geom);
1428 d.BodyDisable(Body);
1429 }
1430
1447 _parent_scene.addActivePrim(this); 1431 _parent_scene.addActivePrim(this);
1448 } 1432 }
1449 1433
@@ -1484,12 +1468,16 @@ namespace OpenSim.Region.Physics.OdePlugin
1484 prm.m_collisionscore = 0; 1468 prm.m_collisionscore = 0;
1485 } 1469 }
1486 } 1470 }
1471 if (Amotor != IntPtr.Zero)
1472 {
1473 d.JointDestroy(Amotor);
1474 Amotor = IntPtr.Zero;
1475 }
1487 d.BodyDestroy(Body); 1476 d.BodyDestroy(Body);
1488 } 1477 }
1489 Body = IntPtr.Zero; 1478 Body = IntPtr.Zero;
1490 } 1479 }
1491 _mass = primMass; 1480 _mass = primMass;
1492 m_disabled = true;
1493 m_collisionscore = 0; 1481 m_collisionscore = 0;
1494 } 1482 }
1495 1483
@@ -2115,49 +2103,72 @@ namespace OpenSim.Region.Physics.OdePlugin
2115 d.BodySetTorque(Body, 0f, 0f, 0f); 2103 d.BodySetTorque(Body, 0f, 0f, 0f);
2116 d.BodySetLinearVel(Body, 0f, 0f, 0f); 2104 d.BodySetLinearVel(Body, 0f, 0f, 0f);
2117 d.BodySetAngularVel(Body, 0f, 0f, 0f); 2105 d.BodySetAngularVel(Body, 0f, 0f, 0f);
2118
2119 } 2106 }
2120 } 2107 }
2121 2108
2122 private void changeSelectedStatus(bool newval) 2109 private void changeSelectedStatus(bool newval)
2123 { 2110 {
2111 if (m_lastdoneSelected == newval)
2112 return;
2113
2114 m_lastdoneSelected = newval;
2115 DoSelectedStatus(newval);
2116 }
2117
2118 private void CheckDelaySelect()
2119 {
2120 if (m_delaySelect)
2121 {
2122 DoSelectedStatus(m_isSelected);
2123 }
2124 }
2125
2126 private void DoSelectedStatus(bool newval)
2127 {
2124 m_isSelected = newval; 2128 m_isSelected = newval;
2125 Stop(); 2129 Stop();
2126 2130
2127 if (newval) 2131 if (newval)
2128 { 2132 {
2129 m_collisionCategories = CollisionCategories.Selected; 2133 if (!childPrim && Body != IntPtr.Zero)
2130 m_collisionFlags = (CollisionCategories.Sensor | CollisionCategories.Space); 2134 d.BodyDisable(Body);
2131 2135
2132 if (prim_geom != IntPtr.Zero) 2136 if (m_delaySelect)
2133 { 2137 {
2134 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 2138 if (!childPrim)
2135 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 2139 {
2140 foreach (OdePrim prm in childrenPrim)
2141 {
2142 d.GeomDisable(prm.prim_geom);
2143 prm.m_delaySelect = false;
2144 }
2145 }
2146 d.GeomDisable(prim_geom);
2147 m_delaySelect = false;
2148 }
2149 else
2150 {
2151 m_delaySelect = true;
2136 } 2152 }
2137
2138 disableBodySoft();
2139 } 2153 }
2140 else 2154 else
2141 { 2155 {
2142 m_collisionCategories = CollisionCategories.Geom; 2156 if (!childPrim && Body != IntPtr.Zero && !m_disabled)
2143 2157 d.BodyEnable(Body);
2144 if (m_isphysical)
2145 m_collisionCategories |= CollisionCategories.Body;
2146
2147 m_collisionFlags = m_default_collisionFlags;
2148
2149 if (m_collidesLand)
2150 m_collisionFlags |= CollisionCategories.Land;
2151 if (m_collidesWater)
2152 m_collisionFlags |= CollisionCategories.Water;
2153 2158
2154 if (prim_geom != IntPtr.Zero) 2159 if (!childPrim)
2155 { 2160 {
2156 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 2161 foreach (OdePrim prm in childrenPrim)
2157 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 2162 {
2163 if(!prm.m_disabled)
2164 d.GeomEnable(prm.prim_geom);
2165 prm.m_delaySelect = false;
2166 }
2158 } 2167 }
2168 if(!m_disabled)
2169 d.GeomEnable(prim_geom);
2159 2170
2160 enableBodySoft(); 2171 m_delaySelect = false;
2161 } 2172 }
2162 2173
2163 resetCollisionAccounting(); 2174 resetCollisionAccounting();
@@ -2165,6 +2176,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2165 2176
2166 private void changePosition(Vector3 newPos) 2177 private void changePosition(Vector3 newPos)
2167 { 2178 {
2179 CheckDelaySelect();
2168 if (m_isphysical) 2180 if (m_isphysical)
2169 { 2181 {
2170 if (childPrim) // inertia is messed, must rebuild 2182 if (childPrim) // inertia is messed, must rebuild
@@ -2207,6 +2219,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2207 2219
2208 private void changeOrientation(Quaternion newOri) 2220 private void changeOrientation(Quaternion newOri)
2209 { 2221 {
2222 CheckDelaySelect();
2210 if (m_isphysical) 2223 if (m_isphysical)
2211 { 2224 {
2212 if (childPrim) // inertia is messed, must rebuild 2225 if (childPrim) // inertia is messed, must rebuild
@@ -2258,6 +2271,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2258 2271
2259 private void changePositionAndOrientation(Vector3 newPos, Quaternion newOri) 2272 private void changePositionAndOrientation(Vector3 newPos, Quaternion newOri)
2260 { 2273 {
2274 CheckDelaySelect();
2261 if (m_isphysical) 2275 if (m_isphysical)
2262 { 2276 {
2263 if (childPrim && m_building) // inertia is messed, must rebuild 2277 if (childPrim && m_building) // inertia is messed, must rebuild
@@ -2342,6 +2356,8 @@ namespace OpenSim.Region.Physics.OdePlugin
2342 2356
2343 private void changePhysicsStatus(bool NewStatus) 2357 private void changePhysicsStatus(bool NewStatus)
2344 { 2358 {
2359 CheckDelaySelect();
2360
2345 m_isphysical = NewStatus; 2361 m_isphysical = NewStatus;
2346 2362
2347 if (!childPrim) 2363 if (!childPrim)
@@ -2384,6 +2400,8 @@ namespace OpenSim.Region.Physics.OdePlugin
2384 2400
2385 private void changeprimsizeshape() 2401 private void changeprimsizeshape()
2386 { 2402 {
2403 CheckDelaySelect();
2404
2387 OdePrim parent = (OdePrim)_parent; 2405 OdePrim parent = (OdePrim)_parent;
2388 2406
2389 bool chp = childPrim; 2407 bool chp = childPrim;
@@ -2508,7 +2526,6 @@ namespace OpenSim.Region.Physics.OdePlugin
2508 } 2526 }
2509 2527
2510 m_collisionscore = 0; 2528 m_collisionscore = 0;
2511 m_interpenetrationcount = 0;
2512 } 2529 }
2513 } 2530 }
2514 2531
@@ -2528,7 +2545,6 @@ namespace OpenSim.Region.Physics.OdePlugin
2528 } 2545 }
2529 } 2546 }
2530 m_collisionscore = 0; 2547 m_collisionscore = 0;
2531 m_interpenetrationcount = 0;
2532 } 2548 }
2533 } 2549 }
2534 2550
@@ -2565,6 +2581,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2565 else 2581 else
2566 { 2582 {
2567 m_building = false; 2583 m_building = false;
2584 CheckDelaySelect();
2568 if (!childPrim) 2585 if (!childPrim)
2569 MakeBody(); 2586 MakeBody();
2570 } 2587 }
@@ -2575,18 +2592,26 @@ namespace OpenSim.Region.Physics.OdePlugin
2575 } 2592 }
2576 } 2593 }
2577 2594
2578 private void changeVehicleType(int value) 2595 public void changeSetVehicle(VehicleData vdata)
2579 { 2596 {
2580 if (m_vehicle == null) 2597 if (m_vehicle == null)
2598 m_vehicle = new ODEDynamics(this);
2599 m_vehicle.DoSetVehicle(vdata);
2600 }
2601 private void changeVehicleType(int value)
2602 {
2603 if (value == (int)Vehicle.TYPE_NONE)
2581 { 2604 {
2582 if (value != (int)Vehicle.TYPE_NONE) 2605 if (m_vehicle != null)
2583 { 2606 m_vehicle = null;
2584 m_vehicle = new ODEDynamics(this);
2585 m_vehicle.ProcessTypeChange((Vehicle)value);
2586 }
2587 } 2607 }
2588 else 2608 else
2609 {
2610 if (m_vehicle == null)
2611 m_vehicle = new ODEDynamics(this);
2612
2589 m_vehicle.ProcessTypeChange((Vehicle)value); 2613 m_vehicle.ProcessTypeChange((Vehicle)value);
2614 }
2590 } 2615 }
2591 2616
2592 private void changeVehicleFloatParam(strVehicleFloatParam fp) 2617 private void changeVehicleFloatParam(strVehicleFloatParam fp)
@@ -2595,8 +2620,6 @@ namespace OpenSim.Region.Physics.OdePlugin
2595 return; 2620 return;
2596 2621
2597 m_vehicle.ProcessFloatVehicleParam((Vehicle)fp.param, fp.value); 2622 m_vehicle.ProcessFloatVehicleParam((Vehicle)fp.param, fp.value);
2598 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2599 d.BodyEnable(Body);
2600 } 2623 }
2601 2624
2602 private void changeVehicleVectorParam(strVehicleVectorParam vp) 2625 private void changeVehicleVectorParam(strVehicleVectorParam vp)
@@ -2604,8 +2627,6 @@ namespace OpenSim.Region.Physics.OdePlugin
2604 if (m_vehicle == null) 2627 if (m_vehicle == null)
2605 return; 2628 return;
2606 m_vehicle.ProcessVectorVehicleParam((Vehicle)vp.param, vp.value); 2629 m_vehicle.ProcessVectorVehicleParam((Vehicle)vp.param, vp.value);
2607 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2608 d.BodyEnable(Body);
2609 } 2630 }
2610 2631
2611 private void changeVehicleRotationParam(strVehicleQuatParam qp) 2632 private void changeVehicleRotationParam(strVehicleQuatParam qp)
@@ -2613,8 +2634,6 @@ namespace OpenSim.Region.Physics.OdePlugin
2613 if (m_vehicle == null) 2634 if (m_vehicle == null)
2614 return; 2635 return;
2615 m_vehicle.ProcessRotationVehicleParam((Vehicle)qp.param, qp.value); 2636 m_vehicle.ProcessRotationVehicleParam((Vehicle)qp.param, qp.value);
2616 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2617 d.BodyEnable(Body);
2618 } 2637 }
2619 2638
2620 private void changeVehicleFlags(strVehicleBoolParam bp) 2639 private void changeVehicleFlags(strVehicleBoolParam bp)
@@ -2622,8 +2641,6 @@ namespace OpenSim.Region.Physics.OdePlugin
2622 if (m_vehicle == null) 2641 if (m_vehicle == null)
2623 return; 2642 return;
2624 m_vehicle.ProcessVehicleFlags(bp.param, bp.value); 2643 m_vehicle.ProcessVehicleFlags(bp.param, bp.value);
2625 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2626 d.BodyEnable(Body);
2627 } 2644 }
2628 2645
2629 #endregion 2646 #endregion
@@ -2849,41 +2866,6 @@ namespace OpenSim.Region.Physics.OdePlugin
2849 { 2866 {
2850 if (Body != IntPtr.Zero) 2867 if (Body != IntPtr.Zero)
2851 { 2868 {
2852 if (m_crossingfailures != 0 && m_crossingfailures < 5)
2853 {
2854 _position.X = Util.Clip(_position.X, 0.4f, _parent_scene.WorldExtents.X - 0.4f);
2855 _position.Y = Util.Clip(_position.Y, 0.4f, _parent_scene.WorldExtents.Y - 0.4f);
2856 _position.Z = Util.Clip(_position.Z + 0.2f, -100f, 50000f);
2857
2858 float tmp = _parent_scene.GetTerrainHeightAtXY(_position.X, _position.Y);
2859 if (_position.Z < tmp)
2860 _position.Z = tmp + 0.2f;
2861
2862 m_lastposition = _position;
2863 m_lastorientation = _orientation;
2864 _velocity.X = 0;
2865 _velocity.Y = 0;
2866 _velocity.Z = 0;
2867
2868 m_lastVelocity = _velocity;
2869 m_rotationalVelocity = _velocity;
2870 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
2871 m_vehicle.Stop();
2872
2873 m_crossingfailures = 0; // do this only once
2874 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
2875 d.BodySetAngularVel(Body, 0, 0, 0);
2876 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2877 enableBodySoft();
2878 base.RequestPhysicsterseUpdate();
2879 return;
2880 }
2881
2882 else if (m_crossingfailures != 0)
2883 {
2884 return;
2885 }
2886
2887 Vector3 pv = Vector3.Zero; 2869 Vector3 pv = Vector3.Zero;
2888 bool lastZeroFlag = _zeroFlag; 2870 bool lastZeroFlag = _zeroFlag;
2889 2871
@@ -2899,24 +2881,21 @@ namespace OpenSim.Region.Physics.OdePlugin
2899 // we can't let it keeping moving and having colisions 2881 // we can't let it keeping moving and having colisions
2900 // since it can be stucked between something like terrain and edge 2882 // since it can be stucked between something like terrain and edge
2901 // so lets stop and disable it until something else kicks it 2883 // so lets stop and disable it until something else kicks it
2902 if (m_crossingfailures == 0)
2903 {
2904 2884
2905 _position.X = Util.Clip(lpos.X, -0.5f, _parent_scene.WorldExtents.X + 0.5f); 2885 _position.X = Util.Clip(lpos.X, -0.2f, _parent_scene.WorldExtents.X + 0.2f);
2906 _position.Y = Util.Clip(lpos.Y, -0.5f, _parent_scene.WorldExtents.Y + 0.5f); 2886 _position.Y = Util.Clip(lpos.Y, -0.2f, _parent_scene.WorldExtents.Y + 0.2f);
2907 _position.Z = Util.Clip(lpos.Z, -100f, 50000f); 2887 _position.Z = Util.Clip(lpos.Z, -100f, 50000f);
2908 2888
2909 m_lastposition = _position; 2889 m_lastposition = _position;
2910 m_lastorientation = _orientation; 2890// m_lastorientation = _orientation;
2911 2891
2912 d.BodySetLinearVel(Body, 0, 0, 0); // stop it 2892 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
2913 d.BodySetAngularVel(Body, 0, 0, 0); 2893// d.BodySetAngularVel(Body, 0, 0, 0);
2914 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 2894 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2915 disableBodySoft(); // stop collisions 2895 disableBodySoft(); // stop collisions
2916 m_crossingfailures++; // do this only once 2896 m_outbounds = true;
2917 base.RequestPhysicsterseUpdate(); 2897 base.RequestPhysicsterseUpdate();
2918 return; 2898 return;
2919 }
2920 } 2899 }
2921 2900
2922 if (lpos.Z < -100 || lpos.Z > 100000f) 2901 if (lpos.Z < -100 || lpos.Z > 100000f)
@@ -3159,6 +3138,7 @@ namespace OpenSim.Region.Physics.OdePlugin
3159 else 3138 else
3160 ChildRemove(this, false); 3139 ChildRemove(this, false);
3161 3140
3141 m_vehicle = null;
3162 RemoveGeom(); 3142 RemoveGeom();
3163 m_targetSpace = IntPtr.Zero; 3143 m_targetSpace = IntPtr.Zero;
3164 if (m_eventsubscription > 0) 3144 if (m_eventsubscription > 0)
@@ -3273,6 +3253,9 @@ namespace OpenSim.Region.Physics.OdePlugin
3273 changeVehicleRotationParam((strVehicleQuatParam) arg); 3253 changeVehicleRotationParam((strVehicleQuatParam) arg);
3274 break; 3254 break;
3275 3255
3256 case changes.SetVehicle:
3257 changeSetVehicle((VehicleData) arg);
3258 break;
3276 case changes.Null: 3259 case changes.Null:
3277 donullchange(); 3260 donullchange();
3278 break; 3261 break;