aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
diff options
context:
space:
mode:
authorMelanie2013-01-10 01:38:03 +0000
committerMelanie2013-01-10 01:38:03 +0000
commit3a495ccd561c9e1e95407d8657065265176a03dd (patch)
treecb7e7343e7c9a15bfdd77632d389fc6b6288b709 /OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
parentMerge branch 'avination' into careminster (diff)
parentOn baked texture save, replace any HG ID with an ordinary asset ID so the HGA... (diff)
downloadopensim-SC-3a495ccd561c9e1e95407d8657065265176a03dd.zip
opensim-SC-3a495ccd561c9e1e95407d8657065265176a03dd.tar.gz
opensim-SC-3a495ccd561c9e1e95407d8657065265176a03dd.tar.bz2
opensim-SC-3a495ccd561c9e1e95407d8657065265176a03dd.tar.xz
Merge branch 'master' into careminster
Conflicts: OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs57
1 files changed, 31 insertions, 26 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 13c2539..c34c05a 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -137,6 +137,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
137 get { return Type != Vehicle.TYPE_NONE && Prim.IsPhysical; } 137 get { return Type != Vehicle.TYPE_NONE && Prim.IsPhysical; }
138 } 138 }
139 139
140 #region Vehicle parameter setting
140 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue) 141 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
141 { 142 {
142 VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); 143 VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue);
@@ -546,6 +547,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
546 m_verticalAttractionMotor.FrictionTimescale = new Vector3(BSMotor.Infinite, BSMotor.Infinite, 0.1f); 547 m_verticalAttractionMotor.FrictionTimescale = new Vector3(BSMotor.Infinite, BSMotor.Infinite, 0.1f);
547 m_verticalAttractionMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) 548 m_verticalAttractionMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging)
548 } 549 }
550 #endregion // Vehicle parameter setting
549 551
550 // Some of the properties of this prim may have changed. 552 // Some of the properties of this prim may have changed.
551 // Do any updating needed for a vehicle 553 // Do any updating needed for a vehicle
@@ -854,6 +856,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
854 // The movement computed in the linear motor is relative to the vehicle 856 // The movement computed in the linear motor is relative to the vehicle
855 // coordinates. Rotate the movement to world coordinates. 857 // coordinates. Rotate the movement to world coordinates.
856 linearMotorContribution *= VehicleOrientation; 858 linearMotorContribution *= VehicleOrientation;
859 // All the contributions after this are world relative (mostly Z modifications)
857 860
858 // ================================================================== 861 // ==================================================================
859 // Buoyancy: force to overcome gravity. 862 // Buoyancy: force to overcome gravity.
@@ -925,7 +928,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
925 // TODO: Consider taking the rotated size of the object or possibly casting a ray. 928 // TODO: Consider taking the rotated size of the object or possibly casting a ray.
926 if (VehiclePosition.Z < GetTerrainHeight(VehiclePosition)) 929 if (VehiclePosition.Z < GetTerrainHeight(VehiclePosition))
927 { 930 {
928 // TODO: correct position by applying force rather than forcing position. 931 // Force position because applying force won't get the vehicle through the terrain
929 Vector3 newPosition = VehiclePosition; 932 Vector3 newPosition = VehiclePosition;
930 newPosition.Z = GetTerrainHeight(VehiclePosition) + 1f; 933 newPosition.Z = GetTerrainHeight(VehiclePosition) + 1f;
931 VehiclePosition = newPosition; 934 VehiclePosition = newPosition;
@@ -980,14 +983,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
980 float verticalCorrectionVelocity = verticalError / m_VhoverTimescale; 983 float verticalCorrectionVelocity = verticalError / m_VhoverTimescale;
981 984
982 // TODO: implement m_VhoverEfficiency correctly 985 // TODO: implement m_VhoverEfficiency correctly
983 if (Math.Abs(verticalError) > m_VhoverEfficiency) 986 ret = new Vector3(0f, 0f, verticalCorrectionVelocity);
984 {
985 ret = new Vector3(0f, 0f, verticalCorrectionVelocity);
986 }
987 } 987 }
988 988
989 VDetailLog("{0}, MoveLinear,hover,pos={1},ret={2},hoverTS={3},height={4},target={5}", 989 VDetailLog("{0}, MoveLinear,hover,pos={1},eff={2},hoverTS={3},height={4},target={5},ret={6}",
990 Prim.LocalID, VehiclePosition, ret, m_VhoverTimescale, m_VhoverHeight, m_VhoverTargetHeight); 990 Prim.LocalID, VehiclePosition, m_VhoverEfficiency, m_VhoverTimescale, m_VhoverHeight, m_VhoverTargetHeight, ret);
991 } 991 }
992 992
993 return ret; 993 return ret;
@@ -1109,6 +1109,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1109 + deflectionContribution 1109 + deflectionContribution
1110 + bankingContribution; 1110 + bankingContribution;
1111 1111
1112 // Add of the above computation are made relative to vehicle coordinates.
1113 // Convert to world coordinates.
1114 m_lastAngularVelocity *= VehicleOrientation;
1115
1112 // ================================================================== 1116 // ==================================================================
1113 // Apply the correction velocity. 1117 // Apply the correction velocity.
1114 // TODO: Should this be applied as an angular force (torque)? 1118 // TODO: Should this be applied as an angular force (torque)?
@@ -1220,19 +1224,21 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1220 public Vector3 ComputeAngularDeflection() 1224 public Vector3 ComputeAngularDeflection()
1221 { 1225 {
1222 Vector3 ret = Vector3.Zero; 1226 Vector3 ret = Vector3.Zero;
1223 return ret; // DEBUG DEBUG DEBUG 1227
1224 // Disable angular deflection for the moment.
1225 // Since angularMotorUp and angularDeflection are computed independently, they will calculate 1228 // Since angularMotorUp and angularDeflection are computed independently, they will calculate
1226 // approximately the same X or Y correction. When added together (when contributions are combined) 1229 // approximately the same X or Y correction. When added together (when contributions are combined)
1227 // this creates an over-correction and then wabbling as the target is overshot. 1230 // this creates an over-correction and then wabbling as the target is overshot.
1228 // TODO: rethink how the different correction computations inter-relate. 1231 // TODO: rethink how the different correction computations inter-relate.
1229 1232
1230 if (m_angularDeflectionEfficiency != 0) 1233 if (m_angularDeflectionEfficiency != 0 && VehicleVelocity != Vector3.Zero)
1231 { 1234 {
1232 // The direction the vehicle is moving 1235 // The direction the vehicle is moving
1233 Vector3 movingDirection = VehicleVelocity; 1236 Vector3 movingDirection = VehicleVelocity;
1234 movingDirection.Normalize(); 1237 movingDirection.Normalize();
1235 1238
1239 // If the vehicle is going backward, it is still pointing forward
1240 movingDirection *= Math.Sign(VehicleForwardSpeed);
1241
1236 // The direction the vehicle is pointing 1242 // The direction the vehicle is pointing
1237 Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation; 1243 Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation;
1238 pointingDirection.Normalize(); 1244 pointingDirection.Normalize();
@@ -1241,6 +1247,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1241 Vector3 deflectionError = movingDirection - pointingDirection; 1247 Vector3 deflectionError = movingDirection - pointingDirection;
1242 1248
1243 // Don't try to correct very large errors (not our job) 1249 // Don't try to correct very large errors (not our job)
1250 // if (Math.Abs(deflectionError.X) > PIOverFour) deflectionError.X = PIOverTwo * Math.Sign(deflectionError.X);
1251 // if (Math.Abs(deflectionError.Y) > PIOverFour) deflectionError.Y = PIOverTwo * Math.Sign(deflectionError.Y);
1252 // if (Math.Abs(deflectionError.Z) > PIOverFour) deflectionError.Z = PIOverTwo * Math.Sign(deflectionError.Z);
1244 if (Math.Abs(deflectionError.X) > PIOverFour) deflectionError.X = 0f; 1253 if (Math.Abs(deflectionError.X) > PIOverFour) deflectionError.X = 0f;
1245 if (Math.Abs(deflectionError.Y) > PIOverFour) deflectionError.Y = 0f; 1254 if (Math.Abs(deflectionError.Y) > PIOverFour) deflectionError.Y = 0f;
1246 if (Math.Abs(deflectionError.Z) > PIOverFour) deflectionError.Z = 0f; 1255 if (Math.Abs(deflectionError.Z) > PIOverFour) deflectionError.Z = 0f;
@@ -1296,33 +1305,29 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1296 1305
1297 if (m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff) 1306 if (m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff)
1298 { 1307 {
1299 // This works by rotating a unit vector to the orientation of the vehicle. The 1308 // Rotate a UnitZ vector (pointing up) to how the vehicle is oriented.
1300 // roll (tilt) will be Y component of a tilting Z vector (zero for no tilt 1309 // As the vehicle rolls to the right or left, the Y value will increase from
1301 // up to one for full over). 1310 // zero (straight up) to 1 or -1 (full tilt right or left)
1302 Vector3 rollComponents = Vector3.UnitZ * VehicleOrientation; 1311 Vector3 rollComponents = Vector3.UnitZ * VehicleOrientation;
1303 1312
1304 // Figure out the yaw value for this much roll. 1313 // Figure out the yaw value for this much roll.
1305 float turnComponent = rollComponents.Y * rollComponents.Y * m_bankingEfficiency; 1314 // Squared because that seems to give a good value
1306 // Keep the sign 1315 float yawAngle = (float)Math.Asin(rollComponents.Y * rollComponents.Y) * m_bankingEfficiency;
1307 if (rollComponents.Y < 0f)
1308 turnComponent = -turnComponent;
1309
1310 // TODO: there must be a better computation of the banking force.
1311 float bankingTurnForce = turnComponent;
1312 1316
1313 // actual error = static turn error + dynamic turn error 1317 // actual error = static turn error + dynamic turn error
1314 float mixedBankingError = bankingTurnForce * (1f - m_bankingMix) + bankingTurnForce * m_bankingMix * VehicleForwardSpeed; 1318 float mixedYawAngle = yawAngle * (1f - m_bankingMix) + yawAngle * m_bankingMix * VehicleForwardSpeed;
1319
1315 // TODO: the banking effect should not go to infinity but what to limit it to? 1320 // TODO: the banking effect should not go to infinity but what to limit it to?
1316 mixedBankingError = ClampInRange(-20f, mixedBankingError, 20f); 1321 mixedYawAngle = ClampInRange(-20f, mixedYawAngle, 20f);
1317 1322
1318 // Build the force vector to change rotation from what it is to what it should be 1323 // Build the force vector to change rotation from what it is to what it should be
1319 ret.Z = -mixedBankingError; 1324 ret.Z = -mixedYawAngle;
1320 1325
1321 // Don't do it all at once. 1326 // Don't do it all at once.
1322 ret /= m_bankingTimescale; 1327 ret /= m_bankingTimescale;
1323 1328
1324 VDetailLog("{0}, MoveAngular,Banking,rollComp={1},speed={2},turnComp={3},bankErr={4},mixedBankErr={5},ret={6}", 1329 VDetailLog("{0}, MoveAngular,Banking,rollComp={1},speed={2},rollComp={3},yAng={4},mYAng={5},ret={6}",
1325 Prim.LocalID, rollComponents, VehicleForwardSpeed, turnComponent, bankingTurnForce, mixedBankingError, ret); 1330 Prim.LocalID, rollComponents, VehicleForwardSpeed, rollComponents, yawAngle, mixedYawAngle, ret);
1326 } 1331 }
1327 return ret; 1332 return ret;
1328 } 1333 }