diff options
author | Robert Adams | 2015-04-05 20:20:37 -0700 |
---|---|---|
committer | Robert Adams | 2015-04-05 20:20:37 -0700 |
commit | 8d6628484107e3ebe2c29b2b754e43c164545cf1 (patch) | |
tree | 6818e60a31d52879fb913a9fbb4262b21640665d /OpenSim/Region/Physics/BulletSPlugin | |
parent | Parameterize sleeps in LSL functions. (diff) | |
download | opensim-SC-8d6628484107e3ebe2c29b2b754e43c164545cf1.zip opensim-SC-8d6628484107e3ebe2c29b2b754e43c164545cf1.tar.gz opensim-SC-8d6628484107e3ebe2c29b2b754e43c164545cf1.tar.bz2 opensim-SC-8d6628484107e3ebe2c29b2b754e43c164545cf1.tar.xz |
BulletSim: implement VEHICLE_REFERENCE_FRAME. Thanks Vegaslon!.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index a4ef709..c6d6331 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -945,7 +945,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
945 | { | 945 | { |
946 | get | 946 | get |
947 | { | 947 | { |
948 | return VehicleVelocity * Quaternion.Inverse(Quaternion.Normalize(VehicleOrientation)); | 948 | return VehicleVelocity * Quaternion.Inverse(Quaternion.Normalize(VehicleFrameOrientation)); |
949 | } | 949 | } |
950 | } | 950 | } |
951 | 951 | ||
@@ -956,6 +956,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
956 | return VehicleForwardVelocity.X; | 956 | return VehicleForwardVelocity.X; |
957 | } | 957 | } |
958 | } | 958 | } |
959 | private Quaternion VehicleFrameOrientation | ||
960 | { | ||
961 | get | ||
962 | { | ||
963 | return VehicleOrientation * m_referenceFrame; | ||
964 | } | ||
965 | } | ||
959 | 966 | ||
960 | #endregion // Known vehicle value functions | 967 | #endregion // Known vehicle value functions |
961 | 968 | ||
@@ -1065,7 +1072,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1065 | linearMotorCorrectionV -= (currentVelV * frictionFactorV); | 1072 | linearMotorCorrectionV -= (currentVelV * frictionFactorV); |
1066 | 1073 | ||
1067 | // Motor is vehicle coordinates. Rotate it to world coordinates | 1074 | // Motor is vehicle coordinates. Rotate it to world coordinates |
1068 | Vector3 linearMotorVelocityW = linearMotorCorrectionV * VehicleOrientation; | 1075 | Vector3 linearMotorVelocityW = linearMotorCorrectionV * VehicleFrameOrientation; |
1069 | 1076 | ||
1070 | // If we're a ground vehicle, don't add any upward Z movement | 1077 | // If we're a ground vehicle, don't add any upward Z movement |
1071 | if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0) | 1078 | if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0) |
@@ -1107,7 +1114,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1107 | linearDeflectionV *= new Vector3(1, -1, -1); | 1114 | linearDeflectionV *= new Vector3(1, -1, -1); |
1108 | 1115 | ||
1109 | // Correction is vehicle relative. Convert to world coordinates. | 1116 | // Correction is vehicle relative. Convert to world coordinates. |
1110 | Vector3 linearDeflectionW = linearDeflectionV * VehicleOrientation; | 1117 | Vector3 linearDeflectionW = linearDeflectionV * VehicleFrameOrientation; |
1111 | 1118 | ||
1112 | // Optionally, if not colliding, don't effect world downward velocity. Let falling things fall. | 1119 | // Optionally, if not colliding, don't effect world downward velocity. Let falling things fall. |
1113 | if (BSParam.VehicleLinearDeflectionNotCollidingNoZ && !m_controllingPrim.HasSomeCollision) | 1120 | if (BSParam.VehicleLinearDeflectionNotCollidingNoZ && !m_controllingPrim.HasSomeCollision) |
@@ -1403,7 +1410,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1403 | { | 1410 | { |
1404 | // The user wants this many radians per second angular change? | 1411 | // The user wants this many radians per second angular change? |
1405 | Vector3 origVehicleRotationalVelocity = VehicleRotationalVelocity; // DEBUG DEBUG | 1412 | Vector3 origVehicleRotationalVelocity = VehicleRotationalVelocity; // DEBUG DEBUG |
1406 | Vector3 currentAngularV = VehicleRotationalVelocity * Quaternion.Inverse(VehicleOrientation); | 1413 | Vector3 currentAngularV = VehicleRotationalVelocity * Quaternion.Inverse(VehicleFrameOrientation); |
1407 | Vector3 angularMotorContributionV = m_angularMotor.Step(pTimestep, currentAngularV); | 1414 | Vector3 angularMotorContributionV = m_angularMotor.Step(pTimestep, currentAngularV); |
1408 | 1415 | ||
1409 | // ================================================================== | 1416 | // ================================================================== |
@@ -1424,7 +1431,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1424 | Vector3 frictionFactorW = ComputeFrictionFactor(m_angularFrictionTimescale, pTimestep); | 1431 | Vector3 frictionFactorW = ComputeFrictionFactor(m_angularFrictionTimescale, pTimestep); |
1425 | angularMotorContributionV -= (currentAngularV * frictionFactorW); | 1432 | angularMotorContributionV -= (currentAngularV * frictionFactorW); |
1426 | 1433 | ||
1427 | Vector3 angularMotorContributionW = angularMotorContributionV * VehicleOrientation; | 1434 | Vector3 angularMotorContributionW = angularMotorContributionV * VehicleFrameOrientation; |
1428 | VehicleRotationalVelocity += angularMotorContributionW; | 1435 | VehicleRotationalVelocity += angularMotorContributionW; |
1429 | 1436 | ||
1430 | VDetailLog("{0}, MoveAngular,angularTurning,curAngVelV={1},origVehRotVel={2},vehRotVel={3},frictFact={4}, angContribV={5},angContribW={6}", | 1437 | VDetailLog("{0}, MoveAngular,angularTurning,curAngVelV={1},origVehRotVel={2},vehRotVel={3},frictFact={4}, angContribV={5},angContribW={6}", |
@@ -1445,7 +1452,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1445 | // If vertical attaction timescale is reasonable | 1452 | // If vertical attaction timescale is reasonable |
1446 | if (BSParam.VehicleEnableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) | 1453 | if (BSParam.VehicleEnableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) |
1447 | { | 1454 | { |
1448 | Vector3 vehicleUpAxis = Vector3.UnitZ * VehicleOrientation; | 1455 | Vector3 vehicleUpAxis = Vector3.UnitZ * VehicleFrameOrientation; |
1449 | switch (BSParam.VehicleAngularVerticalAttractionAlgorithm) | 1456 | switch (BSParam.VehicleAngularVerticalAttractionAlgorithm) |
1450 | { | 1457 | { |
1451 | case 0: | 1458 | case 0: |
@@ -1466,7 +1473,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1466 | 1473 | ||
1467 | if ((m_flags & VehicleFlag.LIMIT_ROLL_ONLY) != 0) | 1474 | if ((m_flags & VehicleFlag.LIMIT_ROLL_ONLY) != 0) |
1468 | { | 1475 | { |
1469 | Vector3 vehicleForwardAxis = Vector3.UnitX * VehicleOrientation; | 1476 | Vector3 vehicleForwardAxis = Vector3.UnitX * VehicleFrameOrientation; |
1470 | torqueVector = ProjectVector(torqueVector, vehicleForwardAxis); | 1477 | torqueVector = ProjectVector(torqueVector, vehicleForwardAxis); |
1471 | } | 1478 | } |
1472 | 1479 | ||
@@ -1491,13 +1498,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1491 | 1498 | ||
1492 | // Create a rotation that is only the vehicle's rotation around Z | 1499 | // Create a rotation that is only the vehicle's rotation around Z |
1493 | Vector3 currentEulerW = Vector3.Zero; | 1500 | Vector3 currentEulerW = Vector3.Zero; |
1494 | VehicleOrientation.GetEulerAngles(out currentEulerW.X, out currentEulerW.Y, out currentEulerW.Z); | 1501 | VehicleFrameOrientation.GetEulerAngles(out currentEulerW.X, out currentEulerW.Y, out currentEulerW.Z); |
1495 | Quaternion justZOrientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, currentEulerW.Z); | 1502 | Quaternion justZOrientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, currentEulerW.Z); |
1496 | 1503 | ||
1497 | // Create the axis that is perpendicular to the up vector and the rotated up vector. | 1504 | // Create the axis that is perpendicular to the up vector and the rotated up vector. |
1498 | Vector3 differenceAxisW = Vector3.Cross(Vector3.UnitZ * justZOrientation, Vector3.UnitZ * VehicleOrientation); | 1505 | Vector3 differenceAxisW = Vector3.Cross(Vector3.UnitZ * justZOrientation, Vector3.UnitZ * VehicleFrameOrientation); |
1499 | // Compute the angle between those to vectors. | 1506 | // Compute the angle between those to vectors. |
1500 | double differenceAngle = Math.Acos((double)Vector3.Dot(Vector3.UnitZ, Vector3.Normalize(Vector3.UnitZ * VehicleOrientation))); | 1507 | double differenceAngle = Math.Acos((double)Vector3.Dot(Vector3.UnitZ, Vector3.Normalize(Vector3.UnitZ * VehicleFrameOrientation))); |
1501 | // 'differenceAngle' is the angle to rotate and 'differenceAxis' is the plane to rotate in to get the vehicle vertical | 1508 | // 'differenceAngle' is the angle to rotate and 'differenceAxis' is the plane to rotate in to get the vehicle vertical |
1502 | 1509 | ||
1503 | // Reduce the change by the time period it is to change in. Timestep is handled when velocity is applied. | 1510 | // Reduce the change by the time period it is to change in. Timestep is handled when velocity is applied. |
@@ -1530,7 +1537,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1530 | Vector3 origRotVelW = VehicleRotationalVelocity; // DEBUG DEBUG | 1537 | Vector3 origRotVelW = VehicleRotationalVelocity; // DEBUG DEBUG |
1531 | 1538 | ||
1532 | // Take a vector pointing up and convert it from world to vehicle relative coords. | 1539 | // Take a vector pointing up and convert it from world to vehicle relative coords. |
1533 | Vector3 verticalError = Vector3.Normalize(Vector3.UnitZ * VehicleOrientation); | 1540 | Vector3 verticalError = Vector3.Normalize(Vector3.UnitZ * VehicleFrameOrientation); |
1534 | 1541 | ||
1535 | // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) | 1542 | // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) |
1536 | // is now: | 1543 | // is now: |
@@ -1561,7 +1568,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1561 | vertContributionV /= m_verticalAttractionTimescale; | 1568 | vertContributionV /= m_verticalAttractionTimescale; |
1562 | 1569 | ||
1563 | // Rotate the vehicle rotation to the world coordinates. | 1570 | // Rotate the vehicle rotation to the world coordinates. |
1564 | VehicleRotationalVelocity += (vertContributionV * VehicleOrientation); | 1571 | VehicleRotationalVelocity += (vertContributionV * VehicleFrameOrientation); |
1565 | 1572 | ||
1566 | VDetailLog("{0}, MoveAngular,verticalAttraction,,upAxis={1},origRotVW={2},vertError={3},unscaledV={4},eff={5},ts={6},vertContribV={7}", | 1573 | VDetailLog("{0}, MoveAngular,verticalAttraction,,upAxis={1},origRotVW={2},vertError={3},unscaledV={4},eff={5},ts={6},vertContribV={7}", |
1567 | ControllingPrim.LocalID, | 1574 | ControllingPrim.LocalID, |
@@ -1602,7 +1609,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1602 | movingDirection *= Math.Sign(VehicleForwardSpeed); | 1609 | movingDirection *= Math.Sign(VehicleForwardSpeed); |
1603 | 1610 | ||
1604 | // The direction the vehicle is pointing | 1611 | // The direction the vehicle is pointing |
1605 | Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation; | 1612 | Vector3 pointingDirection = Vector3.UnitX * VehicleFrameOrientation; |
1606 | //Predict where the Vehicle will be pointing after AngularVelocity change is applied. This will keep | 1613 | //Predict where the Vehicle will be pointing after AngularVelocity change is applied. This will keep |
1607 | // from overshooting and allow this correction to merge with the Vertical Attraction peacefully. | 1614 | // from overshooting and allow this correction to merge with the Vertical Attraction peacefully. |
1608 | Vector3 predictedPointingDirection = pointingDirection * Quaternion.CreateFromAxisAngle(VehicleRotationalVelocity, 0f); | 1615 | Vector3 predictedPointingDirection = pointingDirection * Quaternion.CreateFromAxisAngle(VehicleRotationalVelocity, 0f); |
@@ -1675,7 +1682,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1675 | // Rotate a UnitZ vector (pointing up) to how the vehicle is oriented. | 1682 | // Rotate a UnitZ vector (pointing up) to how the vehicle is oriented. |
1676 | // As the vehicle rolls to the right or left, the Y value will increase from | 1683 | // As the vehicle rolls to the right or left, the Y value will increase from |
1677 | // zero (straight up) to 1 or -1 (full tilt right or left) | 1684 | // zero (straight up) to 1 or -1 (full tilt right or left) |
1678 | Vector3 rollComponents = Vector3.UnitZ * VehicleOrientation; | 1685 | Vector3 rollComponents = Vector3.UnitZ * VehicleFrameOrientation; |
1679 | 1686 | ||
1680 | // Figure out the yaw value for this much roll. | 1687 | // Figure out the yaw value for this much roll. |
1681 | float yawAngle = m_angularMotorDirection.X * m_bankingEfficiency; | 1688 | float yawAngle = m_angularMotorDirection.X * m_bankingEfficiency; |