Vehicle Linear parameter adjustments

avinationmerge
Kitto Flora 2009-12-31 16:07:36 -05:00
parent 67cfe34e67
commit 3f901d313b
3 changed files with 75 additions and 38 deletions

View File

@ -83,6 +83,12 @@ namespace OpenSim.Region.Physics.OdePlugin
// private IntPtr m_jointGroup = IntPtr.Zero; // private IntPtr m_jointGroup = IntPtr.Zero;
// private IntPtr m_aMotor = IntPtr.Zero; // private IntPtr m_aMotor = IntPtr.Zero;
// Correction factors, to match Sl
private static float m_linearVelocityFactor = 0.9f;
private static float m_linearAttackFactor = 0.4f;
private static float m_linearDecayFactor = 0.5f;
private static float m_linearFrictionFactor = 1.2f;
// Vehicle properties // Vehicle properties
private Vehicle m_type = Vehicle.TYPE_NONE; // If a 'VEHICLE', and what kind private Vehicle m_type = Vehicle.TYPE_NONE; // If a 'VEHICLE', and what kind
@ -98,7 +104,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// Linear properties // Linear properties
private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time
private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL, for max limiting
private Vector3 m_dir = Vector3.Zero; // velocity applied to body private Vector3 m_dir = Vector3.Zero; // velocity applied to body
private Vector3 m_linearFrictionTimescale = Vector3.Zero; private Vector3 m_linearFrictionTimescale = Vector3.Zero;
private float m_linearMotorDecayTimescale = 0; private float m_linearMotorDecayTimescale = 0;
@ -267,8 +273,9 @@ namespace OpenSim.Region.Physics.OdePlugin
m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
break; break;
case Vehicle.LINEAR_MOTOR_DIRECTION: case Vehicle.LINEAR_MOTOR_DIRECTION:
m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); pValue *= m_linearVelocityFactor;
m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); // velocity requested by LSL, decayed by time
m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); // velocity requested by LSL, for max limiting
break; break;
case Vehicle.LINEAR_MOTOR_OFFSET: case Vehicle.LINEAR_MOTOR_OFFSET:
// m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z); // m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
@ -453,6 +460,17 @@ namespace OpenSim.Region.Physics.OdePlugin
MoveAngular(pTimestep); MoveAngular(pTimestep);
}// end Step }// end Step
internal void Halt()
{ // Kill all motions, when non-physical
m_linearMotorDirection = Vector3.Zero;
m_linearMotorDirectionLASTSET = Vector3.Zero;
m_dir = Vector3.Zero;
m_lastLinearVelocityVector = Vector3.Zero;
m_angularMotorDirection = Vector3.Zero;
m_angularMotorVelocity = Vector3.Zero;
m_lastAngularVelocity = Vector3.Zero;
}
private void MoveLinear(float pTimestep, OdeScene _pParentScene) private void MoveLinear(float pTimestep, OdeScene _pParentScene)
{ {
if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) // requested m_linearMotorDirection is significant if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) // requested m_linearMotorDirection is significant
@ -460,9 +478,15 @@ namespace OpenSim.Region.Physics.OdePlugin
if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body); if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body);
// add drive to body // add drive to body
Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep); float linfactor = m_linearMotorTimescale/pTimestep;
m_lastLinearVelocityVector += (addAmount*10); // lastLinearVelocityVector is the current body velocity vector? // Linear accel
Vector3 addAmount1 = (m_linearMotorDirection/linfactor) * 0.8f;
// Differential accel
Vector3 addAmount2 = ((m_linearMotorDirection - m_lastLinearVelocityVector)/linfactor) * 1.6f;
// SL correction
Vector3 addAmount = (addAmount1 + addAmount2) * m_linearAttackFactor;
m_lastLinearVelocityVector += addAmount; // lastLinearVelocityVector is the current body velocity vector
//if(frcount == 0) Console.WriteLine("AL {0} + AD {1} AS{2} V {3}", addAmount1, addAmount2, addAmount, m_lastLinearVelocityVector);
// This will work temporarily, but we really need to compare speed on an axis // This will work temporarily, but we really need to compare speed on an axis
// KF: Limit body velocity to applied velocity? // KF: Limit body velocity to applied velocity?
if (Math.Abs(m_lastLinearVelocityVector.X) > Math.Abs(m_linearMotorDirectionLASTSET.X)) if (Math.Abs(m_lastLinearVelocityVector.X) > Math.Abs(m_linearMotorDirectionLASTSET.X))
@ -475,7 +499,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// decay applied velocity // decay applied velocity
Vector3 decayfraction = ((Vector3.One/(m_linearMotorDecayTimescale/pTimestep))); Vector3 decayfraction = ((Vector3.One/(m_linearMotorDecayTimescale/pTimestep)));
//Console.WriteLine("decay: " + decayfraction); //Console.WriteLine("decay: " + decayfraction);
m_linearMotorDirection -= m_linearMotorDirection * decayfraction * 0.5f; m_linearMotorDirection -= m_linearMotorDirection * decayfraction * m_linearDecayFactor;
//Console.WriteLine("actual: " + m_linearMotorDirection); //Console.WriteLine("actual: " + m_linearMotorDirection);
} }
else else
@ -560,7 +584,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// apply friction // apply friction
Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep); Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep);
m_lastLinearVelocityVector -= m_lastLinearVelocityVector * decayamount; m_lastLinearVelocityVector -= m_lastLinearVelocityVector * decayamount * m_linearFrictionFactor;
} // end MoveLinear() } // end MoveLinear()
private void MoveAngular(float pTimestep) private void MoveAngular(float pTimestep)

