aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs129
1 files changed, 24 insertions, 105 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 6a5461a..e56276a 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -72,7 +72,8 @@ public class BSPrim : BSPhysObject
72 72
73 private int CrossingFailures { get; set; } 73 private int CrossingFailures { get; set; }
74 74
75 public BSDynamics VehicleController { get; private set; } 75 public BSDynamics VehicleActor;
76 public string VehicleActorName = "BasicVehicle";
76 77
77 private BSVMotor _targetMotor; 78 private BSVMotor _targetMotor;
78 private OMV.Vector3 _PIDTarget; 79 private OMV.Vector3 _PIDTarget;
@@ -100,11 +101,12 @@ public class BSPrim : BSPhysObject
100 _isPhysical = pisPhysical; 101 _isPhysical = pisPhysical;
101 _isVolumeDetect = false; 102 _isVolumeDetect = false;
102 103
103 VehicleController = new BSDynamics(PhysicsScene, this); // add vehicleness 104 VehicleActor = new BSDynamics(PhysicsScene, this, VehicleActorName);
105 PhysicalActors.Add(VehicleActorName, VehicleActor);
104 106
105 _mass = CalculateMass(); 107 _mass = CalculateMass();
106 108
107 DetailLog("{0},BSPrim.constructor,call", LocalID); 109 // DetailLog("{0},BSPrim.constructor,call", LocalID);
108 // do the actual object creation at taint time 110 // do the actual object creation at taint time
109 PhysicsScene.TaintedObject("BSPrim.create", delegate() 111 PhysicsScene.TaintedObject("BSPrim.create", delegate()
110 { 112 {
@@ -126,7 +128,7 @@ public class BSPrim : BSPhysObject
126 // Undo any vehicle properties 128 // Undo any vehicle properties
127 this.VehicleType = (int)Vehicle.TYPE_NONE; 129 this.VehicleType = (int)Vehicle.TYPE_NONE;
128 130
129 PhysicsScene.TaintedObject("BSPrim.destroy", delegate() 131 PhysicsScene.TaintedObject("BSPrim.Destroy", delegate()
130 { 132 {
131 DetailLog("{0},BSPrim.Destroy,taint,", LocalID); 133 DetailLog("{0},BSPrim.Destroy,taint,", LocalID);
132 // If there are physical body and shape, release my use of same. 134 // If there are physical body and shape, release my use of same.
@@ -257,98 +259,32 @@ public class BSPrim : BSPhysObject
257 }); 259 });
258 } 260 }
259 261
260 bool TryExperimentalLockAxisCode = false;
261 BSConstraint LockAxisConstraint = null;
262 public override void LockAngularMotion(OMV.Vector3 axis) 262 public override void LockAngularMotion(OMV.Vector3 axis)
263 { 263 {
264 DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis); 264 DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis);
265 265
266 // "1" means free, "0" means locked 266 // "1" means free, "0" means locked
267 OMV.Vector3 locking = new OMV.Vector3(1f, 1f, 1f); 267 OMV.Vector3 locking = LockedAxisFree;
268 if (axis.X != 1) locking.X = 0f; 268 if (axis.X != 1) locking.X = 0f;
269 if (axis.Y != 1) locking.Y = 0f; 269 if (axis.Y != 1) locking.Y = 0f;
270 if (axis.Z != 1) locking.Z = 0f; 270 if (axis.Z != 1) locking.Z = 0f;
271 LockedAxis = locking; 271 LockedAxis = locking;
272 272
273 if (TryExperimentalLockAxisCode && LockedAxis != LockedAxisFree) 273 if (LockedAxis != LockedAxisFree)
274 { 274 {
275 // Lock that axis by creating a 6DOF constraint that has one end in the world and
276 // the other in the object.
277 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817
278 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380
279
280 PhysicsScene.TaintedObject("BSPrim.LockAngularMotion", delegate() 275 PhysicsScene.TaintedObject("BSPrim.LockAngularMotion", delegate()
281 { 276 {
282 CleanUpLockAxisPhysicals(true /* inTaintTime */); 277 // If there is not already an axis locker, make one
283 278 if (!PhysicalActors.HasActor(LockedAxisActorName))
284 BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, PhysBody,
285 OMV.Vector3.Zero, OMV.Quaternion.Inverse(RawOrientation),
286 true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */);
287 LockAxisConstraint = axisConstrainer;
288 PhysicsScene.Constraints.AddConstraint(LockAxisConstraint);
289
290 // The constraint is tied to the world and oriented to the prim.
291
292 // Free to move linearly
293 OMV.Vector3 linearLow = OMV.Vector3.Zero;
294 OMV.Vector3 linearHigh = PhysicsScene.TerrainManager.DefaultRegionSize;
295 axisConstrainer.SetLinearLimits(linearLow, linearHigh);
296
297 // Angular with some axis locked
298 float f2PI = (float)Math.PI * 2f;
299 OMV.Vector3 angularLow = new OMV.Vector3(-f2PI, -f2PI, -f2PI);
300 OMV.Vector3 angularHigh = new OMV.Vector3(f2PI, f2PI, f2PI);
301 if (LockedAxis.X != 1f)
302 {
303 angularLow.X = 0f;
304 angularHigh.X = 0f;
305 }
306 if (LockedAxis.Y != 1f)
307 {
308 angularLow.Y = 0f;
309 angularHigh.Y = 0f;
310 }
311 if (LockedAxis.Z != 1f)
312 { 279 {
313 angularLow.Z = 0f; 280 DetailLog("{0},BSPrim.LockAngularMotion,taint,registeringLockAxisActor", LocalID);
314 angularHigh.Z = 0f; 281 PhysicalActors.Add(LockedAxisActorName, new BSActorLockAxis(PhysicsScene, this, LockedAxisActorName));
315 } 282 }
316 axisConstrainer.SetAngularLimits(angularLow, angularHigh); 283 UpdatePhysicalParameters();
317
318 DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}",
319 LocalID, linearLow, linearHigh, angularLow, angularHigh);
320
321 // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo.
322 axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f);
323
324 axisConstrainer.RecomputeConstraintVariables(RawMass);
325 }); 284 });
326 } 285 }
327 else
328 {
329 // Everything seems unlocked
330 CleanUpLockAxisPhysicals(false /* inTaintTime */);
331 }
332
333 return; 286 return;
334 } 287 }
335 // Get rid of any constraint built for LockAxis
336 // Most often the constraint is removed when the constraint collection is cleaned for this prim.
337 private void CleanUpLockAxisPhysicals(bool inTaintTime)
338 {
339 if (LockAxisConstraint != null)
340 {
341 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.CleanUpLockAxisPhysicals", delegate()
342 {
343 if (LockAxisConstraint != null)
344 {
345 PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint);
346 LockAxisConstraint = null;
347 DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", LocalID);
348 }
349 });
350 }
351 }
352 288
353 public override OMV.Vector3 RawPosition 289 public override OMV.Vector3 RawPosition
354 { 290 {
@@ -604,7 +540,7 @@ public class BSPrim : BSPhysObject
604 540
605 public override int VehicleType { 541 public override int VehicleType {
606 get { 542 get {
607 return (int)VehicleController.Type; // if we are a vehicle, return that type 543 return (int)VehicleActor.Type; // if we are a vehicle, return that type
608 } 544 }
609 set { 545 set {
610 Vehicle type = (Vehicle)value; 546 Vehicle type = (Vehicle)value;
@@ -613,20 +549,8 @@ public class BSPrim : BSPhysObject
613 { 549 {
614 // Done at taint time so we're sure the physics engine is not using the variables 550 // Done at taint time so we're sure the physics engine is not using the variables
615 // Vehicle code changes the parameters for this vehicle type. 551 // Vehicle code changes the parameters for this vehicle type.
616 VehicleController.ProcessTypeChange(type); 552 VehicleActor.ProcessTypeChange(type);
617 ActivateIfPhysical(false); 553 ActivateIfPhysical(false);
618
619 // If an active vehicle, register the vehicle code to be called before each step
620 if (VehicleController.Type == Vehicle.TYPE_NONE)
621 {
622 UnRegisterPreStepAction("BSPrim.Vehicle", LocalID);
623 UnRegisterPostStepAction("BSPrim.Vehicle", LocalID);
624 }
625 else
626 {
627 RegisterPreStepAction("BSPrim.Vehicle", LocalID, VehicleController.Step);
628 RegisterPostStepAction("BSPrim.Vehicle", LocalID, VehicleController.PostStep);
629 }
630 }); 554 });
631 } 555 }
632 } 556 }
@@ -634,7 +558,7 @@ public class BSPrim : BSPhysObject
634 { 558 {
635 PhysicsScene.TaintedObject("BSPrim.VehicleFloatParam", delegate() 559 PhysicsScene.TaintedObject("BSPrim.VehicleFloatParam", delegate()
636 { 560 {
637 VehicleController.ProcessFloatVehicleParam((Vehicle)param, value); 561 VehicleActor.ProcessFloatVehicleParam((Vehicle)param, value);
638 ActivateIfPhysical(false); 562 ActivateIfPhysical(false);
639 }); 563 });
640 } 564 }
@@ -642,7 +566,7 @@ public class BSPrim : BSPhysObject
642 { 566 {
643 PhysicsScene.TaintedObject("BSPrim.VehicleVectorParam", delegate() 567 PhysicsScene.TaintedObject("BSPrim.VehicleVectorParam", delegate()
644 { 568 {
645 VehicleController.ProcessVectorVehicleParam((Vehicle)param, value); 569 VehicleActor.ProcessVectorVehicleParam((Vehicle)param, value);
646 ActivateIfPhysical(false); 570 ActivateIfPhysical(false);
647 }); 571 });
648 } 572 }
@@ -650,7 +574,7 @@ public class BSPrim : BSPhysObject
650 { 574 {
651 PhysicsScene.TaintedObject("BSPrim.VehicleRotationParam", delegate() 575 PhysicsScene.TaintedObject("BSPrim.VehicleRotationParam", delegate()
652 { 576 {
653 VehicleController.ProcessRotationVehicleParam((Vehicle)param, rotation); 577 VehicleActor.ProcessRotationVehicleParam((Vehicle)param, rotation);
654 ActivateIfPhysical(false); 578 ActivateIfPhysical(false);
655 }); 579 });
656 } 580 }
@@ -658,7 +582,7 @@ public class BSPrim : BSPhysObject
658 { 582 {
659 PhysicsScene.TaintedObject("BSPrim.VehicleFlags", delegate() 583 PhysicsScene.TaintedObject("BSPrim.VehicleFlags", delegate()
660 { 584 {
661 VehicleController.ProcessVehicleFlags(param, remove); 585 VehicleActor.ProcessVehicleFlags(param, remove);
662 }); 586 });
663 } 587 }
664 588
@@ -915,7 +839,8 @@ public class BSPrim : BSPhysObject
915 MakeDynamic(IsStatic); 839 MakeDynamic(IsStatic);
916 840
917 // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters) 841 // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters)
918 VehicleController.Refresh(); 842 VehicleActor.Refresh();
843 PhysicalActors.Refresh();
919 844
920 // Arrange for collision events if the simulator wants them 845 // Arrange for collision events if the simulator wants them
921 EnableCollisions(SubscribedEvents()); 846 EnableCollisions(SubscribedEvents());
@@ -1721,9 +1646,9 @@ public class BSPrim : BSPhysObject
1721 volume *= (profileEnd - profileBegin); 1646 volume *= (profileEnd - profileBegin);
1722 1647
1723 returnMass = Density * BSParam.DensityScaleFactor * volume; 1648 returnMass = Density * BSParam.DensityScaleFactor * volume;
1724 DetailLog("{0},BSPrim.CalculateMass,den={1},vol={2},mass={3}", LocalID, Density, volume, returnMass);
1725 1649
1726 returnMass = Util.Clamp(returnMass, BSParam.MinimumObjectMass, BSParam.MaximumObjectMass); 1650 returnMass = Util.Clamp(returnMass, BSParam.MinimumObjectMass, BSParam.MaximumObjectMass);
1651 // DetailLog("{0},BSPrim.CalculateMass,den={1},vol={2},mass={3}", LocalID, Density, volume, returnMass);
1727 1652
1728 return returnMass; 1653 return returnMass;
1729 }// end CalculateMass 1654 }// end CalculateMass
@@ -1752,7 +1677,8 @@ public class BSPrim : BSPhysObject
1752 1677
1753 protected virtual void RemoveBodyDependencies() 1678 protected virtual void RemoveBodyDependencies()
1754 { 1679 {
1755 VehicleController.RemoveBodyDependencies(this); 1680 VehicleActor.RemoveBodyDependencies();
1681 PhysicalActors.RemoveBodyDependencies();
1756 } 1682 }
1757 1683
1758 // The physics engine says that properties have updated. Update same and inform 1684 // The physics engine says that properties have updated. Update same and inform
@@ -1761,13 +1687,6 @@ public class BSPrim : BSPhysObject
1761 { 1687 {
1762 TriggerPreUpdatePropertyAction(ref entprop); 1688 TriggerPreUpdatePropertyAction(ref entprop);
1763 1689
1764 // A temporary kludge to suppress the rotational effects introduced on vehicles by Bullet
1765 // TODO: handle physics introduced by Bullet with computed vehicle physics.
1766 if (VehicleController.IsActive)
1767 {
1768 entprop.RotationalVelocity = OMV.Vector3.Zero;
1769 }
1770
1771 // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG 1690 // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG
1772 1691
1773 // Assign directly to the local variables so the normal set actions do not happen 1692 // Assign directly to the local variables so the normal set actions do not happen