diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 140 |
1 files changed, 97 insertions, 43 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 7b98f9d..c6d6331 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -42,7 +42,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
42 | { | 42 | { |
43 | public sealed class BSDynamics : BSActor | 43 | public sealed class BSDynamics : BSActor |
44 | { | 44 | { |
45 | #pragma warning disable 414 | ||
45 | private static string LogHeader = "[BULLETSIM VEHICLE]"; | 46 | private static string LogHeader = "[BULLETSIM VEHICLE]"; |
47 | #pragma warning restore 414 | ||
46 | 48 | ||
47 | // the prim this dynamic controller belongs to | 49 | // the prim this dynamic controller belongs to |
48 | private BSPrimLinkable ControllingPrim { get; set; } | 50 | private BSPrimLinkable ControllingPrim { get; set; } |
@@ -74,8 +76,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
74 | private Vector3 m_linearMotorOffset = Vector3.Zero; // the point of force can be offset from the center | 76 | private Vector3 m_linearMotorOffset = Vector3.Zero; // the point of force can be offset from the center |
75 | private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL | 77 | private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL |
76 | private Vector3 m_linearFrictionTimescale = Vector3.Zero; | 78 | private Vector3 m_linearFrictionTimescale = Vector3.Zero; |
77 | private float m_linearMotorDecayTimescale = 0; | 79 | private float m_linearMotorDecayTimescale = 1; |
78 | private float m_linearMotorTimescale = 0; | 80 | private float m_linearMotorTimescale = 1; |
79 | private Vector3 m_lastLinearVelocityVector = Vector3.Zero; | 81 | private Vector3 m_lastLinearVelocityVector = Vector3.Zero; |
80 | private Vector3 m_lastPositionVector = Vector3.Zero; | 82 | private Vector3 m_lastPositionVector = Vector3.Zero; |
81 | // private bool m_LinearMotorSetLastFrame = false; | 83 | // private bool m_LinearMotorSetLastFrame = false; |
@@ -86,8 +88,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
86 | private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor | 88 | private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor |
87 | // private int m_angularMotorApply = 0; // application frame counter | 89 | // private int m_angularMotorApply = 0; // application frame counter |
88 | private Vector3 m_angularMotorVelocity = Vector3.Zero; // current angular motor velocity | 90 | private Vector3 m_angularMotorVelocity = Vector3.Zero; // current angular motor velocity |
89 | private float m_angularMotorTimescale = 0; // motor angular velocity ramp up rate | 91 | private float m_angularMotorTimescale = 1; // motor angular velocity ramp up rate |
90 | private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate | 92 | private float m_angularMotorDecayTimescale = 1; // motor angular velocity decay rate |
91 | private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate | 93 | private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate |
92 | private Vector3 m_lastAngularVelocity = Vector3.Zero; | 94 | private Vector3 m_lastAngularVelocity = Vector3.Zero; |
93 | private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body | 95 | private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body |
@@ -101,7 +103,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
101 | 103 | ||
102 | //Banking properties | 104 | //Banking properties |
103 | private float m_bankingEfficiency = 0; | 105 | private float m_bankingEfficiency = 0; |
104 | private float m_bankingMix = 0; | 106 | private float m_bankingMix = 1; |
105 | private float m_bankingTimescale = 0; | 107 | private float m_bankingTimescale = 0; |
106 | 108 | ||
107 | //Hover and Buoyancy properties | 109 | //Hover and Buoyancy properties |
@@ -122,8 +124,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
122 | private float m_verticalAttractionTimescale = 510f; | 124 | private float m_verticalAttractionTimescale = 510f; |
123 | 125 | ||
124 | // Just some recomputed constants: | 126 | // Just some recomputed constants: |
127 | #pragma warning disable 414 | ||
128 | static readonly float TwoPI = ((float)Math.PI) * 2f; | ||
129 | static readonly float FourPI = ((float)Math.PI) * 4f; | ||
125 | static readonly float PIOverFour = ((float)Math.PI) / 4f; | 130 | static readonly float PIOverFour = ((float)Math.PI) / 4f; |
126 | static readonly float PIOverTwo = ((float)Math.PI) / 2f; | 131 | static readonly float PIOverTwo = ((float)Math.PI) / 2f; |
132 | #pragma warning restore 414 | ||
127 | 133 | ||
128 | public BSDynamics(BSScene myScene, BSPrim myPrim, string actorName) | 134 | public BSDynamics(BSScene myScene, BSPrim myPrim, string actorName) |
129 | : base(myScene, myPrim, actorName) | 135 | : base(myScene, myPrim, actorName) |
@@ -155,56 +161,58 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
155 | public void ProcessFloatVehicleParam(Vehicle pParam, float pValue) | 161 | public void ProcessFloatVehicleParam(Vehicle pParam, float pValue) |
156 | { | 162 | { |
157 | VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", ControllingPrim.LocalID, pParam, pValue); | 163 | VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", ControllingPrim.LocalID, pParam, pValue); |
164 | float clampTemp; | ||
165 | |||
158 | switch (pParam) | 166 | switch (pParam) |
159 | { | 167 | { |
160 | case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY: | 168 | case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY: |
161 | m_angularDeflectionEfficiency = ClampInRange(0f, pValue, 1f); | 169 | m_angularDeflectionEfficiency = ClampInRange(0f, pValue, 1f); |
162 | break; | 170 | break; |
163 | case Vehicle.ANGULAR_DEFLECTION_TIMESCALE: | 171 | case Vehicle.ANGULAR_DEFLECTION_TIMESCALE: |
164 | m_angularDeflectionTimescale = Math.Max(pValue, 0.01f); | 172 | m_angularDeflectionTimescale = ClampInRange(0.25f, pValue, 120); |
165 | break; | 173 | break; |
166 | case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE: | 174 | case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE: |
167 | m_angularMotorDecayTimescale = ClampInRange(0.01f, pValue, 120); | 175 | m_angularMotorDecayTimescale = ClampInRange(0.25f, pValue, 120); |
168 | m_angularMotor.TargetValueDecayTimeScale = m_angularMotorDecayTimescale; | 176 | m_angularMotor.TargetValueDecayTimeScale = m_angularMotorDecayTimescale; |
169 | break; | 177 | break; |
170 | case Vehicle.ANGULAR_MOTOR_TIMESCALE: | 178 | case Vehicle.ANGULAR_MOTOR_TIMESCALE: |
171 | m_angularMotorTimescale = Math.Max(pValue, 0.01f); | 179 | m_angularMotorTimescale = ClampInRange(0.25f, pValue, 120); |
172 | m_angularMotor.TimeScale = m_angularMotorTimescale; | 180 | m_angularMotor.TimeScale = m_angularMotorTimescale; |
173 | break; | 181 | break; |
174 | case Vehicle.BANKING_EFFICIENCY: | 182 | case Vehicle.BANKING_EFFICIENCY: |
175 | m_bankingEfficiency = ClampInRange(-1f, pValue, 1f); | 183 | m_bankingEfficiency = ClampInRange(-1f, pValue, 1f); |
176 | break; | 184 | break; |
177 | case Vehicle.BANKING_MIX: | 185 | case Vehicle.BANKING_MIX: |
178 | m_bankingMix = Math.Max(pValue, 0.01f); | 186 | m_bankingMix = ClampInRange(0.01f, pValue, 1); |
179 | break; | 187 | break; |
180 | case Vehicle.BANKING_TIMESCALE: | 188 | case Vehicle.BANKING_TIMESCALE: |
181 | m_bankingTimescale = Math.Max(pValue, 0.01f); | 189 | m_bankingTimescale = ClampInRange(0.25f, pValue, 120); |
182 | break; | 190 | break; |
183 | case Vehicle.BUOYANCY: | 191 | case Vehicle.BUOYANCY: |
184 | m_VehicleBuoyancy = ClampInRange(-1f, pValue, 1f); | 192 | m_VehicleBuoyancy = ClampInRange(-1f, pValue, 1f); |
185 | m_VehicleGravity = ControllingPrim.ComputeGravity(m_VehicleBuoyancy); | 193 | m_VehicleGravity = ControllingPrim.ComputeGravity(m_VehicleBuoyancy); |
186 | break; | 194 | break; |
187 | case Vehicle.HOVER_EFFICIENCY: | 195 | case Vehicle.HOVER_EFFICIENCY: |
188 | m_VhoverEfficiency = ClampInRange(0f, pValue, 1f); | 196 | m_VhoverEfficiency = ClampInRange(0.01f, pValue, 1f); |
189 | break; | 197 | break; |
190 | case Vehicle.HOVER_HEIGHT: | 198 | case Vehicle.HOVER_HEIGHT: |
191 | m_VhoverHeight = pValue; | 199 | m_VhoverHeight = ClampInRange(0f, pValue, 1000000f); |
192 | break; | 200 | break; |
193 | case Vehicle.HOVER_TIMESCALE: | 201 | case Vehicle.HOVER_TIMESCALE: |
194 | m_VhoverTimescale = Math.Max(pValue, 0.01f); | 202 | m_VhoverTimescale = ClampInRange(0.01f, pValue, 120); |
195 | break; | 203 | break; |
196 | case Vehicle.LINEAR_DEFLECTION_EFFICIENCY: | 204 | case Vehicle.LINEAR_DEFLECTION_EFFICIENCY: |
197 | m_linearDeflectionEfficiency = ClampInRange(0f, pValue, 1f); | 205 | m_linearDeflectionEfficiency = ClampInRange(0f, pValue, 1f); |
198 | break; | 206 | break; |
199 | case Vehicle.LINEAR_DEFLECTION_TIMESCALE: | 207 | case Vehicle.LINEAR_DEFLECTION_TIMESCALE: |
200 | m_linearDeflectionTimescale = Math.Max(pValue, 0.01f); | 208 | m_linearDeflectionTimescale = ClampInRange(0.01f, pValue, 120); |
201 | break; | 209 | break; |
202 | case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE: | 210 | case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE: |
203 | m_linearMotorDecayTimescale = ClampInRange(0.01f, pValue, 120); | 211 | m_linearMotorDecayTimescale = ClampInRange(0.01f, pValue, 120); |
204 | m_linearMotor.TargetValueDecayTimeScale = m_linearMotorDecayTimescale; | 212 | m_linearMotor.TargetValueDecayTimeScale = m_linearMotorDecayTimescale; |
205 | break; | 213 | break; |
206 | case Vehicle.LINEAR_MOTOR_TIMESCALE: | 214 | case Vehicle.LINEAR_MOTOR_TIMESCALE: |
207 | m_linearMotorTimescale = Math.Max(pValue, 0.01f); | 215 | m_linearMotorTimescale = ClampInRange(0.01f, pValue, 120); |
208 | m_linearMotor.TimeScale = m_linearMotorTimescale; | 216 | m_linearMotor.TimeScale = m_linearMotorTimescale; |
209 | break; | 217 | break; |
210 | case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY: | 218 | case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY: |
@@ -212,30 +220,35 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
212 | m_verticalAttractionMotor.Efficiency = m_verticalAttractionEfficiency; | 220 | m_verticalAttractionMotor.Efficiency = m_verticalAttractionEfficiency; |
213 | break; | 221 | break; |
214 | case Vehicle.VERTICAL_ATTRACTION_TIMESCALE: | 222 | case Vehicle.VERTICAL_ATTRACTION_TIMESCALE: |
215 | m_verticalAttractionTimescale = Math.Max(pValue, 0.01f); | 223 | m_verticalAttractionTimescale = ClampInRange(0.01f, pValue, 120); |
216 | m_verticalAttractionMotor.TimeScale = m_verticalAttractionTimescale; | 224 | m_verticalAttractionMotor.TimeScale = m_verticalAttractionTimescale; |
217 | break; | 225 | break; |
218 | 226 | ||
219 | // These are vector properties but the engine lets you use a single float value to | 227 | // These are vector properties but the engine lets you use a single float value to |
220 | // set all of the components to the same value | 228 | // set all of the components to the same value |
221 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: | 229 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: |
222 | m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue); | 230 | clampTemp = ClampInRange(0.01f, pValue, 120); |
231 | m_angularFrictionTimescale = new Vector3(clampTemp, clampTemp, clampTemp); | ||
223 | break; | 232 | break; |
224 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 233 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
225 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); | 234 | clampTemp = ClampInRange(-TwoPI, pValue, TwoPI); |
235 | m_angularMotorDirection = new Vector3(clampTemp, clampTemp, clampTemp); | ||
226 | m_angularMotor.Zero(); | 236 | m_angularMotor.Zero(); |
227 | m_angularMotor.SetTarget(m_angularMotorDirection); | 237 | m_angularMotor.SetTarget(m_angularMotorDirection); |
228 | break; | 238 | break; |
229 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 239 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
230 | m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); | 240 | clampTemp = ClampInRange(0.01f, pValue, 120); |
241 | m_linearFrictionTimescale = new Vector3(clampTemp, clampTemp, clampTemp); | ||
231 | break; | 242 | break; |
232 | case Vehicle.LINEAR_MOTOR_DIRECTION: | 243 | case Vehicle.LINEAR_MOTOR_DIRECTION: |
233 | m_linearMotorDirection = new Vector3(pValue, pValue, pValue); | 244 | clampTemp = ClampInRange(-BSParam.MaxLinearVelocity, pValue, BSParam.MaxLinearVelocity); |
234 | m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue); | 245 | m_linearMotorDirection = new Vector3(clampTemp, clampTemp, clampTemp); |
246 | m_linearMotorDirectionLASTSET = new Vector3(clampTemp, clampTemp, clampTemp); | ||
235 | m_linearMotor.SetTarget(m_linearMotorDirection); | 247 | m_linearMotor.SetTarget(m_linearMotorDirection); |
236 | break; | 248 | break; |
237 | case Vehicle.LINEAR_MOTOR_OFFSET: | 249 | case Vehicle.LINEAR_MOTOR_OFFSET: |
238 | m_linearMotorOffset = new Vector3(pValue, pValue, pValue); | 250 | clampTemp = ClampInRange(-1000, pValue, 1000); |
251 | m_linearMotorOffset = new Vector3(clampTemp, clampTemp, clampTemp); | ||
239 | break; | 252 | break; |
240 | 253 | ||
241 | } | 254 | } |
@@ -247,29 +260,46 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
247 | switch (pParam) | 260 | switch (pParam) |
248 | { | 261 | { |
249 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: | 262 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: |
263 | pValue.X = ClampInRange(0.25f, pValue.X, 120); | ||
264 | pValue.Y = ClampInRange(0.25f, pValue.Y, 120); | ||
265 | pValue.Z = ClampInRange(0.25f, pValue.Z, 120); | ||
250 | m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 266 | m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
251 | break; | 267 | break; |
252 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 268 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
253 | // Limit requested angular speed to 2 rps= 4 pi rads/sec | 269 | // Limit requested angular speed to 2 rps= 4 pi rads/sec |
254 | pValue.X = ClampInRange(-12.56f, pValue.X, 12.56f); | 270 | pValue.X = ClampInRange(-FourPI, pValue.X, FourPI); |
255 | pValue.Y = ClampInRange(-12.56f, pValue.Y, 12.56f); | 271 | pValue.Y = ClampInRange(-FourPI, pValue.Y, FourPI); |
256 | pValue.Z = ClampInRange(-12.56f, pValue.Z, 12.56f); | 272 | pValue.Z = ClampInRange(-FourPI, pValue.Z, FourPI); |
257 | m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); | 273 | m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); |
258 | m_angularMotor.Zero(); | 274 | m_angularMotor.Zero(); |
259 | m_angularMotor.SetTarget(m_angularMotorDirection); | 275 | m_angularMotor.SetTarget(m_angularMotorDirection); |
260 | break; | 276 | break; |
261 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 277 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
278 | pValue.X = ClampInRange(0.25f, pValue.X, 120); | ||
279 | pValue.Y = ClampInRange(0.25f, pValue.Y, 120); | ||
280 | pValue.Z = ClampInRange(0.25f, pValue.Z, 120); | ||
262 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 281 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
263 | break; | 282 | break; |
264 | case Vehicle.LINEAR_MOTOR_DIRECTION: | 283 | case Vehicle.LINEAR_MOTOR_DIRECTION: |
284 | pValue.X = ClampInRange(-BSParam.MaxLinearVelocity, pValue.X, BSParam.MaxLinearVelocity); | ||
285 | pValue.Y = ClampInRange(-BSParam.MaxLinearVelocity, pValue.Y, BSParam.MaxLinearVelocity); | ||
286 | pValue.Z = ClampInRange(-BSParam.MaxLinearVelocity, pValue.Z, BSParam.MaxLinearVelocity); | ||
265 | m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); | 287 | m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); |
266 | m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); | 288 | m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); |
267 | m_linearMotor.SetTarget(m_linearMotorDirection); | 289 | m_linearMotor.SetTarget(m_linearMotorDirection); |
268 | break; | 290 | break; |
269 | case Vehicle.LINEAR_MOTOR_OFFSET: | 291 | case Vehicle.LINEAR_MOTOR_OFFSET: |
292 | // Not sure the correct range to limit this variable | ||
293 | pValue.X = ClampInRange(-1000, pValue.X, 1000); | ||
294 | pValue.Y = ClampInRange(-1000, pValue.Y, 1000); | ||
295 | pValue.Z = ClampInRange(-1000, pValue.Z, 1000); | ||
270 | m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z); | 296 | m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z); |
271 | break; | 297 | break; |
272 | case Vehicle.BLOCK_EXIT: | 298 | case Vehicle.BLOCK_EXIT: |
299 | // Not sure the correct range to limit this variable | ||
300 | pValue.X = ClampInRange(-10000, pValue.X, 10000); | ||
301 | pValue.Y = ClampInRange(-10000, pValue.Y, 10000); | ||
302 | pValue.Z = ClampInRange(-10000, pValue.Z, 10000); | ||
273 | m_BlockingEndPoint = new Vector3(pValue.X, pValue.Y, pValue.Z); | 303 | m_BlockingEndPoint = new Vector3(pValue.X, pValue.Y, pValue.Z); |
274 | break; | 304 | break; |
275 | } | 305 | } |
@@ -915,7 +945,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
915 | { | 945 | { |
916 | get | 946 | get |
917 | { | 947 | { |
918 | return VehicleVelocity * Quaternion.Inverse(Quaternion.Normalize(VehicleOrientation)); | 948 | return VehicleVelocity * Quaternion.Inverse(Quaternion.Normalize(VehicleFrameOrientation)); |
919 | } | 949 | } |
920 | } | 950 | } |
921 | 951 | ||
@@ -926,6 +956,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
926 | return VehicleForwardVelocity.X; | 956 | return VehicleForwardVelocity.X; |
927 | } | 957 | } |
928 | } | 958 | } |
959 | private Quaternion VehicleFrameOrientation | ||
960 | { | ||
961 | get | ||
962 | { | ||
963 | return VehicleOrientation * m_referenceFrame; | ||
964 | } | ||
965 | } | ||
929 | 966 | ||
930 | #endregion // Known vehicle value functions | 967 | #endregion // Known vehicle value functions |
931 | 968 | ||
@@ -1011,8 +1048,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1011 | VDetailLog("{0}, MoveLinear,clampMax,origVelW={1},lenSq={2},maxVelSq={3},,newVelW={4}", | 1048 | VDetailLog("{0}, MoveLinear,clampMax,origVelW={1},lenSq={2},maxVelSq={3},,newVelW={4}", |
1012 | ControllingPrim.LocalID, origVelW, newVelocityLengthSq, BSParam.VehicleMaxLinearVelocitySquared, VehicleVelocity); | 1049 | ControllingPrim.LocalID, origVelW, newVelocityLengthSq, BSParam.VehicleMaxLinearVelocitySquared, VehicleVelocity); |
1013 | } | 1050 | } |
1014 | else if (newVelocityLengthSq < 0.001f) | 1051 | else if (newVelocityLengthSq < BSParam.VehicleMinLinearVelocitySquared) |
1052 | { | ||
1053 | Vector3 origVelW = VehicleVelocity; // DEBUG DEBUG | ||
1054 | VDetailLog("{0}, MoveLinear,clampMin,origVelW={1},lenSq={2}", | ||
1055 | ControllingPrim.LocalID, origVelW, newVelocityLengthSq); | ||
1015 | VehicleVelocity = Vector3.Zero; | 1056 | VehicleVelocity = Vector3.Zero; |
1057 | } | ||
1016 | 1058 | ||
1017 | VDetailLog("{0}, MoveLinear,done,isColl={1},newVel={2}", ControllingPrim.LocalID, ControllingPrim.HasSomeCollision, VehicleVelocity ); | 1059 | VDetailLog("{0}, MoveLinear,done,isColl={1},newVel={2}", ControllingPrim.LocalID, ControllingPrim.HasSomeCollision, VehicleVelocity ); |
1018 | 1060 | ||
@@ -1030,7 +1072,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1030 | linearMotorCorrectionV -= (currentVelV * frictionFactorV); | 1072 | linearMotorCorrectionV -= (currentVelV * frictionFactorV); |
1031 | 1073 | ||
1032 | // Motor is vehicle coordinates. Rotate it to world coordinates | 1074 | // Motor is vehicle coordinates. Rotate it to world coordinates |
1033 | Vector3 linearMotorVelocityW = linearMotorCorrectionV * VehicleOrientation; | 1075 | Vector3 linearMotorVelocityW = linearMotorCorrectionV * VehicleFrameOrientation; |
1034 | 1076 | ||
1035 | // If we're a ground vehicle, don't add any upward Z movement | 1077 | // If we're a ground vehicle, don't add any upward Z movement |
1036 | if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0) | 1078 | if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != 0) |
@@ -1072,7 +1114,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1072 | linearDeflectionV *= new Vector3(1, -1, -1); | 1114 | linearDeflectionV *= new Vector3(1, -1, -1); |
1073 | 1115 | ||
1074 | // Correction is vehicle relative. Convert to world coordinates. | 1116 | // Correction is vehicle relative. Convert to world coordinates. |
1075 | Vector3 linearDeflectionW = linearDeflectionV * VehicleOrientation; | 1117 | Vector3 linearDeflectionW = linearDeflectionV * VehicleFrameOrientation; |
1076 | 1118 | ||
1077 | // Optionally, if not colliding, don't effect world downward velocity. Let falling things fall. | 1119 | // Optionally, if not colliding, don't effect world downward velocity. Let falling things fall. |
1078 | if (BSParam.VehicleLinearDeflectionNotCollidingNoZ && !m_controllingPrim.HasSomeCollision) | 1120 | if (BSParam.VehicleLinearDeflectionNotCollidingNoZ && !m_controllingPrim.HasSomeCollision) |
@@ -1106,7 +1148,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1106 | { | 1148 | { |
1107 | // m_VhoverEfficiency: 0=bouncy, 1=totally damped | 1149 | // m_VhoverEfficiency: 0=bouncy, 1=totally damped |
1108 | // m_VhoverTimescale: time to achieve height | 1150 | // m_VhoverTimescale: time to achieve height |
1109 | if ((m_flags & (VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT)) != 0) | 1151 | if ((m_flags & (VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT)) != 0 && (m_VhoverHeight > 0) && (m_VhoverTimescale < 300)) |
1110 | { | 1152 | { |
1111 | // We should hover, get the target height | 1153 | // We should hover, get the target height |
1112 | if ((m_flags & VehicleFlag.HOVER_WATER_ONLY) != 0) | 1154 | if ((m_flags & VehicleFlag.HOVER_WATER_ONLY) != 0) |
@@ -1368,7 +1410,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1368 | { | 1410 | { |
1369 | // The user wants this many radians per second angular change? | 1411 | // The user wants this many radians per second angular change? |
1370 | Vector3 origVehicleRotationalVelocity = VehicleRotationalVelocity; // DEBUG DEBUG | 1412 | Vector3 origVehicleRotationalVelocity = VehicleRotationalVelocity; // DEBUG DEBUG |
1371 | Vector3 currentAngularV = VehicleRotationalVelocity * Quaternion.Inverse(VehicleOrientation); | 1413 | Vector3 currentAngularV = VehicleRotationalVelocity * Quaternion.Inverse(VehicleFrameOrientation); |
1372 | Vector3 angularMotorContributionV = m_angularMotor.Step(pTimestep, currentAngularV); | 1414 | Vector3 angularMotorContributionV = m_angularMotor.Step(pTimestep, currentAngularV); |
1373 | 1415 | ||
1374 | // ================================================================== | 1416 | // ================================================================== |
@@ -1389,7 +1431,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1389 | Vector3 frictionFactorW = ComputeFrictionFactor(m_angularFrictionTimescale, pTimestep); | 1431 | Vector3 frictionFactorW = ComputeFrictionFactor(m_angularFrictionTimescale, pTimestep); |
1390 | angularMotorContributionV -= (currentAngularV * frictionFactorW); | 1432 | angularMotorContributionV -= (currentAngularV * frictionFactorW); |
1391 | 1433 | ||
1392 | Vector3 angularMotorContributionW = angularMotorContributionV * VehicleOrientation; | 1434 | Vector3 angularMotorContributionW = angularMotorContributionV * VehicleFrameOrientation; |
1393 | VehicleRotationalVelocity += angularMotorContributionW; | 1435 | VehicleRotationalVelocity += angularMotorContributionW; |
1394 | 1436 | ||
1395 | VDetailLog("{0}, MoveAngular,angularTurning,curAngVelV={1},origVehRotVel={2},vehRotVel={3},frictFact={4}, angContribV={5},angContribW={6}", | 1437 | VDetailLog("{0}, MoveAngular,angularTurning,curAngVelV={1},origVehRotVel={2},vehRotVel={3},frictFact={4}, angContribV={5},angContribW={6}", |
@@ -1410,7 +1452,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1410 | // If vertical attaction timescale is reasonable | 1452 | // If vertical attaction timescale is reasonable |
1411 | if (BSParam.VehicleEnableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) | 1453 | if (BSParam.VehicleEnableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) |
1412 | { | 1454 | { |
1413 | Vector3 vehicleUpAxis = Vector3.UnitZ * VehicleOrientation; | 1455 | Vector3 vehicleUpAxis = Vector3.UnitZ * VehicleFrameOrientation; |
1414 | switch (BSParam.VehicleAngularVerticalAttractionAlgorithm) | 1456 | switch (BSParam.VehicleAngularVerticalAttractionAlgorithm) |
1415 | { | 1457 | { |
1416 | case 0: | 1458 | case 0: |
@@ -1429,6 +1471,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1429 | // This is only half the distance to the target so it will take 2 seconds to complete the turn. | 1471 | // This is only half the distance to the target so it will take 2 seconds to complete the turn. |
1430 | Vector3 torqueVector = Vector3.Cross(predictedUp, Vector3.UnitZ); | 1472 | Vector3 torqueVector = Vector3.Cross(predictedUp, Vector3.UnitZ); |
1431 | 1473 | ||
1474 | if ((m_flags & VehicleFlag.LIMIT_ROLL_ONLY) != 0) | ||
1475 | { | ||
1476 | Vector3 vehicleForwardAxis = Vector3.UnitX * VehicleFrameOrientation; | ||
1477 | torqueVector = ProjectVector(torqueVector, vehicleForwardAxis); | ||
1478 | } | ||
1479 | |||
1432 | // Scale vector by our timescale since it is an acceleration it is r/s^2 or radians a timescale squared | 1480 | // Scale vector by our timescale since it is an acceleration it is r/s^2 or radians a timescale squared |
1433 | Vector3 vertContributionV = torqueVector * verticalAttractionSpeed * verticalAttractionSpeed; | 1481 | Vector3 vertContributionV = torqueVector * verticalAttractionSpeed * verticalAttractionSpeed; |
1434 | 1482 | ||
@@ -1450,13 +1498,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1450 | 1498 | ||
1451 | // Create a rotation that is only the vehicle's rotation around Z | 1499 | // Create a rotation that is only the vehicle's rotation around Z |
1452 | Vector3 currentEulerW = Vector3.Zero; | 1500 | Vector3 currentEulerW = Vector3.Zero; |
1453 | VehicleOrientation.GetEulerAngles(out currentEulerW.X, out currentEulerW.Y, out currentEulerW.Z); | 1501 | VehicleFrameOrientation.GetEulerAngles(out currentEulerW.X, out currentEulerW.Y, out currentEulerW.Z); |
1454 | Quaternion justZOrientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, currentEulerW.Z); | 1502 | Quaternion justZOrientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, currentEulerW.Z); |
1455 | 1503 | ||
1456 | // Create the axis that is perpendicular to the up vector and the rotated up vector. | 1504 | // Create the axis that is perpendicular to the up vector and the rotated up vector. |
1457 | Vector3 differenceAxisW = Vector3.Cross(Vector3.UnitZ * justZOrientation, Vector3.UnitZ * VehicleOrientation); | 1505 | Vector3 differenceAxisW = Vector3.Cross(Vector3.UnitZ * justZOrientation, Vector3.UnitZ * VehicleFrameOrientation); |
1458 | // Compute the angle between those to vectors. | 1506 | // Compute the angle between those to vectors. |
1459 | double differenceAngle = Math.Acos((double)Vector3.Dot(Vector3.UnitZ, Vector3.Normalize(Vector3.UnitZ * VehicleOrientation))); | 1507 | double differenceAngle = Math.Acos((double)Vector3.Dot(Vector3.UnitZ, Vector3.Normalize(Vector3.UnitZ * VehicleFrameOrientation))); |
1460 | // 'differenceAngle' is the angle to rotate and 'differenceAxis' is the plane to rotate in to get the vehicle vertical | 1508 | // 'differenceAngle' is the angle to rotate and 'differenceAxis' is the plane to rotate in to get the vehicle vertical |
1461 | 1509 | ||
1462 | // Reduce the change by the time period it is to change in. Timestep is handled when velocity is applied. | 1510 | // Reduce the change by the time period it is to change in. Timestep is handled when velocity is applied. |
@@ -1489,7 +1537,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1489 | Vector3 origRotVelW = VehicleRotationalVelocity; // DEBUG DEBUG | 1537 | Vector3 origRotVelW = VehicleRotationalVelocity; // DEBUG DEBUG |
1490 | 1538 | ||
1491 | // Take a vector pointing up and convert it from world to vehicle relative coords. | 1539 | // Take a vector pointing up and convert it from world to vehicle relative coords. |
1492 | Vector3 verticalError = Vector3.Normalize(Vector3.UnitZ * VehicleOrientation); | 1540 | Vector3 verticalError = Vector3.Normalize(Vector3.UnitZ * VehicleFrameOrientation); |
1493 | 1541 | ||
1494 | // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) | 1542 | // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) |
1495 | // is now: | 1543 | // is now: |
@@ -1520,7 +1568,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1520 | vertContributionV /= m_verticalAttractionTimescale; | 1568 | vertContributionV /= m_verticalAttractionTimescale; |
1521 | 1569 | ||
1522 | // Rotate the vehicle rotation to the world coordinates. | 1570 | // Rotate the vehicle rotation to the world coordinates. |
1523 | VehicleRotationalVelocity += (vertContributionV * VehicleOrientation); | 1571 | VehicleRotationalVelocity += (vertContributionV * VehicleFrameOrientation); |
1524 | 1572 | ||
1525 | VDetailLog("{0}, MoveAngular,verticalAttraction,,upAxis={1},origRotVW={2},vertError={3},unscaledV={4},eff={5},ts={6},vertContribV={7}", | 1573 | VDetailLog("{0}, MoveAngular,verticalAttraction,,upAxis={1},origRotVW={2},vertError={3},unscaledV={4},eff={5},ts={6},vertContribV={7}", |
1526 | ControllingPrim.LocalID, | 1574 | ControllingPrim.LocalID, |
@@ -1561,7 +1609,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1561 | movingDirection *= Math.Sign(VehicleForwardSpeed); | 1609 | movingDirection *= Math.Sign(VehicleForwardSpeed); |
1562 | 1610 | ||
1563 | // The direction the vehicle is pointing | 1611 | // The direction the vehicle is pointing |
1564 | Vector3 pointingDirection = Vector3.UnitX * VehicleOrientation; | 1612 | Vector3 pointingDirection = Vector3.UnitX * VehicleFrameOrientation; |
1565 | //Predict where the Vehicle will be pointing after AngularVelocity change is applied. This will keep | 1613 | //Predict where the Vehicle will be pointing after AngularVelocity change is applied. This will keep |
1566 | // from overshooting and allow this correction to merge with the Vertical Attraction peacefully. | 1614 | // from overshooting and allow this correction to merge with the Vertical Attraction peacefully. |
1567 | Vector3 predictedPointingDirection = pointingDirection * Quaternion.CreateFromAxisAngle(VehicleRotationalVelocity, 0f); | 1615 | Vector3 predictedPointingDirection = pointingDirection * Quaternion.CreateFromAxisAngle(VehicleRotationalVelocity, 0f); |
@@ -1586,7 +1634,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1586 | deflectContributionV = (-deflectionError) * ClampInRange(0, m_angularDeflectionEfficiency/m_angularDeflectionTimescale,1f); | 1634 | deflectContributionV = (-deflectionError) * ClampInRange(0, m_angularDeflectionEfficiency/m_angularDeflectionTimescale,1f); |
1587 | //deflectContributionV /= m_angularDeflectionTimescale; | 1635 | //deflectContributionV /= m_angularDeflectionTimescale; |
1588 | 1636 | ||
1589 | // VehicleRotationalVelocity += deflectContributionV * VehicleOrientation; | ||
1590 | VehicleRotationalVelocity += deflectContributionV; | 1637 | VehicleRotationalVelocity += deflectContributionV; |
1591 | VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", | 1638 | VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", |
1592 | ControllingPrim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContributionV); | 1639 | ControllingPrim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContributionV); |
@@ -1635,7 +1682,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1635 | // Rotate a UnitZ vector (pointing up) to how the vehicle is oriented. | 1682 | // Rotate a UnitZ vector (pointing up) to how the vehicle is oriented. |
1636 | // As the vehicle rolls to the right or left, the Y value will increase from | 1683 | // As the vehicle rolls to the right or left, the Y value will increase from |
1637 | // zero (straight up) to 1 or -1 (full tilt right or left) | 1684 | // zero (straight up) to 1 or -1 (full tilt right or left) |
1638 | Vector3 rollComponents = Vector3.UnitZ * VehicleOrientation; | 1685 | Vector3 rollComponents = Vector3.UnitZ * VehicleFrameOrientation; |
1639 | 1686 | ||
1640 | // Figure out the yaw value for this much roll. | 1687 | // Figure out the yaw value for this much roll. |
1641 | float yawAngle = m_angularMotorDirection.X * m_bankingEfficiency; | 1688 | float yawAngle = m_angularMotorDirection.X * m_bankingEfficiency; |
@@ -1644,7 +1691,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1644 | 1691 | ||
1645 | // TODO: the banking effect should not go to infinity but what to limit it to? | 1692 | // TODO: the banking effect should not go to infinity but what to limit it to? |
1646 | // And what should happen when this is being added to a user defined yaw that is already PI*4? | 1693 | // And what should happen when this is being added to a user defined yaw that is already PI*4? |
1647 | mixedYawAngle = ClampInRange(-12, mixedYawAngle, 12); | 1694 | mixedYawAngle = ClampInRange(-FourPI, mixedYawAngle, FourPI); |
1648 | 1695 | ||
1649 | // Build the force vector to change rotation from what it is to what it should be | 1696 | // Build the force vector to change rotation from what it is to what it should be |
1650 | bankingContributionV.Z = -mixedYawAngle; | 1697 | bankingContributionV.Z = -mixedYawAngle; |
@@ -1652,7 +1699,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1652 | // Don't do it all at once. Fudge because 1 second is too fast with most user defined roll as PI*4. | 1699 | // Don't do it all at once. Fudge because 1 second is too fast with most user defined roll as PI*4. |
1653 | bankingContributionV /= m_bankingTimescale * BSParam.VehicleAngularBankingTimescaleFudge; | 1700 | bankingContributionV /= m_bankingTimescale * BSParam.VehicleAngularBankingTimescaleFudge; |
1654 | 1701 | ||
1655 | //VehicleRotationalVelocity += bankingContributionV * VehicleOrientation; | ||
1656 | VehicleRotationalVelocity += bankingContributionV; | 1702 | VehicleRotationalVelocity += bankingContributionV; |
1657 | 1703 | ||
1658 | 1704 | ||
@@ -1730,6 +1776,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1730 | 1776 | ||
1731 | } | 1777 | } |
1732 | 1778 | ||
1779 | //Given a Vector and a unit vector will return the amount of the vector is on the same axis as the unit. | ||
1780 | private Vector3 ProjectVector(Vector3 vector, Vector3 onNormal) | ||
1781 | { | ||
1782 | float vectorDot = Vector3.Dot(vector, onNormal); | ||
1783 | return onNormal * vectorDot; | ||
1784 | |||
1785 | } | ||
1786 | |||
1733 | private float ClampInRange(float low, float val, float high) | 1787 | private float ClampInRange(float low, float val, float high) |
1734 | { | 1788 | { |
1735 | return Math.Max(low, Math.Min(val, high)); | 1789 | return Math.Max(low, Math.Min(val, high)); |