diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 187 |
1 files changed, 85 insertions, 102 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index f2c7cec..dbe44de 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: |
@@ -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 linearMotorCorrection = 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 linearMotorVelocity = linearMotorCorrection * 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 (linearMotorVelocity.Z > 0f) |
971 | { | 975 | linearMotorVelocity.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 += linearMotorVelocity; | ||
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, linearMotorCorrection, linearMotorVelocity); |
993 | } | 983 | } |
994 | 984 | ||
995 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) | 985 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) |
@@ -1202,62 +1192,27 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1202 | // set directly on the vehicle. | 1192 | // set directly on the vehicle. |
1203 | private void MoveAngular(float pTimestep) | 1193 | private void MoveAngular(float pTimestep) |
1204 | { | 1194 | { |
1205 | // The user wants this many radians per second angular change? | 1195 | // VehicleRotationalVelocity = Vector3.Zero; |
1206 | Vector3 angularMotorContribution = m_angularMotor.Step(pTimestep); | ||
1207 | |||
1208 | // ================================================================== | ||
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 | ComputeAngularTurning(pTimestep); |
1226 | 1198 | ||
1227 | Vector3 bankingContribution = ComputeAngularBanking(); | 1199 | ComputeAngularVerticalAttraction(); |
1228 | 1200 | ||
1229 | // ================================================================== | 1201 | ComputeAngularDeflection(); |
1230 | m_lastVertAttractor = verticalAttractionContribution; | ||
1231 | |||
1232 | m_lastAngularVelocity = angularMotorContribution | ||
1233 | + verticalAttractionContribution | ||
1234 | + deflectionContribution | ||
1235 | + bankingContribution; | ||
1236 | 1202 | ||
1237 | // Add of the above computation are made relative to vehicle coordinates. | 1203 | ComputeAngularBanking(); |
1238 | // Convert to world coordinates. | ||
1239 | m_lastAngularVelocity *= VehicleOrientation; | ||
1240 | 1204 | ||
1241 | // ================================================================== | 1205 | // ================================================================== |
1242 | // Apply the correction velocity. | 1206 | 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 | { | 1207 | { |
1257 | // The vehicle is not adding anything angular wise. | 1208 | // The vehicle is not adding anything angular wise. |
1258 | VehicleRotationalVelocity = Vector3.Zero; | 1209 | VehicleRotationalVelocity = Vector3.Zero; |
1259 | VDetailLog("{0}, MoveAngular,done,zero", Prim.LocalID); | 1210 | VDetailLog("{0}, MoveAngular,done,zero", Prim.LocalID); |
1260 | } | 1211 | } |
1212 | else | ||
1213 | { | ||
1214 | VDetailLog("{0}, MoveAngular,done,nonZero,angVel={1}", Prim.LocalID, VehicleRotationalVelocity); | ||
1215 | } | ||
1261 | 1216 | ||
1262 | // ================================================================== | 1217 | // ================================================================== |
1263 | //Offset section | 1218 | //Offset section |
@@ -1291,6 +1246,31 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1291 | } | 1246 | } |
1292 | 1247 | ||
1293 | } | 1248 | } |
1249 | |||
1250 | private void ComputeAngularTurning(float pTimestep) | ||
1251 | { | ||
1252 | // The user wants this many radians per second angular change? | ||
1253 | Vector3 currentAngular = VehicleRotationalVelocity * Quaternion.Inverse(VehicleOrientation); | ||
1254 | Vector3 angularMotorContribution = m_angularMotor.Step(pTimestep, currentAngular); | ||
1255 | |||
1256 | // ================================================================== | ||
1257 | // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : | ||
1258 | // This flag prevents linear deflection parallel to world z-axis. This is useful | ||
1259 | // for preventing ground vehicles with large linear deflection, like bumper cars, | ||
1260 | // from climbing their linear deflection into the sky. | ||
1261 | // That is, NO_DEFLECTION_UP says angular motion should not add any pitch or roll movement | ||
1262 | // TODO: This is here because this is where ODE put it but documentation says it | ||
1263 | // is a linear effect. Where should this check go? | ||
1264 | if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0) | ||
1265 | { | ||
1266 | angularMotorContribution.X = 0f; | ||
1267 | angularMotorContribution.Y = 0f; | ||
1268 | } | ||
1269 | |||
1270 | VehicleRotationalVelocity += angularMotorContribution * VehicleOrientation; | ||
1271 | VDetailLog("{0}, MoveAngular,angularTurning,angularMotorContrib={1}", Prim.LocalID, angularMotorContribution); | ||
1272 | } | ||
1273 | |||
1294 | // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: | 1274 | // 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 | 1275 | // 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 | 1276 | // enabling the "vertical attractor" behavior that springs the vehicle's local z-axis to |
@@ -1299,13 +1279,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1299 | // and then set the VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY to control the damping. An | 1279 | // 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 | 1280 | // 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. | 1281 | // efficiency of 1.0 will cause the spring to reach its equilibrium with exponential decay. |
1302 | public Vector3 ComputeAngularVerticalAttraction() | 1282 | public void ComputeAngularVerticalAttraction() |
1303 | { | 1283 | { |
1304 | Vector3 ret = Vector3.Zero; | ||
1305 | |||
1306 | // If vertical attaction timescale is reasonable | 1284 | // If vertical attaction timescale is reasonable |
1307 | if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) | 1285 | if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) |
1308 | { | 1286 | { |
1287 | Vector3 vertContribution = Vector3.Zero; | ||
1288 | |||
1309 | // Take a vector pointing up and convert it from world to vehicle relative coords. | 1289 | // Take a vector pointing up and convert it from world to vehicle relative coords. |
1310 | Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; | 1290 | Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; |
1311 | 1291 | ||
@@ -1319,37 +1299,36 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1319 | 1299 | ||
1320 | // Y error means needed rotation around X axis and visa versa. | 1300 | // 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. | 1301 | // Since the error goes from zero to one, the asin is the corresponding angle. |
1322 | ret.X = (float)Math.Asin(verticalError.Y); | 1302 | vertContribution.X = (float)Math.Asin(verticalError.Y); |
1323 | // (Tilt forward (positive X) needs to tilt back (rotate negative) around Y axis.) | 1303 | // (Tilt forward (positive X) needs to tilt back (rotate negative) around Y axis.) |
1324 | ret.Y = -(float)Math.Asin(verticalError.X); | 1304 | vertContribution.Y = -(float)Math.Asin(verticalError.X); |
1325 | 1305 | ||
1326 | // If verticalError.Z is negative, the vehicle is upside down. Add additional push. | 1306 | // If verticalError.Z is negative, the vehicle is upside down. Add additional push. |
1327 | if (verticalError.Z < 0f) | 1307 | if (verticalError.Z < 0f) |
1328 | { | 1308 | { |
1329 | ret.X += PIOverFour; | 1309 | vertContribution.X += PIOverFour; |
1330 | ret.Y += PIOverFour; | 1310 | // vertContribution.Y -= PIOverFour; |
1331 | } | 1311 | } |
1332 | 1312 | ||
1333 | // 'ret' is now the necessary velocity to correct tilt in one second. | 1313 | // 'vertContrbution' is now the necessary angular correction to correct tilt in one second. |
1334 | // Correction happens over a number of seconds. | 1314 | // Correction happens over a number of seconds. |
1335 | Vector3 unscaledContrib = ret; | 1315 | Vector3 unscaledContrib = vertContribution; // DEBUG DEBUG |
1336 | ret /= m_verticalAttractionTimescale; | 1316 | vertContribution /= m_verticalAttractionTimescale; |
1317 | |||
1318 | VehicleRotationalVelocity += vertContribution * VehicleOrientation; | ||
1337 | 1319 | ||
1338 | VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},eff={3},ts={4},vertAttr={5}", | 1320 | VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},eff={3},ts={4},vertAttr={5}", |
1339 | Prim.LocalID, verticalError, unscaledContrib, m_verticalAttractionEfficiency, m_verticalAttractionTimescale, ret); | 1321 | Prim.LocalID, verticalError, unscaledContrib, m_verticalAttractionEfficiency, m_verticalAttractionTimescale, vertContribution); |
1340 | } | 1322 | } |
1341 | return ret; | ||
1342 | } | 1323 | } |
1343 | 1324 | ||
1344 | // Return the angular correction to correct the direction the vehicle is pointing to be | 1325 | // Angular correction to correct the direction the vehicle is pointing to be |
1345 | // the direction is should want to be pointing. | 1326 | // the direction is should want to be pointing. |
1346 | // The vehicle is moving in some direction and correct its orientation to it is pointing | 1327 | // The vehicle is moving in some direction and correct its orientation to it is pointing |
1347 | // in that direction. | 1328 | // in that direction. |
1348 | // TODO: implement reference frame. | 1329 | // TODO: implement reference frame. |
1349 | public Vector3 ComputeAngularDeflection() | 1330 | public void ComputeAngularDeflection() |
1350 | { | 1331 | { |
1351 | Vector3 ret = Vector3.Zero; | ||
1352 | |||
1353 | // Since angularMotorUp and angularDeflection are computed independently, they will calculate | 1332 | // 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) | 1333 | // 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. | 1334 | // this creates an over-correction and then wabbling as the target is overshot. |
@@ -1357,6 +1336,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1357 | 1336 | ||
1358 | if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleForwardSpeed > 0.2) | 1337 | if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleForwardSpeed > 0.2) |
1359 | { | 1338 | { |
1339 | Vector3 deflectContribution = Vector3.Zero; | ||
1340 | |||
1360 | // The direction the vehicle is moving | 1341 | // The direction the vehicle is moving |
1361 | Vector3 movingDirection = VehicleVelocity; | 1342 | Vector3 movingDirection = VehicleVelocity; |
1362 | movingDirection.Normalize(); | 1343 | movingDirection.Normalize(); |
@@ -1382,18 +1363,19 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1382 | // ret = m_angularDeflectionCorrectionMotor(1f, deflectionError); | 1363 | // ret = m_angularDeflectionCorrectionMotor(1f, deflectionError); |
1383 | 1364 | ||
1384 | // Scale the correction by recovery timescale and efficiency | 1365 | // Scale the correction by recovery timescale and efficiency |
1385 | ret = (-deflectionError) * m_angularDeflectionEfficiency; | 1366 | deflectContribution = (-deflectionError) * m_angularDeflectionEfficiency; |
1386 | ret /= m_angularDeflectionTimescale; | 1367 | deflectContribution /= m_angularDeflectionTimescale; |
1368 | |||
1369 | VehicleRotationalVelocity += deflectContribution * VehicleOrientation; | ||
1387 | 1370 | ||
1388 | VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", | 1371 | VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", |
1389 | Prim.LocalID, movingDirection, pointingDirection, deflectionError, ret); | 1372 | Prim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContribution); |
1390 | VDetailLog("{0}, MoveAngular,Deflection,fwdSpd={1},defEff={2},defTS={3}", | 1373 | VDetailLog("{0}, MoveAngular,Deflection,fwdSpd={1},defEff={2},defTS={3}", |
1391 | Prim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale); | 1374 | Prim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale); |
1392 | } | 1375 | } |
1393 | return ret; | ||
1394 | } | 1376 | } |
1395 | 1377 | ||
1396 | // Return an angular change to rotate the vehicle around the Z axis when the vehicle | 1378 | // Angular change to rotate the vehicle around the Z axis when the vehicle |
1397 | // is tipped around the X axis. | 1379 | // is tipped around the X axis. |
1398 | // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: | 1380 | // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: |
1399 | // The vertical attractor feature must be enabled in order for the banking behavior to | 1381 | // The vertical attractor feature must be enabled in order for the banking behavior to |
@@ -1424,12 +1406,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1424 | // world z-axis is determined by the VEHICLE_BANKING_TIMESCALE. So if you want the vehicle to | 1406 | // 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 | 1407 | // 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. | 1408 | // make a sluggish vehicle by giving it a timescale of several seconds. |
1427 | public Vector3 ComputeAngularBanking() | 1409 | public void ComputeAngularBanking() |
1428 | { | 1410 | { |
1429 | Vector3 ret = Vector3.Zero; | ||
1430 | |||
1431 | if (enableAngularBanking && m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff) | 1411 | if (enableAngularBanking && m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff) |
1432 | { | 1412 | { |
1413 | Vector3 bankingContribution = Vector3.Zero; | ||
1414 | |||
1433 | // Rotate a UnitZ vector (pointing up) to how the vehicle is oriented. | 1415 | // 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 | 1416 | // 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) | 1417 | // zero (straight up) to 1 or -1 (full tilt right or left) |
@@ -1446,15 +1428,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1446 | mixedYawAngle = ClampInRange(-20f, mixedYawAngle, 20f); | 1428 | mixedYawAngle = ClampInRange(-20f, mixedYawAngle, 20f); |
1447 | 1429 | ||
1448 | // Build the force vector to change rotation from what it is to what it should be | 1430 | // Build the force vector to change rotation from what it is to what it should be |
1449 | ret.Z = -mixedYawAngle; | 1431 | bankingContribution.Z = -mixedYawAngle; |
1450 | 1432 | ||
1451 | // Don't do it all at once. | 1433 | // Don't do it all at once. |
1452 | ret /= m_bankingTimescale; | 1434 | bankingContribution /= m_bankingTimescale; |
1435 | |||
1436 | VehicleRotationalVelocity += bankingContribution * VehicleOrientation; | ||
1453 | 1437 | ||
1454 | VDetailLog("{0}, MoveAngular,Banking,rollComp={1},speed={2},rollComp={3},yAng={4},mYAng={5},ret={6}", | 1438 | 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); | 1439 | Prim.LocalID, rollComponents, VehicleForwardSpeed, rollComponents, yawAngle, mixedYawAngle, bankingContribution); |
1456 | } | 1440 | } |
1457 | return ret; | ||
1458 | } | 1441 | } |
1459 | 1442 | ||
1460 | // This is from previous instantiations of XXXDynamics.cs. | 1443 | // This is from previous instantiations of XXXDynamics.cs. |