diff options
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs | 202 | ||||
-rw-r--r-- | OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs | 111 |
2 files changed, 157 insertions, 156 deletions
diff --git a/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs index e8894f7..67f8af5 100644 --- a/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs | |||
@@ -180,6 +180,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
180 | internal int m_material = (int)Material.Wood; | 180 | internal int m_material = (int)Material.Wood; |
181 | 181 | ||
182 | private int frcount = 0; // Used to limit dynamics debug output to | 182 | private int frcount = 0; // Used to limit dynamics debug output to |
183 | private int revcount = 0; // Reverse motion while > 0 | ||
183 | 184 | ||
184 | private IntPtr m_body = IntPtr.Zero; | 185 | private IntPtr m_body = IntPtr.Zero; |
185 | 186 | ||
@@ -1888,22 +1889,19 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1888 | 1889 | ||
1889 | public void changemove(float timestep) | 1890 | public void changemove(float timestep) |
1890 | { | 1891 | { |
1891 | //Console.WriteLine("changemove for {0}", m_primName ); | 1892 | //Console.WriteLine("changemove sing/root {0} to {1}", m_primName, _position ); |
1892 | |||
1893 | if (m_isphysical) | 1893 | if (m_isphysical) |
1894 | { | 1894 | { |
1895 | //Console.WriteLine("phys {0} {1} {2}", m_disabled, m_taintremove, childPrim); | 1895 | //Console.WriteLine("phys {0} {1} {2}", m_disabled, m_taintremove, childPrim); |
1896 | // if (!m_disabled && !m_taintremove && !childPrim) After one edit m_disabled is sometimes set, disabling further edits! | 1896 | // if (!m_disabled && !m_taintremove && !childPrim) After one edit m_disabled is sometimes set, disabling further edits! |
1897 | if (!m_taintremove && !childPrim) | 1897 | if (!m_taintremove && !childPrim) |
1898 | { | 1898 | { |
1899 | //Console.WriteLine("physOK"); | ||
1900 | if (Body == IntPtr.Zero) | 1899 | if (Body == IntPtr.Zero) |
1901 | enableBody(); | 1900 | enableBody(); |
1902 | //Prim auto disable after 20 frames, | 1901 | //Prim auto disable after 20 frames, |
1903 | //if you move it, re-enable the prim manually. | 1902 | //if you move it, re-enable the prim manually. |
1904 | if (_parent != null) | 1903 | if (_parent != null) |
1905 | { | 1904 | { |
1906 | //Console.WriteLine("physChild"); | ||
1907 | if (m_linkJoint != IntPtr.Zero) | 1905 | if (m_linkJoint != IntPtr.Zero) |
1908 | { | 1906 | { |
1909 | d.JointDestroy(m_linkJoint); | 1907 | d.JointDestroy(m_linkJoint); |
@@ -1912,7 +1910,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1912 | } | 1910 | } |
1913 | if (Body != IntPtr.Zero) | 1911 | if (Body != IntPtr.Zero) |
1914 | { | 1912 | { |
1915 | //Console.WriteLine("physNotIPZ"); | ||
1916 | d.BodySetPosition(Body, _position.X, _position.Y, _position.Z); | 1913 | d.BodySetPosition(Body, _position.X, _position.Y, _position.Z); |
1917 | 1914 | ||
1918 | if (_parent != null) | 1915 | if (_parent != null) |
@@ -1945,7 +1942,6 @@ Console.WriteLine(" JointCreateFixed"); | |||
1945 | } | 1942 | } |
1946 | else | 1943 | else |
1947 | { | 1944 | { |
1948 | //Console.WriteLine("NONphys"); | ||
1949 | // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position); | 1945 | // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position); |
1950 | // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position); | 1946 | // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position); |
1951 | _parent_scene.waitForSpaceUnlock(m_targetSpace); | 1947 | _parent_scene.waitForSpaceUnlock(m_targetSpace); |
@@ -2382,9 +2378,7 @@ Console.WriteLine(" JointCreateFixed"); | |||
2382 | if (IsPhysical) | 2378 | if (IsPhysical) |
2383 | { | 2379 | { |
2384 | if (Body != IntPtr.Zero) | 2380 | if (Body != IntPtr.Zero) |
2385 | { | ||
2386 | d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z); | 2381 | d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z); |
2387 | } | ||
2388 | } | 2382 | } |
2389 | 2383 | ||
2390 | //resetCollisionAccounting(); | 2384 | //resetCollisionAccounting(); |
@@ -2394,31 +2388,9 @@ Console.WriteLine(" JointCreateFixed"); | |||
2394 | 2388 | ||
2395 | public void UpdatePositionAndVelocity() | 2389 | public void UpdatePositionAndVelocity() |
2396 | { | 2390 | { |
2397 | return; // moved to the Move() method | 2391 | return; // moved to the Move () method |
2398 | } | ||
2399 | /* No one uses this? | ||
2400 | public Matrix4 FromDMass(d.Mass pMass) | ||
2401 | { | ||
2402 | Matrix4 obj; | ||
2403 | obj.M11 = pMass.I.M00; | ||
2404 | obj.M12 = pMass.I.M01; | ||
2405 | obj.M13 = pMass.I.M02; | ||
2406 | obj.M14 = 0; | ||
2407 | obj.M21 = pMass.I.M10; | ||
2408 | obj.M22 = pMass.I.M11; | ||
2409 | obj.M23 = pMass.I.M12; | ||
2410 | obj.M24 = 0; | ||
2411 | obj.M31 = pMass.I.M20; | ||
2412 | obj.M32 = pMass.I.M21; | ||
2413 | obj.M33 = pMass.I.M22; | ||
2414 | obj.M34 = 0; | ||
2415 | obj.M41 = 0; | ||
2416 | obj.M42 = 0; | ||
2417 | obj.M43 = 0; | ||
2418 | obj.M44 = 1; | ||
2419 | return obj; | ||
2420 | } | 2392 | } |
2421 | */ | 2393 | |
2422 | public d.Mass FromMatrix4(Matrix4 pMat, ref d.Mass obj) | 2394 | public d.Mass FromMatrix4(Matrix4 pMat, ref d.Mass obj) |
2423 | { | 2395 | { |
2424 | obj.I.M00 = pMat[0, 0]; | 2396 | obj.I.M00 = pMat[0, 0]; |
@@ -2996,44 +2968,114 @@ Console.WriteLine(" JointCreateFixed"); | |||
2996 | float fx = 0; | 2968 | float fx = 0; |
2997 | float fy = 0; | 2969 | float fy = 0; |
2998 | float fz = 0; | 2970 | float fz = 0; |
2971 | Vector3 linvel; // velocity applied, including any reversal | ||
2972 | int outside = 0; | ||
2973 | |||
2974 | // If geomCrossingFailuresBeforeOutofbounds is set to 0 in OpenSim.ini then phys objects bounce off region borders. | ||
2975 | // This is a temp patch until proper region crossing is developed. | ||
2976 | |||
2977 | int failureLimit = _parent_scene.geomCrossingFailuresBeforeOutofbounds; | ||
2978 | int fence = _parent_scene.geomRegionFence; | ||
2979 | |||
2980 | float border_limit = 0.05f; // original limit | ||
2981 | if (fence == 1) border_limit = 0.5f; // bounce point | ||
2999 | 2982 | ||
3000 | frcount++; // used to limit debug comment output | 2983 | frcount++; // used to limit debug comment output |
3001 | if (frcount > 100) | 2984 | if (frcount > 100) |
3002 | frcount = 0; | 2985 | frcount = 0; |
3003 | 2986 | ||
3004 | if (IsPhysical && (Body != IntPtr.Zero) && !m_isSelected && !childPrim) // KF: Only move root prims. | 2987 | if(revcount > 0) revcount--; |
2988 | |||
2989 | if (IsPhysical && (Body != IntPtr.Zero) && !m_isSelected && !childPrim) // Only move root prims. | ||
3005 | { | 2990 | { |
3006 | 2991 | // Old public void UpdatePositionAndVelocity(), more accuratley calculated here | |
3007 | // Old public void UpdatePositionAndVelocity(), more accuratley calculated here | ||
3008 | bool lastZeroFlag = _zeroFlag; // was it stopped | 2992 | bool lastZeroFlag = _zeroFlag; // was it stopped |
2993 | |||
3009 | d.Vector3 vec = d.BodyGetPosition(Body); | 2994 | d.Vector3 vec = d.BodyGetPosition(Body); |
3010 | d.Quaternion ori = d.BodyGetQuaternion(Body); | ||
3011 | d.Vector3 vel = d.BodyGetLinearVel(Body); | ||
3012 | // d.Vector3 rotvel = d.BodyGetAngularVel(Body); | ||
3013 | d.Vector3 torque = d.BodyGetTorque(Body); | ||
3014 | _torque = new Vector3(torque.X, torque.Y, torque.Z); | ||
3015 | Vector3 l_position = Vector3.Zero; | 2995 | Vector3 l_position = Vector3.Zero; |
3016 | Quaternion l_orientation = Quaternion.Identity; | ||
3017 | |||
3018 | m_lastposition = _position; | ||
3019 | m_lastorientation = _orientation; | ||
3020 | |||
3021 | l_position.X = vec.X; | 2996 | l_position.X = vec.X; |
3022 | l_position.Y = vec.Y; | 2997 | l_position.Y = vec.Y; |
3023 | l_position.Z = vec.Z; | 2998 | l_position.Z = vec.Z; |
3024 | l_orientation.X = ori.X; | 2999 | m_lastposition = _position; |
3025 | l_orientation.Y = ori.Y; | 3000 | _position = l_position; |
3026 | l_orientation.Z = ori.Z; | 3001 | |
3027 | l_orientation.W = ori.W; | 3002 | d.Quaternion ori = d.BodyGetQuaternion(Body); |
3003 | // Quaternion l_orientation = Quaternion.Identity; | ||
3004 | _orientation.X = ori.X; | ||
3005 | _orientation.Y = ori.Y; | ||
3006 | _orientation.Z = ori.Z; | ||
3007 | _orientation.W = ori.W; | ||
3008 | m_lastorientation = _orientation; | ||
3009 | |||
3010 | d.Vector3 vel = d.BodyGetLinearVel(Body); | ||
3011 | m_lastVelocity = _velocity; | ||
3012 | _velocity.X = vel.X; | ||
3013 | _velocity.Y = vel.Y; | ||
3014 | _velocity.Z = vel.Z; | ||
3015 | _acceleration = ((_velocity - m_lastVelocity) / timestep); | ||
3016 | |||
3017 | d.Vector3 torque = d.BodyGetTorque(Body); | ||
3018 | _torque = new Vector3(torque.X, torque.Y, torque.Z); | ||
3019 | |||
3020 | base.RequestPhysicsterseUpdate(); | ||
3021 | |||
3028 | //Console.WriteLine("Move {0} at {1}", m_primName, l_position); | 3022 | //Console.WriteLine("Move {0} at {1}", m_primName, l_position); |
3029 | 3023 | ||
3030 | // Check if outside region horizontally | 3024 | // Check if outside region |
3031 | if (l_position.X > ((int)_parent_scene.WorldExtents.X - 0.05f) || | 3025 | // In Scene.cs/CrossPrimGroupIntoNewRegion the object is checked for 0.1M from border! |
3032 | l_position.X < 0f || | 3026 | if (l_position.X > ((float)_parent_scene.WorldExtents.X - border_limit)) |
3033 | l_position.Y > ((int)_parent_scene.WorldExtents.Y - 0.05f) || | 3027 | { |
3034 | l_position.Y < 0f) | 3028 | l_position.X = ((float)_parent_scene.WorldExtents.X - border_limit); |
3029 | outside = 1; | ||
3030 | } | ||
3031 | |||
3032 | if (l_position.X < border_limit) | ||
3033 | { | ||
3034 | l_position.X = border_limit; | ||
3035 | outside = 2; | ||
3036 | } | ||
3037 | if (l_position.Y > ((float)_parent_scene.WorldExtents.Y - border_limit)) | ||
3038 | { | ||
3039 | l_position.Y = ((float)_parent_scene.WorldExtents.Y - border_limit); | ||
3040 | outside = 3; | ||
3041 | } | ||
3042 | |||
3043 | if (l_position.Y < border_limit) | ||
3044 | { | ||
3045 | l_position.Y = border_limit; | ||
3046 | outside = 4; | ||
3047 | } | ||
3048 | |||
3049 | if (outside > 0) | ||
3035 | { | 3050 | { |
3036 | if (m_crossingfailures < _parent_scene.geomCrossingFailuresBeforeOutofbounds) | 3051 | //Console.WriteLine(" fence = {0}",fence); |
3052 | |||
3053 | //Console.WriteLine("Border {0}", l_position); | ||
3054 | if (fence == 1) // bounce object off boundary | ||
3055 | { | ||
3056 | if (revcount == 0) | ||
3057 | { | ||
3058 | if (outside < 3) | ||
3059 | { | ||
3060 | _velocity.X = -_velocity.X; | ||
3061 | } | ||
3062 | else | ||
3063 | { | ||
3064 | _velocity.Y = -_velocity.Y; | ||
3065 | } | ||
3066 | if (m_type != Vehicle.TYPE_NONE) Halt(); | ||
3067 | _position = l_position; | ||
3068 | m_taintposition = _position; | ||
3069 | m_lastVelocity = _velocity; | ||
3070 | _acceleration = Vector3.Zero; | ||
3071 | d.BodySetPosition(Body, _position.X, _position.Y, _position.Z); | ||
3072 | d.BodySetLinearVel(Body, _velocity.X, _velocity.Y, _velocity.Z); | ||
3073 | base.RequestPhysicsterseUpdate(); | ||
3074 | |||
3075 | revcount = 25; // wait for object to move away from border | ||
3076 | } | ||
3077 | } // else old crossing mode | ||
3078 | else if (m_crossingfailures < failureLimit) | ||
3037 | { // keep trying to cross? | 3079 | { // keep trying to cross? |
3038 | _position = l_position; | 3080 | _position = l_position; |
3039 | //_parent_scene.remActivePrim(this); | 3081 | //_parent_scene.remActivePrim(this); |
@@ -3043,9 +3085,12 @@ Console.WriteLine(" JointCreateFixed"); | |||
3043 | else | 3085 | else |
3044 | { // Too many tries | 3086 | { // Too many tries |
3045 | if (_parent == null) base.RaiseOutOfBounds(l_position); | 3087 | if (_parent == null) base.RaiseOutOfBounds(l_position); |
3088 | //Console.WriteLine("ROOB 2"); | ||
3089 | |||
3046 | return; // Dont process any other motion? | 3090 | return; // Dont process any other motion? |
3047 | } | 3091 | } // end various methods |
3048 | } // end outside region horizontally | 3092 | } // end outside region horizontally |
3093 | |||
3049 | 3094 | ||
3050 | if (l_position.Z < 0) | 3095 | if (l_position.Z < 0) |
3051 | { | 3096 | { |
@@ -3057,6 +3102,8 @@ Console.WriteLine(" JointCreateFixed"); | |||
3057 | 3102 | ||
3058 | //IsPhysical = false; | 3103 | //IsPhysical = false; |
3059 | if (_parent == null) base.RaiseOutOfBounds(_position); | 3104 | if (_parent == null) base.RaiseOutOfBounds(_position); |
3105 | //Console.WriteLine("ROOB 3"); | ||
3106 | |||
3060 | 3107 | ||
3061 | _acceleration.X = 0; // This stuff may stop client display but it has no | 3108 | _acceleration.X = 0; // This stuff may stop client display but it has no |
3062 | _acceleration.Y = 0; // effect on the object in phys engine! | 3109 | _acceleration.Y = 0; // effect on the object in phys engine! |
@@ -3081,10 +3128,9 @@ Console.WriteLine(" JointCreateFixed"); | |||
3081 | if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02) | 3128 | if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02) |
3082 | && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02) | 3129 | && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02) |
3083 | && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02) | 3130 | && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02) |
3084 | && (1.0 - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)) < 0.0001)) // KF 0.01 is far to large | 3131 | && (1.0 - Math.Abs(Quaternion.Dot(m_lastorientation, _orientation)) < 0.0001)) // KF 0.01 is far to large |
3085 | { | 3132 | { |
3086 | _zeroFlag = true; | 3133 | _zeroFlag = true; |
3087 | //Console.WriteLine("ZFT 2"); | ||
3088 | m_throttleUpdates = false; | 3134 | m_throttleUpdates = false; |
3089 | } | 3135 | } |
3090 | else | 3136 | else |
@@ -3104,10 +3150,7 @@ Console.WriteLine(" JointCreateFixed"); | |||
3104 | _acceleration.X = 0; | 3150 | _acceleration.X = 0; |
3105 | _acceleration.Y = 0; | 3151 | _acceleration.Y = 0; |
3106 | _acceleration.Z = 0; | 3152 | _acceleration.Z = 0; |
3107 | //_orientation.w = 0f; | 3153 | |
3108 | //_orientation.X = 0f; | ||
3109 | //_orientation.Y = 0f; | ||
3110 | //_orientation.Z = 0f; | ||
3111 | m_rotationalVelocity.X = 0; | 3154 | m_rotationalVelocity.X = 0; |
3112 | m_rotationalVelocity.Y = 0; | 3155 | m_rotationalVelocity.Y = 0; |
3113 | m_rotationalVelocity.Z = 0; | 3156 | m_rotationalVelocity.Z = 0; |
@@ -3132,26 +3175,6 @@ Console.WriteLine(" JointCreateFixed"); | |||
3132 | base.RequestPhysicsterseUpdate(); | 3175 | base.RequestPhysicsterseUpdate(); |
3133 | } | 3176 | } |
3134 | } | 3177 | } |
3135 | |||
3136 | m_lastVelocity = _velocity; | ||
3137 | |||
3138 | _position = l_position; | ||
3139 | |||
3140 | _velocity.X = vel.X; | ||
3141 | _velocity.Y = vel.Y; | ||
3142 | _velocity.Z = vel.Z; | ||
3143 | // Why 2 calcs??? | ||
3144 | // _acceleration = ((_velocity - m_lastVelocity) / 0.1f); | ||
3145 | // _acceleration = new Vector3(_velocity.X - m_lastVelocity.X / 0.1f, | ||
3146 | // _velocity.Y - m_lastVelocity.Y / 0.1f, | ||
3147 | // _velocity.Z - m_lastVelocity.Z / 0.1f); | ||
3148 | |||
3149 | _acceleration = ((_velocity - m_lastVelocity) / timestep); | ||
3150 | |||
3151 | _orientation.X = ori.X; | ||
3152 | _orientation.Y = ori.Y; | ||
3153 | _orientation.Z = ori.Z; | ||
3154 | _orientation.W = ori.W; | ||
3155 | m_lastUpdateSent = false; | 3178 | m_lastUpdateSent = false; |
3156 | if (!m_throttleUpdates || throttleCounter > _parent_scene.geomUpdatesPerThrottledUpdate) | 3179 | if (!m_throttleUpdates || throttleCounter > _parent_scene.geomUpdatesPerThrottledUpdate) |
3157 | { | 3180 | { |
@@ -3167,11 +3190,8 @@ Console.WriteLine(" JointCreateFixed"); | |||
3167 | } | 3190 | } |
3168 | m_lastposition = l_position; | 3191 | m_lastposition = l_position; |
3169 | 3192 | ||
3170 | /// End of old UpdatePositionAndVelocity insert | 3193 | /// End UpdatePositionAndVelocity insert |
3171 | 3194 | ||
3172 | //if (!Acceleration.ApproxEquals(Vector3.Zero, 0.01f)) Console.WriteLine("Move " + m_primName + " Accel=" + Acceleration); | ||
3173 | // if(frcount == 0) Console.WriteLine("Move " + m_primName + " VTyp " + m_type + | ||
3174 | // " usePID=" + m_usePID + " seHover=" + m_useHoverPID + " useAPID=" + m_useAPID); | ||
3175 | if (m_type != Vehicle.TYPE_NONE) | 3195 | if (m_type != Vehicle.TYPE_NONE) |
3176 | { | 3196 | { |
3177 | // get body attitude | 3197 | // get body attitude |
@@ -3299,11 +3319,12 @@ Console.WriteLine(" JointCreateFixed"); | |||
3299 | { // not hovering, Gravity rules | 3319 | { // not hovering, Gravity rules |
3300 | m_wLinObjectVel.Z = vel_now.Z; | 3320 | m_wLinObjectVel.Z = vel_now.Z; |
3301 | } | 3321 | } |
3302 | 3322 | linvel = m_wLinObjectVel; | |
3303 | 3323 | ||
3304 | // Vehicle Linear Motion done ======================================= | 3324 | // Vehicle Linear Motion done ======================================= |
3305 | // Apply velocity | 3325 | // Apply velocity |
3306 | d.BodySetLinearVel(Body, m_wLinObjectVel.X, m_wLinObjectVel.Y, m_wLinObjectVel.Z); | 3326 | //if(frcount == 0) Console.WriteLine("LV {0}", linvel); |
3327 | d.BodySetLinearVel(Body, linvel.X, linvel.Y, linvel.Z); | ||
3307 | // apply gravity force | 3328 | // apply gravity force |
3308 | d.BodyAddForce(Body, grav.X, grav.Y, grav.Z); | 3329 | d.BodyAddForce(Body, grav.X, grav.Y, grav.Z); |
3309 | //if(frcount == 0) Console.WriteLine("Grav {0}", grav); | 3330 | //if(frcount == 0) Console.WriteLine("Grav {0}", grav); |
@@ -3626,9 +3647,10 @@ Console.WriteLine(" JointCreateFixed"); | |||
3626 | // react to the physics scene by moving it's position. | 3647 | // react to the physics scene by moving it's position. |
3627 | // Avatar to Avatar collisions | 3648 | // Avatar to Avatar collisions |
3628 | // Prim to avatar collisions | 3649 | // Prim to avatar collisions |
3650 | d.Vector3 dlinvel = vel; | ||
3629 | 3651 | ||
3630 | d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight); | 3652 | d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight); |
3631 | d.BodySetLinearVel(Body, vel.X, vel.Y, 0); | 3653 | d.BodySetLinearVel(Body, dlinvel.X, dlinvel.Y, dlinvel.Z); |
3632 | d.BodyAddForce(Body, 0, 0, fz); | 3654 | d.BodyAddForce(Body, 0, 0, fz); |
3633 | //KF this prevents furthur motions return; | 3655 | //KF this prevents furthur motions return; |
3634 | } | 3656 | } |
diff --git a/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs index deb6164..79e2986 100644 --- a/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs | |||
@@ -224,6 +224,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
224 | public float bodyPIDG = 25; | 224 | public float bodyPIDG = 25; |
225 | 225 | ||
226 | public int geomCrossingFailuresBeforeOutofbounds = 5; | 226 | public int geomCrossingFailuresBeforeOutofbounds = 5; |
227 | public int geomRegionFence = 0; | ||
227 | 228 | ||
228 | public float bodyMotorJointMaxforceTensor = 2; | 229 | public float bodyMotorJointMaxforceTensor = 2; |
229 | 230 | ||
@@ -447,6 +448,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
447 | geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 3); | 448 | geomContactPointsStartthrottle = physicsconfig.GetInt("geom_contactpoints_start_throttling", 3); |
448 | geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15); | 449 | geomUpdatesPerThrottledUpdate = physicsconfig.GetInt("geom_updates_before_throttled_update", 15); |
449 | geomCrossingFailuresBeforeOutofbounds = physicsconfig.GetInt("geom_crossing_failures_before_outofbounds", 5); | 450 | geomCrossingFailuresBeforeOutofbounds = physicsconfig.GetInt("geom_crossing_failures_before_outofbounds", 5); |
451 | geomRegionFence = physicsconfig.GetInt("region_border_fence", 0); | ||
450 | 452 | ||
451 | geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", 10.000006836f); | 453 | geomDefaultDensity = physicsconfig.GetFloat("geometry_default_density", 10.000006836f); |
452 | bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", 20); | 454 | bodyFramesAutoDisable = physicsconfig.GetInt("body_frames_auto_disable", 20); |
@@ -3419,76 +3421,56 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3419 | 3421 | ||
3420 | public void SetTerrain(float[] heightMap, Vector3 pOffset) | 3422 | public void SetTerrain(float[] heightMap, Vector3 pOffset) |
3421 | { | 3423 | { |
3422 | // this._heightmap[i] = (double)heightMap[i]; | ||
3423 | // dbm (danx0r) -- creating a buffer zone of one extra sample all around | ||
3424 | //_origheightmap = heightMap; | ||
3425 | 3424 | ||
3425 | uint regionsize = (uint) Constants.RegionSize; // visible region size eg. 256(M) | ||
3426 | |||
3427 | uint heightmapWidth = regionsize + 1; // ODE map size 257 x 257 (Meters) (1 extra | ||
3428 | uint heightmapHeight = regionsize + 1; | ||
3429 | |||
3430 | uint heightmapWidthSamples = (uint)regionsize + 2; // Sample file size, 258 x 258 samples | ||
3431 | uint heightmapHeightSamples = (uint)regionsize + 2; | ||
3432 | |||
3433 | // Array of height samples for ODE | ||
3426 | float[] _heightmap; | 3434 | float[] _heightmap; |
3435 | _heightmap = new float[(heightmapWidthSamples * heightmapHeightSamples)]; // loaded samples 258 x 258 | ||
3427 | 3436 | ||
3428 | // zero out a heightmap array float array (single dimension [flattened])) | 3437 | // Other ODE parameters |
3429 | //if ((int)Constants.RegionSize == 256) | ||
3430 | // _heightmap = new float[514 * 514]; | ||
3431 | //else | ||
3432 | |||
3433 | _heightmap = new float[(((int)Constants.RegionSize + 2) * ((int)Constants.RegionSize + 2))]; | ||
3434 | |||
3435 | uint heightmapWidth = Constants.RegionSize + 1; | ||
3436 | uint heightmapHeight = Constants.RegionSize + 1; | ||
3437 | |||
3438 | uint heightmapWidthSamples; | ||
3439 | |||
3440 | uint heightmapHeightSamples; | ||
3441 | |||
3442 | //if (((int)Constants.RegionSize) == 256) | ||
3443 | //{ | ||
3444 | // heightmapWidthSamples = 2 * (uint)Constants.RegionSize + 2; | ||
3445 | // heightmapHeightSamples = 2 * (uint)Constants.RegionSize + 2; | ||
3446 | // heightmapWidth++; | ||
3447 | // heightmapHeight++; | ||
3448 | //} | ||
3449 | //else | ||
3450 | //{ | ||
3451 | |||
3452 | heightmapWidthSamples = (uint)Constants.RegionSize + 1; | ||
3453 | heightmapHeightSamples = (uint)Constants.RegionSize + 1; | ||
3454 | //} | ||
3455 | |||
3456 | const float scale = 1.0f; | 3438 | const float scale = 1.0f; |
3457 | const float offset = 0.0f; | 3439 | const float offset = 0.0f; |
3458 | const float thickness = 0.2f; | 3440 | const float thickness = 2.0f; // Was 0.2f, Larger appears to prevent Av fall-through |
3459 | const int wrap = 0; | 3441 | const int wrap = 0; |
3460 | 3442 | ||
3461 | int regionsize = (int) Constants.RegionSize + 2; | 3443 | float hfmin = 2000f; |
3462 | //Double resolution | 3444 | float hfmax = -2000f; |
3463 | //if (((int)Constants.RegionSize) == 256) | 3445 | float minele = 0.0f; // Dont allow -ve heights |
3464 | // heightMap = ResizeTerrain512Interpolation(heightMap); | ||
3465 | |||
3466 | |||
3467 | // if (((int)Constants.RegionSize) == 256 && (int)Constants.RegionSize == 256) | ||
3468 | // regionsize = 512; | ||
3469 | |||
3470 | float hfmin = 2000; | ||
3471 | float hfmax = -2000; | ||
3472 | 3446 | ||
3473 | for (int x = 0; x < heightmapWidthSamples; x++) | 3447 | uint x = 0; |
3448 | uint y = 0; | ||
3449 | uint xx = 0; | ||
3450 | uint yy = 0; | ||
3451 | |||
3452 | // load the height samples array from the heightMap | ||
3453 | for ( x = 0; x < heightmapWidthSamples; x++) // 0 to 257 | ||
3454 | { | ||
3455 | for ( y = 0; y < heightmapHeightSamples; y++) // 0 to 257 | ||
3474 | { | 3456 | { |
3475 | for (int y = 0; y < heightmapHeightSamples; y++) | 3457 | xx = x - 1; |
3476 | { | 3458 | if (xx < 0) xx = 0; |
3477 | int xx = Util.Clip(x - 1, 0, regionsize - 1); | 3459 | if (xx > (regionsize - 1)) xx = regionsize - 1; |
3478 | int yy = Util.Clip(y - 1, 0, regionsize - 1); | 3460 | |
3479 | 3461 | yy = y - 1; | |
3480 | 3462 | if (yy < 0) yy = 0; | |
3481 | float val= heightMap[yy * (int)Constants.RegionSize + xx]; | 3463 | if (yy > (regionsize - 1)) yy = regionsize - 1; |
3482 | _heightmap[x * ((int)Constants.RegionSize + 2) + y] = val; | 3464 | // Input xx = 0 0 1 2 ..... 254 255 255 256 total in |
3483 | 3465 | // Output x = 0 1 2 3 ..... 255 256 257 258 total out | |
3484 | hfmin = (val < hfmin) ? val : hfmin; | 3466 | float val= heightMap[(yy * regionsize) + xx]; // input from heightMap, <0-255 * 256> <0-255> |
3485 | hfmax = (val > hfmax) ? val : hfmax; | 3467 | if (val < minele) val = minele; |
3486 | } | 3468 | _heightmap[x * (regionsize + 2) + y] = val; // samples output to _heightmap, <0-257 * 258> <0-257> |
3469 | hfmin = (val < hfmin) ? val : hfmin; | ||
3470 | hfmax = (val > hfmax) ? val : hfmax; | ||
3487 | } | 3471 | } |
3472 | } | ||
3488 | 3473 | ||
3489 | |||
3490 | |||
3491 | |||
3492 | lock (OdeLock) | 3474 | lock (OdeLock) |
3493 | { | 3475 | { |
3494 | IntPtr GroundGeom = IntPtr.Zero; | 3476 | IntPtr GroundGeom = IntPtr.Zero; |
@@ -3504,19 +3486,17 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3504 | d.SpaceRemove(space, GroundGeom); | 3486 | d.SpaceRemove(space, GroundGeom); |
3505 | d.GeomDestroy(GroundGeom); | 3487 | d.GeomDestroy(GroundGeom); |
3506 | } | 3488 | } |
3507 | |||
3508 | } | 3489 | } |
3509 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); | 3490 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); |
3510 | d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0, heightmapWidth + 1, heightmapHeight + 1, | 3491 | d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmap, 0, |
3511 | (int)heightmapWidthSamples + 1, (int)heightmapHeightSamples + 1, scale, | 3492 | heightmapWidth, heightmapHeight, (int)heightmapWidthSamples, |
3512 | offset, thickness, wrap); | 3493 | (int)heightmapHeightSamples, scale, offset, thickness, wrap); |
3513 | d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); | 3494 | d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); |
3514 | GroundGeom = d.CreateHeightfield(space, HeightmapData, 1); | 3495 | GroundGeom = d.CreateHeightfield(space, HeightmapData, 1); |
3515 | if (GroundGeom != IntPtr.Zero) | 3496 | if (GroundGeom != IntPtr.Zero) |
3516 | { | 3497 | { |
3517 | d.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land)); | 3498 | d.GeomSetCategoryBits(GroundGeom, (int)(CollisionCategories.Land)); |
3518 | d.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space)); | 3499 | d.GeomSetCollideBits(GroundGeom, (int)(CollisionCategories.Space)); |
3519 | |||
3520 | } | 3500 | } |
3521 | geom_name_map[GroundGeom] = "Terrain"; | 3501 | geom_name_map[GroundGeom] = "Terrain"; |
3522 | 3502 | ||
@@ -3534,7 +3514,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3534 | 3514 | ||
3535 | d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); | 3515 | d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); |
3536 | d.GeomSetRotation(GroundGeom, ref R); | 3516 | d.GeomSetRotation(GroundGeom, ref R); |
3537 | d.GeomSetPosition(GroundGeom, (pOffset.X + ((int)Constants.RegionSize * 0.5f)) - 1, (pOffset.Y + ((int)Constants.RegionSize * 0.5f)) - 1, 0); | 3517 | d.GeomSetPosition(GroundGeom, (pOffset.X + (regionsize * 0.5f)) - 0.5f, (pOffset.Y + (regionsize * 0.5f)) - 0.5f, 0); |
3538 | IntPtr testGround = IntPtr.Zero; | 3518 | IntPtr testGround = IntPtr.Zero; |
3539 | if (RegionTerrain.TryGetValue(pOffset, out testGround)) | 3519 | if (RegionTerrain.TryGetValue(pOffset, out testGround)) |
3540 | { | 3520 | { |
@@ -3542,7 +3522,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3542 | } | 3522 | } |
3543 | RegionTerrain.Add(pOffset, GroundGeom, GroundGeom); | 3523 | RegionTerrain.Add(pOffset, GroundGeom, GroundGeom); |
3544 | TerrainHeightFieldHeights.Add(GroundGeom,_heightmap); | 3524 | TerrainHeightFieldHeights.Add(GroundGeom,_heightmap); |
3545 | |||
3546 | } | 3525 | } |
3547 | } | 3526 | } |
3548 | 3527 | ||