aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs48
1 files changed, 45 insertions, 3 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 5549984..65df741 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -321,7 +321,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
321 } 321 }
322 } 322 }
323 323
324 internal void ProcessTypeChange(Vehicle pType) 324 public void ProcessTypeChange(Vehicle pType)
325 { 325 {
326 VDetailLog("{0},ProcessTypeChange,type={1}", Prim.LocalID, pType); 326 VDetailLog("{0},ProcessTypeChange,type={1}", Prim.LocalID, pType);
327 // Set Defaults For Type 327 // Set Defaults For Type
@@ -1301,14 +1301,52 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1301 // efficiency of 1.0 will cause the spring to reach its equilibrium with exponential decay. 1301 // efficiency of 1.0 will cause the spring to reach its equilibrium with exponential decay.
1302 public void ComputeAngularVerticalAttraction() 1302 public void ComputeAngularVerticalAttraction()
1303 { 1303 {
1304
1304 // If vertical attaction timescale is reasonable 1305 // If vertical attaction timescale is reasonable
1305 if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) 1306 if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff)
1306 { 1307 {
1308 // Possible solution derived from a discussion at:
1309 // http://stackoverflow.com/questions/14939657/computing-vector-from-quaternion-works-computing-quaternion-from-vector-does-no
1310
1311 // Create a rotation that is only the vehicle's rotation around Z
1312 Vector3 currentEuler = Vector3.Zero;
1313 VehicleOrientation.GetEulerAngles(out currentEuler.X, out currentEuler.Y, out currentEuler.Z);
1314 Quaternion justZOrientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, currentEuler.Z);
1315
1316 // Create the axis that is perpendicular to the up vector and the rotated up vector.
1317 Vector3 differenceAxis = Vector3.Cross(Vector3.UnitZ * justZOrientation, Vector3.UnitZ * VehicleOrientation);
1318 // Compute the angle between those to vectors.
1319 double differenceAngle = Math.Acos((double)Vector3.Dot(Vector3.UnitZ, Vector3.Normalize(Vector3.UnitZ * VehicleOrientation)));
1320 // 'differenceAngle' is the angle to rotate and 'differenceAxis' is the plane to rotate in to get the vehicle vertical
1321
1322 // Reduce the change by the time period it is to change in. Timestep is handled when velocity is applied.
1323 // TODO: add 'efficiency'.
1324 differenceAngle /= m_verticalAttractionTimescale;
1325
1326 // Create the quaterian representing the correction angle
1327 Quaternion correctionRotation = Quaternion.CreateFromAxisAngle(differenceAxis, (float)differenceAngle);
1328
1329 // Turn that quaternion into Euler values to make it into velocities to apply.
1330 Vector3 vertContributionV = Vector3.Zero;
1331 correctionRotation.GetEulerAngles(out vertContributionV.X, out vertContributionV.Y, out vertContributionV.Z);
1332 vertContributionV *= -1f;
1333
1334 VehicleRotationalVelocity += vertContributionV;
1335
1336 VDetailLog("{0}, MoveAngular,verticalAttraction,diffAxis={1},diffAng={2},corrRot={3},contrib={4}",
1337 Prim.LocalID,
1338 differenceAxis,
1339 differenceAngle,
1340 correctionRotation,
1341 vertContributionV);
1342
1343 // ===================================================================
1344 /*
1307 Vector3 vertContributionV = Vector3.Zero; 1345 Vector3 vertContributionV = Vector3.Zero;
1308 Vector3 origRotVelW = VehicleRotationalVelocity; // DEBUG DEBUG 1346 Vector3 origRotVelW = VehicleRotationalVelocity; // DEBUG DEBUG
1309 1347
1310 // Take a vector pointing up and convert it from world to vehicle relative coords. 1348 // Take a vector pointing up and convert it from world to vehicle relative coords.
1311 Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; 1349 Vector3 verticalError = Vector3.Normalize(Vector3.UnitZ * VehicleOrientation);
1312 1350
1313 // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) 1351 // If vertical attraction correction is needed, the vector that was pointing up (UnitZ)
1314 // is now: 1352 // is now:
@@ -1334,13 +1372,17 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1334 // 'vertContrbution' is now the necessary angular correction to correct tilt in one second. 1372 // 'vertContrbution' is now the necessary angular correction to correct tilt in one second.
1335 // Correction happens over a number of seconds. 1373 // Correction happens over a number of seconds.
1336 Vector3 unscaledContribVerticalErrorV = vertContributionV; // DEBUG DEBUG 1374 Vector3 unscaledContribVerticalErrorV = vertContributionV; // DEBUG DEBUG
1375
1376 // The correction happens over the user's time period
1337 vertContributionV /= m_verticalAttractionTimescale; 1377 vertContributionV /= m_verticalAttractionTimescale;
1338 1378
1339 VehicleRotationalVelocity += vertContributionV; 1379 // Rotate the vehicle rotation to the world coordinates.
1380 VehicleRotationalVelocity += (vertContributionV * VehicleOrientation);
1340 1381
1341 VDetailLog("{0}, MoveAngular,verticalAttraction,,origRotVW={1},vertError={2},unscaledV={3},eff={4},ts={5},vertContribV={6}", 1382 VDetailLog("{0}, MoveAngular,verticalAttraction,,origRotVW={1},vertError={2},unscaledV={3},eff={4},ts={5},vertContribV={6}",
1342 Prim.LocalID, origRotVelW, verticalError, unscaledContribVerticalErrorV, 1383 Prim.LocalID, origRotVelW, verticalError, unscaledContribVerticalErrorV,
1343 m_verticalAttractionEfficiency, m_verticalAttractionTimescale, vertContributionV); 1384 m_verticalAttractionEfficiency, m_verticalAttractionTimescale, vertContributionV);
1385 */
1344 } 1386 }
1345 } 1387 }
1346 1388