diff options
author | Robert Adams | 2012-12-18 23:05:59 -0800 |
---|---|---|
committer | Robert Adams | 2012-12-18 23:05:59 -0800 |
commit | a9b9c0f0351a6749bf55c29b2891fa40928b4c39 (patch) | |
tree | aa8c44483807efacee5edcfdb14073765c691324 /OpenSim/Region | |
parent | BulletSim: initial implementation of a PID motor. Not hooked up yet. (diff) | |
download | opensim-SC-a9b9c0f0351a6749bf55c29b2891fa40928b4c39.zip opensim-SC-a9b9c0f0351a6749bf55c29b2891fa40928b4c39.tar.gz opensim-SC-a9b9c0f0351a6749bf55c29b2891fa40928b4c39.tar.bz2 opensim-SC-a9b9c0f0351a6749bf55c29b2891fa40928b4c39.tar.xz |
BulletSim: improve angularVerticalAttraction calculation to compute angular correction velocity rather than estimating correction (excuse to use trig functions).
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 5887249..912aadd 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -1003,7 +1003,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1003 | // Not colliding if the vehicle is off the ground | 1003 | // Not colliding if the vehicle is off the ground |
1004 | if (!Prim.IsColliding) | 1004 | if (!Prim.IsColliding) |
1005 | { | 1005 | { |
1006 | // downForce = new Vector3(0, 0, (-distanceAboveGround / m_bankingTimescale) * pTimestep); | ||
1007 | // downForce = new Vector3(0, 0, -distanceAboveGround / m_bankingTimescale); | 1006 | // downForce = new Vector3(0, 0, -distanceAboveGround / m_bankingTimescale); |
1008 | ret = new Vector3(0, 0, -distanceAboveGround); | 1007 | ret = new Vector3(0, 0, -distanceAboveGround); |
1009 | } | 1008 | } |
@@ -1135,31 +1134,30 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1135 | // zero and one. | 1134 | // zero and one. |
1136 | // The value of Z is how far the rotation is off with 1 meaning none and 0 being 90 degrees. | 1135 | // The value of Z is how far the rotation is off with 1 meaning none and 0 being 90 degrees. |
1137 | 1136 | ||
1137 | // Y error means needed rotation around X axis and visa versa. | ||
1138 | // Since the error goes from zero to one, the asin is the corresponding angle. | ||
1139 | ret.X = (float)Math.Asin(verticalError.Y); | ||
1140 | ret.Y = (float)Math.Asin(verticalError.X); | ||
1141 | |||
1138 | // If verticalError.Z is negative, the vehicle is upside down. Add additional push. | 1142 | // If verticalError.Z is negative, the vehicle is upside down. Add additional push. |
1139 | if (verticalError.Z < 0f) | 1143 | if (verticalError.Z < 0f) |
1140 | { | 1144 | { |
1141 | verticalError.X = 2f - verticalError.X; | 1145 | ret.X += (float)Math.PI / 4f; |
1142 | verticalError.Y = 2f - verticalError.Y; | 1146 | ret.Y += (float)Math.PI / 4f; |
1143 | } | 1147 | } |
1144 | 1148 | ||
1145 | // Y error means needed rotation around X axis and visa versa. | 1149 | // Put the signs back on so the rotation is in the correct direction. |
1146 | ret.X = verticalError.Y; | 1150 | ret.X *= (float)Math.Sign(verticalError.Y); |
1147 | ret.Y = - verticalError.X; | 1151 | // (Tilt forward (positive X) needs to tilt back (rotate negative) around Y axis.) |
1148 | ret.Z = 0f; | 1152 | ret.Y *= -(float)Math.Sign(verticalError.X); |
1149 | |||
1150 | // Scale the correction force by how far we're off from vertical. | ||
1151 | // Z error of one says little error. As Z gets smaller, the vehicle is leaning farther over. | ||
1152 | float clampedSqrZError = ClampInRange(0.01f, verticalError.Z * verticalError.Z, 1f); | ||
1153 | float vertForce = 1f / clampedSqrZError; | ||
1154 | |||
1155 | ret *= vertForce; | ||
1156 | 1153 | ||
1157 | // Correction happens over a number of seconds. | 1154 | // 'ret' is now the necessary velocity to correct tilt in one second. |
1155 | // Correction happens over a number of seconds. | ||
1158 | Vector3 unscaledContrib = ret; | 1156 | Vector3 unscaledContrib = ret; |
1159 | ret /= m_verticalAttractionTimescale; | 1157 | ret /= m_verticalAttractionTimescale; |
1160 | 1158 | ||
1161 | VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},vertForce={3},eff={4},vertAttr={5}", | 1159 | VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},eff={3},vertAttr={4}", |
1162 | Prim.LocalID, verticalError, unscaledContrib, vertForce, m_verticalAttractionEfficiency, ret); | 1160 | Prim.LocalID, verticalError, unscaledContrib, m_verticalAttractionEfficiency, ret); |
1163 | } | 1161 | } |
1164 | return ret; | 1162 | return ret; |
1165 | } | 1163 | } |
@@ -1172,7 +1170,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1172 | public Vector3 ComputeAngularDeflection() | 1170 | public Vector3 ComputeAngularDeflection() |
1173 | { | 1171 | { |
1174 | Vector3 ret = Vector3.Zero; | 1172 | Vector3 ret = Vector3.Zero; |
1175 | return ret; // DEBUG DEBUG DEBUG debug one force at a time | ||
1176 | 1173 | ||
1177 | if (m_angularDeflectionEfficiency != 0) | 1174 | if (m_angularDeflectionEfficiency != 0) |
1178 | { | 1175 | { |