diff options
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | 201 |
1 files changed, 132 insertions, 69 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs index 0ccdbc0..e5fa1d7 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | |||
@@ -155,6 +155,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
155 | public float m_collisionscore; | 155 | public float m_collisionscore; |
156 | int m_colliderfilter = 0; | 156 | int m_colliderfilter = 0; |
157 | 157 | ||
158 | public IntPtr collide_geom; // for objects: geom if single prim space it linkset | ||
159 | |||
158 | private float m_density = 10.000006836f; // Aluminum g/cm3; | 160 | private float m_density = 10.000006836f; // Aluminum g/cm3; |
159 | 161 | ||
160 | public bool _zeroFlag; | 162 | public bool _zeroFlag; |
@@ -220,6 +222,18 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
220 | { | 222 | { |
221 | get | 223 | get |
222 | { | 224 | { |
225 | if (m_isphysical) | ||
226 | { | ||
227 | ODEDynamics veh; | ||
228 | if (_parent != null) | ||
229 | veh = ((OdePrim)_parent).m_vehicle; | ||
230 | else | ||
231 | veh = m_vehicle; | ||
232 | |||
233 | if (veh != null) | ||
234 | if (veh.Type != Vehicle.TYPE_NONE && veh.EngineActive) | ||
235 | return new ContactData(0, 0); | ||
236 | } | ||
223 | return primContactData; | 237 | return primContactData; |
224 | } | 238 | } |
225 | } | 239 | } |
@@ -453,8 +467,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
453 | { | 467 | { |
454 | get | 468 | get |
455 | { | 469 | { |
456 | // Averate previous velocity with the new one so | ||
457 | // client object interpolation works a 'little' better | ||
458 | if (_zeroFlag) | 470 | if (_zeroFlag) |
459 | return Vector3.Zero; | 471 | return Vector3.Zero; |
460 | return _velocity; | 472 | return _velocity; |
@@ -833,6 +845,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
833 | body_autodisable_frames = parent_scene.bodyFramesAutoDisable; | 845 | body_autodisable_frames = parent_scene.bodyFramesAutoDisable; |
834 | 846 | ||
835 | prim_geom = IntPtr.Zero; | 847 | prim_geom = IntPtr.Zero; |
848 | collide_geom = IntPtr.Zero; | ||
836 | Body = IntPtr.Zero; | 849 | Body = IntPtr.Zero; |
837 | 850 | ||
838 | if (!size.IsFinite()) | 851 | if (!size.IsFinite()) |
@@ -1367,7 +1380,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1367 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); | 1380 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); |
1368 | m_collisionscore = 0; | 1381 | m_collisionscore = 0; |
1369 | 1382 | ||
1370 | if (m_targetSpace != _parent_scene.ActiveSpace) | 1383 | // if (m_targetSpace != _parent_scene.ActiveSpace) |
1371 | { | 1384 | { |
1372 | if (m_targetSpace != IntPtr.Zero) | 1385 | if (m_targetSpace != IntPtr.Zero) |
1373 | { | 1386 | { |
@@ -1376,9 +1389,26 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1376 | d.SpaceRemove(m_targetSpace, prim_geom); | 1389 | d.SpaceRemove(m_targetSpace, prim_geom); |
1377 | } | 1390 | } |
1378 | 1391 | ||
1392 | // m_targetSpace = _parent_scene.ActiveSpace; | ||
1393 | // d.SpaceAdd(m_targetSpace, prim_geom); | ||
1394 | } | ||
1395 | |||
1396 | |||
1397 | if (childrenPrim.Count == 0) | ||
1398 | { | ||
1399 | collide_geom = prim_geom; | ||
1379 | m_targetSpace = _parent_scene.ActiveSpace; | 1400 | m_targetSpace = _parent_scene.ActiveSpace; |
1380 | d.SpaceAdd(m_targetSpace, prim_geom); | 1401 | d.SpaceAdd(m_targetSpace, prim_geom); |
1381 | } | 1402 | } |
1403 | else | ||
1404 | { | ||
1405 | m_targetSpace = d.HashSpaceCreate(_parent_scene.ActiveSpace); | ||
1406 | d.HashSpaceSetLevels(m_targetSpace, -2, 8); | ||
1407 | d.SpaceSetSublevel(m_targetSpace, 3); | ||
1408 | d.SpaceSetCleanup(m_targetSpace, false); | ||
1409 | d.SpaceAdd(m_targetSpace, prim_geom); | ||
1410 | collide_geom = m_targetSpace; | ||
1411 | } | ||
1382 | 1412 | ||
1383 | lock (childrenPrim) | 1413 | lock (childrenPrim) |
1384 | { | 1414 | { |
@@ -1396,15 +1426,15 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1396 | d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); | 1426 | d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); |
1397 | prm.m_collisionscore = 0; | 1427 | prm.m_collisionscore = 0; |
1398 | 1428 | ||
1399 | if (prm.m_targetSpace != _parent_scene.ActiveSpace) | 1429 | if (prm.m_targetSpace != m_targetSpace) |
1400 | { | 1430 | { |
1401 | if (prm.m_targetSpace != IntPtr.Zero) | 1431 | if (prm.m_targetSpace != IntPtr.Zero) |
1402 | { | 1432 | { |
1403 | _parent_scene.waitForSpaceUnlock(m_targetSpace); | 1433 | _parent_scene.waitForSpaceUnlock(prm.m_targetSpace); |
1404 | if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom)) | 1434 | if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom)) |
1405 | d.SpaceRemove(prm.m_targetSpace, prm.prim_geom); | 1435 | d.SpaceRemove(prm.m_targetSpace, prm.prim_geom); |
1406 | } | 1436 | } |
1407 | prm.m_targetSpace = _parent_scene.ActiveSpace; | 1437 | prm.m_targetSpace = m_targetSpace; |
1408 | d.SpaceAdd(m_targetSpace, prm.prim_geom); | 1438 | d.SpaceAdd(m_targetSpace, prm.prim_geom); |
1409 | } | 1439 | } |
1410 | 1440 | ||
@@ -1427,8 +1457,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1427 | d.GeomDisable(prim_geom); | 1457 | d.GeomDisable(prim_geom); |
1428 | d.BodyDisable(Body); | 1458 | d.BodyDisable(Body); |
1429 | } | 1459 | } |
1460 | else | ||
1461 | { | ||
1462 | d.BodySetAngularVel(Body, m_rotationalVelocity.X, m_rotationalVelocity.Y, m_rotationalVelocity.Z); | ||
1463 | d.BodySetLinearVel(Body, _velocity.X, _velocity.Y, _velocity.Z); | ||
1464 | } | ||
1430 | 1465 | ||
1431 | _parent_scene.addActivePrim(this); | 1466 | _parent_scene.addActivePrim(this); |
1467 | _parent_scene.addActiveGroups(this); | ||
1432 | } | 1468 | } |
1433 | 1469 | ||
1434 | private void DestroyBody() | 1470 | private void DestroyBody() |
@@ -1473,6 +1509,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1473 | d.JointDestroy(Amotor); | 1509 | d.JointDestroy(Amotor); |
1474 | Amotor = IntPtr.Zero; | 1510 | Amotor = IntPtr.Zero; |
1475 | } | 1511 | } |
1512 | _parent_scene.remActiveGroup(this); | ||
1476 | d.BodyDestroy(Body); | 1513 | d.BodyDestroy(Body); |
1477 | } | 1514 | } |
1478 | Body = IntPtr.Zero; | 1515 | Body = IntPtr.Zero; |
@@ -2390,8 +2427,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2390 | else | 2427 | else |
2391 | */ | 2428 | */ |
2392 | DestroyBody(); | 2429 | DestroyBody(); |
2393 | Stop(); | ||
2394 | } | 2430 | } |
2431 | Stop(); | ||
2395 | } | 2432 | } |
2396 | } | 2433 | } |
2397 | 2434 | ||
@@ -2576,7 +2613,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2576 | if ((bool)newbuilding) | 2613 | if ((bool)newbuilding) |
2577 | { | 2614 | { |
2578 | m_building = true; | 2615 | m_building = true; |
2579 | DestroyBody(); | 2616 | if (!childPrim) |
2617 | DestroyBody(); | ||
2580 | } | 2618 | } |
2581 | else | 2619 | else |
2582 | { | 2620 | { |
@@ -2648,12 +2686,95 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2648 | public void Move() | 2686 | public void Move() |
2649 | { | 2687 | { |
2650 | if (!childPrim && m_isphysical && Body != IntPtr.Zero && | 2688 | if (!childPrim && m_isphysical && Body != IntPtr.Zero && |
2651 | !m_disabled && !m_isSelected && d.BodyIsEnabled(Body) && !m_building) // KF: Only move root prims. | 2689 | !m_disabled && !m_isSelected && d.BodyIsEnabled(Body) && !m_building && !m_outbounds) |
2690 | // !m_disabled && !m_isSelected && !m_building && !m_outbounds) | ||
2652 | { | 2691 | { |
2653 | // if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body); // KF add 161009 | 2692 | // if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body); // KF add 161009 |
2654 | 2693 | ||
2655 | float timestep = _parent_scene.ODE_STEPSIZE; | 2694 | float timestep = _parent_scene.ODE_STEPSIZE; |
2656 | 2695 | ||
2696 | // check outside region | ||
2697 | d.Vector3 lpos; | ||
2698 | d.GeomCopyPosition(prim_geom, out lpos); // root position that is seem by rest of simulator | ||
2699 | |||
2700 | if (lpos.Z < -100 || lpos.Z > 100000f) | ||
2701 | { | ||
2702 | m_outbounds = true; | ||
2703 | |||
2704 | lpos.Z = Util.Clip(lpos.Z, -100f, 100000f); | ||
2705 | _acceleration.X = 0; | ||
2706 | _acceleration.Y = 0; | ||
2707 | _acceleration.Z = 0; | ||
2708 | |||
2709 | _velocity.X = 0; | ||
2710 | _velocity.Y = 0; | ||
2711 | _velocity.Z = 0; | ||
2712 | m_rotationalVelocity.X = 0; | ||
2713 | m_rotationalVelocity.Y = 0; | ||
2714 | m_rotationalVelocity.Z = 0; | ||
2715 | |||
2716 | d.BodySetLinearVel(Body, 0, 0, 0); // stop it | ||
2717 | d.BodySetAngularVel(Body, 0, 0, 0); // stop it | ||
2718 | d.BodySetPosition(Body, lpos.X, lpos.Y, lpos.Z); // put it somewhere | ||
2719 | m_lastposition = _position; | ||
2720 | m_lastorientation = _orientation; | ||
2721 | |||
2722 | base.RequestPhysicsterseUpdate(); | ||
2723 | |||
2724 | m_throttleUpdates = false; | ||
2725 | throttleCounter = 0; | ||
2726 | _zeroFlag = true; | ||
2727 | |||
2728 | disableBodySoft(); // disable it and colisions | ||
2729 | base.RaiseOutOfBounds(_position); | ||
2730 | return; | ||
2731 | } | ||
2732 | |||
2733 | if (lpos.X < 0f) | ||
2734 | { | ||
2735 | _position.X = Util.Clip(lpos.X, -2f, -0.1f); | ||
2736 | m_outbounds = true; | ||
2737 | } | ||
2738 | else if(lpos.X > _parent_scene.WorldExtents.X) | ||
2739 | { | ||
2740 | _position.X = Util.Clip(lpos.X, _parent_scene.WorldExtents.X + 0.1f, _parent_scene.WorldExtents.X + 2f); | ||
2741 | m_outbounds = true; | ||
2742 | } | ||
2743 | if (lpos.Y < 0f) | ||
2744 | { | ||
2745 | _position.Y = Util.Clip(lpos.Y, -2f, -0.1f); | ||
2746 | m_outbounds = true; | ||
2747 | } | ||
2748 | else if(lpos.Y > _parent_scene.WorldExtents.Y) | ||
2749 | { | ||
2750 | _position.Y = Util.Clip(lpos.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f); | ||
2751 | m_outbounds = true; | ||
2752 | } | ||
2753 | |||
2754 | if(m_outbounds) | ||
2755 | { | ||
2756 | m_lastposition = _position; | ||
2757 | m_lastorientation = _orientation; | ||
2758 | |||
2759 | d.Vector3 dtmp = d.BodyGetAngularVel(Body); | ||
2760 | m_rotationalVelocity.X = dtmp.X; | ||
2761 | m_rotationalVelocity.Y = dtmp.Y; | ||
2762 | m_rotationalVelocity.Z = dtmp.Z; | ||
2763 | |||
2764 | dtmp = d.BodyGetLinearVel(Body); | ||
2765 | _velocity.X = dtmp.X; | ||
2766 | _velocity.Y = dtmp.Y; | ||
2767 | _velocity.Z = dtmp.Z; | ||
2768 | |||
2769 | d.BodySetLinearVel(Body, 0, 0, 0); // stop it | ||
2770 | d.BodySetAngularVel(Body, 0, 0, 0); | ||
2771 | d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); | ||
2772 | disableBodySoft(); // stop collisions | ||
2773 | base.RequestPhysicsterseUpdate(); | ||
2774 | return; | ||
2775 | } | ||
2776 | |||
2777 | |||
2657 | float fx = 0; | 2778 | float fx = 0; |
2658 | float fy = 0; | 2779 | float fy = 0; |
2659 | float fz = 0; | 2780 | float fz = 0; |
@@ -2862,7 +2983,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2862 | public void UpdatePositionAndVelocity(float simulatedtime) | 2983 | public void UpdatePositionAndVelocity(float simulatedtime) |
2863 | { | 2984 | { |
2864 | // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! | 2985 | // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! |
2865 | if (_parent == null && !m_disabled && !m_building) | 2986 | if (_parent == null && !m_disabled && !m_building && !m_outbounds) |
2866 | { | 2987 | { |
2867 | if (Body != IntPtr.Zero) | 2988 | if (Body != IntPtr.Zero) |
2868 | { | 2989 | { |
@@ -2872,64 +2993,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2872 | d.Vector3 lpos; | 2993 | d.Vector3 lpos; |
2873 | d.GeomCopyPosition(prim_geom, out lpos); // root position that is seem by rest of simulator | 2994 | d.GeomCopyPosition(prim_geom, out lpos); // root position that is seem by rest of simulator |
2874 | 2995 | ||
2875 | // we need to use root position since that's all the rest of scene uses | ||
2876 | if (lpos.X < 0f || lpos.X > _parent_scene.WorldExtents.X | ||
2877 | || lpos.Y < 0f || lpos.Y > _parent_scene.WorldExtents.Y | ||
2878 | ) | ||
2879 | { | ||
2880 | // we are outside current region | ||
2881 | // we can't let it keeping moving and having colisions | ||
2882 | // since it can be stucked between something like terrain and edge | ||
2883 | // so lets stop and disable it until something else kicks it | ||
2884 | |||
2885 | _position.X = Util.Clip(lpos.X, -0.2f, _parent_scene.WorldExtents.X + 0.2f); | ||
2886 | _position.Y = Util.Clip(lpos.Y, -0.2f, _parent_scene.WorldExtents.Y + 0.2f); | ||
2887 | _position.Z = Util.Clip(lpos.Z, -100f, 50000f); | ||
2888 | |||
2889 | m_lastposition = _position; | ||
2890 | // m_lastorientation = _orientation; | ||
2891 | |||
2892 | d.BodySetLinearVel(Body, 0, 0, 0); // stop it | ||
2893 | // d.BodySetAngularVel(Body, 0, 0, 0); | ||
2894 | d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); | ||
2895 | disableBodySoft(); // stop collisions | ||
2896 | m_outbounds = true; | ||
2897 | base.RequestPhysicsterseUpdate(); | ||
2898 | return; | ||
2899 | } | ||
2900 | |||
2901 | if (lpos.Z < -100 || lpos.Z > 100000f) | ||
2902 | { | ||
2903 | lpos.Z = Util.Clip(lpos.Z, -100f, 50000f); | ||
2904 | |||
2905 | _acceleration.X = 0; | ||
2906 | _acceleration.Y = 0; | ||
2907 | _acceleration.Z = 0; | ||
2908 | |||
2909 | _velocity.X = 0; | ||
2910 | _velocity.Y = 0; | ||
2911 | _velocity.Z = 0; | ||
2912 | m_rotationalVelocity.X = 0; | ||
2913 | m_rotationalVelocity.Y = 0; | ||
2914 | m_rotationalVelocity.Z = 0; | ||
2915 | |||
2916 | d.BodySetLinearVel(Body, 0, 0, 0); // stop it | ||
2917 | d.BodySetAngularVel(Body, 0, 0, 0); // stop it | ||
2918 | d.BodySetPosition(Body, lpos.X, lpos.Y, lpos.Z); // put it somewhere | ||
2919 | m_lastposition = _position; | ||
2920 | m_lastorientation = _orientation; | ||
2921 | |||
2922 | base.RequestPhysicsterseUpdate(); | ||
2923 | |||
2924 | m_throttleUpdates = false; | ||
2925 | throttleCounter = 0; | ||
2926 | _zeroFlag = true; | ||
2927 | |||
2928 | disableBodySoft(); // disable it and colisions | ||
2929 | base.RaiseOutOfBounds(_position); | ||
2930 | |||
2931 | return; | ||
2932 | } | ||
2933 | 2996 | ||
2934 | d.Quaternion ori; | 2997 | d.Quaternion ori; |
2935 | d.GeomCopyQuaternion(prim_geom, out ori); | 2998 | d.GeomCopyQuaternion(prim_geom, out ori); |