BulletSim: small change to add position correction force with AddForce rather than just storing it in the variable

connector_plugin^2
Robert Adams 2012-11-24 20:11:38 -08:00
parent 22d5bf8ff9
commit 9a42405944
2 changed files with 22 additions and 16 deletions

View File

@ -518,13 +518,18 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{ {
if (IsActive) if (IsActive)
{ {
VDetailLog("{0},BSDynamics.Refresh", Prim.LocalID);
m_vehicleMass = Prim.Linkset.LinksetMass;
// Friction effects are handled by this vehicle code // Friction effects are handled by this vehicle code
BulletSimAPI.SetFriction2(Prim.PhysBody.ptr, 0f); BulletSimAPI.SetFriction2(Prim.PhysBody.ptr, 0f);
BulletSimAPI.SetHitFraction2(Prim.PhysBody.ptr, 0f); BulletSimAPI.SetHitFraction2(Prim.PhysBody.ptr, 0f);
// BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, 0.8f); BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, 0.8f);
BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, new Vector3(1f, 1f, 1f));
VDetailLog("{0},BSDynamics.Refresh,zeroingFriction and adding damping", Prim.LocalID);
} }
} }
@ -560,8 +565,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// m_lastLinearVelocityVector = Prim.ForceVelocity * Quaternion.Inverse(Prim.ForceOrientation); // DEBUG: // m_lastLinearVelocityVector = Prim.ForceVelocity * Quaternion.Inverse(Prim.ForceOrientation); // DEBUG:
// END DEBUG // END DEBUG
m_vehicleMass = Prim.Linkset.LinksetMass;
MoveLinear(pTimestep); MoveLinear(pTimestep);
// Commented out for debug // Commented out for debug
MoveAngular(pTimestep); MoveAngular(pTimestep);
@ -650,6 +653,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// if (rotatedSize.Z < terrainHeight) // if (rotatedSize.Z < terrainHeight)
if (pos.Z < terrainHeight) if (pos.Z < terrainHeight)
{ {
// TODO: correct position by applying force rather than forcing position.
pos.Z = terrainHeight + 2; pos.Z = terrainHeight + 2;
Prim.ForcePosition = pos; Prim.ForcePosition = pos;
VDetailLog("{0},MoveLinear,terrainHeight,terrainHeight={1},pos={2}", Prim.LocalID, terrainHeight, pos); VDetailLog("{0},MoveLinear,terrainHeight,terrainHeight={1},pos={2}", Prim.LocalID, terrainHeight, pos);
@ -810,9 +814,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
private void MoveAngular(float pTimestep) private void MoveAngular(float pTimestep)
{ {
// m_angularMotorDirection // angular velocity requested by LSL motor // m_angularMotorDirection // angular velocity requested by LSL motor
// m_angularMotorApply // application frame counter
// m_angularMotorVelocity // current angular motor velocity (ramps up and down) // m_angularMotorVelocity // current angular motor velocity (ramps up and down)
// m_angularMotorTimescale // motor angular velocity ramp up rate // m_angularMotorTimescale // motor angular velocity ramp up time
// m_angularMotorDecayTimescale // motor angular velocity decay rate // m_angularMotorDecayTimescale // motor angular velocity decay rate
// m_angularFrictionTimescale // body angular velocity decay rate // m_angularFrictionTimescale // body angular velocity decay rate
// m_lastAngularVelocity // what was last applied to body // m_lastAngularVelocity // what was last applied to body
@ -847,7 +850,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{ {
float VAservo = pTimestep * 0.2f / m_verticalAttractionTimescale; float VAservo = pTimestep * 0.2f / m_verticalAttractionTimescale;
if (Prim.IsColliding) if (Prim.IsColliding)
VAservo = pTimestep * 0.05f / (m_verticalAttractionTimescale); VAservo = pTimestep * 0.05f / m_verticalAttractionTimescale;
VAservo *= (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency); VAservo *= (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency);
@ -925,6 +928,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
float mix = Math.Abs(m_bankingMix); float mix = Math.Abs(m_bankingMix);
if (m_angularMotorVelocity.X == 0) if (m_angularMotorVelocity.X == 0)
{ {
// The vehicle is stopped
/*if (!parent.Orientation.ApproxEquals(this.m_referenceFrame, 0.25f)) /*if (!parent.Orientation.ApproxEquals(this.m_referenceFrame, 0.25f))
{ {
Vector3 axisAngle; Vector3 axisAngle;
@ -938,9 +942,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
}*/ }*/
} }
else else
banking.Z += (effSquared*(mult*mix))*(m_angularMotorVelocity.X) * 4; {
banking.Z += (effSquared * (mult * mix)) * (m_angularMotorVelocity.X) * 4;
}
//If they are colliding, we probably shouldn't shove the prim around... probably
if (!Prim.IsColliding && Math.Abs(m_angularMotorVelocity.X) > mix) if (!Prim.IsColliding && Math.Abs(m_angularMotorVelocity.X) > mix)
//If they are colliding, we probably shouldn't shove the prim around... probably
{ {
float angVelZ = m_angularMotorVelocity.X*-1; float angVelZ = m_angularMotorVelocity.X*-1;
/*if(angVelZ > mix) /*if(angVelZ > mix)
@ -957,8 +964,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
banking += bankingRot; banking += bankingRot;
} }
m_angularMotorVelocity.X *= m_bankingEfficiency == 1 ? 0.0f : 1 - m_bankingEfficiency; m_angularMotorVelocity.X *= m_bankingEfficiency == 1 ? 0.0f : 1 - m_bankingEfficiency;
VDetailLog("{0},MoveAngular,Banking,bEff={1},angMotVel={2},banking={3}", VDetailLog("{0},MoveAngular,Banking,bEff={1},angMotVel={2},effSq={3},mult={4},mix={5},banking={6}",
Prim.LocalID, m_bankingEfficiency, m_angularMotorVelocity, banking); Prim.LocalID, m_bankingEfficiency, m_angularMotorVelocity, effSquared, mult, mix, banking);
} }
#endregion #endregion

View File

@ -342,13 +342,12 @@ public sealed class BSPrim : BSPhysObject
// TODO: check for out of bounds // TODO: check for out of bounds
// The above code computes a force to apply to correct any out-of-bounds problems. Apply same. // The above code computes a force to apply to correct any out-of-bounds problems. Apply same.
// TODO: This should be intergrated with a geneal physics action mechanism.
// TODO: This should be moderated with PID'ness.
if (ret) if (ret)
{ {
PhysicsScene.TaintedObject(inTaintTime, "BSPrim.PositionSanityCheck:belowTerrain", delegate() // Apply upforce and overcome gravity.
{ AddForce(upForce - PhysicsScene.DefaultGravity, false, inTaintTime);
// Apply upforce and overcome gravity.
ForceVelocity = ForceVelocity + upForce - PhysicsScene.DefaultGravity;
});
} }
return ret; return ret;
} }