aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs43
1 files changed, 23 insertions, 20 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index ef68471..48ba419 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -87,7 +87,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
87 private float m_angularMotorTimescale = 0; // motor angular velocity ramp up rate 87 private float m_angularMotorTimescale = 0; // motor angular velocity ramp up rate
88 private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate 88 private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate
89 private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate 89 private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate
90 private Vector3 m_lastAngularCorrection = Vector3.Zero; 90 private Vector3 m_lastAngularVelocity = Vector3.Zero;
91 private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body 91 private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body
92 92
93 //Deflection properties 93 //Deflection properties
@@ -128,7 +128,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
128 // Return 'true' if this vehicle is doing vehicle things 128 // Return 'true' if this vehicle is doing vehicle things
129 public bool IsActive 129 public bool IsActive
130 { 130 {
131 get { return Type != Vehicle.TYPE_NONE; } 131 get { return Type != Vehicle.TYPE_NONE && Prim.IsPhysical; }
132 } 132 }
133 133
134 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue) 134 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
@@ -664,6 +664,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
664 // an UpdateProperties event to send the changes up to the simulator. 664 // an UpdateProperties event to send the changes up to the simulator.
665 BulletSimAPI.PushUpdate2(Prim.PhysBody.ptr); 665 BulletSimAPI.PushUpdate2(Prim.PhysBody.ptr);
666 } 666 }
667 m_knownChanged = 0;
667 } 668 }
668 669
669 // Since the computation of terrain height can be a little involved, this routine 670 // Since the computation of terrain height can be a little involved, this routine
@@ -993,11 +994,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
993 public Vector3 ComputeLinearMotorUp(float pTimestep) 994 public Vector3 ComputeLinearMotorUp(float pTimestep)
994 { 995 {
995 Vector3 ret = Vector3.Zero; 996 Vector3 ret = Vector3.Zero;
997 float distanceAboveGround = 0f;
996 998
997 if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0) 999 if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0)
998 { 1000 {
999 float targetHeight = Type == Vehicle.TYPE_BOAT ? GetWaterLevel(VehiclePosition) : GetTerrainHeight(VehiclePosition); 1001 float targetHeight = Type == Vehicle.TYPE_BOAT ? GetWaterLevel(VehiclePosition) : GetTerrainHeight(VehiclePosition);
1000 float distanceAboveGround = VehiclePosition.Z - targetHeight; 1002 distanceAboveGround = VehiclePosition.Z - targetHeight;
1001 // Not colliding if the vehicle is off the ground 1003 // Not colliding if the vehicle is off the ground
1002 if (!Prim.IsColliding) 1004 if (!Prim.IsColliding)
1003 { 1005 {
@@ -1010,9 +1012,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1010 // has a decay factor. This says this force should 1012 // has a decay factor. This says this force should
1011 // be computed with a motor. 1013 // be computed with a motor.
1012 // TODO: add interaction with banking. 1014 // TODO: add interaction with banking.
1013 VDetailLog("{0}, MoveLinear,limitMotorUp,distAbove={1},colliding={2},ret={3}",
1014 Prim.LocalID, distanceAboveGround, Prim.IsColliding, ret);
1015 } 1015 }
1016 VDetailLog("{0}, MoveLinear,limitMotorUp,distAbove={1},colliding={2},ret={3}",
1017 Prim.LocalID, distanceAboveGround, Prim.IsColliding, ret);
1016 return ret; 1018 return ret;
1017 } 1019 }
1018 1020
@@ -1049,8 +1051,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1049 // ================================================================== 1051 // ==================================================================
1050 m_lastVertAttractor = verticalAttractionContribution; 1052 m_lastVertAttractor = verticalAttractionContribution;
1051 1053
1054 // DEBUG DEBUG DEBUG: optionally scale the angular velocity. Debugging SL vs ODE turning functions.
1055 Vector3 originalAngularMotorContrib = angularMotorContribution;
1056 if (PhysicsScene.VehicleScaleAngularVelocityByTimestep)
1057 angularMotorContribution *= pTimestep;
1058
1052 // Sum corrections 1059 // Sum corrections
1053 m_lastAngularCorrection = angularMotorContribution 1060 m_lastAngularVelocity = angularMotorContribution
1054 + verticalAttractionContribution 1061 + verticalAttractionContribution
1055 + deflectionContribution 1062 + deflectionContribution
1056 + bankingContribution; 1063 + bankingContribution;
@@ -1058,19 +1065,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1058 // ================================================================== 1065 // ==================================================================
1059 // Apply the correction velocity. 1066 // Apply the correction velocity.
1060 // TODO: Should this be applied as an angular force (torque)? 1067 // TODO: Should this be applied as an angular force (torque)?
1061 if (!m_lastAngularCorrection.ApproxEquals(Vector3.Zero, 0.01f)) 1068 if (!m_lastAngularVelocity.ApproxEquals(Vector3.Zero, 0.01f))
1062 { 1069 {
1063 // DEBUG DEBUG DEBUG: optionally scale the angular velocity. Debugging SL vs ODE turning functions. 1070 VehicleRotationalVelocity = m_lastAngularVelocity;
1064 Vector3 scaledCorrection = m_lastAngularCorrection;
1065 if (PhysicsScene.VehicleScaleAngularVelocityByTimestep)
1066 scaledCorrection *= pTimestep;
1067 VehicleRotationalVelocity = scaledCorrection;
1068 1071
1069 VDetailLog("{0}, MoveAngular,done,nonZero,angMotorContrib={1},vertAttrContrib={2},bankContrib={3},deflectContrib={4},totalContrib={5},scaledCorr={6}", 1072 VDetailLog("{0}, MoveAngular,done,nonZero,angMotorContrib={1},vertAttrContrib={2},bankContrib={3},deflectContrib={4},totalContrib={5}",
1070 Prim.LocalID, 1073 Prim.LocalID,
1071 angularMotorContribution, verticalAttractionContribution, 1074 angularMotorContribution, verticalAttractionContribution,
1072 bankingContribution, deflectionContribution, 1075 bankingContribution, deflectionContribution,
1073 m_lastAngularCorrection, scaledCorrection 1076 m_lastAngularVelocity
1074 ); 1077 );
1075 } 1078 }
1076 else 1079 else
@@ -1124,18 +1127,18 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1124 { 1127 {
1125 Vector3 ret = Vector3.Zero; 1128 Vector3 ret = Vector3.Zero;
1126 1129
1127 // If vertical attaction timescale is reasonable and we applied an angular force last time... 1130 // If vertical attaction timescale is reasonable
1128 if (m_verticalAttractionTimescale < m_verticalAttractionCutoff) 1131 if (m_verticalAttractionTimescale < m_verticalAttractionCutoff)
1129 { 1132 {
1130 // Take a vector pointing up and convert it from world to vehicle relative coords. 1133 // Take a vector pointing up and convert it from world to vehicle relative coords.
1131 Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; 1134 Vector3 verticalError = Vector3.UnitZ * VehicleOrientation;
1132 verticalError.Normalize();
1133 1135
1134 // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) 1136 // If vertical attraction correction is needed, the vector that was pointing up (UnitZ)
1135 // is now leaning to one side (rotated around the X axis) and the Y value will 1137 // is now:
1136 // go from zero (nearly straight up) to one (completely to the side) or leaning 1138 // leaning to one side: rotated around the X axis with the Y value going
1137 // front-to-back (rotated around the Y axis) and the value of X will be between 1139 // from zero (nearly straight up) to one (completely to the side)) or
1138 // zero and one. 1140 // leaning front-to-back: rotated around the Y axis with the value of X being between
1141 // zero and one.
1139 // The value of Z is how far the rotation is off with 1 meaning none and 0 being 90 degrees. 1142 // The value of Z is how far the rotation is off with 1 meaning none and 0 being 90 degrees.
1140 1143
1141 // If verticalError.Z is negative, the vehicle is upside down. Add additional push. 1144 // If verticalError.Z is negative, the vehicle is upside down. Add additional push.