diff options
Diffstat (limited to 'OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs')
-rw-r--r-- | OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs | 179 |
1 files changed, 138 insertions, 41 deletions
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs index d8a2272..fa32441 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs | |||
@@ -648,6 +648,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
648 | break; | 648 | break; |
649 | 649 | ||
650 | } | 650 | } |
651 | // disable mouse steering | ||
652 | m_flags &= ~(VehicleFlag.MOUSELOOK_STEER | | ||
653 | VehicleFlag.MOUSELOOK_BANK | | ||
654 | VehicleFlag.CAMERA_DECOUPLED); | ||
651 | 655 | ||
652 | m_lmDecay = (1.0f - 1.0f / m_linearMotorDecayTimescale); | 656 | m_lmDecay = (1.0f - 1.0f / m_linearMotorDecayTimescale); |
653 | m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale; | 657 | m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale; |
@@ -794,6 +798,28 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
794 | 798 | ||
795 | float ldampZ = 0; | 799 | float ldampZ = 0; |
796 | 800 | ||
801 | bool mousemode = false; | ||
802 | bool mousemodebank = false; | ||
803 | |||
804 | float bankingEfficiency; | ||
805 | float verticalAttractionTimescale = m_verticalAttractionTimescale; | ||
806 | |||
807 | if((m_flags & (VehicleFlag.MOUSELOOK_STEER | VehicleFlag.MOUSELOOK_BANK)) != 0 ) | ||
808 | { | ||
809 | mousemode = true; | ||
810 | mousemodebank = (m_flags & VehicleFlag.MOUSELOOK_BANK) != 0; | ||
811 | if(mousemodebank) | ||
812 | { | ||
813 | bankingEfficiency = m_bankingEfficiency; | ||
814 | if(verticalAttractionTimescale < 149.9) | ||
815 | verticalAttractionTimescale *= 2.0f; // reduce current instability | ||
816 | } | ||
817 | else | ||
818 | bankingEfficiency = 0; | ||
819 | } | ||
820 | else | ||
821 | bankingEfficiency = m_bankingEfficiency; | ||
822 | |||
797 | // linear motor | 823 | // linear motor |
798 | if (m_lmEfect > 0.01 && m_linearMotorTimescale < 1000) | 824 | if (m_lmEfect > 0.01 && m_linearMotorTimescale < 1000) |
799 | { | 825 | { |
@@ -930,12 +956,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
930 | } | 956 | } |
931 | 957 | ||
932 | // vertical atractor | 958 | // vertical atractor |
933 | if (m_verticalAttractionTimescale < 300) | 959 | if (verticalAttractionTimescale < 300) |
934 | { | 960 | { |
935 | float roll; | 961 | float roll; |
936 | float pitch; | 962 | float pitch; |
937 | 963 | ||
938 | float ftmp = m_invtimestep / m_verticalAttractionTimescale / m_verticalAttractionTimescale; | 964 | float ftmp = m_invtimestep / verticalAttractionTimescale / verticalAttractionTimescale; |
939 | 965 | ||
940 | float ftmp2; | 966 | float ftmp2; |
941 | ftmp2 = 0.5f * m_verticalAttractionEfficiency * m_invtimestep; | 967 | ftmp2 = 0.5f * m_verticalAttractionEfficiency * m_invtimestep; |
@@ -967,7 +993,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
967 | torque.Y += effpitch * ftmp; | 993 | torque.Y += effpitch * ftmp; |
968 | } | 994 | } |
969 | 995 | ||
970 | if (m_bankingEfficiency != 0 && Math.Abs(effroll) > 0.01) | 996 | if (bankingEfficiency != 0 && Math.Abs(effroll) > 0.01) |
971 | { | 997 | { |
972 | 998 | ||
973 | float broll = effroll; | 999 | float broll = effroll; |
@@ -1018,58 +1044,129 @@ namespace OpenSim.Region.PhysicsModule.ubOde | |||
1018 | m_amdampZ = 1 / m_angularFrictionTimescale.Z; | 1044 | m_amdampZ = 1 / m_angularFrictionTimescale.Z; |
1019 | } | 1045 | } |
1020 | 1046 | ||
1021 | // angular motor | 1047 | if(mousemode) |
1022 | if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000) | ||
1023 | { | 1048 | { |
1024 | tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error | 1049 | CameraData cam = rootPrim.TryGetCameraData(); |
1025 | tmpV *= m_amEfect / m_angularMotorTimescale; // error to correct in this timestep | 1050 | if(cam.Valid && cam.MouseLook) |
1026 | torque.X += tmpV.X * m_ampwr; | 1051 | { |
1027 | torque.Y += tmpV.Y * m_ampwr; | 1052 | Vector3 dirv = cam.CameraAtAxis * irotq; |
1028 | torque.Z += tmpV.Z; | ||
1029 | 1053 | ||
1030 | m_amEfect *= m_amDecay; | 1054 | float invamts = 1.0f/m_angularMotorTimescale; |
1031 | } | 1055 | float tmp; |
1032 | else | ||
1033 | m_amEfect = 0; | ||
1034 | 1056 | ||
1035 | // angular deflection | 1057 | // get out of x == 0 plane |
1036 | if (m_angularDeflectionEfficiency > 0) | 1058 | if(Math.Abs(dirv.X) < 0.001f) |
1037 | { | 1059 | dirv.X = 0.001f; |
1038 | Vector3 dirv; | 1060 | |
1039 | 1061 | if (Math.Abs(dirv.Z) > 0.01) | |
1040 | if (curLocalVel.X > 0.01f) | 1062 | { |
1041 | dirv = curLocalVel; | 1063 | tmp = -(float)Math.Atan2(dirv.Z, dirv.X) * m_angularMotorDirection.Y; |
1042 | else if (curLocalVel.X < -0.01f) | 1064 | if(tmp < -4f) |
1043 | // use oposite | 1065 | tmp = -4f; |
1044 | dirv = -curLocalVel; | 1066 | else if(tmp > 4f) |
1067 | tmp = 4f; | ||
1068 | torque.Y += (tmp - curLocalAngVel.Y) * invamts; | ||
1069 | torque.Y -= curLocalAngVel.Y * m_amdampY; | ||
1070 | } | ||
1071 | else | ||
1072 | torque.Y -= curLocalAngVel.Y * m_invtimestep; | ||
1073 | |||
1074 | if (Math.Abs(dirv.Y) > 0.01) | ||
1075 | { | ||
1076 | if(mousemodebank) | ||
1077 | { | ||
1078 | tmp = -(float)Math.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.X; | ||
1079 | if(tmp < -4f) | ||
1080 | tmp = -4f; | ||
1081 | else if(tmp > 4f) | ||
1082 | tmp = 4f; | ||
1083 | torque.X += (tmp - curLocalAngVel.X) * invamts; | ||
1084 | } | ||
1085 | else | ||
1086 | { | ||
1087 | tmp = (float)Math.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.Z; | ||
1088 | tmp *= invamts; | ||
1089 | if(tmp < -4f) | ||
1090 | tmp = -4f; | ||
1091 | else if(tmp > 4f) | ||
1092 | tmp = 4f; | ||
1093 | torque.Z += (tmp - curLocalAngVel.Z) * invamts; | ||
1094 | } | ||
1095 | torque.X -= curLocalAngVel.X * m_amdampX; | ||
1096 | torque.Z -= curLocalAngVel.Z * m_amdampZ; | ||
1097 | } | ||
1098 | else | ||
1099 | { | ||
1100 | if(mousemodebank) | ||
1101 | torque.X -= curLocalAngVel.X * m_invtimestep; | ||
1102 | else | ||
1103 | torque.Z -= curLocalAngVel.Z * m_invtimestep; | ||
1104 | } | ||
1105 | } | ||
1045 | else | 1106 | else |
1046 | { | 1107 | { |
1047 | // make it fall into small positive x case | 1108 | if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0) |
1048 | dirv.X = 0.01f; | 1109 | { |
1049 | dirv.Y = curLocalVel.Y; | 1110 | torque.X -= curLocalAngVel.X * 10f; |
1050 | dirv.Z = curLocalVel.Z; | 1111 | torque.Y -= curLocalAngVel.Y * 10f; |
1112 | torque.Z -= curLocalAngVel.Z * 10f; | ||
1113 | } | ||
1051 | } | 1114 | } |
1115 | } | ||
1116 | else | ||
1117 | { | ||
1118 | // angular motor | ||
1119 | if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000) | ||
1120 | { | ||
1121 | tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error | ||
1122 | tmpV *= m_amEfect / m_angularMotorTimescale; // error to correct in this timestep | ||
1123 | torque.X += tmpV.X * m_ampwr; | ||
1124 | torque.Y += tmpV.Y * m_ampwr; | ||
1125 | torque.Z += tmpV.Z; | ||
1052 | 1126 | ||
1053 | float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale; | 1127 | m_amEfect *= m_amDecay; |
1128 | } | ||
1129 | else | ||
1130 | m_amEfect = 0; | ||
1054 | 1131 | ||
1055 | if (Math.Abs(dirv.Z) > 0.01) | 1132 | // angular deflection |
1133 | if (m_angularDeflectionEfficiency > 0) | ||
1056 | { | 1134 | { |
1057 | torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp; | 1135 | Vector3 dirv; |
1136 | |||
1137 | if (curLocalVel.X > 0.01f) | ||
1138 | dirv = curLocalVel; | ||
1139 | else if (curLocalVel.X < -0.01f) | ||
1140 | // use oposite | ||
1141 | dirv = -curLocalVel; | ||
1142 | else | ||
1143 | { | ||
1144 | // make it fall into small positive x case | ||
1145 | dirv.X = 0.01f; | ||
1146 | dirv.Y = curLocalVel.Y; | ||
1147 | dirv.Z = curLocalVel.Z; | ||
1148 | } | ||
1149 | |||
1150 | float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale; | ||
1151 | |||
1152 | if (Math.Abs(dirv.Z) > 0.01) | ||
1153 | { | ||
1154 | torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp; | ||
1155 | } | ||
1156 | |||
1157 | if (Math.Abs(dirv.Y) > 0.01) | ||
1158 | { | ||
1159 | torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp; | ||
1160 | } | ||
1058 | } | 1161 | } |
1059 | 1162 | ||
1060 | if (Math.Abs(dirv.Y) > 0.01) | 1163 | if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0) |
1061 | { | 1164 | { |
1062 | torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp; | 1165 | torque.X -= curLocalAngVel.X * m_amdampX; |
1166 | torque.Y -= curLocalAngVel.Y * m_amdampY; | ||
1167 | torque.Z -= curLocalAngVel.Z * m_amdampZ; | ||
1063 | } | 1168 | } |
1064 | } | 1169 | } |
1065 | |||
1066 | // angular friction | ||
1067 | if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0) | ||
1068 | { | ||
1069 | torque.X -= curLocalAngVel.X * m_amdampX; | ||
1070 | torque.Y -= curLocalAngVel.Y * m_amdampY; | ||
1071 | torque.Z -= curLocalAngVel.Z * m_amdampZ; | ||
1072 | } | ||
1073 | 1170 | ||
1074 | force *= dmass.mass; | 1171 | force *= dmass.mass; |
1075 | 1172 | ||