improve old ODE prim region borders

avinationmerge
UbitUmarov 2015-09-07 13:27:13 +01:00
parent 7276a89ddd
commit 2a84ef861a
1 changed files with 84 additions and 37 deletions

View File

@ -1691,6 +1691,9 @@ Console.WriteLine(" JointCreateFixed");
float fy = 0; float fy = 0;
float fz = 0; float fz = 0;
if (outofBounds)
return;
if (IsPhysical && (Body != IntPtr.Zero) && !m_isSelected && !childPrim) // KF: Only move root prims. if (IsPhysical && (Body != IntPtr.Zero) && !m_isSelected && !childPrim) // KF: Only move root prims.
{ {
if (m_vehicle.Type != Vehicle.TYPE_NONE) if (m_vehicle.Type != Vehicle.TYPE_NONE)
@ -2664,6 +2667,7 @@ Console.WriteLine(" JointCreateFixed");
public override void CrossingFailure() public override void CrossingFailure()
{ {
/*
m_crossingfailures++; m_crossingfailures++;
if (m_crossingfailures > _parent_scene.geomCrossingFailuresBeforeOutofbounds) if (m_crossingfailures > _parent_scene.geomCrossingFailuresBeforeOutofbounds)
{ {
@ -2674,6 +2678,27 @@ Console.WriteLine(" JointCreateFixed");
{ {
m_log.Warn("[PHYSICS]: Too many crossing failures for: " + Name); m_log.Warn("[PHYSICS]: Too many crossing failures for: " + Name);
} }
*/
_position.X = Util.Clip(_position.X, 0.5f, _parent_scene.WorldExtents.X - 0.5f);
_position.Y = Util.Clip(_position.Y, 0.5f, _parent_scene.WorldExtents.Y - 0.5f);
_position.Z = Util.Clip(_position.Z + 0.2f, -100f, 50000f);
m_lastposition = _position;
_velocity.X = 0;
_velocity.Y = 0;
_velocity.Z = 0;
m_lastVelocity = _velocity;
if (Body != IntPtr.Zero)
{
d.BodySetLinearVel(Body, 0, 0, 0); // stop it
d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
}
outofBounds = false;
base.RequestPhysicsterseUpdate();
} }
public override float Buoyancy public override float Buoyancy
@ -2712,6 +2737,8 @@ Console.WriteLine(" JointCreateFixed");
internal void UpdatePositionAndVelocity() internal void UpdatePositionAndVelocity()
{ {
// no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
if (outofBounds)
return;
if (_parent == null) if (_parent == null)
{ {
Vector3 pv = Vector3.Zero; Vector3 pv = Vector3.Zero;
@ -2728,12 +2755,6 @@ Console.WriteLine(" JointCreateFixed");
Vector3 l_position = Vector3.Zero; Vector3 l_position = Vector3.Zero;
Quaternion l_orientation = Quaternion.Identity; Quaternion l_orientation = Quaternion.Identity;
// kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!)
//if (vec.X < 0.0f) { vec.X = 0.0f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); }
//if (vec.Y < 0.0f) { vec.Y = 0.0f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); }
//if (vec.X > 255.95f) { vec.X = 255.95f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); }
//if (vec.Y > 255.95f) { vec.Y = 255.95f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); }
m_lastposition = _position; m_lastposition = _position;
m_lastorientation = _orientation; m_lastorientation = _orientation;
@ -2745,10 +2766,44 @@ Console.WriteLine(" JointCreateFixed");
l_orientation.Z = ori.Z; l_orientation.Z = ori.Z;
l_orientation.W = ori.W; l_orientation.W = ori.W;
if (l_position.Z < 0)
{
// This is so prim that get lost underground don't fall forever and suck up
//
// Sim resources and memory.
// Disables the prim's movement physics....
// It's a hack and will generate a console message if it fails.
//IsPhysical = false;
_acceleration.X = 0;
_acceleration.Y = 0;
_acceleration.Z = 0;
_velocity.X = 0;
_velocity.Y = 0;
_velocity.Z = 0;
m_rotationalVelocity.X = 0;
m_rotationalVelocity.Y = 0;
m_rotationalVelocity.Z = 0;
if (_parent == null)
base.RaiseOutOfBounds(_position);
if (_parent == null)
base.RequestPhysicsterseUpdate();
m_throttleUpdates = false;
throttleCounter = 0;
_zeroFlag = true;
//outofBounds = true;
return;
}
if (l_position.X > ((int)_parent_scene.WorldExtents.X - 0.05f) || l_position.X < 0f || l_position.Y > ((int)_parent_scene.WorldExtents.Y - 0.05f) || l_position.Y < 0f) if (l_position.X > ((int)_parent_scene.WorldExtents.X - 0.05f) || l_position.X < 0f || l_position.Y > ((int)_parent_scene.WorldExtents.Y - 0.05f) || l_position.Y < 0f)
{ {
//base.RaiseOutOfBounds(l_position); //base.RaiseOutOfBounds(l_position);
/*
if (m_crossingfailures < _parent_scene.geomCrossingFailuresBeforeOutofbounds) if (m_crossingfailures < _parent_scene.geomCrossingFailuresBeforeOutofbounds)
{ {
_position = l_position; _position = l_position;
@ -2763,40 +2818,32 @@ Console.WriteLine(" JointCreateFixed");
base.RaiseOutOfBounds(l_position); base.RaiseOutOfBounds(l_position);
return; return;
} }
} */
outofBounds = true;
// part near the border on outside
if (l_position.X < 0)
Util.Clamp(l_position.X, -0.1f, -2f);
else
Util.Clamp(l_position.X, _parent_scene.WorldExtents.X + 0.1f, _parent_scene.WorldExtents.X + 2f);
if (l_position.Y < 0)
Util.Clamp(l_position.Y, -0.1f, -2f);
else
Util.Clamp(l_position.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f);
if (l_position.Z < 0) d.BodySetPosition(Body, l_position.X, l_position.Y, l_position.Z);
{
// This is so prim that get lost underground don't fall forever and suck up
//
// Sim resources and memory.
// Disables the prim's movement physics....
// It's a hack and will generate a console message if it fails.
//IsPhysical = false; // stop it
if (_parent == null) d.BodySetAngularVel(Body, 0, 0, 0);
base.RaiseOutOfBounds(_position); d.BodySetLinearVel(Body, 0, 0, 0);
disableBodySoft();
_acceleration.X = 0;
_acceleration.Y = 0;
_acceleration.Z = 0;
_velocity.X = 0;
_velocity.Y = 0;
_velocity.Z = 0;
m_rotationalVelocity.X = 0;
m_rotationalVelocity.Y = 0;
m_rotationalVelocity.Z = 0;
// tell framework to fix it
if (_parent == null) if (_parent == null)
base.RequestPhysicsterseUpdate(); base.RequestPhysicsterseUpdate();
return;
m_throttleUpdates = false;
throttleCounter = 0;
_zeroFlag = true;
//outofBounds = true;
} }
//float Adiff = 1.0f - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)); //float Adiff = 1.0f - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation));
//Console.WriteLine("Adiff " + Name + " = " + Adiff); //Console.WriteLine("Adiff " + Name + " = " + Adiff);
if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02) if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02)