diff options
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | 218 |
1 files changed, 140 insertions, 78 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs index 0ccdbc0..db07565 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; |
@@ -185,7 +187,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
185 | public ODEDynamics m_vehicle; | 187 | public ODEDynamics m_vehicle; |
186 | 188 | ||
187 | internal int m_material = (int)Material.Wood; | 189 | internal int m_material = (int)Material.Wood; |
188 | protected ContactData primContactData = new ContactData { mu = 0f, bounce = 0.1f }; | 190 | private float mu; |
191 | private float bounce; | ||
189 | 192 | ||
190 | /// <summary> | 193 | /// <summary> |
191 | /// Is this prim subject to physics? Even if not, it's still solid for collision purposes. | 194 | /// Is this prim subject to physics? Even if not, it's still solid for collision purposes. |
@@ -216,13 +219,23 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
216 | } | 219 | } |
217 | } | 220 | } |
218 | 221 | ||
219 | public override ContactData ContactData | 222 | public override void getContactData(ref ContactData cdata) |
220 | { | 223 | { |
221 | get | 224 | cdata.mu = mu; |
225 | cdata.bounce = bounce; | ||
226 | |||
227 | if (m_isphysical) | ||
222 | { | 228 | { |
223 | return primContactData; | 229 | ODEDynamics veh; |
230 | if (_parent != null) | ||
231 | veh = ((OdePrim)_parent).m_vehicle; | ||
232 | else | ||
233 | veh = m_vehicle; | ||
234 | |||
235 | if (veh != null && veh.Type != Vehicle.TYPE_NONE) | ||
236 | cdata.mu *= veh.FrictionFactor; | ||
224 | } | 237 | } |
225 | } | 238 | } |
226 | 239 | ||
227 | public override int PhysicsActorType | 240 | public override int PhysicsActorType |
228 | { | 241 | { |
@@ -453,8 +466,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
453 | { | 466 | { |
454 | get | 467 | get |
455 | { | 468 | { |
456 | // Averate previous velocity with the new one so | ||
457 | // client object interpolation works a 'little' better | ||
458 | if (_zeroFlag) | 469 | if (_zeroFlag) |
459 | return Vector3.Zero; | 470 | return Vector3.Zero; |
460 | return _velocity; | 471 | return _velocity; |
@@ -733,8 +744,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
733 | public override void SetMaterial(int pMaterial) | 744 | public override void SetMaterial(int pMaterial) |
734 | { | 745 | { |
735 | m_material = pMaterial; | 746 | m_material = pMaterial; |
736 | primContactData.mu = _parent_scene.m_materialContactsData[pMaterial].mu; | 747 | mu = _parent_scene.m_materialContactsData[pMaterial].mu; |
737 | primContactData.bounce = _parent_scene.m_materialContactsData[pMaterial].bounce; | 748 | bounce = _parent_scene.m_materialContactsData[pMaterial].bounce; |
738 | } | 749 | } |
739 | 750 | ||
740 | public void setPrimForRemoval() | 751 | public void setPrimForRemoval() |
@@ -833,6 +844,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
833 | body_autodisable_frames = parent_scene.bodyFramesAutoDisable; | 844 | body_autodisable_frames = parent_scene.bodyFramesAutoDisable; |
834 | 845 | ||
835 | prim_geom = IntPtr.Zero; | 846 | prim_geom = IntPtr.Zero; |
847 | collide_geom = IntPtr.Zero; | ||
836 | Body = IntPtr.Zero; | 848 | Body = IntPtr.Zero; |
837 | 849 | ||
838 | if (!size.IsFinite()) | 850 | if (!size.IsFinite()) |
@@ -886,8 +898,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
886 | m_isSelected = false; | 898 | m_isSelected = false; |
887 | m_delaySelect = false; | 899 | m_delaySelect = false; |
888 | 900 | ||
889 | primContactData.mu = parent_scene.m_materialContactsData[(int)Material.Wood].mu; | 901 | mu = parent_scene.m_materialContactsData[(int)Material.Wood].mu; |
890 | primContactData.bounce = parent_scene.m_materialContactsData[(int)Material.Wood].bounce; | 902 | bounce = parent_scene.m_materialContactsData[(int)Material.Wood].bounce; |
891 | 903 | ||
892 | CalcPrimBodyData(); | 904 | CalcPrimBodyData(); |
893 | 905 | ||
@@ -1367,7 +1379,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1367 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); | 1379 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); |
1368 | m_collisionscore = 0; | 1380 | m_collisionscore = 0; |
1369 | 1381 | ||
1370 | if (m_targetSpace != _parent_scene.ActiveSpace) | 1382 | // if (m_targetSpace != _parent_scene.ActiveSpace) |
1371 | { | 1383 | { |
1372 | if (m_targetSpace != IntPtr.Zero) | 1384 | if (m_targetSpace != IntPtr.Zero) |
1373 | { | 1385 | { |
@@ -1376,9 +1388,26 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1376 | d.SpaceRemove(m_targetSpace, prim_geom); | 1388 | d.SpaceRemove(m_targetSpace, prim_geom); |
1377 | } | 1389 | } |
1378 | 1390 | ||
1391 | // m_targetSpace = _parent_scene.ActiveSpace; | ||
1392 | // d.SpaceAdd(m_targetSpace, prim_geom); | ||
1393 | } | ||
1394 | |||
1395 | |||
1396 | if (childrenPrim.Count == 0) | ||
1397 | { | ||
1398 | collide_geom = prim_geom; | ||
1379 | m_targetSpace = _parent_scene.ActiveSpace; | 1399 | m_targetSpace = _parent_scene.ActiveSpace; |
1380 | d.SpaceAdd(m_targetSpace, prim_geom); | 1400 | d.SpaceAdd(m_targetSpace, prim_geom); |
1381 | } | 1401 | } |
1402 | else | ||
1403 | { | ||
1404 | m_targetSpace = d.HashSpaceCreate(_parent_scene.ActiveSpace); | ||
1405 | d.HashSpaceSetLevels(m_targetSpace, -2, 8); | ||
1406 | d.SpaceSetSublevel(m_targetSpace, 3); | ||
1407 | d.SpaceSetCleanup(m_targetSpace, false); | ||
1408 | d.SpaceAdd(m_targetSpace, prim_geom); | ||
1409 | collide_geom = m_targetSpace; | ||
1410 | } | ||
1382 | 1411 | ||
1383 | lock (childrenPrim) | 1412 | lock (childrenPrim) |
1384 | { | 1413 | { |
@@ -1396,15 +1425,15 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1396 | d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); | 1425 | d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); |
1397 | prm.m_collisionscore = 0; | 1426 | prm.m_collisionscore = 0; |
1398 | 1427 | ||
1399 | if (prm.m_targetSpace != _parent_scene.ActiveSpace) | 1428 | if (prm.m_targetSpace != m_targetSpace) |
1400 | { | 1429 | { |
1401 | if (prm.m_targetSpace != IntPtr.Zero) | 1430 | if (prm.m_targetSpace != IntPtr.Zero) |
1402 | { | 1431 | { |
1403 | _parent_scene.waitForSpaceUnlock(m_targetSpace); | 1432 | _parent_scene.waitForSpaceUnlock(prm.m_targetSpace); |
1404 | if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom)) | 1433 | if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom)) |
1405 | d.SpaceRemove(prm.m_targetSpace, prm.prim_geom); | 1434 | d.SpaceRemove(prm.m_targetSpace, prm.prim_geom); |
1406 | } | 1435 | } |
1407 | prm.m_targetSpace = _parent_scene.ActiveSpace; | 1436 | prm.m_targetSpace = m_targetSpace; |
1408 | d.SpaceAdd(m_targetSpace, prm.prim_geom); | 1437 | d.SpaceAdd(m_targetSpace, prm.prim_geom); |
1409 | } | 1438 | } |
1410 | 1439 | ||
@@ -1427,8 +1456,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1427 | d.GeomDisable(prim_geom); | 1456 | d.GeomDisable(prim_geom); |
1428 | d.BodyDisable(Body); | 1457 | d.BodyDisable(Body); |
1429 | } | 1458 | } |
1459 | else | ||
1460 | { | ||
1461 | d.BodySetAngularVel(Body, m_rotationalVelocity.X, m_rotationalVelocity.Y, m_rotationalVelocity.Z); | ||
1462 | d.BodySetLinearVel(Body, _velocity.X, _velocity.Y, _velocity.Z); | ||
1463 | } | ||
1430 | 1464 | ||
1431 | _parent_scene.addActivePrim(this); | 1465 | _parent_scene.addActivePrim(this); |
1466 | _parent_scene.addActiveGroups(this); | ||
1432 | } | 1467 | } |
1433 | 1468 | ||
1434 | private void DestroyBody() | 1469 | private void DestroyBody() |
@@ -1473,6 +1508,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1473 | d.JointDestroy(Amotor); | 1508 | d.JointDestroy(Amotor); |
1474 | Amotor = IntPtr.Zero; | 1509 | Amotor = IntPtr.Zero; |
1475 | } | 1510 | } |
1511 | _parent_scene.remActiveGroup(this); | ||
1476 | d.BodyDestroy(Body); | 1512 | d.BodyDestroy(Body); |
1477 | } | 1513 | } |
1478 | Body = IntPtr.Zero; | 1514 | Body = IntPtr.Zero; |
@@ -2390,8 +2426,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2390 | else | 2426 | else |
2391 | */ | 2427 | */ |
2392 | DestroyBody(); | 2428 | DestroyBody(); |
2393 | Stop(); | ||
2394 | } | 2429 | } |
2430 | Stop(); | ||
2395 | } | 2431 | } |
2396 | } | 2432 | } |
2397 | 2433 | ||
@@ -2576,7 +2612,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2576 | if ((bool)newbuilding) | 2612 | if ((bool)newbuilding) |
2577 | { | 2613 | { |
2578 | m_building = true; | 2614 | m_building = true; |
2579 | DestroyBody(); | 2615 | if (!childPrim) |
2616 | DestroyBody(); | ||
2580 | } | 2617 | } |
2581 | else | 2618 | else |
2582 | { | 2619 | { |
@@ -2648,12 +2685,95 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2648 | public void Move() | 2685 | public void Move() |
2649 | { | 2686 | { |
2650 | if (!childPrim && m_isphysical && Body != IntPtr.Zero && | 2687 | if (!childPrim && m_isphysical && Body != IntPtr.Zero && |
2651 | !m_disabled && !m_isSelected && d.BodyIsEnabled(Body) && !m_building) // KF: Only move root prims. | 2688 | !m_disabled && !m_isSelected && d.BodyIsEnabled(Body) && !m_building && !m_outbounds) |
2689 | // !m_disabled && !m_isSelected && !m_building && !m_outbounds) | ||
2652 | { | 2690 | { |
2653 | // if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body); // KF add 161009 | 2691 | // if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body); // KF add 161009 |
2654 | 2692 | ||
2655 | float timestep = _parent_scene.ODE_STEPSIZE; | 2693 | float timestep = _parent_scene.ODE_STEPSIZE; |
2656 | 2694 | ||
2695 | // check outside region | ||
2696 | d.Vector3 lpos; | ||
2697 | d.GeomCopyPosition(prim_geom, out lpos); // root position that is seem by rest of simulator | ||
2698 | |||
2699 | if (lpos.Z < -100 || lpos.Z > 100000f) | ||
2700 | { | ||
2701 | m_outbounds = true; | ||
2702 | |||
2703 | lpos.Z = Util.Clip(lpos.Z, -100f, 100000f); | ||
2704 | _acceleration.X = 0; | ||
2705 | _acceleration.Y = 0; | ||
2706 | _acceleration.Z = 0; | ||
2707 | |||
2708 | _velocity.X = 0; | ||
2709 | _velocity.Y = 0; | ||
2710 | _velocity.Z = 0; | ||
2711 | m_rotationalVelocity.X = 0; | ||
2712 | m_rotationalVelocity.Y = 0; | ||
2713 | m_rotationalVelocity.Z = 0; | ||
2714 | |||
2715 | d.BodySetLinearVel(Body, 0, 0, 0); // stop it | ||
2716 | d.BodySetAngularVel(Body, 0, 0, 0); // stop it | ||
2717 | d.BodySetPosition(Body, lpos.X, lpos.Y, lpos.Z); // put it somewhere | ||
2718 | m_lastposition = _position; | ||
2719 | m_lastorientation = _orientation; | ||
2720 | |||
2721 | base.RequestPhysicsterseUpdate(); | ||
2722 | |||
2723 | m_throttleUpdates = false; | ||
2724 | throttleCounter = 0; | ||
2725 | _zeroFlag = true; | ||
2726 | |||
2727 | disableBodySoft(); // disable it and colisions | ||
2728 | base.RaiseOutOfBounds(_position); | ||
2729 | return; | ||
2730 | } | ||
2731 | |||
2732 | if (lpos.X < 0f) | ||
2733 | { | ||
2734 | _position.X = Util.Clip(lpos.X, -2f, -0.1f); | ||
2735 | m_outbounds = true; | ||
2736 | } | ||
2737 | else if(lpos.X > _parent_scene.WorldExtents.X) | ||
2738 | { | ||
2739 | _position.X = Util.Clip(lpos.X, _parent_scene.WorldExtents.X + 0.1f, _parent_scene.WorldExtents.X + 2f); | ||
2740 | m_outbounds = true; | ||
2741 | } | ||
2742 | if (lpos.Y < 0f) | ||
2743 | { | ||
2744 | _position.Y = Util.Clip(lpos.Y, -2f, -0.1f); | ||
2745 | m_outbounds = true; | ||
2746 | } | ||
2747 | else if(lpos.Y > _parent_scene.WorldExtents.Y) | ||
2748 | { | ||
2749 | _position.Y = Util.Clip(lpos.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f); | ||
2750 | m_outbounds = true; | ||
2751 | } | ||
2752 | |||
2753 | if(m_outbounds) | ||
2754 | { | ||
2755 | m_lastposition = _position; | ||
2756 | m_lastorientation = _orientation; | ||
2757 | |||
2758 | d.Vector3 dtmp = d.BodyGetAngularVel(Body); | ||
2759 | m_rotationalVelocity.X = dtmp.X; | ||
2760 | m_rotationalVelocity.Y = dtmp.Y; | ||
2761 | m_rotationalVelocity.Z = dtmp.Z; | ||
2762 | |||
2763 | dtmp = d.BodyGetLinearVel(Body); | ||
2764 | _velocity.X = dtmp.X; | ||
2765 | _velocity.Y = dtmp.Y; | ||
2766 | _velocity.Z = dtmp.Z; | ||
2767 | |||
2768 | d.BodySetLinearVel(Body, 0, 0, 0); // stop it | ||
2769 | d.BodySetAngularVel(Body, 0, 0, 0); | ||
2770 | d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); | ||
2771 | disableBodySoft(); // stop collisions | ||
2772 | base.RequestPhysicsterseUpdate(); | ||
2773 | return; | ||
2774 | } | ||
2775 | |||
2776 | |||
2657 | float fx = 0; | 2777 | float fx = 0; |
2658 | float fy = 0; | 2778 | float fy = 0; |
2659 | float fz = 0; | 2779 | float fz = 0; |
@@ -2862,7 +2982,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2862 | public void UpdatePositionAndVelocity(float simulatedtime) | 2982 | public void UpdatePositionAndVelocity(float simulatedtime) |
2863 | { | 2983 | { |
2864 | // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! | 2984 | // 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) | 2985 | if (_parent == null && !m_disabled && !m_building && !m_outbounds) |
2866 | { | 2986 | { |
2867 | if (Body != IntPtr.Zero) | 2987 | if (Body != IntPtr.Zero) |
2868 | { | 2988 | { |
@@ -2872,64 +2992,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2872 | d.Vector3 lpos; | 2992 | d.Vector3 lpos; |
2873 | d.GeomCopyPosition(prim_geom, out lpos); // root position that is seem by rest of simulator | 2993 | d.GeomCopyPosition(prim_geom, out lpos); // root position that is seem by rest of simulator |
2874 | 2994 | ||
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 | 2995 | ||
2934 | d.Quaternion ori; | 2996 | d.Quaternion ori; |
2935 | d.GeomCopyQuaternion(prim_geom, out ori); | 2997 | d.GeomCopyQuaternion(prim_geom, out ori); |