aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs55
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSMotors.cs46
2 files changed, 74 insertions, 27 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 7fd7b82..bf8a004 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -80,6 +80,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
80 private Quaternion m_referenceFrame = Quaternion.Identity; 80 private Quaternion m_referenceFrame = Quaternion.Identity;
81 81
82 // Linear properties 82 // Linear properties
83 private BSVMotor m_linearMotor = new BSVMotor("LinearMotor");
83 private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time 84 private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time
84 private Vector3 m_linearMotorOffset = Vector3.Zero; // the point of force can be offset from the center 85 private Vector3 m_linearMotorOffset = Vector3.Zero; // the point of force can be offset from the center
85 private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL 86 private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL
@@ -152,7 +153,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
152 m_angularDeflectionTimescale = Math.Max(pValue, 0.01f); 153 m_angularDeflectionTimescale = Math.Max(pValue, 0.01f);
153 break; 154 break;
154 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE: 155 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
155 m_angularMotorDecayTimescale = Math.Max(pValue, 0.01f); 156 m_angularMotorDecayTimescale = Math.Max(0.01f, Math.Min(pValue,120));
156 break; 157 break;
157 case Vehicle.ANGULAR_MOTOR_TIMESCALE: 158 case Vehicle.ANGULAR_MOTOR_TIMESCALE:
158 m_angularMotorTimescale = Math.Max(pValue, 0.01f); 159 m_angularMotorTimescale = Math.Max(pValue, 0.01f);
@@ -185,10 +186,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
185 m_linearDeflectionTimescale = Math.Max(pValue, 0.01f); 186 m_linearDeflectionTimescale = Math.Max(pValue, 0.01f);
186 break; 187 break;
187 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE: 188 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
188 m_linearMotorDecayTimescale = Math.Max(pValue, 0.01f); 189 m_linearMotorDecayTimescale = Math.Max(0.01f, Math.Min(pValue,120));
190 m_linearMotor.TargetValueDecayTimeScale = m_linearMotorDecayTimescale;
189 break; 191 break;
190 case Vehicle.LINEAR_MOTOR_TIMESCALE: 192 case Vehicle.LINEAR_MOTOR_TIMESCALE:
191 m_linearMotorTimescale = Math.Max(pValue, 0.01f); 193 m_linearMotorTimescale = Math.Max(pValue, 0.01f);
194 m_linearMotor.TimeScale = m_linearMotorTimescale;
192 break; 195 break;
193 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY: 196 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
194 m_verticalAttractionEfficiency = Math.Max(0.1f, Math.Min(pValue, 1f)); 197 m_verticalAttractionEfficiency = Math.Max(0.1f, Math.Min(pValue, 1f));
@@ -208,10 +211,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
208 break; 211 break;
209 case Vehicle.LINEAR_FRICTION_TIMESCALE: 212 case Vehicle.LINEAR_FRICTION_TIMESCALE:
210 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); 213 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
214 m_linearMotor.FrictionTimescale = m_linearFrictionTimescale;
211 break; 215 break;
212 case Vehicle.LINEAR_MOTOR_DIRECTION: 216 case Vehicle.LINEAR_MOTOR_DIRECTION:
213 m_linearMotorDirection = new Vector3(pValue, pValue, pValue); 217 m_linearMotorDirection = new Vector3(pValue, pValue, pValue);
214 m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue); 218 m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue);
219 m_linearMotor.SetTarget(m_linearMotorDirection);
215 break; 220 break;
216 case Vehicle.LINEAR_MOTOR_OFFSET: 221 case Vehicle.LINEAR_MOTOR_OFFSET:
217 m_linearMotorOffset = new Vector3(pValue, pValue, pValue); 222 m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
@@ -238,10 +243,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
238 break; 243 break;
239 case Vehicle.LINEAR_FRICTION_TIMESCALE: 244 case Vehicle.LINEAR_FRICTION_TIMESCALE:
240 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); 245 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
246 m_linearMotor.FrictionTimescale = m_linearFrictionTimescale;
241 break; 247 break;
242 case Vehicle.LINEAR_MOTOR_DIRECTION: 248 case Vehicle.LINEAR_MOTOR_DIRECTION:
243 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); 249 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
244 m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); 250 m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z);
251 m_linearMotor.SetTarget(m_linearMotorDirection);
245 break; 252 break;
246 case Vehicle.LINEAR_MOTOR_OFFSET: 253 case Vehicle.LINEAR_MOTOR_OFFSET:
247 m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z); 254 m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
@@ -319,6 +326,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
319 326
320 m_referenceFrame = Quaternion.Identity; 327 m_referenceFrame = Quaternion.Identity;
321 m_flags = (VehicleFlag)0; 328 m_flags = (VehicleFlag)0;
329
322 break; 330 break;
323 331
324 case Vehicle.TYPE_SLED: 332 case Vehicle.TYPE_SLED:
@@ -510,6 +518,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
510 | VehicleFlag.HOVER_GLOBAL_HEIGHT); 518 | VehicleFlag.HOVER_GLOBAL_HEIGHT);
511 break; 519 break;
512 } 520 }
521
522 // Update any physical parameters based on this type.
523 Refresh();
524
525 m_linearMotor = new BSVMotor("LinearMotor", m_linearMotorTimescale, m_linearMotorDecayTimescale, m_linearFrictionTimescale, 1f);
526 m_linearMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging)
513 } 527 }
514 528
515 // Some of the properties of this prim may have changed. 529 // Some of the properties of this prim may have changed.
@@ -518,18 +532,25 @@ namespace OpenSim.Region.Physics.BulletSPlugin
518 { 532 {
519 if (IsActive) 533 if (IsActive)
520 { 534 {
521 VDetailLog("{0},BSDynamics.Refresh", Prim.LocalID);
522 m_vehicleMass = Prim.Linkset.LinksetMass; 535 m_vehicleMass = Prim.Linkset.LinksetMass;
523 536
524 // Friction effects are handled by this vehicle code 537 // Friction effects are handled by this vehicle code
525 BulletSimAPI.SetFriction2(Prim.PhysBody.ptr, 0f); 538 float friction = 0f;
526 BulletSimAPI.SetHitFraction2(Prim.PhysBody.ptr, 0f); 539 BulletSimAPI.SetFriction2(Prim.PhysBody.ptr, friction);
527 540
528 BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, PhysicsScene.Params.vehicleAngularDamping); 541 // Moderate angular movement introduced by Bullet.
529 542 // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle.
530 BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, new Vector3(1f, 1f, 1f)); 543 // Maybe compute linear and angular factor and damping from params.
531 544 float angularDamping = PhysicsScene.Params.vehicleAngularDamping;
532 545 BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, angularDamping);
546
547 // DEBUG DEBUG DEBUG: use uniform inertia to smooth movement added by Bullet
548 // Vector3 localInertia = new Vector3(1f, 1f, 1f);
549 Vector3 localInertia = new Vector3(m_vehicleMass, m_vehicleMass, m_vehicleMass);
550 BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia);
551
552 VDetailLog("{0},BSDynamics.Refresh,frict={1},inert={2},aDamp={3}",
553 Prim.LocalID, friction, localInertia, angularDamping);
533 } 554 }
534 } 555 }
535 556
@@ -591,6 +612,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
591 // Also does hover and float. 612 // Also does hover and float.
592 private void MoveLinear(float pTimestep) 613 private void MoveLinear(float pTimestep)
593 { 614 {
615 /*
594 // m_linearMotorDirection is the target direction we are moving relative to the vehicle coordinates 616 // m_linearMotorDirection is the target direction we are moving relative to the vehicle coordinates
595 // m_lastLinearVelocityVector is the current speed we are moving in that direction 617 // m_lastLinearVelocityVector is the current speed we are moving in that direction
596 if (m_linearMotorDirection.LengthSquared() > 0.001f) 618 if (m_linearMotorDirection.LengthSquared() > 0.001f)
@@ -627,6 +649,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
627 649
628 VDetailLog("{0},MoveLinear,zeroed", Prim.LocalID); 650 VDetailLog("{0},MoveLinear,zeroed", Prim.LocalID);
629 } 651 }
652 */
653
654 m_newVelocity = m_linearMotor.Step(pTimestep);
655
656 // Rotate new object velocity from vehicle relative to world coordinates
657 m_newVelocity *= Prim.ForceOrientation;
630 658
631 // m_newVelocity is velocity computed from linear motor in world coordinates 659 // m_newVelocity is velocity computed from linear motor in world coordinates
632 660
@@ -785,12 +813,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
785 m_newVelocity.Z = 0; 813 m_newVelocity.Z = 0;
786 814
787 // Clamp REALLY high or low velocities 815 // Clamp REALLY high or low velocities
788 if (m_newVelocity.LengthSquared() > 1e6f) 816 float newVelocityLengthSq = m_newVelocity.LengthSquared();
817 if (newVelocityLengthSq > 1e6f)
789 { 818 {
790 m_newVelocity /= m_newVelocity.Length(); 819 m_newVelocity /= m_newVelocity.Length();
791 m_newVelocity *= 1000f; 820 m_newVelocity *= 1000f;
792 } 821 }
793 else if (m_newVelocity.LengthSquared() < 1e-6f) 822 else if (newVelocityLengthSq < 1e-6f)
794 m_newVelocity = Vector3.Zero; 823 m_newVelocity = Vector3.Zero;
795 824
796 // Stuff new linear velocity into the vehicle 825 // Stuff new linear velocity into the vehicle
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs
index b8bdd87..68eec2d 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs
@@ -7,13 +7,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin
7{ 7{
8public abstract class BSMotor 8public abstract class BSMotor
9{ 9{
10 public BSMotor() 10 public BSMotor(string useName)
11 { 11 {
12 UseName = useName;
12 PhysicsScene = null; 13 PhysicsScene = null;
13 } 14 }
14 public virtual void Reset() { } 15 public virtual void Reset() { }
15 public virtual void Zero() { } 16 public virtual void Zero() { }
16 17
18 public string UseName { get; private set; }
17 // Used only for outputting debug information. Might not be set so check for null. 19 // Used only for outputting debug information. Might not be set so check for null.
18 public BSScene PhysicsScene { get; set; } 20 public BSScene PhysicsScene { get; set; }
19 protected void MDetailLog(string msg, params Object[] parms) 21 protected void MDetailLog(string msg, params Object[] parms)
@@ -35,17 +37,25 @@ public class BSVMotor : BSMotor
35 37
36 public float TimeScale { get; set; } 38 public float TimeScale { get; set; }
37 public float TargetValueDecayTimeScale { get; set; } 39 public float TargetValueDecayTimeScale { get; set; }
38 public Vector3 CurrentValueReductionTimescale { get; set; } 40 public Vector3 FrictionTimescale { get; set; }
39 public float Efficiency { get; set; } 41 public float Efficiency { get; set; }
40 42
41 public Vector3 TargetValue { get; private set; } 43 public Vector3 TargetValue { get; private set; }
42 public Vector3 CurrentValue { get; private set; } 44 public Vector3 CurrentValue { get; private set; }
43 45
44 BSVMotor(float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) : base() 46 public BSVMotor(string useName)
47 : base(useName)
48 {
49 TimeScale = TargetValueDecayTimeScale = Efficiency = 1f;
50 FrictionTimescale = Vector3.Zero;
51 CurrentValue = TargetValue = Vector3.Zero;
52 }
53 public BSVMotor(string useName, float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency)
54 : this(useName)
45 { 55 {
46 TimeScale = timeScale; 56 TimeScale = timeScale;
47 TargetValueDecayTimeScale = decayTimeScale; 57 TargetValueDecayTimeScale = decayTimeScale;
48 CurrentValueReductionTimescale = frictionTimeScale; 58 FrictionTimescale = frictionTimeScale;
49 Efficiency = efficiency; 59 Efficiency = efficiency;
50 CurrentValue = TargetValue = Vector3.Zero; 60 CurrentValue = TargetValue = Vector3.Zero;
51 } 61 }
@@ -60,10 +70,10 @@ public class BSVMotor : BSMotor
60 public Vector3 Step(float timeStep) 70 public Vector3 Step(float timeStep)
61 { 71 {
62 Vector3 returnCurrent = Vector3.Zero; 72 Vector3 returnCurrent = Vector3.Zero;
63 if (CurrentValue.LengthSquared() > 0.001f) 73 if (!CurrentValue.ApproxEquals(TargetValue, 0.01f))
64 { 74 {
65 // Vector3 origDir = Target; // DEBUG 75 Vector3 origTarget = TargetValue; // DEBUG
66 // Vector3 origVel = CurrentValue; // DEBUG 76 Vector3 origCurrVal = CurrentValue; // DEBUG
67 77
68 // Add (desiredVector - currentAppliedVector) / howLongItShouldTakeToComplete 78 // Add (desiredVector - currentAppliedVector) / howLongItShouldTakeToComplete
69 Vector3 addAmount = (TargetValue - CurrentValue)/TimeScale * timeStep; 79 Vector3 addAmount = (TargetValue - CurrentValue)/TimeScale * timeStep;
@@ -74,11 +84,17 @@ public class BSVMotor : BSMotor
74 float decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep; 84 float decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep;
75 TargetValue *= (1f - decayFactor); 85 TargetValue *= (1f - decayFactor);
76 86
77 Vector3 frictionFactor = (Vector3.One / CurrentValueReductionTimescale) * timeStep; 87 Vector3 frictionFactor = Vector3.Zero;
88 frictionFactor = (Vector3.One / FrictionTimescale) * timeStep;
78 CurrentValue *= (Vector3.One - frictionFactor); 89 CurrentValue *= (Vector3.One - frictionFactor);
79 90
80 MDetailLog("{0},BSVMotor.Step,nonZero,curr={1},target={2},add={3},decay={4},frict={5},ret={6}", 91 MDetailLog("{0},BSVMotor.Step,nonZero,{1},origTarget={2},origCurr={3},timeStep={4},timeScale={5},addAmnt={6},targetDecay={7},decayFact={8},fricTS={9},frictFact={10}",
81 BSScene.DetailLogZero, TargetValue, CurrentValue, 92 BSScene.DetailLogZero, UseName, origTarget, origCurrVal,
93 timeStep, TimeScale, addAmount,
94 TargetValueDecayTimeScale, decayFactor,
95 FrictionTimescale, frictionFactor);
96 MDetailLog("{0},BSVMotor.Step,nonZero,{1},curr={2},target={3},add={4},decay={5},frict={6},ret={7}",
97 BSScene.DetailLogZero, UseName, TargetValue, CurrentValue,
82 addAmount, decayFactor, frictionFactor, returnCurrent); 98 addAmount, decayFactor, frictionFactor, returnCurrent);
83 } 99 }
84 else 100 else
@@ -87,8 +103,8 @@ public class BSVMotor : BSMotor
87 CurrentValue = Vector3.Zero; 103 CurrentValue = Vector3.Zero;
88 TargetValue = Vector3.Zero; 104 TargetValue = Vector3.Zero;
89 105
90 MDetailLog("{0},BSVMotor.Step,zero,curr={1},target={2},ret={3}", 106 MDetailLog("{0},BSVMotor.Step,zero,{1},curr={2},target={3},ret={4}",
91 BSScene.DetailLogZero, TargetValue, CurrentValue, returnCurrent); 107 BSScene.DetailLogZero, UseName, TargetValue, CurrentValue, returnCurrent);
92 108
93 } 109 }
94 return returnCurrent; 110 return returnCurrent;
@@ -105,7 +121,8 @@ public class BSFMotor : BSMotor
105 public float Target { get; private set; } 121 public float Target { get; private set; }
106 public float CurrentValue { get; private set; } 122 public float CurrentValue { get; private set; }
107 123
108 BSFMotor(float timeScale, float decayTimescale, float friction, float efficiency) : base() 124 public BSFMotor(string useName, float timeScale, float decayTimescale, float friction, float efficiency)
125 : base(useName)
109 { 126 {
110 } 127 }
111 public void SetCurrent(float target) 128 public void SetCurrent(float target)
@@ -122,7 +139,8 @@ public class BSFMotor : BSMotor
122public class BSPIDMotor : BSMotor 139public class BSPIDMotor : BSMotor
123{ 140{
124 // TODO: write and use this one 141 // TODO: write and use this one
125 BSPIDMotor() : base() 142 public BSPIDMotor(string useName)
143 : base(useName)
126 { 144 {
127 } 145 }
128} 146}