diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 193 |
1 files changed, 87 insertions, 106 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index f2c7cec..fe7891e 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -231,6 +231,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
231 | break; | 231 | break; |
232 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 232 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
233 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); | 233 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); |
234 | m_angularMotor.Zero(); | ||
234 | m_angularMotor.SetTarget(m_angularMotorDirection); | 235 | m_angularMotor.SetTarget(m_angularMotorDirection); |
235 | break; | 236 | break; |
236 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 237 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
@@ -264,6 +265,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
264 | pValue.Y = ClampInRange(-12.56f, pValue.Y, 12.56f); | 265 | pValue.Y = ClampInRange(-12.56f, pValue.Y, 12.56f); |
265 | pValue.Z = ClampInRange(-12.56f, pValue.Z, 12.56f); | 266 | pValue.Z = ClampInRange(-12.56f, pValue.Z, 12.56f); |
266 | m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); | 267 | m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); |
268 | m_angularMotor.Zero(); | ||
267 | m_angularMotor.SetTarget(m_angularMotorDirection); | 269 | m_angularMotor.SetTarget(m_angularMotorDirection); |
268 | break; | 270 | break; |
269 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 271 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
@@ -688,7 +690,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
688 | // Bullet does a bunch of smoothing for changing parameters. | 690 | // Bullet does a bunch of smoothing for changing parameters. |
689 | // Since the vehicle is demanding this setting, we override Bullet's smoothing | 691 | // Since the vehicle is demanding this setting, we override Bullet's smoothing |
690 | // by telling Bullet the value was the same last time. | 692 | // by telling Bullet the value was the same last time. |
691 | PhysicsScene.PE.SetInterpolationLinearVelocity(Prim.PhysBody, m_knownVelocity); | 693 | // PhysicsScene.PE.SetInterpolationLinearVelocity(Prim.PhysBody, m_knownVelocity); |
692 | } | 694 | } |
693 | 695 | ||
694 | if ((m_knownChanged & m_knownChangedForce) != 0) | 696 | if ((m_knownChanged & m_knownChangedForce) != 0) |
@@ -700,7 +702,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
700 | if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) | 702 | if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) |
701 | { | 703 | { |
702 | Prim.ForceRotationalVelocity = m_knownRotationalVelocity; | 704 | Prim.ForceRotationalVelocity = m_knownRotationalVelocity; |
703 | PhysicsScene.PE.SetInterpolationAngularVelocity(Prim.PhysBody, m_knownRotationalVelocity); | 705 | // PhysicsScene.PE.SetInterpolationAngularVelocity(Prim.PhysBody, m_knownRotationalVelocity); |
704 | } | 706 | } |
705 | 707 | ||
706 | if ((m_knownChanged & m_knownChangedRotationalImpulse) != 0) | 708 | if ((m_knownChanged & m_knownChangedRotationalImpulse) != 0) |
@@ -720,10 +722,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
720 | 722 | ||
721 | // Since the computation of terrain height can be a little involved, this routine | 723 | // Since the computation of terrain height can be a little involved, this routine |
722 | // is used to fetch the height only once for each vehicle simulation step. | 724 | // is used to fetch the height only once for each vehicle simulation step. |
725 | Vector3 lastRememberedHeightPos; | ||
723 | private float GetTerrainHeight(Vector3 pos) | 726 | private float GetTerrainHeight(Vector3 pos) |
724 | { | 727 | { |
725 | if ((m_knownHas & m_knownChangedTerrainHeight) == 0) | 728 | if ((m_knownHas & m_knownChangedTerrainHeight) == 0 || pos != lastRememberedHeightPos) |
726 | { | 729 | { |
730 | lastRememberedHeightPos = pos; | ||
727 | m_knownTerrainHeight = Prim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos); | 731 | m_knownTerrainHeight = Prim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos); |
728 | m_knownHas |= m_knownChangedTerrainHeight; | 732 | m_knownHas |= m_knownChangedTerrainHeight; |
729 | } | 733 | } |
@@ -943,10 +947,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
943 | // ================================================================== | 947 | // ================================================================== |
944 | // Clamp high or low velocities | 948 | // Clamp high or low velocities |
945 | float newVelocityLengthSq = VehicleVelocity.LengthSquared(); | 949 | float newVelocityLengthSq = VehicleVelocity.LengthSquared(); |
946 | if (newVelocityLengthSq > 1000f) | 950 | if (newVelocityLengthSq > BSParam.VehicleMaxLinearVelocity) |
947 | { | 951 | { |
948 | VehicleVelocity /= VehicleVelocity.Length(); | 952 | VehicleVelocity /= VehicleVelocity.Length(); |
949 | VehicleVelocity *= 1000f; | 953 | VehicleVelocity *= BSParam.VehicleMaxLinearVelocity; |
950 | } | 954 | } |
951 | else if (newVelocityLengthSq < 0.001f) | 955 | else if (newVelocityLengthSq < 0.001f) |
952 | VehicleVelocity = Vector3.Zero; | 956 | VehicleVelocity = Vector3.Zero; |
@@ -957,39 +961,25 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
957 | 961 | ||
958 | public void ComputeLinearVelocity(float pTimestep) | 962 | public void ComputeLinearVelocity(float pTimestep) |
959 | { | 963 | { |
960 | Vector3 linearMotorStep = m_linearMotor.Step(pTimestep); | 964 | // Step the motor from the current value. Get the correction needed this step. |
965 | Vector3 currentVel = VehicleVelocity * Quaternion.Inverse(VehicleOrientation); | ||
966 | Vector3 linearMotorCorrectionV = m_linearMotor.Step(pTimestep, currentVel); | ||
961 | 967 | ||
962 | // The movement computed in the linear motor is relative to the vehicle | 968 | // Motor is vehicle coordinates. Rotate it to world coordinates |
963 | // coordinates. Rotate the movement to world coordinates. | 969 | Vector3 linearMotorVelocityW = linearMotorCorrectionV * VehicleOrientation; |
964 | Vector3 linearMotorVelocity = linearMotorStep * VehicleOrientation; | ||
965 | 970 | ||
966 | // If we're a ground vehicle, don't loose any Z action (like gravity acceleration). | 971 | // If we're a ground vehicle, don't add any upward Z movement |
967 | float mixFactor = 1f; // 1 means use all linear motor Z value, 0 means use all existing Z | ||
968 | if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0) | 972 | if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0) |
969 | { | 973 | { |
970 | if (!Prim.IsColliding) | 974 | if (linearMotorVelocityW.Z > 0f) |
971 | { | 975 | linearMotorVelocityW.Z = 0f; |
972 | // If a ground vehicle and not on the ground, I want gravity effect | ||
973 | mixFactor = 0.2f; | ||
974 | } | ||
975 | } | ||
976 | else | ||
977 | { | ||
978 | // I'm not a ground vehicle but don't totally loose the effect of the environment | ||
979 | mixFactor = 0.8f; | ||
980 | } | 976 | } |
981 | linearMotorVelocity.Z = mixFactor * linearMotorVelocity.Z + (1f - mixFactor) * VehicleVelocity.Z; | ||
982 | |||
983 | // What we want to contribute to the vehicle's existing velocity | ||
984 | Vector3 linearMotorForce = linearMotorVelocity - VehicleVelocity; | ||
985 | |||
986 | // Act against the inertia of the vehicle | ||
987 | linearMotorForce *= m_vehicleMass; | ||
988 | 977 | ||
989 | VehicleAddForceImpulse(linearMotorForce * pTimestep); | 978 | // Add this correction to the velocity to make it faster/slower. |
979 | VehicleVelocity += linearMotorVelocityW; | ||
990 | 980 | ||
991 | VDetailLog("{0}, MoveLinear,velocity,vehVel={1},step={2},stepVel={3},mix={4},force={5}", | 981 | VDetailLog("{0}, MoveLinear,velocity,vehVel={1},correction={2},force={3}", |
992 | Prim.LocalID, VehicleVelocity, linearMotorStep, linearMotorVelocity, mixFactor, linearMotorForce); | 982 | Prim.LocalID, VehicleVelocity, linearMotorCorrectionV, linearMotorVelocityW); |
993 | } | 983 | } |
994 | 984 | ||
995 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) | 985 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) |
@@ -1133,8 +1123,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1133 | // a downward raycast to find what is below. | 1123 | // a downward raycast to find what is below. |
1134 | public void ComputeLinearMotorUp(float pTimestep) | 1124 | public void ComputeLinearMotorUp(float pTimestep) |
1135 | { | 1125 | { |
1136 | Vector3 ret = Vector3.Zero; | ||
1137 | |||
1138 | if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0) | 1126 | if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0) |
1139 | { | 1127 | { |
1140 | // This code tries to decide if the object is not on the ground and then pushing down | 1128 | // This code tries to decide if the object is not on the ground and then pushing down |
@@ -1202,62 +1190,27 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1202 | // set directly on the vehicle. | 1190 | // set directly on the vehicle. |
1203 | private void MoveAngular(float pTimestep) | 1191 | private void MoveAngular(float pTimestep) |
1204 | { | 1192 | { |
1205 | // The user wants this many radians per second angular change? | 1193 | // VehicleRotationalVelocity = Vector3.Zero; |
1206 | Vector3 angularMotorContribution = m_angularMotor.Step(pTimestep); | ||
1207 | 1194 | ||
1208 | // ================================================================== | 1195 | ComputeAngularTurning(pTimestep); |
1209 | // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : | ||
1210 | // This flag prevents linear deflection parallel to world z-axis. This is useful | ||
1211 | // for preventing ground vehicles with large linear deflection, like bumper cars, | ||
1212 | // from climbing their linear deflection into the sky. | ||
1213 | // That is, NO_DEFLECTION_UP says angular motion should not add any pitch or roll movement | ||
1214 | // TODO: This is here because this is where ODE put it but documentation says it | ||
1215 | // is a linear effect. Where should this check go? | ||
1216 | if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0) | ||
1217 | { | ||
1218 | angularMotorContribution.X = 0f; | ||
1219 | angularMotorContribution.Y = 0f; | ||
1220 | VDetailLog("{0}, MoveAngular,noDeflectionUp,angularMotorContrib={1}", Prim.LocalID, angularMotorContribution); | ||
1221 | } | ||
1222 | |||
1223 | Vector3 verticalAttractionContribution = ComputeAngularVerticalAttraction(); | ||
1224 | 1196 | ||
1225 | Vector3 deflectionContribution = ComputeAngularDeflection(); | 1197 | ComputeAngularVerticalAttraction(); |
1226 | 1198 | ||
1227 | Vector3 bankingContribution = ComputeAngularBanking(); | 1199 | ComputeAngularDeflection(); |
1228 | 1200 | ||
1229 | // ================================================================== | 1201 | ComputeAngularBanking(); |
1230 | m_lastVertAttractor = verticalAttractionContribution; | ||
1231 | |||
1232 | m_lastAngularVelocity = angularMotorContribution | ||
1233 | + verticalAttractionContribution | ||
1234 | + deflectionContribution | ||
1235 | + bankingContribution; | ||
1236 | |||
1237 | // Add of the above computation are made relative to vehicle coordinates. | ||
1238 | // Convert to world coordinates. | ||
1239 | m_lastAngularVelocity *= VehicleOrientation; | ||
1240 | 1202 | ||
1241 | // ================================================================== | 1203 | // ================================================================== |
1242 | // Apply the correction velocity. | 1204 | if (VehicleRotationalVelocity.ApproxEquals(Vector3.Zero, 0.01f)) |
1243 | // TODO: Should this be applied as an angular force (torque)? | ||
1244 | if (!m_lastAngularVelocity.ApproxEquals(Vector3.Zero, 0.01f)) | ||
1245 | { | ||
1246 | VehicleRotationalVelocity = m_lastAngularVelocity; | ||
1247 | |||
1248 | VDetailLog("{0}, MoveAngular,done,nonZero,angMotorContrib={1},vertAttrContrib={2},bankContrib={3},deflectContrib={4},totalContrib={5}", | ||
1249 | Prim.LocalID, | ||
1250 | angularMotorContribution, verticalAttractionContribution, | ||
1251 | bankingContribution, deflectionContribution, | ||
1252 | m_lastAngularVelocity | ||
1253 | ); | ||
1254 | } | ||
1255 | else | ||
1256 | { | 1205 | { |
1257 | // The vehicle is not adding anything angular wise. | 1206 | // The vehicle is not adding anything angular wise. |
1258 | VehicleRotationalVelocity = Vector3.Zero; | 1207 | VehicleRotationalVelocity = Vector3.Zero; |
1259 | VDetailLog("{0}, MoveAngular,done,zero", Prim.LocalID); | 1208 | VDetailLog("{0}, MoveAngular,done,zero", Prim.LocalID); |
1260 | } | 1209 | } |
1210 | else | ||
1211 | { | ||
1212 | VDetailLog("{0}, MoveAngular,done,nonZero,angVel={1}", Prim.LocalID, VehicleRotationalVelocity); | ||
1213 | } | ||
1261 | 1214 | ||
1262 | // ================================================================== | 1215 | // ================================================================== |
1263 | //Offset section | 1216 | //Offset section |
@@ -1291,6 +1244,31 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1291 | } | 1244 | } |
1292 | 1245 | ||
1293 | } | 1246 | } |
1247 | |||
1248 | private void ComputeAngularTurning(float pTimestep) | ||
1249 | { | ||
1250 | // The user wants this many radians per second angular change? | ||
1251 | Vector3 currentAngularV = VehicleRotationalVelocity * Quaternion.Inverse(VehicleOrientation); | ||
1252 | Vector3 angularMotorContributionV = m_angularMotor.Step(pTimestep, currentAngularV); | ||
1253 | |||
1254 | // ================================================================== | ||
1255 | // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : | ||
1256 | // This flag prevents linear deflection parallel to world z-axis. This is useful | ||
1257 | // for preventing ground vehicles with large linear deflection, like bumper cars, | ||
1258 | // from climbing their linear deflection into the sky. | ||
1259 | // That is, NO_DEFLECTION_UP says angular motion should not add any pitch or roll movement | ||
1260 | // TODO: This is here because this is where ODE put it but documentation says it | ||
1261 | // is a linear effect. Where should this check go? | ||
1262 | if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0) | ||
1263 | { | ||
1264 | angularMotorContributionV.X = 0f; | ||
1265 | angularMotorContributionV.Y = 0f; | ||
1266 | } | ||
1267 | |||
1268 | VehicleRotationalVelocity += angularMotorContributionV * VehicleOrientation; | ||
1269 | VDetailLog("{0}, MoveAngular,angularTurning,angularMotorContrib={1}", Prim.LocalID, angularMotorContributionV); | ||
1270 | } | ||
1271 | |||
1294 | // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: | 1272 | // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: |
1295 | // Some vehicles, like boats, should always keep their up-side up. This can be done by | 1273 | // Some vehicles, like boats, should always keep their up-side up. This can be done by |
1296 | // enabling the "vertical attractor" behavior that springs the vehicle's local z-axis to | 1274 | // enabling the "vertical attractor" behavior that springs the vehicle's local z-axis to |
@@ -1299,13 +1277,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1299 | // and then set the VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY to control the damping. An | 1277 | // and then set the VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY to control the damping. An |
1300 | // efficiency of 0.0 will cause the spring to wobble around its equilibrium, while an | 1278 | // efficiency of 0.0 will cause the spring to wobble around its equilibrium, while an |
1301 | // efficiency of 1.0 will cause the spring to reach its equilibrium with exponential decay. | 1279 | // efficiency of 1.0 will cause the spring to reach its equilibrium with exponential decay. |
1302 | public Vector3 ComputeAngularVerticalAttraction() | 1280 | public void ComputeAngularVerticalAttraction() |
1303 | { | 1281 | { |
1304 | Vector3 ret = Vector3.Zero; | ||
1305 | |||
1306 | // If vertical attaction timescale is reasonable | 1282 | // If vertical attaction timescale is reasonable |
1307 | if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) | 1283 | if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) |
1308 | { | 1284 | { |
1285 | Vector3 vertContributionV = Vector3.Zero; | ||
1286 | |||
1309 | // Take a vector pointing up and convert it from world to vehicle relative coords. | 1287 | // Take a vector pointing up and convert it from world to vehicle relative coords. |
1310 | Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; | 1288 | Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; |
1311 | 1289 | ||
@@ -1319,37 +1297,36 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1319 | 1297 | ||
1320 | // Y error means needed rotation around X axis and visa versa. | 1298 | // Y error means needed rotation around X axis and visa versa. |
1321 | // Since the error goes from zero to one, the asin is the corresponding angle. | 1299 | // Since the error goes from zero to one, the asin is the corresponding angle. |
1322 | ret.X = (float)Math.Asin(verticalError.Y); | 1300 | vertContributionV.X = (float)Math.Asin(verticalError.Y); |
1323 | // (Tilt forward (positive X) needs to tilt back (rotate negative) around Y axis.) | 1301 | // (Tilt forward (positive X) needs to tilt back (rotate negative) around Y axis.) |
1324 | ret.Y = -(float)Math.Asin(verticalError.X); | 1302 | vertContributionV.Y = -(float)Math.Asin(verticalError.X); |
1325 | 1303 | ||
1326 | // If verticalError.Z is negative, the vehicle is upside down. Add additional push. | 1304 | // If verticalError.Z is negative, the vehicle is upside down. Add additional push. |
1327 | if (verticalError.Z < 0f) | 1305 | if (verticalError.Z < 0f) |
1328 | { | 1306 | { |
1329 | ret.X += PIOverFour; | 1307 | vertContributionV.X += PIOverFour; |
1330 | ret.Y += PIOverFour; | 1308 | // vertContribution.Y -= PIOverFour; |
1331 | } | 1309 | } |
1332 | 1310 | ||
1333 | // 'ret' is now the necessary velocity to correct tilt in one second. | 1311 | // 'vertContrbution' is now the necessary angular correction to correct tilt in one second. |
1334 | // Correction happens over a number of seconds. | 1312 | // Correction happens over a number of seconds. |
1335 | Vector3 unscaledContrib = ret; | 1313 | Vector3 unscaledContrib = vertContributionV; // DEBUG DEBUG |
1336 | ret /= m_verticalAttractionTimescale; | 1314 | vertContributionV /= m_verticalAttractionTimescale; |
1315 | |||
1316 | VehicleRotationalVelocity += vertContributionV * VehicleOrientation; | ||
1337 | 1317 | ||
1338 | VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},eff={3},ts={4},vertAttr={5}", | 1318 | VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},eff={3},ts={4},vertAttr={5}", |
1339 | Prim.LocalID, verticalError, unscaledContrib, m_verticalAttractionEfficiency, m_verticalAttractionTimescale, ret); | 1319 | Prim.LocalID, verticalError, unscaledContrib, m_verticalAttractionEfficiency, m_verticalAttractionTimescale, vertContributionV); |
1340 | } | 1320 | } |
1341 | return ret; | ||
1342 | } | 1321 | } |
1343 | 1322 | ||
1344 | // Return the angular correction to correct the direction the vehicle is pointing to be | 1323 | // Angular correction to correct the direction the vehicle is pointing to be |
1345 | // the direction is should want to be pointing. | 1324 | // the direction is should want to be pointing. |
1346 | // The vehicle is moving in some direction and correct its orientation to it is pointing | 1325 | // The vehicle is moving in some direction and correct its orientation to it is pointing |
1347 | // in that direction. | 1326 | // in that direction. |
1348 | // TODO: implement reference frame. | 1327 | // TODO: implement reference frame. |
1349 | public Vector3 ComputeAngularDeflection() | 1328 | public void ComputeAngularDeflection() |
1350 | { | 1329 | { |
1351 | Vector3 ret = Vector3.Zero; | ||
1352 | |||
1353 | // Since angularMotorUp and angularDeflection are computed independently, they will calculate | 1330 | // Since angularMotorUp and angularDeflection are computed independently, they will calculate |
1354 | // approximately the same X or Y correction. When added together (when contributions are combined) | 1331 | // approximately the same X or Y correction. When added together (when contributions are combined) |
1355 | // this creates an over-correction and then wabbling as the target is overshot. | 1332 | // this creates an over-correction and then wabbling as the target is overshot. |
@@ -1357,6 +1334,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1357 | 1334 | ||
1358 | if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleForwardSpeed > 0.2) | 1335 | if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleForwardSpeed > 0.2) |
1359 | { | 1336 | { |
1337 | Vector3 deflectContributionV = Vector3.Zero; | ||
1338 | |||
1360 | // The direction the vehicle is moving | 1339 | // The direction the vehicle is moving |
1361 | Vector3 movingDirection = VehicleVelocity; | 1340 | Vector3 movingDirection = VehicleVelocity; |
1362 | movingDirection.Normalize(); | 1341 | movingDirection.Normalize(); |
@@ -1382,18 +1361,19 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1382 | // ret = m_angularDeflectionCorrectionMotor(1f, deflectionError); | 1361 | // ret = m_angularDeflectionCorrectionMotor(1f, deflectionError); |
1383 | 1362 | ||
1384 | // Scale the correction by recovery timescale and efficiency | 1363 | // Scale the correction by recovery timescale and efficiency |
1385 | ret = (-deflectionError) * m_angularDeflectionEfficiency; | 1364 | deflectContributionV = (-deflectionError) * m_angularDeflectionEfficiency; |
1386 | ret /= m_angularDeflectionTimescale; | 1365 | deflectContributionV /= m_angularDeflectionTimescale; |
1366 | |||
1367 | VehicleRotationalVelocity += deflectContributionV * VehicleOrientation; | ||
1387 | 1368 | ||
1388 | VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", | 1369 | VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", |
1389 | Prim.LocalID, movingDirection, pointingDirection, deflectionError, ret); | 1370 | Prim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContributionV); |
1390 | VDetailLog("{0}, MoveAngular,Deflection,fwdSpd={1},defEff={2},defTS={3}", | 1371 | VDetailLog("{0}, MoveAngular,Deflection,fwdSpd={1},defEff={2},defTS={3}", |
1391 | Prim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale); | 1372 | Prim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale); |
1392 | } | 1373 | } |
1393 | return ret; | ||
1394 | } | 1374 | } |
1395 | 1375 | ||
1396 | // Return an angular change to rotate the vehicle around the Z axis when the vehicle | 1376 | // Angular change to rotate the vehicle around the Z axis when the vehicle |
1397 | // is tipped around the X axis. | 1377 | // is tipped around the X axis. |
1398 | // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: | 1378 | // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: |
1399 | // The vertical attractor feature must be enabled in order for the banking behavior to | 1379 | // The vertical attractor feature must be enabled in order for the banking behavior to |
@@ -1424,12 +1404,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1424 | // world z-axis is determined by the VEHICLE_BANKING_TIMESCALE. So if you want the vehicle to | 1404 | // world z-axis is determined by the VEHICLE_BANKING_TIMESCALE. So if you want the vehicle to |
1425 | // bank quickly then give it a banking timescale of about a second or less, otherwise you can | 1405 | // bank quickly then give it a banking timescale of about a second or less, otherwise you can |
1426 | // make a sluggish vehicle by giving it a timescale of several seconds. | 1406 | // make a sluggish vehicle by giving it a timescale of several seconds. |
1427 | public Vector3 ComputeAngularBanking() | 1407 | public void ComputeAngularBanking() |
1428 | { | 1408 | { |
1429 | Vector3 ret = Vector3.Zero; | ||
1430 | |||
1431 | if (enableAngularBanking && m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff) | 1409 | if (enableAngularBanking && m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff) |
1432 | { | 1410 | { |
1411 | Vector3 bankingContributionV = Vector3.Zero; | ||
1412 | |||
1433 | // Rotate a UnitZ vector (pointing up) to how the vehicle is oriented. | 1413 | // Rotate a UnitZ vector (pointing up) to how the vehicle is oriented. |
1434 | // As the vehicle rolls to the right or left, the Y value will increase from | 1414 | // As the vehicle rolls to the right or left, the Y value will increase from |
1435 | // zero (straight up) to 1 or -1 (full tilt right or left) | 1415 | // zero (straight up) to 1 or -1 (full tilt right or left) |
@@ -1446,15 +1426,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1446 | mixedYawAngle = ClampInRange(-20f, mixedYawAngle, 20f); | 1426 | mixedYawAngle = ClampInRange(-20f, mixedYawAngle, 20f); |
1447 | 1427 | ||
1448 | // Build the force vector to change rotation from what it is to what it should be | 1428 | // Build the force vector to change rotation from what it is to what it should be |
1449 | ret.Z = -mixedYawAngle; | 1429 | bankingContributionV.Z = -mixedYawAngle; |
1450 | 1430 | ||
1451 | // Don't do it all at once. | 1431 | // Don't do it all at once. |
1452 | ret /= m_bankingTimescale; | 1432 | bankingContributionV /= m_bankingTimescale; |
1433 | |||
1434 | VehicleRotationalVelocity += bankingContributionV * VehicleOrientation; | ||
1453 | 1435 | ||
1454 | VDetailLog("{0}, MoveAngular,Banking,rollComp={1},speed={2},rollComp={3},yAng={4},mYAng={5},ret={6}", | 1436 | VDetailLog("{0}, MoveAngular,Banking,rollComp={1},speed={2},rollComp={3},yAng={4},mYAng={5},ret={6}", |
1455 | Prim.LocalID, rollComponents, VehicleForwardSpeed, rollComponents, yawAngle, mixedYawAngle, ret); | 1437 | Prim.LocalID, rollComponents, VehicleForwardSpeed, rollComponents, yawAngle, mixedYawAngle, bankingContributionV); |
1456 | } | 1438 | } |
1457 | return ret; | ||
1458 | } | 1439 | } |
1459 | 1440 | ||
1460 | // This is from previous instantiations of XXXDynamics.cs. | 1441 | // This is from previous instantiations of XXXDynamics.cs. |