aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorRobert Adams2012-12-05 09:45:33 -0800
committerRobert Adams2012-12-06 09:30:35 -0800
commit6d7f66f78192c686f2f9666bbb4c4517310c30a7 (patch)
treee157ad4f48fe68a09a2c4410ab6ddd7e3d0d4c1b /OpenSim
parentBulletSim: Vehicle angular vertical attraction works. Other vehicle angular f... (diff)
downloadopensim-SC_OLD-6d7f66f78192c686f2f9666bbb4c4517310c30a7.zip
opensim-SC_OLD-6d7f66f78192c686f2f9666bbb4c4517310c30a7.tar.gz
opensim-SC_OLD-6d7f66f78192c686f2f9666bbb4c4517310c30a7.tar.bz2
opensim-SC_OLD-6d7f66f78192c686f2f9666bbb4c4517310c30a7.tar.xz
BulletSim: Don't add gravity to down force -- let Bullet do that. Add VehicleAddForce to set of managed vehicle prim properties.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs42
1 files changed, 28 insertions, 14 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index a83d966..09aee17 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -618,15 +618,17 @@ namespace OpenSim.Region.Physics.BulletSPlugin
618 private float? m_knownWaterLevel; 618 private float? m_knownWaterLevel;
619 private Vector3? m_knownPosition; 619 private Vector3? m_knownPosition;
620 private Vector3? m_knownVelocity; 620 private Vector3? m_knownVelocity;
621 private Vector3? m_knownForce;
621 private Quaternion? m_knownOrientation; 622 private Quaternion? m_knownOrientation;
622 private Vector3? m_knownRotationalVelocity; 623 private Vector3? m_knownRotationalVelocity;
623 private Vector3? m_knownRotationalForce; 624 private Vector3? m_knownRotationalForce;
624 625
625 private const int m_knownChangedPosition = 1 << 0; 626 private const int m_knownChangedPosition = 1 << 0;
626 private const int m_knownChangedVelocity = 1 << 1; 627 private const int m_knownChangedVelocity = 1 << 1;
627 private const int m_knownChangedOrientation = 1 << 2; 628 private const int m_knownChangedForce = 1 << 2;
628 private const int m_knownChangedRotationalVelocity = 1 << 3; 629 private const int m_knownChangedOrientation = 1 << 3;
629 private const int m_knownChangedRotationalForce = 1 << 4; 630 private const int m_knownChangedRotationalVelocity = 1 << 4;
631 private const int m_knownChangedRotationalForce = 1 << 5;
630 632
631 private void ForgetKnownVehicleProperties() 633 private void ForgetKnownVehicleProperties()
632 { 634 {
@@ -634,6 +636,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
634 m_knownWaterLevel = null; 636 m_knownWaterLevel = null;
635 m_knownPosition = null; 637 m_knownPosition = null;
636 m_knownVelocity = null; 638 m_knownVelocity = null;
639 m_knownForce = null;
637 m_knownOrientation = null; 640 m_knownOrientation = null;
638 m_knownRotationalVelocity = null; 641 m_knownRotationalVelocity = null;
639 m_knownRotationalForce = null; 642 m_knownRotationalForce = null;
@@ -652,6 +655,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
652 Prim.ForceVelocity = VehicleVelocity; 655 Prim.ForceVelocity = VehicleVelocity;
653 BulletSimAPI.SetInterpolationLinearVelocity2(Prim.PhysBody.ptr, VehicleVelocity); 656 BulletSimAPI.SetInterpolationLinearVelocity2(Prim.PhysBody.ptr, VehicleVelocity);
654 } 657 }
658 if ((m_knownChanged & m_knownChangedForce) != 0)
659 Prim.AddForce((Vector3)m_knownForce, false, true);
660
655 if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) 661 if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0)
656 { 662 {
657 Prim.ForceRotationalVelocity = VehicleRotationalVelocity; 663 Prim.ForceRotationalVelocity = VehicleRotationalVelocity;
@@ -730,6 +736,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
730 } 736 }
731 } 737 }
732 738
739 private void VehicleAddForce(Vector3 aForce)
740 {
741 m_knownForce += aForce;
742 m_knownChanged |= m_knownChangedForce;
743 }
744
733 private Vector3 VehicleRotationalVelocity 745 private Vector3 VehicleRotationalVelocity
734 { 746 {
735 get 747 get
@@ -784,10 +796,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
784 linearMotorContribution *= VehicleOrientation; 796 linearMotorContribution *= VehicleOrientation;
785 797
786 // ================================================================== 798 // ==================================================================
787 // Gravity and Buoyancy 799 // Buoyancy: force to overcome gravity.
788 // There is some gravity, make a gravity force vector that is applied after object velocity.
789 // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g; 800 // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g;
790 Vector3 grav = Prim.PhysicsScene.DefaultGravity * (1f - m_VehicleBuoyancy); 801 Vector3 buoyancyContribution = Prim.PhysicsScene.DefaultGravity * (m_VehicleBuoyancy - 1f);
791 802
792 Vector3 terrainHeightContribution = ComputeLinearTerrainHeightCorrection(pTimestep); 803 Vector3 terrainHeightContribution = ComputeLinearTerrainHeightCorrection(pTimestep);
793 804
@@ -812,14 +823,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin
812 newVelocity.Z = 0; 823 newVelocity.Z = 0;
813 824
814 // ================================================================== 825 // ==================================================================
815 // Clamp REALLY high or low velocities 826 // Clamp high or low velocities
816 float newVelocityLengthSq = newVelocity.LengthSquared(); 827 float newVelocityLengthSq = newVelocity.LengthSquared();
817 if (newVelocityLengthSq > 1e6f) 828 // if (newVelocityLengthSq > 1e6f)
829 if (newVelocityLengthSq > 1000f)
818 { 830 {
819 newVelocity /= newVelocity.Length(); 831 newVelocity /= newVelocity.Length();
820 newVelocity *= 1000f; 832 newVelocity *= 1000f;
821 } 833 }
822 else if (newVelocityLengthSq < 1e-6f) 834 // else if (newVelocityLengthSq < 1e-6f)
835 else if (newVelocityLengthSq < 0.001f)
823 newVelocity = Vector3.Zero; 836 newVelocity = Vector3.Zero;
824 837
825 // ================================================================== 838 // ==================================================================
@@ -828,15 +841,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin
828 VehicleVelocity = newVelocity; 841 VehicleVelocity = newVelocity;
829 842
830 // Other linear forces are applied as forces. 843 // Other linear forces are applied as forces.
831 Vector3 totalDownForce = grav * m_vehicleMass * pTimestep; 844 Vector3 totalDownForce = buoyancyContribution * m_vehicleMass;
832 if (totalDownForce != Vector3.Zero) 845 if (!totalDownForce.ApproxEquals(Vector3.Zero, 0.01f))
833 { 846 {
834 Prim.AddForce(totalDownForce, false); 847 VehicleAddForce(totalDownForce);
835 } 848 }
836 849
837 VDetailLog("{0}, MoveLinear,done,newVel={1},totDown={2},linContrib={3},terrContrib={4},hoverContrib={5},limitContrib={6}", 850 VDetailLog("{0}, MoveLinear,done,newVel={1},totDown={2},linContrib={3},terrContrib={4},hoverContrib={5},limitContrib={6},buoyContrib={7}",
838 Prim.LocalID, newVelocity, totalDownForce, 851 Prim.LocalID, newVelocity, totalDownForce,
839 linearMotorContribution, terrainHeightContribution, hoverContribution, limitMotorUpContribution 852 linearMotorContribution, terrainHeightContribution, hoverContribution,
853 limitMotorUpContribution, buoyancyContribution
840 ); 854 );
841 855
842 } // end MoveLinear() 856 } // end MoveLinear()