aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs72
1 files changed, 44 insertions, 28 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 7ad7c89..05ab180 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -125,9 +125,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
125 static readonly float PIOverTwo = ((float)Math.PI) / 2f; 125 static readonly float PIOverTwo = ((float)Math.PI) / 2f;
126 126
127 // For debugging, flags to turn on and off individual corrections. 127 // For debugging, flags to turn on and off individual corrections.
128 private bool enableAngularVerticalAttraction; 128 public bool enableAngularVerticalAttraction;
129 private bool enableAngularDeflection; 129 public bool enableAngularDeflection;
130 private bool enableAngularBanking; 130 public bool enableAngularBanking;
131 131
132 public BSDynamics(BSScene myScene, BSPrim myPrim) 132 public BSDynamics(BSScene myScene, BSPrim myPrim)
133 { 133 {
@@ -146,7 +146,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
146 enableAngularBanking = false; 146 enableAngularBanking = false;
147 if (BSParam.VehicleDebuggingEnabled != ConfigurationParameters.numericFalse) 147 if (BSParam.VehicleDebuggingEnabled != ConfigurationParameters.numericFalse)
148 { 148 {
149 enableAngularVerticalAttraction = false; 149 enableAngularVerticalAttraction = true;
150 enableAngularDeflection = false; 150 enableAngularDeflection = false;
151 enableAngularBanking = false; 151 enableAngularBanking = false;
152 } 152 }
@@ -165,7 +165,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
165 } 165 }
166 166
167 #region Vehicle parameter setting 167 #region Vehicle parameter setting
168 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue) 168 public void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
169 { 169 {
170 VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); 170 VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue);
171 switch (pParam) 171 switch (pParam)
@@ -591,14 +591,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin
591 m_vehicleMass = Prim.Linkset.LinksetMass; 591 m_vehicleMass = Prim.Linkset.LinksetMass;
592 592
593 // Friction affects are handled by this vehicle code 593 // Friction affects are handled by this vehicle code
594 float friction = 0f; 594 PhysicsScene.PE.SetFriction(Prim.PhysBody, BSParam.VehicleFriction);
595 PhysicsScene.PE.SetFriction(Prim.PhysBody, friction); 595 PhysicsScene.PE.SetRestitution(Prim.PhysBody, BSParam.VehicleRestitution);
596 596
597 // Moderate angular movement introduced by Bullet. 597 // Moderate angular movement introduced by Bullet.
598 // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. 598 // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle.
599 // Maybe compute linear and angular factor and damping from params. 599 // Maybe compute linear and angular factor and damping from params.
600 float angularDamping = BSParam.VehicleAngularDamping; 600 PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, BSParam.VehicleAngularDamping);
601 PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, angularDamping); 601 PhysicsScene.PE.SetLinearFactor(Prim.PhysBody, BSParam.VehicleLinearFactorV);
602 PhysicsScene.PE.SetAngularFactorV(Prim.PhysBody, BSParam.VehicleAngularFactorV);
602 603
603 // Vehicles report collision events so we know when it's on the ground 604 // Vehicles report collision events so we know when it's on the ground
604 PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); 605 PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS);
@@ -613,8 +614,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
613 // The actual vehicle gravity is set to zero in Bullet so we can do all the application of same. 614 // The actual vehicle gravity is set to zero in Bullet so we can do all the application of same.
614 PhysicsScene.PE.SetGravity(Prim.PhysBody, Vector3.Zero); 615 PhysicsScene.PE.SetGravity(Prim.PhysBody, Vector3.Zero);
615 616
616 VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4},grav={5}", 617 VDetailLog("{0},BSDynamics.Refresh,mass={1},inert={2},grav={3},aDamp={4},frict={5},rest={6},lFact={7},aFact={8}",
617 Prim.LocalID, m_vehicleMass, friction, Prim.Inertia, angularDamping, m_VehicleGravity); 618 Prim.LocalID, m_vehicleMass, Prim.Inertia, m_VehicleGravity,
619 BSParam.VehicleAngularDamping, BSParam.VehicleFriction, BSParam.VehicleRestitution,
620 BSParam.VehicleLinearFactor, BSParam.VehicleAngularFactor
621 );
618 } 622 }
619 else 623 else
620 { 624 {
@@ -673,13 +677,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
673 private const int m_knownChangedWaterLevel = 1 << 9; 677 private const int m_knownChangedWaterLevel = 1 << 9;
674 private const int m_knownChangedForwardVelocity = 1 <<10; 678 private const int m_knownChangedForwardVelocity = 1 <<10;
675 679
676 private void ForgetKnownVehicleProperties() 680 public void ForgetKnownVehicleProperties()
677 { 681 {
678 m_knownHas = 0; 682 m_knownHas = 0;
679 m_knownChanged = 0; 683 m_knownChanged = 0;
680 } 684 }
681 // Push all the changed values back into the physics engine 685 // Push all the changed values back into the physics engine
682 private void PushKnownChanged() 686 public void PushKnownChanged()
683 { 687 {
684 if (m_knownChanged != 0) 688 if (m_knownChanged != 0)
685 { 689 {
@@ -799,7 +803,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
799 m_knownVelocity = Prim.ForceVelocity; 803 m_knownVelocity = Prim.ForceVelocity;
800 m_knownHas |= m_knownChangedVelocity; 804 m_knownHas |= m_knownChangedVelocity;
801 } 805 }
802 return (Vector3)m_knownVelocity; 806 return m_knownVelocity;
803 } 807 }
804 set 808 set
805 { 809 {
@@ -898,9 +902,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
898 { 902 {
899 if (!IsActive) return; 903 if (!IsActive) return;
900 904
901 if (PhysicsScene.VehiclePhysicalLoggingEnabled)
902 PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody);
903
904 ForgetKnownVehicleProperties(); 905 ForgetKnownVehicleProperties();
905 906
906 MoveLinear(pTimestep); 907 MoveLinear(pTimestep);
@@ -922,6 +923,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin
922 Prim.LocalID, VehiclePosition, m_knownForce, VehicleVelocity, VehicleRotationalVelocity); 923 Prim.LocalID, VehiclePosition, m_knownForce, VehicleVelocity, VehicleRotationalVelocity);
923 } 924 }
924 925
926 // Called after the simulation step
927 internal void PostStep(float pTimestep)
928 {
929 if (!IsActive) return;
930
931 if (PhysicsScene.VehiclePhysicalLoggingEnabled)
932 PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody);
933 }
934
925 // Apply the effect of the linear motor and other linear motions (like hover and float). 935 // Apply the effect of the linear motor and other linear motions (like hover and float).
926 private void MoveLinear(float pTimestep) 936 private void MoveLinear(float pTimestep)
927 { 937 {
@@ -953,10 +963,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
953 // ================================================================== 963 // ==================================================================
954 // Clamp high or low velocities 964 // Clamp high or low velocities
955 float newVelocityLengthSq = VehicleVelocity.LengthSquared(); 965 float newVelocityLengthSq = VehicleVelocity.LengthSquared();
956 if (newVelocityLengthSq > BSParam.VehicleMaxLinearVelocity) 966 if (newVelocityLengthSq > BSParam.VehicleMaxLinearVelocitySq)
957 { 967 {
968 Vector3 origVelW = VehicleVelocity; // DEBUG DEBUG
958 VehicleVelocity /= VehicleVelocity.Length(); 969 VehicleVelocity /= VehicleVelocity.Length();
959 VehicleVelocity *= BSParam.VehicleMaxLinearVelocity; 970 VehicleVelocity *= BSParam.VehicleMaxLinearVelocity;
971 VDetailLog("{0}, MoveLinear,clampMax,origVelW={1},lenSq={2},maxVelSq={3},,newVelW={4}",
972 Prim.LocalID, origVelW, newVelocityLengthSq, BSParam.VehicleMaxLinearVelocitySq, VehicleVelocity);
960 } 973 }
961 else if (newVelocityLengthSq < 0.001f) 974 else if (newVelocityLengthSq < 0.001f)
962 VehicleVelocity = Vector3.Zero; 975 VehicleVelocity = Vector3.Zero;
@@ -968,8 +981,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
968 public void ComputeLinearVelocity(float pTimestep) 981 public void ComputeLinearVelocity(float pTimestep)
969 { 982 {
970 // Step the motor from the current value. Get the correction needed this step. 983 // Step the motor from the current value. Get the correction needed this step.
971 Vector3 currentVel = VehicleVelocity * Quaternion.Inverse(VehicleOrientation); 984 Vector3 origVelW = VehicleVelocity; // DEBUG
972 Vector3 linearMotorCorrectionV = m_linearMotor.Step(pTimestep, currentVel); 985 Vector3 currentVelV = VehicleVelocity * Quaternion.Inverse(VehicleOrientation);
986 Vector3 linearMotorCorrectionV = m_linearMotor.Step(pTimestep, currentVelV);
973 987
974 // Motor is vehicle coordinates. Rotate it to world coordinates 988 // Motor is vehicle coordinates. Rotate it to world coordinates
975 Vector3 linearMotorVelocityW = linearMotorCorrectionV * VehicleOrientation; 989 Vector3 linearMotorVelocityW = linearMotorCorrectionV * VehicleOrientation;
@@ -984,8 +998,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
984 // Add this correction to the velocity to make it faster/slower. 998 // Add this correction to the velocity to make it faster/slower.
985 VehicleVelocity += linearMotorVelocityW; 999 VehicleVelocity += linearMotorVelocityW;
986 1000
987 VDetailLog("{0}, MoveLinear,velocity,vehVel={1},correction={2},force={3}", 1001 VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},correctV={3},correctW={4},newVelW={5}",
988 Prim.LocalID, VehicleVelocity, linearMotorCorrectionV, linearMotorVelocityW); 1002 Prim.LocalID, origVelW, currentVelV, linearMotorCorrectionV, linearMotorVelocityW, VehicleVelocity);
989 } 1003 }
990 1004
991 public void ComputeLinearTerrainHeightCorrection(float pTimestep) 1005 public void ComputeLinearTerrainHeightCorrection(float pTimestep)
@@ -1185,12 +1199,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1185 1199
1186 // Hack to reduce downward force if the vehicle is probably sitting on the ground 1200 // Hack to reduce downward force if the vehicle is probably sitting on the ground
1187 if (Prim.IsColliding && IsGroundVehicle) 1201 if (Prim.IsColliding && IsGroundVehicle)
1188 appliedGravity *= 0.2f; 1202 appliedGravity *= BSParam.VehicleGroundGravityFudge;
1189 1203
1190 VehicleAddForce(appliedGravity); 1204 VehicleAddForce(appliedGravity);
1191 1205
1192 VDetailLog("{0}, MoveLinear,applyGravity,vehGrav={1},appliedForce-{2}", 1206 VDetailLog("{0}, MoveLinear,applyGravity,vehGrav={1},collid={2},appliedForce={3}",
1193 Prim.LocalID, m_VehicleGravity, appliedGravity); 1207 Prim.LocalID, m_VehicleGravity, Prim.IsColliding, appliedGravity);
1194 } 1208 }
1195 1209
1196 // ======================================================================= 1210 // =======================================================================
@@ -1292,6 +1306,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1292 if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) 1306 if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff)
1293 { 1307 {
1294 Vector3 vertContributionV = Vector3.Zero; 1308 Vector3 vertContributionV = Vector3.Zero;
1309 Vector3 origRotVelW = VehicleRotationalVelocity; // DEBUG DEBUG
1295 1310
1296 // Take a vector pointing up and convert it from world to vehicle relative coords. 1311 // Take a vector pointing up and convert it from world to vehicle relative coords.
1297 Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; 1312 Vector3 verticalError = Vector3.UnitZ * VehicleOrientation;
@@ -1319,13 +1334,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1319 1334
1320 // 'vertContrbution' is now the necessary angular correction to correct tilt in one second. 1335 // 'vertContrbution' is now the necessary angular correction to correct tilt in one second.
1321 // Correction happens over a number of seconds. 1336 // Correction happens over a number of seconds.
1322 Vector3 unscaledContrib = vertContributionV; // DEBUG DEBUG 1337 Vector3 unscaledContribVerticalErrorV = vertContributionV; // DEBUG DEBUG
1323 vertContributionV /= m_verticalAttractionTimescale; 1338 vertContributionV /= m_verticalAttractionTimescale;
1324 1339
1325 VehicleRotationalVelocity += vertContributionV * VehicleOrientation; 1340 VehicleRotationalVelocity += vertContributionV * VehicleOrientation;
1326 1341
1327 VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},eff={3},ts={4},vertAttr={5}", 1342 VDetailLog("{0}, MoveAngular,verticalAttraction,,origRotVW={1},vertError={2},unscaledV={3},eff={4},ts={5},vertContribV={6}",
1328 Prim.LocalID, verticalError, unscaledContrib, m_verticalAttractionEfficiency, m_verticalAttractionTimescale, vertContributionV); 1343 Prim.LocalID, origRotVelW, verticalError, unscaledContribVerticalErrorV,
1344 m_verticalAttractionEfficiency, m_verticalAttractionTimescale, vertContributionV);
1329 } 1345 }
1330 } 1346 }
1331 1347