View File

@ -2296,11 +2296,15 @@ Console.WriteLine(" JointCreateFixed");
public override bool IsPhysical public override bool IsPhysical
{ {
get { return m_isphysical; } get { return m_isphysical; }
set { set
{
m_isphysical = value; m_isphysical = value;
if (!m_isphysical) // Zero the remembered last velocity if (!m_isphysical)
m_lastVelocity = Vector3.Zero; { // Zero the remembered last velocity
} m_lastVelocity = Vector3.Zero;
if (m_vehicle.Type != Vehicle.TYPE_NONE) m_vehicle.Halt();
}
}
} }
public void setPrimForRemoval() public void setPrimForRemoval()

View File

@ -229,7 +229,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public int bodyFramesAutoDisable = 20; public int bodyFramesAutoDisable = 20;
protected DateTime m_lastframe = DateTime.UtcNow;
private float[] _watermap; private float[] _watermap;
private bool m_filterCollisions = true; private bool m_filterCollisions = true;
@ -2639,13 +2639,20 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
if (framecount >= int.MaxValue) if (framecount >= int.MaxValue)
framecount = 0; framecount = 0;
//if (m_worldOffset != Vector3.Zero) //if (m_worldOffset != Vector3.Zero)
// return 0; // return 0;
framecount++; framecount++;
float fps = 0; DateTime now = DateTime.UtcNow;
TimeSpan SinceLastFrame = now - m_lastframe;
m_lastframe = now;
float realtime = (float)SinceLastFrame.TotalSeconds;
// Console.WriteLine("ts={0} rt={1}", timeStep, realtime);
timeStep = realtime;
// float fps = 1.0f / realtime;
float fps = 0.0f; // number of ODE steps in this Simulate step
//m_log.Info(timeStep.ToString()); //m_log.Info(timeStep.ToString());
step_time += timeStep; step_time += timeStep;
@ -2691,11 +2698,11 @@ namespace OpenSim.Region.Physics.OdePlugin
// Figure out the Frames Per Second we're going at. // Figure out the Frames Per Second we're going at.
//(step_time == 0.004f, there's 250 of those per second. Times the step time/step size //(step_time == 0.004f, there's 250 of those per second. Times the step time/step size
fps = (step_time / ODE_STEPSIZE) * 1000; // fps = (step_time / ODE_STEPSIZE) * 1000;
// HACK: Using a time dilation of 1.0 to debug rubberbanding issues // HACK: Using a time dilation of 1.0 to debug rubberbanding issues
//m_timeDilation = Math.Min((step_time / ODE_STEPSIZE) / (0.09375f / ODE_STEPSIZE), 1.0f); //m_timeDilation = Math.Min((step_time / ODE_STEPSIZE) / (0.09375f / ODE_STEPSIZE), 1.0f);
step_time = 0.09375f; // step_time = 0.09375f;
while (step_time > 0.0f) while (step_time > 0.0f)
{ {
@ -2716,7 +2723,7 @@ namespace OpenSim.Region.Physics.OdePlugin
foreach (OdeCharacter character in _taintedActors) foreach (OdeCharacter character in _taintedActors)
{ {
character.ProcessTaints(timeStep); character.ProcessTaints(ODE_STEPSIZE);
processedtaints = true; processedtaints = true;
//character.m_collisionscore = 0; //character.m_collisionscore = 0;
@ -2725,7 +2732,7 @@ namespace OpenSim.Region.Physics.OdePlugin
if (processedtaints) if (processedtaints)
_taintedActors.Clear(); _taintedActors.Clear();
} }
} } // end lock _taintedActors
// Modify other objects in the scene. // Modify other objects in the scene.
processedtaints = false; processedtaints = false;
@ -2742,7 +2749,7 @@ namespace OpenSim.Region.Physics.OdePlugin
else else
{ {
//Console.WriteLine("Simulate calls ProcessTaints"); //Console.WriteLine("Simulate calls ProcessTaints");
prim.ProcessTaints(timeStep); prim.ProcessTaints(ODE_STEPSIZE);
} }
processedtaints = true; processedtaints = true;
prim.m_collisionscore = 0; prim.m_collisionscore = 0;
@ -2767,7 +2774,8 @@ namespace OpenSim.Region.Physics.OdePlugin
foreach (PhysicsJoint joint in pendingJoints) foreach (PhysicsJoint joint in pendingJoints)
{ {
//DoJointErrorMessage(joint, "taint: time to create joint with parms: " + joint.RawParams); //DoJointErrorMessage(joint, "taint: time to create joint with parms: " + joint.RawParams);
string[] jointParams = joint.RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); string[] jointParams = joint.RawParams.Split(" ".ToCharArray(),
System.StringSplitOptions.RemoveEmptyEntries);
List<IntPtr> jointBodies = new List<IntPtr>(); List<IntPtr> jointBodies = new List<IntPtr>();
bool allJointBodiesAreReady = true; bool allJointBodiesAreReady = true;
foreach (string jointParam in jointParams) foreach (string jointParam in jointParams)
@ -2934,13 +2942,13 @@ namespace OpenSim.Region.Physics.OdePlugin
//DoJointErrorMessage(successfullyProcessedJoint, "done"); //DoJointErrorMessage(successfullyProcessedJoint, "done");
} }
} }
} } // end SupportsNINJAJoints
if (processedtaints) if (processedtaints)
//Console.WriteLine("Simulate calls Clear of _taintedPrim list"); //Console.WriteLine("Simulate calls Clear of _taintedPrim list");
_taintedPrimH.Clear(); _taintedPrimH.Clear(); // ??? if this only ???
_taintedPrimL.Clear(); _taintedPrimL.Clear();
} } // end lock _taintedPrimLock
// Move characters // Move characters
lock (_characters) lock (_characters)
@ -2949,7 +2957,7 @@ namespace OpenSim.Region.Physics.OdePlugin
foreach (OdeCharacter actor in _characters) foreach (OdeCharacter actor in _characters)
{ {
if (actor != null) if (actor != null)
actor.Move(timeStep, defects); actor.Move(ODE_STEPSIZE, defects);
} }
if (0 != defects.Count) if (0 != defects.Count)
{ {
@ -2958,7 +2966,7 @@ namespace OpenSim.Region.Physics.OdePlugin
RemoveCharacter(defect); RemoveCharacter(defect);
} }
} }
} } // end lock _characters
// Move other active objects // Move other active objects
lock (_activeprims) lock (_activeprims)
@ -2966,9 +2974,9 @@ namespace OpenSim.Region.Physics.OdePlugin
foreach (OdePrim prim in _activeprims) foreach (OdePrim prim in _activeprims)
{ {
prim.m_collisionscore = 0; prim.m_collisionscore = 0;
prim.Move(timeStep); prim.Move(ODE_STEPSIZE);
} }
} } // end lock _activeprims
//if ((framecount % m_randomizeWater) == 0) //if ((framecount % m_randomizeWater) == 0)
// randomizeWater(waterlevel); // randomizeWater(waterlevel);
@ -2976,7 +2984,7 @@ namespace OpenSim.Region.Physics.OdePlugin
//int RayCastTimeMS = m_rayCastManager.ProcessQueuedRequests(); //int RayCastTimeMS = m_rayCastManager.ProcessQueuedRequests();
m_rayCastManager.ProcessQueuedRequests(); m_rayCastManager.ProcessQueuedRequests();
collision_optimized(timeStep); collision_optimized(ODE_STEPSIZE);
lock (_collisionEventPrim) lock (_collisionEventPrim)
{ {
@ -2998,7 +3006,7 @@ namespace OpenSim.Region.Physics.OdePlugin
break; break;
} }
} }
} } // end lock _collisionEventPrim
//if (m_global_contactcount > 5) //if (m_global_contactcount > 5)
//{ //{
@ -3009,8 +3017,9 @@ namespace OpenSim.Region.Physics.OdePlugin
d.WorldQuickStep(world, ODE_STEPSIZE); d.WorldQuickStep(world, ODE_STEPSIZE);
d.JointGroupEmpty(contactgroup); d.JointGroupEmpty(contactgroup);
fps++;
//ode.dunlock(world); //ode.dunlock(world);
} } // end try
catch (Exception e) catch (Exception e)
{ {
m_log.ErrorFormat("[PHYSICS]: {0}, {1}, {2}", e.Message, e.TargetSite, e); m_log.ErrorFormat("[PHYSICS]: {0}, {1}, {2}", e.Message, e.TargetSite, e);
@ -3025,7 +3034,7 @@ namespace OpenSim.Region.Physics.OdePlugin
//fps = 0; //fps = 0;
//} //}
//} //}
} } // end while (step_time > 0.0f)
lock (_characters) lock (_characters)
{ {
@ -3090,7 +3099,7 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
} }
} }
} } // end lock _activeprims
//DumpJointInfo(); //DumpJointInfo();
@ -3111,10 +3120,10 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix);
} }
} } // end lock OdeLock
return fps; return fps * 1000.0f; //NB This is a FRAME COUNT, not a time! AND is divide by 1000 in SimStatusReporter!
} } // end Simulate
public override void GetResults() public override void GetResults()
{ {