diff options
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | 189 |
1 files changed, 120 insertions, 69 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs index 0ccdbc0..17f38e8 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; |
@@ -453,8 +455,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
453 | { | 455 | { |
454 | get | 456 | get |
455 | { | 457 | { |
456 | // Averate previous velocity with the new one so | ||
457 | // client object interpolation works a 'little' better | ||
458 | if (_zeroFlag) | 458 | if (_zeroFlag) |
459 | return Vector3.Zero; | 459 | return Vector3.Zero; |
460 | return _velocity; | 460 | return _velocity; |
@@ -833,6 +833,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
833 | body_autodisable_frames = parent_scene.bodyFramesAutoDisable; | 833 | body_autodisable_frames = parent_scene.bodyFramesAutoDisable; |
834 | 834 | ||
835 | prim_geom = IntPtr.Zero; | 835 | prim_geom = IntPtr.Zero; |
836 | collide_geom = IntPtr.Zero; | ||
836 | Body = IntPtr.Zero; | 837 | Body = IntPtr.Zero; |
837 | 838 | ||
838 | if (!size.IsFinite()) | 839 | if (!size.IsFinite()) |
@@ -1367,7 +1368,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1367 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); | 1368 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); |
1368 | m_collisionscore = 0; | 1369 | m_collisionscore = 0; |
1369 | 1370 | ||
1370 | if (m_targetSpace != _parent_scene.ActiveSpace) | 1371 | // if (m_targetSpace != _parent_scene.ActiveSpace) |
1371 | { | 1372 | { |
1372 | if (m_targetSpace != IntPtr.Zero) | 1373 | if (m_targetSpace != IntPtr.Zero) |
1373 | { | 1374 | { |
@@ -1376,9 +1377,26 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1376 | d.SpaceRemove(m_targetSpace, prim_geom); | 1377 | d.SpaceRemove(m_targetSpace, prim_geom); |
1377 | } | 1378 | } |
1378 | 1379 | ||
1380 | // m_targetSpace = _parent_scene.ActiveSpace; | ||
1381 | // d.SpaceAdd(m_targetSpace, prim_geom); | ||
1382 | } | ||
1383 | |||
1384 | |||
1385 | if (childrenPrim.Count == 0) | ||
1386 | { | ||
1387 | collide_geom = prim_geom; | ||
1379 | m_targetSpace = _parent_scene.ActiveSpace; | 1388 | m_targetSpace = _parent_scene.ActiveSpace; |
1380 | d.SpaceAdd(m_targetSpace, prim_geom); | 1389 | d.SpaceAdd(m_targetSpace, prim_geom); |
1381 | } | 1390 | } |
1391 | else | ||
1392 | { | ||
1393 | m_targetSpace = d.HashSpaceCreate(_parent_scene.ActiveSpace); | ||
1394 | d.HashSpaceSetLevels(m_targetSpace, -2, 8); | ||
1395 | d.SpaceSetSublevel(m_targetSpace, 3); | ||
1396 | d.SpaceSetCleanup(m_targetSpace, false); | ||
1397 | d.SpaceAdd(m_targetSpace, prim_geom); | ||
1398 | collide_geom = m_targetSpace; | ||
1399 | } | ||
1382 | 1400 | ||
1383 | lock (childrenPrim) | 1401 | lock (childrenPrim) |
1384 | { | 1402 | { |
@@ -1396,15 +1414,15 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1396 | d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); | 1414 | d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); |
1397 | prm.m_collisionscore = 0; | 1415 | prm.m_collisionscore = 0; |
1398 | 1416 | ||
1399 | if (prm.m_targetSpace != _parent_scene.ActiveSpace) | 1417 | if (prm.m_targetSpace != m_targetSpace) |
1400 | { | 1418 | { |
1401 | if (prm.m_targetSpace != IntPtr.Zero) | 1419 | if (prm.m_targetSpace != IntPtr.Zero) |
1402 | { | 1420 | { |
1403 | _parent_scene.waitForSpaceUnlock(m_targetSpace); | 1421 | _parent_scene.waitForSpaceUnlock(prm.m_targetSpace); |
1404 | if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom)) | 1422 | if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom)) |
1405 | d.SpaceRemove(prm.m_targetSpace, prm.prim_geom); | 1423 | d.SpaceRemove(prm.m_targetSpace, prm.prim_geom); |
1406 | } | 1424 | } |
1407 | prm.m_targetSpace = _parent_scene.ActiveSpace; | 1425 | prm.m_targetSpace = m_targetSpace; |
1408 | d.SpaceAdd(m_targetSpace, prm.prim_geom); | 1426 | d.SpaceAdd(m_targetSpace, prm.prim_geom); |
1409 | } | 1427 | } |
1410 | 1428 | ||
@@ -1427,8 +1445,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1427 | d.GeomDisable(prim_geom); | 1445 | d.GeomDisable(prim_geom); |
1428 | d.BodyDisable(Body); | 1446 | d.BodyDisable(Body); |
1429 | } | 1447 | } |
1448 | else | ||
1449 | { | ||
1450 | d.BodySetAngularVel(Body, m_rotationalVelocity.X, m_rotationalVelocity.Y, m_rotationalVelocity.Z); | ||
1451 | d.BodySetLinearVel(Body, _velocity.X, _velocity.Y, _velocity.Z); | ||
1452 | } | ||
1430 | 1453 | ||
1431 | _parent_scene.addActivePrim(this); | 1454 | _parent_scene.addActivePrim(this); |
1455 | _parent_scene.addActiveGroups(this); | ||
1432 | } | 1456 | } |
1433 | 1457 | ||
1434 | private void DestroyBody() | 1458 | private void DestroyBody() |
@@ -1473,6 +1497,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1473 | d.JointDestroy(Amotor); | 1497 | d.JointDestroy(Amotor); |
1474 | Amotor = IntPtr.Zero; | 1498 | Amotor = IntPtr.Zero; |
1475 | } | 1499 | } |
1500 | _parent_scene.remActiveGroup(this); | ||
1476 | d.BodyDestroy(Body); | 1501 | d.BodyDestroy(Body); |
1477 | } | 1502 | } |
1478 | Body = IntPtr.Zero; | 1503 | Body = IntPtr.Zero; |
@@ -2390,8 +2415,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2390 | else | 2415 | else |
2391 | */ | 2416 | */ |
2392 | DestroyBody(); | 2417 | DestroyBody(); |
2393 | Stop(); | ||
2394 | } | 2418 | } |
2419 | Stop(); | ||
2395 | } | 2420 | } |
2396 | } | 2421 | } |
2397 | 2422 | ||
@@ -2576,7 +2601,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2576 | if ((bool)newbuilding) | 2601 | if ((bool)newbuilding) |
2577 | { | 2602 | { |
2578 | m_building = true; | 2603 | m_building = true; |
2579 | DestroyBody(); | 2604 | if (!childPrim) |
2605 | DestroyBody(); | ||
2580 | } | 2606 | } |
2581 | else | 2607 | else |
2582 | { | 2608 | { |
@@ -2648,12 +2674,95 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2648 | public void Move() | 2674 | public void Move() |
2649 | { | 2675 | { |
2650 | if (!childPrim && m_isphysical && Body != IntPtr.Zero && | 2676 | if (!childPrim && m_isphysical && Body != IntPtr.Zero && |
2651 | !m_disabled && !m_isSelected && d.BodyIsEnabled(Body) && !m_building) // KF: Only move root prims. | 2677 | !m_disabled && !m_isSelected && d.BodyIsEnabled(Body) && !m_building && !m_outbounds) |
2678 | // !m_disabled && !m_isSelected && !m_building && !m_outbounds) | ||
2652 | { | 2679 | { |
2653 | // if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body); // KF add 161009 | 2680 | // if (!d.BodyIsEnabled(Body)) d.BodyEnable(Body); // KF add 161009 |
2654 | 2681 | ||
2655 | float timestep = _parent_scene.ODE_STEPSIZE; | 2682 | float timestep = _parent_scene.ODE_STEPSIZE; |
2656 | 2683 | ||
2684 | // check outside region | ||
2685 | d.Vector3 lpos; | ||
2686 | d.GeomCopyPosition(prim_geom, out lpos); // root position that is seem by rest of simulator | ||
2687 | |||
2688 | if (lpos.Z < -100 || lpos.Z > 100000f) | ||
2689 | { | ||
2690 | m_outbounds = true; | ||
2691 | |||
2692 | lpos.Z = Util.Clip(lpos.Z, -100f, 100000f); | ||
2693 | _acceleration.X = 0; | ||
2694 | _acceleration.Y = 0; | ||
2695 | _acceleration.Z = 0; | ||
2696 | |||
2697 | _velocity.X = 0; | ||
2698 | _velocity.Y = 0; | ||
2699 | _velocity.Z = 0; | ||
2700 | m_rotationalVelocity.X = 0; | ||
2701 | m_rotationalVelocity.Y = 0; | ||
2702 | m_rotationalVelocity.Z = 0; | ||
2703 | |||
2704 | d.BodySetLinearVel(Body, 0, 0, 0); // stop it | ||
2705 | d.BodySetAngularVel(Body, 0, 0, 0); // stop it | ||
2706 | d.BodySetPosition(Body, lpos.X, lpos.Y, lpos.Z); // put it somewhere | ||
2707 | m_lastposition = _position; | ||
2708 | m_lastorientation = _orientation; | ||
2709 | |||
2710 | base.RequestPhysicsterseUpdate(); | ||
2711 | |||
2712 | m_throttleUpdates = false; | ||
2713 | throttleCounter = 0; | ||
2714 | _zeroFlag = true; | ||
2715 | |||
2716 | disableBodySoft(); // disable it and colisions | ||
2717 | base.RaiseOutOfBounds(_position); | ||
2718 | return; | ||
2719 | } | ||
2720 | |||
2721 | if (lpos.X < 0f) | ||
2722 | { | ||
2723 | _position.X = Util.Clip(lpos.X, -2f, -0.1f); | ||
2724 | m_outbounds = true; | ||
2725 | } | ||
2726 | else if(lpos.X > _parent_scene.WorldExtents.X) | ||
2727 | { | ||
2728 | _position.X = Util.Clip(lpos.X, _parent_scene.WorldExtents.X + 0.1f, _parent_scene.WorldExtents.X + 2f); | ||
2729 | m_outbounds = true; | ||
2730 | } | ||
2731 | if (lpos.Y < 0f) | ||
2732 | { | ||
2733 | _position.Y = Util.Clip(lpos.Y, -2f, -0.1f); | ||
2734 | m_outbounds = true; | ||
2735 | } | ||
2736 | else if(lpos.Y > _parent_scene.WorldExtents.Y) | ||
2737 | { | ||
2738 | _position.Y = Util.Clip(lpos.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f); | ||
2739 | m_outbounds = true; | ||
2740 | } | ||
2741 | |||
2742 | if(m_outbounds) | ||
2743 | { | ||
2744 | m_lastposition = _position; | ||
2745 | m_lastorientation = _orientation; | ||
2746 | |||
2747 | d.Vector3 dtmp = d.BodyGetAngularVel(Body); | ||
2748 | m_rotationalVelocity.X = dtmp.X; | ||
2749 | m_rotationalVelocity.Y = dtmp.Y; | ||
2750 | m_rotationalVelocity.Z = dtmp.Z; | ||
2751 | |||
2752 | dtmp = d.BodyGetLinearVel(Body); | ||
2753 | _velocity.X = dtmp.X; | ||
2754 | _velocity.Y = dtmp.Y; | ||
2755 | _velocity.Z = dtmp.Z; | ||
2756 | |||
2757 | d.BodySetLinearVel(Body, 0, 0, 0); // stop it | ||
2758 | d.BodySetAngularVel(Body, 0, 0, 0); | ||
2759 | d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); | ||
2760 | disableBodySoft(); // stop collisions | ||
2761 | base.RequestPhysicsterseUpdate(); | ||
2762 | return; | ||
2763 | } | ||
2764 | |||
2765 | |||
2657 | float fx = 0; | 2766 | float fx = 0; |
2658 | float fy = 0; | 2767 | float fy = 0; |
2659 | float fz = 0; | 2768 | float fz = 0; |
@@ -2862,7 +2971,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2862 | public void UpdatePositionAndVelocity(float simulatedtime) | 2971 | public void UpdatePositionAndVelocity(float simulatedtime) |
2863 | { | 2972 | { |
2864 | // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! | 2973 | // 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) | 2974 | if (_parent == null && !m_disabled && !m_building && !m_outbounds) |
2866 | { | 2975 | { |
2867 | if (Body != IntPtr.Zero) | 2976 | if (Body != IntPtr.Zero) |
2868 | { | 2977 | { |
@@ -2872,64 +2981,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2872 | d.Vector3 lpos; | 2981 | d.Vector3 lpos; |
2873 | d.GeomCopyPosition(prim_geom, out lpos); // root position that is seem by rest of simulator | 2982 | d.GeomCopyPosition(prim_geom, out lpos); // root position that is seem by rest of simulator |
2874 | 2983 | ||
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 | 2984 | ||
2934 | d.Quaternion ori; | 2985 | d.Quaternion ori; |
2935 | d.GeomCopyQuaternion(prim_geom, out ori); | 2986 | d.GeomCopyQuaternion(prim_geom, out ori); |