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.cs81
1 files changed, 46 insertions, 35 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 525aac4..be8a502 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -161,7 +161,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
161 m_angularMotor.TimeScale = m_angularMotorTimescale; 161 m_angularMotor.TimeScale = m_angularMotorTimescale;
162 break; 162 break;
163 case Vehicle.BANKING_EFFICIENCY: 163 case Vehicle.BANKING_EFFICIENCY:
164 m_bankingEfficiency = Math.Max(-1f, Math.Min(pValue, 1f)); 164 m_bankingEfficiency = ClampInRange(-1f, pValue, 1f);
165 break; 165 break;
166 case Vehicle.BANKING_MIX: 166 case Vehicle.BANKING_MIX:
167 m_bankingMix = Math.Max(pValue, 0.01f); 167 m_bankingMix = Math.Max(pValue, 0.01f);
@@ -170,10 +170,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
170 m_bankingTimescale = Math.Max(pValue, 0.01f); 170 m_bankingTimescale = Math.Max(pValue, 0.01f);
171 break; 171 break;
172 case Vehicle.BUOYANCY: 172 case Vehicle.BUOYANCY:
173 m_VehicleBuoyancy = Math.Max(-1f, Math.Min(pValue, 1f)); 173 m_VehicleBuoyancy = ClampInRange(-1f, pValue, 1f);
174 break; 174 break;
175 case Vehicle.HOVER_EFFICIENCY: 175 case Vehicle.HOVER_EFFICIENCY:
176 m_VhoverEfficiency = Math.Max(0f, Math.Min(pValue, 1f)); 176 m_VhoverEfficiency = ClampInRange(0f, pValue, 1f);
177 break; 177 break;
178 case Vehicle.HOVER_HEIGHT: 178 case Vehicle.HOVER_HEIGHT:
179 m_VhoverHeight = pValue; 179 m_VhoverHeight = pValue;
@@ -188,7 +188,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
188 m_linearDeflectionTimescale = Math.Max(pValue, 0.01f); 188 m_linearDeflectionTimescale = Math.Max(pValue, 0.01f);
189 break; 189 break;
190 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE: 190 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
191 m_linearMotorDecayTimescale = Math.Max(0.01f, Math.Min(pValue,120)); 191 m_linearMotorDecayTimescale = ClampInRange(0.01f, pValue, 120);
192 m_linearMotor.TargetValueDecayTimeScale = m_linearMotorDecayTimescale; 192 m_linearMotor.TargetValueDecayTimeScale = m_linearMotorDecayTimescale;
193 break; 193 break;
194 case Vehicle.LINEAR_MOTOR_TIMESCALE: 194 case Vehicle.LINEAR_MOTOR_TIMESCALE:
@@ -196,7 +196,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
196 m_linearMotor.TimeScale = m_linearMotorTimescale; 196 m_linearMotor.TimeScale = m_linearMotorTimescale;
197 break; 197 break;
198 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY: 198 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
199 m_verticalAttractionEfficiency = Math.Max(0.1f, Math.Min(pValue, 1f)); 199 m_verticalAttractionEfficiency = ClampInRange(0.1f, pValue, 1f);
200 m_verticalAttractionMotor.Efficiency = m_verticalAttractionEfficiency; 200 m_verticalAttractionMotor.Efficiency = m_verticalAttractionEfficiency;
201 break; 201 break;
202 case Vehicle.VERTICAL_ATTRACTION_TIMESCALE: 202 case Vehicle.VERTICAL_ATTRACTION_TIMESCALE:
@@ -607,10 +607,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin
607 } 607 }
608 608
609 #region Known vehicle value functions 609 #region Known vehicle value functions
610 // Vehicle physical parameters that we buffer from constant getting and setting.
611 // The "m_known*" variables are initialized to 'null', fetched only if referenced
612 // and stored back into the physics engine only if updated.
613 // This does two things: 1) saves continuious calls into unmanaged code, and
614 // 2) signals when a physics property update must happen back to the simulator
615 // to update values modified for the vehicle.
610 private int m_knownChanged; 616 private int m_knownChanged;
611 private float? m_knownTerrainHeight; 617 private float? m_knownTerrainHeight;
612 private float? m_knownWaterLevel; 618 private float? m_knownWaterLevel;
613
614 private Vector3? m_knownPosition; 619 private Vector3? m_knownPosition;
615 private Vector3? m_knownVelocity; 620 private Vector3? m_knownVelocity;
616 private Quaternion? m_knownOrientation; 621 private Quaternion? m_knownOrientation;
@@ -642,7 +647,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
642 if ((m_knownChanged & m_knownChangedVelocity) != 0) 647 if ((m_knownChanged & m_knownChangedVelocity) != 0)
643 Prim.ForceVelocity = VehicleVelocity; 648 Prim.ForceVelocity = VehicleVelocity;
644 if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) 649 if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0)
650 {
645 Prim.ForceRotationalVelocity = VehicleRotationalVelocity; 651 Prim.ForceRotationalVelocity = VehicleRotationalVelocity;
652 BulletSimAPI.SetInterpolationAngularVelocity2(Prim.PhysBody.ptr, VehicleRotationalVelocity);
653 }
646 // If we set one of the values (ie, the physics engine didn't do it) we must force 654 // If we set one of the values (ie, the physics engine didn't do it) we must force
647 // an UpdateProperties event to send the changes up to the simulator. 655 // an UpdateProperties event to send the changes up to the simulator.
648 BulletSimAPI.PushUpdate2(Prim.PhysBody.ptr); 656 BulletSimAPI.PushUpdate2(Prim.PhysBody.ptr);
@@ -766,15 +774,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
766 // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g; 774 // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g;
767 Vector3 grav = Prim.PhysicsScene.DefaultGravity * (1f - m_VehicleBuoyancy); 775 Vector3 grav = Prim.PhysicsScene.DefaultGravity * (1f - m_VehicleBuoyancy);
768 776
769 Vector3 pos = VehiclePosition; 777 Vector3 terrainHeightContribution = ComputeLinearTerrainHeightCorrection(pTimestep);
770
771 Vector3 terrainHeightContribution = ComputeLinearTerrainHeightCorrection(ref pos);
772 778
773 Vector3 hoverContribution = ComputeLinearHover(ref pos); 779 Vector3 hoverContribution = ComputeLinearHover(pTimestep);
774 780
775 ComputeLinearBlockingEndPoint(ref pos); 781 ComputeLinearBlockingEndPoint(pTimestep);
776 782
777 Vector3 limitMotorUpContribution = ComputeLinearMotorUp(pos); 783 Vector3 limitMotorUpContribution = ComputeLinearMotorUp(pTimestep);
778 784
779 // ================================================================== 785 // ==================================================================
780 Vector3 newVelocity = linearMotorContribution 786 Vector3 newVelocity = linearMotorContribution
@@ -820,22 +826,21 @@ namespace OpenSim.Region.Physics.BulletSPlugin
820 826
821 } // end MoveLinear() 827 } // end MoveLinear()
822 828
823 public Vector3 ComputeLinearTerrainHeightCorrection(ref Vector3 pos) 829 public Vector3 ComputeLinearTerrainHeightCorrection(float pTimestep)
824 { 830 {
825 Vector3 ret = Vector3.Zero; 831 Vector3 ret = Vector3.Zero;
826 // If below the terrain, move us above the ground a little. 832 // If below the terrain, move us above the ground a little.
827 // TODO: Consider taking the rotated size of the object or possibly casting a ray. 833 // TODO: Consider taking the rotated size of the object or possibly casting a ray.
828 if (pos.Z < GetTerrainHeight(pos)) 834 if (VehiclePosition.Z < GetTerrainHeight(VehiclePosition))
829 { 835 {
830 // TODO: correct position by applying force rather than forcing position. 836 // TODO: correct position by applying force rather than forcing position.
831 pos.Z = GetTerrainHeight(pos) + 2; 837 VehiclePosition += new Vector3(0f, 0f, GetTerrainHeight(VehiclePosition) + 2f);
832 VehiclePosition = pos; 838 VDetailLog("{0}, MoveLinear,terrainHeight,terrainHeight={1},pos={2}", Prim.LocalID, GetTerrainHeight(VehiclePosition), VehiclePosition);
833 VDetailLog("{0}, MoveLinear,terrainHeight,terrainHeight={1},pos={2}", Prim.LocalID, GetTerrainHeight(pos), pos);
834 } 839 }
835 return ret; 840 return ret;
836 } 841 }
837 842
838 public Vector3 ComputeLinearHover(ref Vector3 pos) 843 public Vector3 ComputeLinearHover(float pTimestep)
839 { 844 {
840 Vector3 ret = Vector3.Zero; 845 Vector3 ret = Vector3.Zero;
841 846
@@ -846,11 +851,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
846 // We should hover, get the target height 851 // We should hover, get the target height
847 if ((m_flags & VehicleFlag.HOVER_WATER_ONLY) != 0) 852 if ((m_flags & VehicleFlag.HOVER_WATER_ONLY) != 0)
848 { 853 {
849 m_VhoverTargetHeight = GetWaterLevel(pos) + m_VhoverHeight; 854 m_VhoverTargetHeight = GetWaterLevel(VehiclePosition) + m_VhoverHeight;
850 } 855 }
851 if ((m_flags & VehicleFlag.HOVER_TERRAIN_ONLY) != 0) 856 if ((m_flags & VehicleFlag.HOVER_TERRAIN_ONLY) != 0)
852 { 857 {
853 m_VhoverTargetHeight = GetTerrainHeight(pos) + m_VhoverHeight; 858 m_VhoverTargetHeight = GetTerrainHeight(VehiclePosition) + m_VhoverHeight;
854 } 859 }
855 if ((m_flags & VehicleFlag.HOVER_GLOBAL_HEIGHT) != 0) 860 if ((m_flags & VehicleFlag.HOVER_GLOBAL_HEIGHT) != 0)
856 { 861 {
@@ -860,14 +865,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin
860 if ((m_flags & VehicleFlag.HOVER_UP_ONLY) != 0) 865 if ((m_flags & VehicleFlag.HOVER_UP_ONLY) != 0)
861 { 866 {
862 // If body is already heigher, use its height as target height 867 // If body is already heigher, use its height as target height
863 if (pos.Z > m_VhoverTargetHeight) 868 if (VehiclePosition.Z > m_VhoverTargetHeight)
864 m_VhoverTargetHeight = pos.Z; 869 m_VhoverTargetHeight = VehiclePosition.Z;
865 } 870 }
866 871
867 if ((m_flags & VehicleFlag.LOCK_HOVER_HEIGHT) != 0) 872 if ((m_flags & VehicleFlag.LOCK_HOVER_HEIGHT) != 0)
868 { 873 {
869 if (Math.Abs(pos.Z - m_VhoverTargetHeight) > 0.2f) 874 if (Math.Abs(VehiclePosition.Z - m_VhoverTargetHeight) > 0.2f)
870 { 875 {
876 Vector3 pos = VehiclePosition;
871 pos.Z = m_VhoverTargetHeight; 877 pos.Z = m_VhoverTargetHeight;
872 VehiclePosition = pos; 878 VehiclePosition = pos;
873 } 879 }
@@ -875,7 +881,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
875 else 881 else
876 { 882 {
877 // Error is positive if below the target and negative if above. 883 // Error is positive if below the target and negative if above.
878 float verticalError = m_VhoverTargetHeight - pos.Z; 884 float verticalError = m_VhoverTargetHeight - VehiclePosition.Z;
879 float verticalCorrectionVelocity = verticalError / m_VhoverTimescale; 885 float verticalCorrectionVelocity = verticalError / m_VhoverTimescale;
880 886
881 // TODO: implement m_VhoverEfficiency correctly 887 // TODO: implement m_VhoverEfficiency correctly
@@ -886,16 +892,17 @@ namespace OpenSim.Region.Physics.BulletSPlugin
886 } 892 }
887 893
888 VDetailLog("{0}, MoveLinear,hover,pos={1},ret={2},hoverTS={3},height={4},target={5}", 894 VDetailLog("{0}, MoveLinear,hover,pos={1},ret={2},hoverTS={3},height={4},target={5}",
889 Prim.LocalID, pos, ret, m_VhoverTimescale, m_VhoverHeight, m_VhoverTargetHeight); 895 Prim.LocalID, VehiclePosition, ret, m_VhoverTimescale, m_VhoverHeight, m_VhoverTargetHeight);
890 } 896 }
891 897
892 return ret; 898 return ret;
893 } 899 }
894 900
895 public bool ComputeLinearBlockingEndPoint(ref Vector3 pos) 901 public bool ComputeLinearBlockingEndPoint(float pTimestep)
896 { 902 {
897 bool changed = false; 903 bool changed = false;
898 904
905 Vector3 pos = VehiclePosition;
899 Vector3 posChange = pos - m_lastPositionVector; 906 Vector3 posChange = pos - m_lastPositionVector;
900 if (m_BlockingEndPoint != Vector3.Zero) 907 if (m_BlockingEndPoint != Vector3.Zero)
901 { 908 {
@@ -941,14 +948,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin
941 // VEHICLE_BANKING_TIMESCALE. This is to help prevent ground vehicles from steering 948 // VEHICLE_BANKING_TIMESCALE. This is to help prevent ground vehicles from steering
942 // when they are in mid jump. 949 // when they are in mid jump.
943 // TODO: this code is wrong. Also, what should it do for boats? 950 // TODO: this code is wrong. Also, what should it do for boats?
944 public Vector3 ComputeLinearMotorUp(Vector3 pos) 951 public Vector3 ComputeLinearMotorUp(float pTimestep)
945 { 952 {
946 Vector3 ret = Vector3.Zero; 953 Vector3 ret = Vector3.Zero;
947 if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0) 954 if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0)
948 { 955 {
949 // If the vehicle is motoring into the sky, get it going back down. 956 // If the vehicle is motoring into the sky, get it going back down.
950 // float distanceAboveGround = pos.Z - Math.Max(GetTerrainHeight(pos), GetWaterLevel(pos)); 957 // float distanceAboveGround = pos.Z - Math.Max(GetTerrainHeight(pos), GetWaterLevel(pos));
951 float distanceAboveGround = pos.Z - GetTerrainHeight(pos); 958 float distanceAboveGround = VehiclePosition.Z - GetTerrainHeight(VehiclePosition);
952 if (distanceAboveGround > 1f) 959 if (distanceAboveGround > 1f)
953 { 960 {
954 // downForce = new Vector3(0, 0, (-distanceAboveGround / m_bankingTimescale) * pTimestep); 961 // downForce = new Vector3(0, 0, (-distanceAboveGround / m_bankingTimescale) * pTimestep);
@@ -969,12 +976,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
969 // ======================================================================= 976 // =======================================================================
970 // ======================================================================= 977 // =======================================================================
971 // Apply the effect of the angular motor. 978 // Apply the effect of the angular motor.
972 // The 'contribution' is how much angular correction each function wants. 979 // The 'contribution' is how much angular correction velocity each function wants.
973 // All the contributions are added together and the orientation of the vehicle 980 // All the contributions are added together and the orientation of the vehicle
974 // is changed by all the contributed corrections. 981 // is changed by all the contributed corrections.
975 private void MoveAngular(float pTimestep) 982 private void MoveAngular(float pTimestep)
976 { 983 {
977 Vector3 angularMotorContribution = m_angularMotor.Step(); 984 // The user wants how many radians per second angular change?
985 Vector3 angularMotorContribution = m_angularMotor.Step(pTimestep);
978 986
979 // ================================================================== 987 // ==================================================================
980 // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags : 988 // From http://wiki.secondlife.com/wiki/LlSetVehicleFlags :
@@ -1006,14 +1014,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1006 1014
1007 // ================================================================== 1015 // ==================================================================
1008 // The correction is applied to the current orientation. 1016 // The correction is applied to the current orientation.
1009 // Any angular velocity on the vehicle is not us so zero the current value.
1010 VehicleRotationalVelocity = Vector3.Zero;
1011 if (!m_lastAngularCorrection.ApproxEquals(Vector3.Zero, 0.01f)) 1017 if (!m_lastAngularCorrection.ApproxEquals(Vector3.Zero, 0.01f))
1012 { 1018 {
1013 Vector3 scaledCorrection = m_lastAngularCorrection * pTimestep; 1019 Vector3 scaledCorrection = m_lastAngularCorrection * pTimestep;
1014 Quaternion quatCorrection = Quaternion.CreateFromEulers(scaledCorrection);
1015 1020
1016 VehicleOrientation = Quaternion.Add(VehicleOrientation, quatCorrection); 1021 VehicleRotationalVelocity = scaledCorrection;
1017 1022
1018 VDetailLog("{0}, MoveAngular,done,nonZero,angMotorContrib={1},vertAttrContrib={2},bankContrib={3},deflectContrib={4},totalContrib={5},scaledCorr={6}", 1023 VDetailLog("{0}, MoveAngular,done,nonZero,angMotorContrib={1},vertAttrContrib={2},bankContrib={3},deflectContrib={4},totalContrib={5},scaledCorr={6}",
1019 Prim.LocalID, 1024 Prim.LocalID,
@@ -1022,6 +1027,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1022 m_lastAngularCorrection, scaledCorrection 1027 m_lastAngularCorrection, scaledCorrection
1023 ); 1028 );
1024 } 1029 }
1030 else
1031 {
1032 // The vehicle is not adding anything velocity wise.
1033 VehicleRotationalVelocity = Vector3.Zero;
1034 VDetailLog("{0}, MoveAngular,done,zero", Prim.LocalID);
1035 }
1025 1036
1026 // ================================================================== 1037 // ==================================================================
1027 //Offset section 1038 //Offset section
@@ -1065,7 +1076,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1065 { 1076 {
1066 // Take a vector pointing up and convert it from world to vehicle relative coords. 1077 // Take a vector pointing up and convert it from world to vehicle relative coords.
1067 Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; 1078 Vector3 verticalError = Vector3.UnitZ * VehicleOrientation;
1068 // verticalError.Normalize(); 1079 verticalError.Normalize();
1069 1080
1070 // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) 1081 // If vertical attraction correction is needed, the vector that was pointing up (UnitZ)
1071 // is now leaning to one side (rotated around the X axis) and the Y value will 1082 // is now leaning to one side (rotated around the X axis) and the Y value will