aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs42
1 files changed, 23 insertions, 19 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index c34c05a..47f2759 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -124,6 +124,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
124 static readonly float PIOverFour = ((float)Math.PI) / 4f; 124 static readonly float PIOverFour = ((float)Math.PI) / 4f;
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.
128 private bool enableAngularVerticalAttraction = true;
129 private bool enableAngularDeflection = true;
130 private bool enableAngularBanking = true;
131
127 public BSDynamics(BSScene myScene, BSPrim myPrim) 132 public BSDynamics(BSScene myScene, BSPrim myPrim)
128 { 133 {
129 PhysicsScene = myScene; 134 PhysicsScene = myScene;
@@ -575,11 +580,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
575 PhysicsScene.PE.SetMassProps(Prim.PhysBody, m_vehicleMass, localInertia); 580 PhysicsScene.PE.SetMassProps(Prim.PhysBody, m_vehicleMass, localInertia);
576 PhysicsScene.PE.UpdateInertiaTensor(Prim.PhysBody); 581 PhysicsScene.PE.UpdateInertiaTensor(Prim.PhysBody);
577 582
578 Vector3 grav = PhysicsScene.DefaultGravity * (1f - Prim.Buoyancy); 583 // Set the gravity for the vehicle depending on the buoyancy
584 // TODO: what should be done if prim and vehicle buoyancy differ?
585 Vector3 grav = Prim.ComputeGravity(m_VehicleBuoyancy);
579 PhysicsScene.PE.SetGravity(Prim.PhysBody, grav); 586 PhysicsScene.PE.SetGravity(Prim.PhysBody, grav);
580 587
581 VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4}", 588 VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4},grav={5}",
582 Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping); 589 Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping, grav);
583 } 590 }
584 else 591 else
585 { 592 {
@@ -858,12 +865,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
858 linearMotorContribution *= VehicleOrientation; 865 linearMotorContribution *= VehicleOrientation;
859 // All the contributions after this are world relative (mostly Z modifications) 866 // All the contributions after this are world relative (mostly Z modifications)
860 867
861 // ==================================================================
862 // Buoyancy: force to overcome gravity.
863 // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g;
864 // So, if zero, don't change anything (let gravity happen). If one, negate the effect of gravity.
865 Vector3 buoyancyContribution = Prim.PhysicsScene.DefaultGravity * m_VehicleBuoyancy;
866
867 Vector3 terrainHeightContribution = ComputeLinearTerrainHeightCorrection(pTimestep); 868 Vector3 terrainHeightContribution = ComputeLinearTerrainHeightCorrection(pTimestep);
868 869
869 Vector3 hoverContribution = ComputeLinearHover(pTimestep); 870 Vector3 hoverContribution = ComputeLinearHover(pTimestep);
@@ -873,12 +874,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin
873 Vector3 limitMotorUpContribution = ComputeLinearMotorUp(pTimestep); 874 Vector3 limitMotorUpContribution = ComputeLinearMotorUp(pTimestep);
874 875
875 // ================================================================== 876 // ==================================================================
877 // Select between velocities and forces. Forces will happen over time and
878 // will take into account inertia, collisions, etc. Velocities are
879 // raw updates to the velocity of the vehicle.
876 Vector3 newVelocity = linearMotorContribution 880 Vector3 newVelocity = linearMotorContribution
877 + terrainHeightContribution 881 + terrainHeightContribution
878 + hoverContribution 882 + hoverContribution
879 + limitMotorUpContribution; 883 + limitMotorUpContribution;
880 884
881 Vector3 newForce = buoyancyContribution; 885 Vector3 newForce = Vector3.Zero;
882 886
883 // If not changing some axis, reduce out velocity 887 // If not changing some axis, reduce out velocity
884 if ((m_flags & (VehicleFlag.NO_X)) != 0) 888 if ((m_flags & (VehicleFlag.NO_X)) != 0)
@@ -902,6 +906,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
902 // ================================================================== 906 // ==================================================================
903 // Stuff new linear velocity into the vehicle. 907 // Stuff new linear velocity into the vehicle.
904 // Since the velocity is just being set, it is not scaled by pTimeStep. Bullet will do that for us. 908 // Since the velocity is just being set, it is not scaled by pTimeStep. Bullet will do that for us.
909 // Also not scaled by mass since this is a super-physical setting of velocity.
905 VehicleVelocity = newVelocity; 910 VehicleVelocity = newVelocity;
906 911
907 // Other linear forces are applied as forces. 912 // Other linear forces are applied as forces.
@@ -911,13 +916,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
911 VehicleAddForce(totalDownForce); 916 VehicleAddForce(totalDownForce);
912 } 917 }
913 918
914 VDetailLog("{0}, MoveLinear,done,newVel={1},totDown={2},IsColliding={3}", 919 VDetailLog("{0}, MoveLinear,done,linContrib={1},terrContrib={2},hoverContrib={3},limitContrib={4},totDown={5},isColl={6},newVel={7}",
915 Prim.LocalID, newVelocity, totalDownForce, Prim.IsColliding);
916 VDetailLog("{0}, MoveLinear,done,linContrib={1},terrContrib={2},hoverContrib={3},limitContrib={4},buoyContrib={5}",
917 Prim.LocalID, 920 Prim.LocalID,
918 linearMotorContribution, terrainHeightContribution, hoverContribution, 921 linearMotorContribution, terrainHeightContribution, hoverContribution, limitMotorUpContribution,
919 limitMotorUpContribution, buoyancyContribution 922 totalDownForce, Prim.IsColliding, newVelocity );
920 );
921 923
922 } // end MoveLinear() 924 } // end MoveLinear()
923 925
@@ -1088,6 +1090,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1088 // for preventing ground vehicles with large linear deflection, like bumper cars, 1090 // for preventing ground vehicles with large linear deflection, like bumper cars,
1089 // from climbing their linear deflection into the sky. 1091 // from climbing their linear deflection into the sky.
1090 // That is, NO_DEFLECTION_UP says angular motion should not add any pitch or roll movement 1092 // That is, NO_DEFLECTION_UP says angular motion should not add any pitch or roll movement
1093 // TODO: This is here because this is where ODE put it but documentation says it
1094 // is a linear effect. Where should this check go?
1091 if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0) 1095 if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0)
1092 { 1096 {
1093 angularMotorContribution.X = 0f; 1097 angularMotorContribution.X = 0f;
@@ -1179,7 +1183,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1179 Vector3 ret = Vector3.Zero; 1183 Vector3 ret = Vector3.Zero;
1180 1184
1181 // If vertical attaction timescale is reasonable 1185 // If vertical attaction timescale is reasonable
1182 if (m_verticalAttractionTimescale < m_verticalAttractionCutoff) 1186 if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff)
1183 { 1187 {
1184 // Take a vector pointing up and convert it from world to vehicle relative coords. 1188 // Take a vector pointing up and convert it from world to vehicle relative coords.
1185 Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; 1189 Vector3 verticalError = Vector3.UnitZ * VehicleOrientation;
@@ -1230,7 +1234,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1230 // this creates an over-correction and then wabbling as the target is overshot. 1234 // this creates an over-correction and then wabbling as the target is overshot.
1231 // TODO: rethink how the different correction computations inter-relate. 1235 // TODO: rethink how the different correction computations inter-relate.
1232 1236
1233 if (m_angularDeflectionEfficiency != 0 && VehicleVelocity != Vector3.Zero) 1237 if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleVelocity != Vector3.Zero)
1234 { 1238 {
1235 // The direction the vehicle is moving 1239 // The direction the vehicle is moving
1236 Vector3 movingDirection = VehicleVelocity; 1240 Vector3 movingDirection = VehicleVelocity;
@@ -1303,7 +1307,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1303 { 1307 {
1304 Vector3 ret = Vector3.Zero; 1308 Vector3 ret = Vector3.Zero;
1305 1309
1306 if (m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff) 1310 if (enableAngularBanking && m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff)
1307 { 1311 {
1308 // Rotate a UnitZ vector (pointing up) to how the vehicle is oriented. 1312 // Rotate a UnitZ vector (pointing up) to how the vehicle is oriented.
1309 // As the vehicle rolls to the right or left, the Y value will increase from 1313 // As the vehicle rolls to the right or left, the Y value will increase from