aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorRobert Adams2012-10-25 08:04:20 -0700
committerRobert Adams2012-11-03 21:12:46 -0700
commit804b332d45c3989958f5ec08e1509ba373fb84b1 (patch)
tree587774c28a74886120cd6b95682db41da3b0d3fe /OpenSim/Region
parentHG Suitcase Inventory: if RootFolder type doesn't work, look for any folder w... (diff)
downloadopensim-SC_OLD-804b332d45c3989958f5ec08e1509ba373fb84b1.zip
opensim-SC_OLD-804b332d45c3989958f5ec08e1509ba373fb84b1.tar.gz
opensim-SC_OLD-804b332d45c3989958f5ec08e1509ba373fb84b1.tar.bz2
opensim-SC_OLD-804b332d45c3989958f5ec08e1509ba373fb84b1.tar.xz
BulletSim: Add banking and other new code to vechile dynamics. Add third party license and contributor in for for Aurora-Sim project for physics code.
Diffstat (limited to 'OpenSim/Region')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BS6DofConstraint.cs2
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs2
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs2
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs489
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSHingeConstraint.cs2
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs2
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs2
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs4
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSScene.cs2
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs2
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs2
11 files changed, 323 insertions, 188 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BS6DofConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BS6DofConstraint.cs
index 3306a97..310df3d 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BS6DofConstraint.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BS6DofConstraint.cs
@@ -32,7 +32,7 @@ using OpenMetaverse;
32namespace OpenSim.Region.Physics.BulletSPlugin 32namespace OpenSim.Region.Physics.BulletSPlugin
33{ 33{
34 34
35public class BS6DofConstraint : BSConstraint 35public sealed class BS6DofConstraint : BSConstraint
36{ 36{
37 private static string LogHeader = "[BULLETSIM 6DOF CONSTRAINT]"; 37 private static string LogHeader = "[BULLETSIM 6DOF CONSTRAINT]";
38 38
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index a041ba8..9fea9b8 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -34,7 +34,7 @@ using OpenSim.Region.Physics.Manager;
34 34
35namespace OpenSim.Region.Physics.BulletSPlugin 35namespace OpenSim.Region.Physics.BulletSPlugin
36{ 36{
37public class BSCharacter : BSPhysObject 37public sealed class BSCharacter : BSPhysObject
38{ 38{
39 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 39 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
40 private static readonly string LogHeader = "[BULLETS CHAR]"; 40 private static readonly string LogHeader = "[BULLETS CHAR]";
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs
index 22ea367..b9add06 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs
@@ -33,7 +33,7 @@ using OpenMetaverse;
33namespace OpenSim.Region.Physics.BulletSPlugin 33namespace OpenSim.Region.Physics.BulletSPlugin
34{ 34{
35 35
36public class BSConstraintCollection : IDisposable 36public sealed class BSConstraintCollection : IDisposable
37{ 37{
38 // private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 38 // private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
39 // private static readonly string LogHeader = "[CONSTRAINT COLLECTION]"; 39 // private static readonly string LogHeader = "[CONSTRAINT COLLECTION]";
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 117c878..9b59bef 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -52,7 +52,7 @@ using OpenSim.Region.Physics.Manager;
52 52
53namespace OpenSim.Region.Physics.BulletSPlugin 53namespace OpenSim.Region.Physics.BulletSPlugin
54{ 54{
55 public class BSDynamics 55 public sealed class BSDynamics
56 { 56 {
57 private BSScene PhysicsScene { get; set; } 57 private BSScene PhysicsScene { get; set; }
58 // the prim this dynamic controller belongs to 58 // the prim this dynamic controller belongs to
@@ -72,8 +72,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
72 // LIMIT_ROLL_ONLY 72 // LIMIT_ROLL_ONLY
73 private Vector3 m_BlockingEndPoint = Vector3.Zero; 73 private Vector3 m_BlockingEndPoint = Vector3.Zero;
74 private Quaternion m_RollreferenceFrame = Quaternion.Identity; 74 private Quaternion m_RollreferenceFrame = Quaternion.Identity;
75 private Quaternion m_referenceFrame = Quaternion.Identity;
76
75 // Linear properties 77 // Linear properties
76 private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time 78 private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time
79 private Vector3 m_linearMotorOffset = Vector3.Zero; // the point of force can be offset from the center
77 private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL 80 private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL
78 private Vector3 m_newVelocity = Vector3.Zero; // velocity computed to be applied to body 81 private Vector3 m_newVelocity = Vector3.Zero; // velocity computed to be applied to body
79 private Vector3 m_linearFrictionTimescale = Vector3.Zero; 82 private Vector3 m_linearFrictionTimescale = Vector3.Zero;
@@ -95,19 +98,19 @@ namespace OpenSim.Region.Physics.BulletSPlugin
95 private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body 98 private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body
96 99
97 //Deflection properties 100 //Deflection properties
98 // private float m_angularDeflectionEfficiency = 0; 101 private float m_angularDeflectionEfficiency = 0;
99 // private float m_angularDeflectionTimescale = 0; 102 private float m_angularDeflectionTimescale = 0;
100 // private float m_linearDeflectionEfficiency = 0; 103 private float m_linearDeflectionEfficiency = 0;
101 // private float m_linearDeflectionTimescale = 0; 104 private float m_linearDeflectionTimescale = 0;
102 105
103 //Banking properties 106 //Banking properties
104 // private float m_bankingEfficiency = 0; 107 private float m_bankingEfficiency = 0;
105 // private float m_bankingMix = 0; 108 private float m_bankingMix = 0;
106 // private float m_bankingTimescale = 0; 109 private float m_bankingTimescale = 0;
107 110
108 //Hover and Buoyancy properties 111 //Hover and Buoyancy properties
109 private float m_VhoverHeight = 0f; 112 private float m_VhoverHeight = 0f;
110// private float m_VhoverEfficiency = 0f; 113 private float m_VhoverEfficiency = 0f;
111 private float m_VhoverTimescale = 0f; 114 private float m_VhoverTimescale = 0f;
112 private float m_VhoverTargetHeight = -1.0f; // if <0 then no hover, else its the current target height 115 private float m_VhoverTargetHeight = -1.0f; // if <0 then no hover, else its the current target height
113 private float m_VehicleBuoyancy = 0f; //KF: m_VehicleBuoyancy is set by VEHICLE_BUOYANCY for a vehicle. 116 private float m_VehicleBuoyancy = 0f; //KF: m_VehicleBuoyancy is set by VEHICLE_BUOYANCY for a vehicle.
@@ -138,10 +141,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
138 switch (pParam) 141 switch (pParam)
139 { 142 {
140 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY: 143 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY:
141 // m_angularDeflectionEfficiency = Math.Max(pValue, 0.01f); 144 m_angularDeflectionEfficiency = Math.Max(pValue, 0.01f);
142 break; 145 break;
143 case Vehicle.ANGULAR_DEFLECTION_TIMESCALE: 146 case Vehicle.ANGULAR_DEFLECTION_TIMESCALE:
144 // m_angularDeflectionTimescale = Math.Max(pValue, 0.01f); 147 m_angularDeflectionTimescale = Math.Max(pValue, 0.01f);
145 break; 148 break;
146 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE: 149 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
147 m_angularMotorDecayTimescale = Math.Max(pValue, 0.01f); 150 m_angularMotorDecayTimescale = Math.Max(pValue, 0.01f);
@@ -150,20 +153,20 @@ namespace OpenSim.Region.Physics.BulletSPlugin
150 m_angularMotorTimescale = Math.Max(pValue, 0.01f); 153 m_angularMotorTimescale = Math.Max(pValue, 0.01f);
151 break; 154 break;
152 case Vehicle.BANKING_EFFICIENCY: 155 case Vehicle.BANKING_EFFICIENCY:
153 // m_bankingEfficiency = Math.Max(pValue, 0.01f); 156 m_bankingEfficiency = Math.Max(-1f, Math.Min(pValue, 1f));
154 break; 157 break;
155 case Vehicle.BANKING_MIX: 158 case Vehicle.BANKING_MIX:
156 // m_bankingMix = Math.Max(pValue, 0.01f); 159 m_bankingMix = Math.Max(pValue, 0.01f);
157 break; 160 break;
158 case Vehicle.BANKING_TIMESCALE: 161 case Vehicle.BANKING_TIMESCALE:
159 // m_bankingTimescale = Math.Max(pValue, 0.01f); 162 m_bankingTimescale = Math.Max(pValue, 0.01f);
160 break; 163 break;
161 case Vehicle.BUOYANCY: 164 case Vehicle.BUOYANCY:
162 m_VehicleBuoyancy = Math.Max(-1f, Math.Min(pValue, 1f)); 165 m_VehicleBuoyancy = Math.Max(-1f, Math.Min(pValue, 1f));
163 break; 166 break;
164// case Vehicle.HOVER_EFFICIENCY: 167 case Vehicle.HOVER_EFFICIENCY:
165// m_VhoverEfficiency = Math.Max(0f, Math.Min(pValue, 1f)); 168 m_VhoverEfficiency = Math.Max(0f, Math.Min(pValue, 1f));
166// break; 169 break;
167 case Vehicle.HOVER_HEIGHT: 170 case Vehicle.HOVER_HEIGHT:
168 m_VhoverHeight = pValue; 171 m_VhoverHeight = pValue;
169 break; 172 break;
@@ -171,10 +174,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
171 m_VhoverTimescale = Math.Max(pValue, 0.01f); 174 m_VhoverTimescale = Math.Max(pValue, 0.01f);
172 break; 175 break;
173 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY: 176 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY:
174 // m_linearDeflectionEfficiency = Math.Max(pValue, 0.01f); 177 m_linearDeflectionEfficiency = Math.Max(pValue, 0.01f);
175 break; 178 break;
176 case Vehicle.LINEAR_DEFLECTION_TIMESCALE: 179 case Vehicle.LINEAR_DEFLECTION_TIMESCALE:
177 // m_linearDeflectionTimescale = Math.Max(pValue, 0.01f); 180 m_linearDeflectionTimescale = Math.Max(pValue, 0.01f);
178 break; 181 break;
179 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE: 182 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
180 m_linearMotorDecayTimescale = Math.Max(pValue, 0.01f); 183 m_linearMotorDecayTimescale = Math.Max(pValue, 0.01f);
@@ -196,7 +199,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
196 break; 199 break;
197 case Vehicle.ANGULAR_MOTOR_DIRECTION: 200 case Vehicle.ANGULAR_MOTOR_DIRECTION:
198 m_angularMotorDirection = new Vector3(pValue, pValue, pValue); 201 m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
199 m_angularMotorApply = 10; 202 m_angularMotorApply = 100;
200 break; 203 break;
201 case Vehicle.LINEAR_FRICTION_TIMESCALE: 204 case Vehicle.LINEAR_FRICTION_TIMESCALE:
202 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); 205 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
@@ -206,7 +209,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
206 m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue); 209 m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue);
207 break; 210 break;
208 case Vehicle.LINEAR_MOTOR_OFFSET: 211 case Vehicle.LINEAR_MOTOR_OFFSET:
209 // m_linearMotorOffset = new Vector3(pValue, pValue, pValue); 212 m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
210 break; 213 break;
211 214
212 } 215 }
@@ -221,15 +224,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
221 m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); 224 m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
222 break; 225 break;
223 case Vehicle.ANGULAR_MOTOR_DIRECTION: 226 case Vehicle.ANGULAR_MOTOR_DIRECTION:
224 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
225 // Limit requested angular speed to 2 rps= 4 pi rads/sec 227 // Limit requested angular speed to 2 rps= 4 pi rads/sec
226 if (m_angularMotorDirection.X > 12.56f) m_angularMotorDirection.X = 12.56f; 228 pValue.X = Math.Max(-12.56f, Math.Min(pValue.X, 12.56f));
227 if (m_angularMotorDirection.X < - 12.56f) m_angularMotorDirection.X = - 12.56f; 229 pValue.Y = Math.Max(-12.56f, Math.Min(pValue.Y, 12.56f));
228 if (m_angularMotorDirection.Y > 12.56f) m_angularMotorDirection.Y = 12.56f; 230 pValue.Z = Math.Max(-12.56f, Math.Min(pValue.Z, 12.56f));
229 if (m_angularMotorDirection.Y < - 12.56f) m_angularMotorDirection.Y = - 12.56f; 231 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
230 if (m_angularMotorDirection.Z > 12.56f) m_angularMotorDirection.Z = 12.56f; 232 m_angularMotorApply = 100;
231 if (m_angularMotorDirection.Z < - 12.56f) m_angularMotorDirection.Z = - 12.56f;
232 m_angularMotorApply = 10;
233 break; 233 break;
234 case Vehicle.LINEAR_FRICTION_TIMESCALE: 234 case Vehicle.LINEAR_FRICTION_TIMESCALE:
235 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); 235 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
@@ -239,7 +239,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
239 m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); 239 m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z);
240 break; 240 break;
241 case Vehicle.LINEAR_MOTOR_OFFSET: 241 case Vehicle.LINEAR_MOTOR_OFFSET:
242 // m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z); 242 m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
243 break; 243 break;
244 case Vehicle.BLOCK_EXIT: 244 case Vehicle.BLOCK_EXIT:
245 m_BlockingEndPoint = new Vector3(pValue.X, pValue.Y, pValue.Z); 245 m_BlockingEndPoint = new Vector3(pValue.X, pValue.Y, pValue.Z);
@@ -253,7 +253,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
253 switch (pParam) 253 switch (pParam)
254 { 254 {
255 case Vehicle.REFERENCE_FRAME: 255 case Vehicle.REFERENCE_FRAME:
256 // m_referenceFrame = pValue; 256 m_referenceFrame = pValue;
257 break; 257 break;
258 case Vehicle.ROLL_FRAME: 258 case Vehicle.ROLL_FRAME:
259 m_RollreferenceFrame = pValue; 259 m_RollreferenceFrame = pValue;
@@ -265,21 +265,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin
265 { 265 {
266 VDetailLog("{0},ProcessVehicleFlags,param={1},remove={2}", Prim.LocalID, pParam, remove); 266 VDetailLog("{0},ProcessVehicleFlags,param={1},remove={2}", Prim.LocalID, pParam, remove);
267 VehicleFlag parm = (VehicleFlag)pParam; 267 VehicleFlag parm = (VehicleFlag)pParam;
268 if (remove) 268 if (pParam == -1)
269 m_flags = (VehicleFlag)0;
270 else
269 { 271 {
270 if (pParam == -1) 272 if (remove)
271 {
272 m_flags = (VehicleFlag)0;
273 }
274 else
275 {
276 m_flags &= ~parm; 273 m_flags &= ~parm;
277 } 274 else
278 } 275 m_flags |= parm;
279 else {
280 m_flags |= parm;
281 } 276 }
282 }//end ProcessVehicleFlags 277 }
283 278
284 internal void ProcessTypeChange(Vehicle pType) 279 internal void ProcessTypeChange(Vehicle pType)
285 { 280 {
@@ -288,99 +283,142 @@ namespace OpenSim.Region.Physics.BulletSPlugin
288 Type = pType; 283 Type = pType;
289 switch (pType) 284 switch (pType)
290 { 285 {
291 case Vehicle.TYPE_NONE: 286 case Vehicle.TYPE_NONE:
292 m_linearFrictionTimescale = new Vector3(0, 0, 0);
293 m_angularFrictionTimescale = new Vector3(0, 0, 0);
294 m_linearMotorDirection = Vector3.Zero; 287 m_linearMotorDirection = Vector3.Zero;
295 m_linearMotorTimescale = 0; 288 m_linearMotorTimescale = 0;
296 m_linearMotorDecayTimescale = 0; 289 m_linearMotorDecayTimescale = 0;
290 m_linearFrictionTimescale = new Vector3(0, 0, 0);
291
297 m_angularMotorDirection = Vector3.Zero; 292 m_angularMotorDirection = Vector3.Zero;
298 m_angularMotorTimescale = 0;
299 m_angularMotorDecayTimescale = 0; 293 m_angularMotorDecayTimescale = 0;
294 m_angularMotorTimescale = 0;
295 m_angularFrictionTimescale = new Vector3(0, 0, 0);
296
300 m_VhoverHeight = 0; 297 m_VhoverHeight = 0;
298 m_VhoverEfficiency = 0;
301 m_VhoverTimescale = 0; 299 m_VhoverTimescale = 0;
302 m_VehicleBuoyancy = 0; 300 m_VehicleBuoyancy = 0;
301
302 m_linearDeflectionEfficiency = 1;
303 m_linearDeflectionTimescale = 1;
304
305 m_angularDeflectionEfficiency = 0;
306 m_angularDeflectionTimescale = 1000;
307
308 m_verticalAttractionEfficiency = 0;
309 m_verticalAttractionTimescale = 0;
310
311 m_bankingEfficiency = 0;
312 m_bankingTimescale = 1000;
313 m_bankingMix = 1;
314
315 m_referenceFrame = Quaternion.Identity;
303 m_flags = (VehicleFlag)0; 316 m_flags = (VehicleFlag)0;
304 break; 317 break;
305 318
306 case Vehicle.TYPE_SLED: 319 case Vehicle.TYPE_SLED:
307 m_linearFrictionTimescale = new Vector3(30, 1, 1000);
308 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
309 m_linearMotorDirection = Vector3.Zero; 320 m_linearMotorDirection = Vector3.Zero;
310 m_linearMotorTimescale = 1000; 321 m_linearMotorTimescale = 1000;
311 m_linearMotorDecayTimescale = 120; 322 m_linearMotorDecayTimescale = 120;
323 m_linearFrictionTimescale = new Vector3(30, 1, 1000);
324
312 m_angularMotorDirection = Vector3.Zero; 325 m_angularMotorDirection = Vector3.Zero;
313 m_angularMotorTimescale = 1000; 326 m_angularMotorTimescale = 1000;
314 m_angularMotorDecayTimescale = 120; 327 m_angularMotorDecayTimescale = 120;
328 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
329
315 m_VhoverHeight = 0; 330 m_VhoverHeight = 0;
316// m_VhoverEfficiency = 1; 331 m_VhoverEfficiency = 10; // TODO: this looks wrong!!
317 m_VhoverTimescale = 10; 332 m_VhoverTimescale = 10;
318 m_VehicleBuoyancy = 0; 333 m_VehicleBuoyancy = 0;
319 // m_linearDeflectionEfficiency = 1; 334
320 // m_linearDeflectionTimescale = 1; 335 m_linearDeflectionEfficiency = 1;
321 // m_angularDeflectionEfficiency = 1; 336 m_linearDeflectionTimescale = 1;
322 // m_angularDeflectionTimescale = 1000; 337
323 // m_bankingEfficiency = 0; 338 m_angularDeflectionEfficiency = 1;
324 // m_bankingMix = 1; 339 m_angularDeflectionTimescale = 1000;
325 // m_bankingTimescale = 10; 340
326 // m_referenceFrame = Quaternion.Identity; 341 m_verticalAttractionEfficiency = 0;
342 m_verticalAttractionTimescale = 0;
343
344 m_bankingEfficiency = 0;
345 m_bankingTimescale = 10;
346 m_bankingMix = 1;
347
348 m_referenceFrame = Quaternion.Identity;
327 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP); 349 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
328 m_flags &= 350 m_flags &=
329 ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | 351 ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
330 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY); 352 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
331 break; 353 break;
332 case Vehicle.TYPE_CAR: 354 case Vehicle.TYPE_CAR:
333 m_linearFrictionTimescale = new Vector3(100, 2, 1000);
334 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
335 m_linearMotorDirection = Vector3.Zero; 355 m_linearMotorDirection = Vector3.Zero;
336 m_linearMotorTimescale = 1; 356 m_linearMotorTimescale = 1;
337 m_linearMotorDecayTimescale = 60; 357 m_linearMotorDecayTimescale = 60;
358 m_linearFrictionTimescale = new Vector3(100, 2, 1000);
359
338 m_angularMotorDirection = Vector3.Zero; 360 m_angularMotorDirection = Vector3.Zero;
339 m_angularMotorTimescale = 1; 361 m_angularMotorTimescale = 1;
340 m_angularMotorDecayTimescale = 0.8f; 362 m_angularMotorDecayTimescale = 0.8f;
363 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
364
341 m_VhoverHeight = 0; 365 m_VhoverHeight = 0;
342// m_VhoverEfficiency = 0; 366 m_VhoverEfficiency = 0;
343 m_VhoverTimescale = 1000; 367 m_VhoverTimescale = 1000;
344 m_VehicleBuoyancy = 0; 368 m_VehicleBuoyancy = 0;
345 // // m_linearDeflectionEfficiency = 1; 369
346 // // m_linearDeflectionTimescale = 2; 370 m_linearDeflectionEfficiency = 1;
347 // // m_angularDeflectionEfficiency = 0; 371 m_linearDeflectionTimescale = 2;
348 // m_angularDeflectionTimescale = 10; 372
373 m_angularDeflectionEfficiency = 0;
374 m_angularDeflectionTimescale = 10;
375
349 m_verticalAttractionEfficiency = 1f; 376 m_verticalAttractionEfficiency = 1f;
350 m_verticalAttractionTimescale = 10f; 377 m_verticalAttractionTimescale = 10f;
351 // m_bankingEfficiency = -0.2f; 378
352 // m_bankingMix = 1; 379 m_bankingEfficiency = -0.2f;
353 // m_bankingTimescale = 1; 380 m_bankingMix = 1;
354 // m_referenceFrame = Quaternion.Identity; 381 m_bankingTimescale = 1;
382
383 m_referenceFrame = Quaternion.Identity;
384 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY
385 | VehicleFlag.HOVER_TERRAIN_ONLY
386 | VehicleFlag.HOVER_GLOBAL_HEIGHT);
355 m_flags |= (VehicleFlag.NO_DEFLECTION_UP 387 m_flags |= (VehicleFlag.NO_DEFLECTION_UP
356 | VehicleFlag.LIMIT_ROLL_ONLY 388 | VehicleFlag.LIMIT_ROLL_ONLY
357 | VehicleFlag.LIMIT_MOTOR_UP); 389 | VehicleFlag.LIMIT_MOTOR_UP
358 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT); 390 | VehicleFlag.HOVER_UP_ONLY);
359 m_flags |= (VehicleFlag.HOVER_UP_ONLY);
360 break; 391 break;
361 case Vehicle.TYPE_BOAT: 392 case Vehicle.TYPE_BOAT:
362 m_linearFrictionTimescale = new Vector3(10, 3, 2);
363 m_angularFrictionTimescale = new Vector3(10,10,10);
364 m_linearMotorDirection = Vector3.Zero; 393 m_linearMotorDirection = Vector3.Zero;
365 m_linearMotorTimescale = 5; 394 m_linearMotorTimescale = 5;
366 m_linearMotorDecayTimescale = 60; 395 m_linearMotorDecayTimescale = 60;
396 m_linearFrictionTimescale = new Vector3(10, 3, 2);
397
367 m_angularMotorDirection = Vector3.Zero; 398 m_angularMotorDirection = Vector3.Zero;
368 m_angularMotorTimescale = 4; 399 m_angularMotorTimescale = 4;
369 m_angularMotorDecayTimescale = 4; 400 m_angularMotorDecayTimescale = 4;
401 m_angularFrictionTimescale = new Vector3(10,10,10);
402
370 m_VhoverHeight = 0; 403 m_VhoverHeight = 0;
371// m_VhoverEfficiency = 0.5f; 404 m_VhoverEfficiency = 0.5f;
372 m_VhoverTimescale = 2; 405 m_VhoverTimescale = 2;
373 m_VehicleBuoyancy = 1; 406 m_VehicleBuoyancy = 1;
374 // m_linearDeflectionEfficiency = 0.5f; 407
375 // m_linearDeflectionTimescale = 3; 408 m_linearDeflectionEfficiency = 0.5f;
376 // m_angularDeflectionEfficiency = 0.5f; 409 m_linearDeflectionTimescale = 3;
377 // m_angularDeflectionTimescale = 5; 410
411 m_angularDeflectionEfficiency = 0.5f;
412 m_angularDeflectionTimescale = 5;
413
378 m_verticalAttractionEfficiency = 0.5f; 414 m_verticalAttractionEfficiency = 0.5f;
379 m_verticalAttractionTimescale = 5f; 415 m_verticalAttractionTimescale = 5f;
380 // m_bankingEfficiency = -0.3f; 416
381 // m_bankingMix = 0.8f; 417 m_bankingEfficiency = -0.3f;
382 // m_bankingTimescale = 1; 418 m_bankingMix = 0.8f;
383 // m_referenceFrame = Quaternion.Identity; 419 m_bankingTimescale = 1;
420
421 m_referenceFrame = Quaternion.Identity;
384 m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY 422 m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY
385 | VehicleFlag.HOVER_GLOBAL_HEIGHT 423 | VehicleFlag.HOVER_GLOBAL_HEIGHT
386 | VehicleFlag.LIMIT_ROLL_ONLY 424 | VehicleFlag.LIMIT_ROLL_ONLY
@@ -390,28 +428,35 @@ namespace OpenSim.Region.Physics.BulletSPlugin
390 | VehicleFlag.HOVER_WATER_ONLY); 428 | VehicleFlag.HOVER_WATER_ONLY);
391 break; 429 break;
392 case Vehicle.TYPE_AIRPLANE: 430 case Vehicle.TYPE_AIRPLANE:
393 m_linearFrictionTimescale = new Vector3(200, 10, 5);
394 m_angularFrictionTimescale = new Vector3(20, 20, 20);
395 m_linearMotorDirection = Vector3.Zero; 431 m_linearMotorDirection = Vector3.Zero;
396 m_linearMotorTimescale = 2; 432 m_linearMotorTimescale = 2;
397 m_linearMotorDecayTimescale = 60; 433 m_linearMotorDecayTimescale = 60;
434 m_linearFrictionTimescale = new Vector3(200, 10, 5);
435
398 m_angularMotorDirection = Vector3.Zero; 436 m_angularMotorDirection = Vector3.Zero;
399 m_angularMotorTimescale = 4; 437 m_angularMotorTimescale = 4;
400 m_angularMotorDecayTimescale = 4; 438 m_angularMotorDecayTimescale = 4;
439 m_angularFrictionTimescale = new Vector3(20, 20, 20);
440
401 m_VhoverHeight = 0; 441 m_VhoverHeight = 0;
402// m_VhoverEfficiency = 0.5f; 442 m_VhoverEfficiency = 0.5f;
403 m_VhoverTimescale = 1000; 443 m_VhoverTimescale = 1000;
404 m_VehicleBuoyancy = 0; 444 m_VehicleBuoyancy = 0;
405 // m_linearDeflectionEfficiency = 0.5f; 445
406 // m_linearDeflectionTimescale = 3; 446 m_linearDeflectionEfficiency = 0.5f;
407 // m_angularDeflectionEfficiency = 1; 447 m_linearDeflectionTimescale = 3;
408 // m_angularDeflectionTimescale = 2; 448
449 m_angularDeflectionEfficiency = 1;
450 m_angularDeflectionTimescale = 2;
451
409 m_verticalAttractionEfficiency = 0.9f; 452 m_verticalAttractionEfficiency = 0.9f;
410 m_verticalAttractionTimescale = 2f; 453 m_verticalAttractionTimescale = 2f;
411 // m_bankingEfficiency = 1; 454
412 // m_bankingMix = 0.7f; 455 m_bankingEfficiency = 1;
413 // m_bankingTimescale = 2; 456 m_bankingMix = 0.7f;
414 // m_referenceFrame = Quaternion.Identity; 457 m_bankingTimescale = 2;
458
459 m_referenceFrame = Quaternion.Identity;
415 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY 460 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY
416 | VehicleFlag.HOVER_TERRAIN_ONLY 461 | VehicleFlag.HOVER_TERRAIN_ONLY
417 | VehicleFlag.HOVER_GLOBAL_HEIGHT 462 | VehicleFlag.HOVER_GLOBAL_HEIGHT
@@ -421,28 +466,36 @@ namespace OpenSim.Region.Physics.BulletSPlugin
421 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY); 466 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY);
422 break; 467 break;
423 case Vehicle.TYPE_BALLOON: 468 case Vehicle.TYPE_BALLOON:
424 m_linearFrictionTimescale = new Vector3(5, 5, 5);
425 m_angularFrictionTimescale = new Vector3(10, 10, 10);
426 m_linearMotorDirection = Vector3.Zero; 469 m_linearMotorDirection = Vector3.Zero;
427 m_linearMotorTimescale = 5; 470 m_linearMotorTimescale = 5;
471 m_linearFrictionTimescale = new Vector3(5, 5, 5);
428 m_linearMotorDecayTimescale = 60; 472 m_linearMotorDecayTimescale = 60;
473
429 m_angularMotorDirection = Vector3.Zero; 474 m_angularMotorDirection = Vector3.Zero;
430 m_angularMotorTimescale = 6; 475 m_angularMotorTimescale = 6;
476 m_angularFrictionTimescale = new Vector3(10, 10, 10);
431 m_angularMotorDecayTimescale = 10; 477 m_angularMotorDecayTimescale = 10;
478
432 m_VhoverHeight = 5; 479 m_VhoverHeight = 5;
433// m_VhoverEfficiency = 0.8f; 480 m_VhoverEfficiency = 0.8f;
434 m_VhoverTimescale = 10; 481 m_VhoverTimescale = 10;
435 m_VehicleBuoyancy = 1; 482 m_VehicleBuoyancy = 1;
436 // m_linearDeflectionEfficiency = 0; 483
437 // m_linearDeflectionTimescale = 5; 484 m_linearDeflectionEfficiency = 0;
438 // m_angularDeflectionEfficiency = 0; 485 m_linearDeflectionTimescale = 5;
439 // m_angularDeflectionTimescale = 5; 486
487 m_angularDeflectionEfficiency = 0;
488 m_angularDeflectionTimescale = 5;
489
440 m_verticalAttractionEfficiency = 1f; 490 m_verticalAttractionEfficiency = 1f;
441 m_verticalAttractionTimescale = 100f; 491 m_verticalAttractionTimescale = 100f;
442 // m_bankingEfficiency = 0; 492
443 // m_bankingMix = 0.7f; 493 m_bankingEfficiency = 0;
444 // m_bankingTimescale = 5; 494 m_bankingMix = 0.7f;
445 // m_referenceFrame = Quaternion.Identity; 495 m_bankingTimescale = 5;
496 m_referenceFrame = Quaternion.Identity;
497
498 m_referenceFrame = Quaternion.Identity;
446 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY 499 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY
447 | VehicleFlag.HOVER_TERRAIN_ONLY 500 | VehicleFlag.HOVER_TERRAIN_ONLY
448 | VehicleFlag.HOVER_UP_ONLY 501 | VehicleFlag.HOVER_UP_ONLY
@@ -452,21 +505,27 @@ namespace OpenSim.Region.Physics.BulletSPlugin
452 | VehicleFlag.HOVER_GLOBAL_HEIGHT); 505 | VehicleFlag.HOVER_GLOBAL_HEIGHT);
453 break; 506 break;
454 } 507 }
455 }//end SetDefaultsForType 508 }
456 509
457 // Some of the properties of this prim may have changed. 510 // Some of the properties of this prim may have changed.
458 // Do any updating needed for a vehicle 511 // Do any updating needed for a vehicle
459 public void Refresh() 512 public void Refresh()
460 { 513 {
461 if (!IsActive) 514 /*
462 return; 515 * Doesnt work unless BSDynamics senses and corrects for all collisions
463 516 if (IsActive)
464 // Set the prim's inertia to zero. The vehicle code handles that and this 517 BulletSimAPI.AddToCollisionFlags2(Prim.BSBody.ptr, CollisionFlags.CF_KINEMATIC_OBJECT);
465 // removes the motion and torque actions introduced by Bullet. 518 else
466 Vector3 inertia = Vector3.Zero; 519 BulletSimAPI.RemoveFromCollisionFlags2(Prim.BSBody.ptr, CollisionFlags.CF_KINEMATIC_OBJECT);
467 // comment out for DEBUG test 520 */
468 // BulletSimAPI.SetMassProps2(Prim.BSBody.ptr, Prim.MassRaw, inertia); 521 /*
469 // BulletSimAPI.UpdateInertiaTensor2(Prim.BSBody.ptr); 522 * Doesn't work because with zero inertia, Bullet will not apply any forces to the object.
523 if (IsActive)
524 {
525 BulletSimAPI.SetMassProps2(Prim.BSBody.ptr, Prim.MassRaw, Vector3.Zero);
526 BulletSimAPI.UpdateInertiaTensor2(Prim.BSBody.ptr);
527 }
528 */
470 } 529 }
471 530
472 // One step of the vehicle properties for the next 'pTimestep' seconds. 531 // One step of the vehicle properties for the next 'pTimestep' seconds.
@@ -478,6 +537,22 @@ namespace OpenSim.Region.Physics.BulletSPlugin
478 MoveAngular(pTimestep); 537 MoveAngular(pTimestep);
479 LimitRotation(pTimestep); 538 LimitRotation(pTimestep);
480 539
540 /* Experimental
541 // Wonder if Bullet could handle collision penetration while this applies the forces.
542 // Apply the computed forces on the vehicle
543 Prim.ForcePosition += Prim.ForceVelocity * Prim.MassRaw * pTimestep;
544
545 if (Prim.ForceRotationalVelocity != Vector3.Zero)
546 {
547 Quaternion newOrientation = Prim.ForceOrientation;
548 newOrientation.Normalize();
549 Quaternion appliedRotation = new Quaternion((Prim.ForceRotationalVelocity * pTimestep), 0f);
550 newOrientation += (appliedRotation * newOrientation) * 0.5f;
551 newOrientation.Normalize();
552 Prim.ForceOrientation = newOrientation;
553 }
554 */
555
481 // remember the position so next step we can limit absolute movement effects 556 // remember the position so next step we can limit absolute movement effects
482 m_lastPositionVector = Prim.ForcePosition; 557 m_lastPositionVector = Prim.ForcePosition;
483 558
@@ -489,59 +564,46 @@ namespace OpenSim.Region.Physics.BulletSPlugin
489 // Also does hover and float. 564 // Also does hover and float.
490 private void MoveLinear(float pTimestep) 565 private void MoveLinear(float pTimestep)
491 { 566 {
492 // m_linearMotorDirection is the direction we are moving relative to the vehicle coordinates 567 // m_linearMotorDirection is the target direction we are moving relative to the vehicle coordinates
493 // m_lastLinearVelocityVector is the speed we are moving in that direction 568 // m_lastLinearVelocityVector is the current speed we are moving in that direction
494 if (m_linearMotorDirection.LengthSquared() > 0.001f) 569 if (m_linearMotorDirection.LengthSquared() > 0.001f)
495 { 570 {
496 Vector3 origDir = m_linearMotorDirection; 571 Vector3 origDir = m_linearMotorDirection;
497 Vector3 origVel = m_lastLinearVelocityVector; 572 Vector3 origVel = m_lastLinearVelocityVector;
498 573
499 // add drive to body 574 // add drive to body
500 // Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale / pTimestep);
501 Vector3 addAmount = (m_linearMotorDirection - m_lastLinearVelocityVector)/(m_linearMotorTimescale / pTimestep); 575 Vector3 addAmount = (m_linearMotorDirection - m_lastLinearVelocityVector)/(m_linearMotorTimescale / pTimestep);
502 // lastLinearVelocityVector is the current body velocity vector 576 // lastLinearVelocityVector is the current body velocity vector
503 // RA: Not sure what the *10 is for. A correction for pTimestep?
504 // m_lastLinearVelocityVector += (addAmount*10);
505 m_lastLinearVelocityVector += addAmount; 577 m_lastLinearVelocityVector += addAmount;
506 578
507 // Limit the velocity vector to less than the last set linear motor direction
508 if (Math.Abs(m_lastLinearVelocityVector.X) > Math.Abs(m_linearMotorDirectionLASTSET.X))
509 m_lastLinearVelocityVector.X = m_linearMotorDirectionLASTSET.X;
510 if (Math.Abs(m_lastLinearVelocityVector.Y) > Math.Abs(m_linearMotorDirectionLASTSET.Y))
511 m_lastLinearVelocityVector.Y = m_linearMotorDirectionLASTSET.Y;
512 if (Math.Abs(m_lastLinearVelocityVector.Z) > Math.Abs(m_linearMotorDirectionLASTSET.Z))
513 m_lastLinearVelocityVector.Z = m_linearMotorDirectionLASTSET.Z;
514
515 /*
516 // decay applied velocity
517 Vector3 decayfraction = Vector3.One/(m_linearMotorDecayTimescale / pTimestep);
518 // (RA: do not know where the 0.5f comes from)
519 m_linearMotorDirection -= m_linearMotorDirection * decayfraction * 0.5f;
520 */
521 float keepfraction = 1.0f - (1.0f / (m_linearMotorDecayTimescale / pTimestep)); 579 float keepfraction = 1.0f - (1.0f / (m_linearMotorDecayTimescale / pTimestep));
522 m_linearMotorDirection *= keepfraction; 580 m_linearMotorDirection *= keepfraction;
523 581
524 VDetailLog("{0},MoveLinear,nonZero,origdir={1},origvel={2},add={3},notDecay={4},dir={5},vel={6}", 582 VDetailLog("{0},MoveLinear,nonZero,origdir={1},origvel={2},add={3},notDecay={4},dir={5},vel={6}",
525 Prim.LocalID, origDir, origVel, addAmount, keepfraction, m_linearMotorDirection, m_lastLinearVelocityVector); 583 Prim.LocalID, origDir, origVel, addAmount, keepfraction, m_linearMotorDirection, m_lastLinearVelocityVector);
584
585 // convert requested object velocity to object relative vector
586 m_newVelocity = m_lastLinearVelocityVector * Prim.ForceOrientation;
526 } 587 }
527 else 588 else
528 { 589 {
529 // if what remains of direction is very small, zero it. 590 // if what remains of direction is very small, zero it.
530 m_linearMotorDirection = Vector3.Zero; 591 m_linearMotorDirection = Vector3.Zero;
531 m_lastLinearVelocityVector = Vector3.Zero; 592 m_lastLinearVelocityVector = Vector3.Zero;
593 m_newVelocity = Vector3.Zero;
594
532 VDetailLog("{0},MoveLinear,zeroed", Prim.LocalID); 595 VDetailLog("{0},MoveLinear,zeroed", Prim.LocalID);
533 } 596 }
534 597
535 // convert requested object velocity to object relative vector 598 // m_newVelocity is velocity computed from linear motor
536 Quaternion rotq = Prim.ForceOrientation;
537 m_newVelocity = m_lastLinearVelocityVector * rotq;
538 599
539 // Add the various forces into m_dir which will be our new direction vector (velocity) 600 // Add the various forces into m_dir which will be our new direction vector (velocity)
540 601
541 // add Gravity and Buoyancy 602 // add Gravity and Buoyancy
542 // There is some gravity, make a gravity force vector that is applied after object velocity. 603 // There is some gravity, make a gravity force vector that is applied after object velocity.
543 // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g; 604 // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g;
544 Vector3 grav = Prim.PhysicsScene.DefaultGravity * (Prim.Linkset.LinksetMass * (1f - m_VehicleBuoyancy)); 605 // Vector3 grav = Prim.PhysicsScene.DefaultGravity * (Prim.Linkset.LinksetMass * (1f - m_VehicleBuoyancy));
606 Vector3 grav = Prim.PhysicsScene.DefaultGravity * (1f - m_VehicleBuoyancy);
545 607
546 /* 608 /*
547 * RA: Not sure why one would do this 609 * RA: Not sure why one would do this
@@ -567,6 +629,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
567 } 629 }
568 630
569 // Check if hovering 631 // Check if hovering
632 // m_VhoverEfficiency: 0=bouncy, 1=totally damped
633 // m_VhoverTimescale: time to achieve height
570 if ((m_flags & (VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT)) != 0) 634 if ((m_flags & (VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT)) != 0)
571 { 635 {
572 // We should hover, get the target height 636 // We should hover, get the target height
@@ -597,13 +661,19 @@ namespace OpenSim.Region.Physics.BulletSPlugin
597 } 661 }
598 else 662 else
599 { 663 {
600 float herr0 = pos.Z - m_VhoverTargetHeight; 664 float horizontalError = pos.Z - m_VhoverTargetHeight;
665 // RA: where does the 50 come from>
666 float horizontalCorrectionVelocity = ((horizontalError * 50.0f) / (m_VhoverTimescale / pTimestep));
601 // Replace Vertical speed with correction figure if significant 667 // Replace Vertical speed with correction figure if significant
602 if (Math.Abs(herr0) > 0.01f) 668 if (Math.Abs(horizontalError) > 0.01f)
603 { 669 {
604 m_newVelocity.Z = -((herr0 * pTimestep * 50.0f) / m_VhoverTimescale); 670 m_newVelocity.Z += horizontalCorrectionVelocity;
605 //KF: m_VhoverEfficiency is not yet implemented 671 //KF: m_VhoverEfficiency is not yet implemented
606 } 672 }
673 else if (horizontalError < -0.01)
674 {
675 m_newVelocity.Z -= horizontalCorrectionVelocity;
676 }
607 else 677 else
608 { 678 {
609 m_newVelocity.Z = 0f; 679 m_newVelocity.Z = 0f;
@@ -678,16 +748,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin
678 if ((m_flags & (VehicleFlag.NO_Z)) != 0) 748 if ((m_flags & (VehicleFlag.NO_Z)) != 0)
679 m_newVelocity.Z = 0; 749 m_newVelocity.Z = 0;
680 750
681 // Apply velocity
682 Prim.ForceVelocity = m_newVelocity;
683 // apply gravity force
684 // Why is this set here? The physics engine already does gravity.
685 Prim.AddForce(grav, false, true);
686
687 // Apply friction 751 // Apply friction
688 Vector3 keepFraction = Vector3.One - (Vector3.One / (m_linearFrictionTimescale / pTimestep)); 752 Vector3 keepFraction = Vector3.One - (Vector3.One / (m_linearFrictionTimescale / pTimestep));
689 m_lastLinearVelocityVector *= keepFraction; 753 m_lastLinearVelocityVector *= keepFraction;
690 754
755 // Apply velocity
756 // Prim.ForceVelocity = m_newVelocity;
757 Prim.AddForce(m_newVelocity, false);
758
691 VDetailLog("{0},MoveLinear,done,lmDir={1},lmVel={2},newVel={3},grav={4},1Mdecay={5}", 759 VDetailLog("{0},MoveLinear,done,lmDir={1},lmVel={2},newVel={3},grav={4},1Mdecay={5}",
692 Prim.LocalID, m_linearMotorDirection, m_lastLinearVelocityVector, m_newVelocity, grav, keepFraction); 760 Prim.LocalID, m_linearMotorDirection, m_lastLinearVelocityVector, m_newVelocity, grav, keepFraction);
693 761
@@ -717,11 +785,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
717 Vector3 origDir = m_angularMotorDirection; 785 Vector3 origDir = m_angularMotorDirection;
718 786
719 // ramp up to new value 787 // ramp up to new value
720 // new velocity += error / ( time to get there / step interval) 788 // new velocity += error / ( time to get there / step interval)
721 // requested speed - last motor speed 789 // requested speed - last motor speed
722 m_angularMotorVelocity.X += (m_angularMotorDirection.X - m_angularMotorVelocity.X) / (m_angularMotorTimescale / pTimestep); 790 m_angularMotorVelocity += (m_angularMotorDirection - m_angularMotorVelocity) / (m_angularMotorTimescale / pTimestep);
723 m_angularMotorVelocity.Y += (m_angularMotorDirection.Y - m_angularMotorVelocity.Y) / (m_angularMotorTimescale / pTimestep);
724 m_angularMotorVelocity.Z += (m_angularMotorDirection.Z - m_angularMotorVelocity.Z) / (m_angularMotorTimescale / pTimestep);
725 791
726 VDetailLog("{0},MoveAngular,angularMotorApply,apply={1},angTScale={2},timeStep={3},origvel={4},origDir={5},vel={6}", 792 VDetailLog("{0},MoveAngular,angularMotorApply,apply={1},angTScale={2},timeStep={3},origvel={4},origDir={5},vel={6}",
727 Prim.LocalID, m_angularMotorApply, m_angularMotorTimescale, pTimestep, origVel, origDir, m_angularMotorVelocity); 793 Prim.LocalID, m_angularMotorApply, m_angularMotorTimescale, pTimestep, origVel, origDir, m_angularMotorVelocity);
@@ -732,46 +798,50 @@ namespace OpenSim.Region.Physics.BulletSPlugin
732 { 798 {
733 // No motor recently applied, keep the body velocity 799 // No motor recently applied, keep the body velocity
734 // and decay the velocity 800 // and decay the velocity
735 m_angularMotorVelocity -= m_angularMotorVelocity / (m_angularMotorDecayTimescale / pTimestep); 801 if (m_angularMotorVelocity.LengthSquared() < 0.0001)
736 if (m_angularMotorVelocity.LengthSquared() < 0.00001)
737 m_angularMotorVelocity = Vector3.Zero; 802 m_angularMotorVelocity = Vector3.Zero;
803 else
804 m_angularMotorVelocity -= m_angularMotorVelocity / (m_angularMotorDecayTimescale / pTimestep);
738 } // end motor section 805 } // end motor section
739 806
740 // Vertical attractor section 807 #region Vertical attactor
808
741 Vector3 vertattr = Vector3.Zero; 809 Vector3 vertattr = Vector3.Zero;
742 Vector3 deflection = Vector3.Zero; 810 Vector3 deflection = Vector3.Zero;
743 Vector3 banking = Vector3.Zero; 811 Vector3 banking = Vector3.Zero;
744 812
745 if (m_verticalAttractionTimescale < 300 && m_lastAngularVelocity != Vector3.Zero) 813 if (m_verticalAttractionTimescale < 300 && m_lastAngularVelocity != Vector3.Zero)
746 { 814 {
747 float VAservo = 0.2f / (m_verticalAttractionTimescale / pTimestep); 815 float VAservo = 0.2f;
816 if (Prim.Linkset.LinksetIsColliding)
817 VAservo = 0.05f / (m_verticalAttractionTimescale / pTimestep);
818
748 VAservo *= (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency); 819 VAservo *= (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency);
749 820
750 // get present body rotation 821 // get present body rotation
751 Quaternion rotq = Prim.ForceOrientation; 822 Quaternion rotq = Prim.ForceOrientation;
752 // vector pointing up 823 // vector pointing up
753 Vector3 verterr = Vector3.Zero; 824 Vector3 verticalError = Vector3.UnitZ;
754 verterr.Z = 1.0f;
755 825
756 // rotate it to Body Angle 826 // rotate it to Body Angle
757 verterr = verterr * rotq; 827 verticalError = verticalError * rotq;
758 // verterr.X and .Y are the World error amounts. They are 0 when there is no error (Vehicle Body is 'vertical'), and .Z will be 1. 828 // verticalError.X and .Y are the World error amounts. They are 0 when there is no error (Vehicle Body is 'vertical'), and .Z will be 1.
759 // As the body leans to its side |.X| will increase to 1 and .Z fall to 0. As body inverts |.X| will fall and .Z will go 829 // As the body leans to its side |.X| will increase to 1 and .Z fall to 0. As body inverts |.X| will fall and .Z will go
760 // negative. Similar for tilt and |.Y|. .X and .Y must be modulated to prevent a stable inverted body. 830 // negative. Similar for tilt and |.Y|. .X and .Y must be modulated to prevent a stable inverted body.
761 831
762 // Error is 0 (no error) to +/- 2 (max error) 832 // Error is 0 (no error) to +/- 2 (max error)
763 if (verterr.Z < 0.0f) 833 if (verticalError.Z < 0.0f)
764 { 834 {
765 verterr.X = 2.0f - verterr.X; 835 verticalError.X = 2.0f - verticalError.X;
766 verterr.Y = 2.0f - verterr.Y; 836 verticalError.Y = 2.0f - verticalError.Y;
767 } 837 }
768 // scale it by VAservo 838 // scale it by VAservo
769 verterr = verterr * VAservo; 839 verticalError = verticalError * VAservo;
770 840
771 // As the body rotates around the X axis, then verterr.Y increases; Rotated around Y then .X increases, so 841 // As the body rotates around the X axis, then verticalError.Y increases; Rotated around Y then .X increases, so
772 // Change Body angular velocity X based on Y, and Y based on X. Z is not changed. 842 // Change Body angular velocity X based on Y, and Y based on X. Z is not changed.
773 vertattr.X = verterr.Y; 843 vertattr.X = verticalError.Y;
774 vertattr.Y = - verterr.X; 844 vertattr.Y = - verticalError.X;
775 vertattr.Z = 0f; 845 vertattr.Z = 0f;
776 846
777 // scaling appears better usingsquare-law 847 // scaling appears better usingsquare-law
@@ -779,10 +849,77 @@ namespace OpenSim.Region.Physics.BulletSPlugin
779 vertattr.X += bounce * angularVelocity.X; 849 vertattr.X += bounce * angularVelocity.X;
780 vertattr.Y += bounce * angularVelocity.Y; 850 vertattr.Y += bounce * angularVelocity.Y;
781 851
782 VDetailLog("{0},MoveAngular,verticalAttraction,verterr={1},bounce={2},vertattr={3}", 852 VDetailLog("{0},MoveAngular,verticalAttraction,verticalError={1},bounce={2},vertattr={3}",
783 Prim.LocalID, verterr, bounce, vertattr); 853 Prim.LocalID, verticalError, bounce, vertattr);
854
855 }
856 #endregion // Vertical attactor
857
858 #region Deflection
859
860 //Forward is the prefered direction, but if the reference frame has changed, we need to take this into account as well
861 Vector3 PreferredAxisOfMotion =
862 new Vector3((10*(m_angularDeflectionEfficiency/m_angularDeflectionTimescale)), 0, 0);
863 PreferredAxisOfMotion *= Quaternion.Add(Prim.ForceOrientation, m_referenceFrame);
864
865 //Multiply it so that it scales linearly
866 //deflection = PreferredAxisOfMotion;
867
868 //deflection = ((PreferredAxisOfMotion * m_angularDeflectionEfficiency) / (m_angularDeflectionTimescale / pTimestep));
869
870 #endregion
784 871
785 } // else vertical attractor is off 872 #region Banking
873
874 if (m_bankingEfficiency != 0)
875 {
876 Vector3 dir = Vector3.One * Prim.ForceOrientation;
877 float mult = (m_bankingMix*m_bankingMix)*-1*(m_bankingMix < 0 ? -1 : 1);
878 //Changes which way it banks in and out of turns
879
880 //Use the square of the efficiency, as it looks much more how SL banking works
881 float effSquared = (m_bankingEfficiency*m_bankingEfficiency);
882 if (m_bankingEfficiency < 0)
883 effSquared *= -1; //Keep the negative!
884
885 float mix = Math.Abs(m_bankingMix);
886 if (m_angularMotorVelocity.X == 0)
887 {
888 /*if (!parent.Orientation.ApproxEquals(this.m_referenceFrame, 0.25f))
889 {
890 Vector3 axisAngle;
891 float angle;
892 parent.Orientation.GetAxisAngle(out axisAngle, out angle);
893 Vector3 rotatedVel = parent.Velocity * parent.Orientation;
894 if ((rotatedVel.X < 0 && axisAngle.Y > 0) || (rotatedVel.X > 0 && axisAngle.Y < 0))
895 m_angularMotorVelocity.X += (effSquared * (mult * mix)) * (1f) * 10;
896 else
897 m_angularMotorVelocity.X += (effSquared * (mult * mix)) * (-1f) * 10;
898 }*/
899 }
900 else
901 banking.Z += (effSquared*(mult*mix))*(m_angularMotorVelocity.X) * 4;
902 if (!Prim.Linkset.LinksetIsColliding && Math.Abs(m_angularMotorVelocity.X) > mix)
903 //If they are colliding, we probably shouldn't shove the prim around... probably
904 {
905 float angVelZ = m_angularMotorVelocity.X*-1;
906 /*if(angVelZ > mix)
907 angVelZ = mix;
908 else if(angVelZ < -mix)
909 angVelZ = -mix;*/
910 //This controls how fast and how far the banking occurs
911 Vector3 bankingRot = new Vector3(angVelZ*(effSquared*mult), 0, 0);
912 if (bankingRot.X > 3)
913 bankingRot.X = 3;
914 else if (bankingRot.X < -3)
915 bankingRot.X = -3;
916 bankingRot *= Prim.ForceOrientation;
917 banking += bankingRot;
918 }
919 m_angularMotorVelocity.X *= m_bankingEfficiency == 1 ? 0.0f : 1 - m_bankingEfficiency;
920 }
921
922 #endregion
786 923
787 m_lastVertAttractor = vertattr; 924 m_lastVertAttractor = vertattr;
788 925
@@ -811,7 +948,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
811 m_lastAngularVelocity -= m_lastAngularVelocity * decayamount; 948 m_lastAngularVelocity -= m_lastAngularVelocity * decayamount;
812 949
813 // Apply to the body 950 // Apply to the body
814 Prim.ForceRotationalVelocity = m_lastAngularVelocity; 951 // Prim.ForceRotationalVelocity = m_lastAngularVelocity;
952 Prim.AddAngularForce(m_lastAngularVelocity, false);
815 953
816 VDetailLog("{0},MoveAngular,done,decay={1},lastAngular={2}", Prim.LocalID, decayamount, m_lastAngularVelocity); 954 VDetailLog("{0},MoveAngular,done,decay={1},lastAngular={2}", Prim.LocalID, decayamount, m_lastAngularVelocity);
817 } //end MoveAngular 955 } //end MoveAngular
@@ -820,38 +958,31 @@ namespace OpenSim.Region.Physics.BulletSPlugin
820 { 958 {
821 Quaternion rotq = Prim.ForceOrientation; 959 Quaternion rotq = Prim.ForceOrientation;
822 Quaternion m_rot = rotq; 960 Quaternion m_rot = rotq;
823 bool changed = false;
824 if (m_RollreferenceFrame != Quaternion.Identity) 961 if (m_RollreferenceFrame != Quaternion.Identity)
825 { 962 {
826 if (rotq.X >= m_RollreferenceFrame.X) 963 if (rotq.X >= m_RollreferenceFrame.X)
827 { 964 {
828 m_rot.X = rotq.X - (m_RollreferenceFrame.X / 2); 965 m_rot.X = rotq.X - (m_RollreferenceFrame.X / 2);
829 changed = true;
830 } 966 }
831 if (rotq.Y >= m_RollreferenceFrame.Y) 967 if (rotq.Y >= m_RollreferenceFrame.Y)
832 { 968 {
833 m_rot.Y = rotq.Y - (m_RollreferenceFrame.Y / 2); 969 m_rot.Y = rotq.Y - (m_RollreferenceFrame.Y / 2);
834 changed = true;
835 } 970 }
836 if (rotq.X <= -m_RollreferenceFrame.X) 971 if (rotq.X <= -m_RollreferenceFrame.X)
837 { 972 {
838 m_rot.X = rotq.X + (m_RollreferenceFrame.X / 2); 973 m_rot.X = rotq.X + (m_RollreferenceFrame.X / 2);
839 changed = true;
840 } 974 }
841 if (rotq.Y <= -m_RollreferenceFrame.Y) 975 if (rotq.Y <= -m_RollreferenceFrame.Y)
842 { 976 {
843 m_rot.Y = rotq.Y + (m_RollreferenceFrame.Y / 2); 977 m_rot.Y = rotq.Y + (m_RollreferenceFrame.Y / 2);
844 changed = true;
845 } 978 }
846 changed = true;
847 } 979 }
848 if ((m_flags & VehicleFlag.LOCK_ROTATION) != 0) 980 if ((m_flags & VehicleFlag.LOCK_ROTATION) != 0)
849 { 981 {
850 m_rot.X = 0; 982 m_rot.X = 0;
851 m_rot.Y = 0; 983 m_rot.Y = 0;
852 changed = true;
853 } 984 }
854 if (changed) 985 if (rotq != m_rot)
855 { 986 {
856 Prim.ForceOrientation = m_rot; 987 Prim.ForceOrientation = m_rot;
857 VDetailLog("{0},LimitRotation,done,orig={1},new={2}", Prim.LocalID, rotq, m_rot); 988 VDetailLog("{0},LimitRotation,done,orig={1},new={2}", Prim.LocalID, rotq, m_rot);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSHingeConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSHingeConstraint.cs
index 7c8a215..76bd930 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSHingeConstraint.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSHingeConstraint.cs
@@ -32,7 +32,7 @@ using OpenMetaverse;
32namespace OpenSim.Region.Physics.BulletSPlugin 32namespace OpenSim.Region.Physics.BulletSPlugin
33{ 33{
34 34
35class BSHingeConstraint : BSConstraint 35public sealed class BSHingeConstraint : BSConstraint
36{ 36{
37 public override ConstraintType Type { get { return ConstraintType.HINGE_CONSTRAINT_TYPE; } } 37 public override ConstraintType Type { get { return ConstraintType.HINGE_CONSTRAINT_TYPE; } }
38 38
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
index c984824..24fe6b9 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
@@ -88,6 +88,8 @@ public abstract class BSLinkset
88 } 88 }
89 } 89 }
90 90
91 public virtual bool LinksetIsColliding { get { return false; } }
92
91 public OMV.Vector3 CenterOfMass 93 public OMV.Vector3 CenterOfMass
92 { 94 {
93 get { return ComputeLinksetCenterOfMass(); } 95 get { return ComputeLinksetCenterOfMass(); }
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
index 8a750b5..003c294 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
@@ -32,7 +32,7 @@ using OMV = OpenMetaverse;
32 32
33namespace OpenSim.Region.Physics.BulletSPlugin 33namespace OpenSim.Region.Physics.BulletSPlugin
34{ 34{
35public class BSLinksetConstraints : BSLinkset 35public sealed class BSLinksetConstraints : BSLinkset
36{ 36{
37 // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]"; 37 // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]";
38 38
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 38ab3de..39d20dc 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -311,6 +311,7 @@ public sealed class BSPrim : BSPhysObject
311 if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) 311 if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0)
312 { 312 {
313 float waterHeight = PhysicsScene.GetWaterLevelAtXYZ(_position); 313 float waterHeight = PhysicsScene.GetWaterLevelAtXYZ(_position);
314 // TODO: a floating motor so object will bob in the water
314 if (Position.Z < waterHeight) 315 if (Position.Z < waterHeight)
315 { 316 {
316 _position.Z = waterHeight; 317 _position.Z = waterHeight;
@@ -902,7 +903,8 @@ public sealed class BSPrim : BSPhysObject
902 } 903 }
903 // DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, fSum); 904 // DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, fSum);
904 // For unknown reasons, "ApplyCentralForce" adds this force to the total force on the object. 905 // For unknown reasons, "ApplyCentralForce" adds this force to the total force on the object.
905 BulletSimAPI.ApplyCentralForce2(BSBody.ptr, fSum); 906 if (fSum != OMV.Vector3.Zero)
907 BulletSimAPI.ApplyCentralForce2(BSBody.ptr, fSum);
906 }; 908 };
907 if (inTaintTime) 909 if (inTaintTime)
908 addForceOperation(); 910 addForceOperation();
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index db0c99e..9e95ce5 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -62,7 +62,7 @@ using OpenMetaverse;
62// 62//
63namespace OpenSim.Region.Physics.BulletSPlugin 63namespace OpenSim.Region.Physics.BulletSPlugin
64{ 64{
65public class BSScene : PhysicsScene, IPhysicsParameters 65public sealed class BSScene : PhysicsScene, IPhysicsParameters
66{ 66{
67 private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 67 private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
68 private static readonly string LogHeader = "[BULLETS SCENE]"; 68 private static readonly string LogHeader = "[BULLETS SCENE]";
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index 30fa50a..1c0e6f5 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -34,7 +34,7 @@ using OpenSim.Region.Physics.ConvexDecompositionDotNet;
34 34
35namespace OpenSim.Region.Physics.BulletSPlugin 35namespace OpenSim.Region.Physics.BulletSPlugin
36{ 36{
37public class BSShapeCollection : IDisposable 37public sealed class BSShapeCollection : IDisposable
38{ 38{
39 private static string LogHeader = "[BULLETSIM SHAPE COLLECTION]"; 39 private static string LogHeader = "[BULLETSIM SHAPE COLLECTION]";
40 40
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
index 880859a..11298fe 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
@@ -40,7 +40,7 @@ using OpenMetaverse;
40 40
41namespace OpenSim.Region.Physics.BulletSPlugin 41namespace OpenSim.Region.Physics.BulletSPlugin
42{ 42{
43public class BSTerrainManager 43public sealed class BSTerrainManager
44{ 44{
45 static string LogHeader = "[BULLETSIM TERRAIN MANAGER]"; 45 static string LogHeader = "[BULLETSIM TERRAIN MANAGER]";
46 46