diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 0dd2aa5..272a162 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -235,7 +235,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
235 | // set all of the components to the same value | 235 | // set all of the components to the same value |
236 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: | 236 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: |
237 | m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue); | 237 | m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue); |
238 | m_angularMotor.FrictionTimescale = m_angularFrictionTimescale; | ||
239 | break; | 238 | break; |
240 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 239 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
241 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); | 240 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); |
@@ -244,7 +243,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
244 | break; | 243 | break; |
245 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 244 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
246 | m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); | 245 | m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); |
247 | m_linearMotor.FrictionTimescale = m_linearFrictionTimescale; | ||
248 | break; | 246 | break; |
249 | case Vehicle.LINEAR_MOTOR_DIRECTION: | 247 | case Vehicle.LINEAR_MOTOR_DIRECTION: |
250 | m_linearMotorDirection = new Vector3(pValue, pValue, pValue); | 248 | m_linearMotorDirection = new Vector3(pValue, pValue, pValue); |
@@ -265,7 +263,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
265 | { | 263 | { |
266 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: | 264 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: |
267 | m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 265 | m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
268 | m_angularMotor.FrictionTimescale = m_angularFrictionTimescale; | ||
269 | break; | 266 | break; |
270 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 267 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
271 | // Limit requested angular speed to 2 rps= 4 pi rads/sec | 268 | // Limit requested angular speed to 2 rps= 4 pi rads/sec |
@@ -278,7 +275,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
278 | break; | 275 | break; |
279 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 276 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
280 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 277 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
281 | m_linearMotor.FrictionTimescale = m_linearFrictionTimescale; | ||
282 | break; | 278 | break; |
283 | case Vehicle.LINEAR_MOTOR_DIRECTION: | 279 | case Vehicle.LINEAR_MOTOR_DIRECTION: |
284 | m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); | 280 | m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); |
@@ -559,14 +555,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
559 | break; | 555 | break; |
560 | } | 556 | } |
561 | 557 | ||
562 | m_linearMotor = new BSVMotor("LinearMotor", m_linearMotorTimescale, | 558 | m_linearMotor = new BSVMotor("LinearMotor", m_linearMotorTimescale, m_linearMotorDecayTimescale, 1f); |
563 | m_linearMotorDecayTimescale, m_linearFrictionTimescale, | ||
564 | 1f); | ||
565 | m_linearMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG DEBUG (enables detail logging) | 559 | m_linearMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG DEBUG (enables detail logging) |
566 | 560 | ||
567 | m_angularMotor = new BSVMotor("AngularMotor", m_angularMotorTimescale, | 561 | m_angularMotor = new BSVMotor("AngularMotor", m_angularMotorTimescale, m_angularMotorDecayTimescale, 1f); |
568 | m_angularMotorDecayTimescale, m_angularFrictionTimescale, | ||
569 | 1f); | ||
570 | m_angularMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG DEBUG (enables detail logging) | 562 | m_angularMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG DEBUG (enables detail logging) |
571 | 563 | ||
572 | /* Not implemented | 564 | /* Not implemented |
@@ -574,7 +566,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
574 | BSMotor.Infinite, BSMotor.InfiniteVector, | 566 | BSMotor.Infinite, BSMotor.InfiniteVector, |
575 | m_verticalAttractionEfficiency); | 567 | m_verticalAttractionEfficiency); |
576 | // Z goes away and we keep X and Y | 568 | // Z goes away and we keep X and Y |
577 | m_verticalAttractionMotor.FrictionTimescale = new Vector3(BSMotor.Infinite, BSMotor.Infinite, 0.1f); | ||
578 | m_verticalAttractionMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) | 569 | m_verticalAttractionMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) |
579 | */ | 570 | */ |
580 | 571 | ||
@@ -1050,8 +1041,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1050 | // Add this correction to the velocity to make it faster/slower. | 1041 | // Add this correction to the velocity to make it faster/slower. |
1051 | VehicleVelocity += linearMotorVelocityW; | 1042 | VehicleVelocity += linearMotorVelocityW; |
1052 | 1043 | ||
1053 | VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},correctV={3},correctW={4},newVelW={5}", | 1044 | // Friction reduces vehicle motion |
1054 | ControllingPrim.LocalID, origVelW, currentVelV, linearMotorCorrectionV, linearMotorVelocityW, VehicleVelocity); | 1045 | Vector3 frictionFactor = ComputeFrictionFactor(m_linearFrictionTimescale, pTimestep); |
1046 | VehicleVelocity -= (VehicleVelocity * frictionFactor); | ||
1047 | |||
1048 | VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},correctV={3},correctW={4},newVelW={5},fricFact={6}", | ||
1049 | ControllingPrim.LocalID, origVelW, currentVelV, linearMotorCorrectionV, | ||
1050 | linearMotorVelocityW, VehicleVelocity, frictionFactor); | ||
1055 | } | 1051 | } |
1056 | 1052 | ||
1057 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) | 1053 | public void ComputeLinearTerrainHeightCorrection(float pTimestep) |
@@ -1342,6 +1338,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1342 | // } | 1338 | // } |
1343 | 1339 | ||
1344 | VehicleRotationalVelocity += angularMotorContributionV * VehicleOrientation; | 1340 | VehicleRotationalVelocity += angularMotorContributionV * VehicleOrientation; |
1341 | |||
1342 | // Reduce any velocity by friction. | ||
1343 | Vector3 frictionFactor = ComputeFrictionFactor(m_angularFrictionTimescale, pTimestep); | ||
1344 | VehicleRotationalVelocity -= (VehicleRotationalVelocity * frictionFactor); | ||
1345 | |||
1345 | VDetailLog("{0}, MoveAngular,angularTurning,angularMotorContrib={1}", ControllingPrim.LocalID, angularMotorContributionV); | 1346 | VDetailLog("{0}, MoveAngular,angularTurning,angularMotorContrib={1}", ControllingPrim.LocalID, angularMotorContributionV); |
1346 | } | 1347 | } |
1347 | 1348 | ||
@@ -1629,6 +1630,23 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1629 | 1630 | ||
1630 | } | 1631 | } |
1631 | 1632 | ||
1633 | // Given a friction vector (reduction in seconds) and a timestep, return the factor to reduce | ||
1634 | // some value by to apply this friction. | ||
1635 | private Vector3 ComputeFrictionFactor(Vector3 friction, float pTimestep) | ||
1636 | { | ||
1637 | Vector3 frictionFactor = Vector3.Zero; | ||
1638 | if (friction != BSMotor.InfiniteVector) | ||
1639 | { | ||
1640 | // frictionFactor = (Vector3.One / FrictionTimescale) * timeStep; | ||
1641 | // Individual friction components can be 'infinite' so compute each separately. | ||
1642 | frictionFactor.X = (friction.X == BSMotor.Infinite) ? 0f : (1f / friction.X); | ||
1643 | frictionFactor.Y = (friction.Y == BSMotor.Infinite) ? 0f : (1f / friction.Y); | ||
1644 | frictionFactor.Z = (friction.Z == BSMotor.Infinite) ? 0f : (1f / friction.Z); | ||
1645 | frictionFactor *= pTimestep; | ||
1646 | } | ||
1647 | return frictionFactor; | ||
1648 | } | ||
1649 | |||
1632 | private float ClampInRange(float low, float val, float high) | 1650 | private float ClampInRange(float low, float val, float high) |
1633 | { | 1651 | { |
1634 | return Math.Max(low, Math.Min(val, high)); | 1652 | return Math.Max(low, Math.Min(val, high)); |