aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs195
1 files changed, 51 insertions, 144 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 85c2627..cf7aa0f 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -39,7 +39,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
39{ 39{
40 40
41 [Serializable] 41 [Serializable]
42public sealed class BSPrim : BSPhysObject 42public class BSPrim : BSPhysObject
43{ 43{
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 private static readonly string LogHeader = "[BULLETS PRIM]"; 45 private static readonly string LogHeader = "[BULLETS PRIM]";
@@ -102,9 +102,6 @@ public sealed class BSPrim : BSPhysObject
102 102
103 _mass = CalculateMass(); 103 _mass = CalculateMass();
104 104
105 // Cause linkset variables to be initialized (like mass)
106 Linkset.Refresh(this);
107
108 DetailLog("{0},BSPrim.constructor,call", LocalID); 105 DetailLog("{0},BSPrim.constructor,call", LocalID);
109 // do the actual object creation at taint time 106 // do the actual object creation at taint time
110 PhysicsScene.TaintedObject("BSPrim.create", delegate() 107 PhysicsScene.TaintedObject("BSPrim.create", delegate()
@@ -121,15 +118,6 @@ public sealed class BSPrim : BSPhysObject
121 // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); 118 // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID);
122 base.Destroy(); 119 base.Destroy();
123 120
124 // Undo any links between me and any other object
125 BSPhysObject parentBefore = Linkset.LinksetRoot; // DEBUG DEBUG
126 int childrenBefore = Linkset.NumberOfChildren; // DEBUG DEBUG
127
128 Linkset = Linkset.RemoveMeFromLinkset(this);
129
130 DetailLog("{0},BSPrim.Destroy,call,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}",
131 LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren);
132
133 // Undo any vehicle properties 121 // Undo any vehicle properties
134 this.VehicleType = (int)Vehicle.TYPE_NONE; 122 this.VehicleType = (int)Vehicle.TYPE_NONE;
135 123
@@ -166,9 +154,9 @@ public sealed class BSPrim : BSPhysObject
166 ForceBodyShapeRebuild(false); 154 ForceBodyShapeRebuild(false);
167 } 155 }
168 } 156 }
169 // Whatever the linkset wants is what I want. 157 // 'unknown' says to choose the best type
170 public override BSPhysicsShapeType PreferredPhysicalShape 158 public override BSPhysicsShapeType PreferredPhysicalShape
171 { get { return Linkset.PreferredPhysicalShape(this); } } 159 { get { return BSPhysicsShapeType.SHAPE_UNKNOWN; } }
172 160
173 public override bool ForceBodyShapeRebuild(bool inTaintTime) 161 public override bool ForceBodyShapeRebuild(bool inTaintTime)
174 { 162 {
@@ -213,33 +201,10 @@ public sealed class BSPrim : BSPhysObject
213 201
214 // link me to the specified parent 202 // link me to the specified parent
215 public override void link(PhysicsActor obj) { 203 public override void link(PhysicsActor obj) {
216 BSPrim parent = obj as BSPrim;
217 if (parent != null)
218 {
219 BSPhysObject parentBefore = Linkset.LinksetRoot;
220 int childrenBefore = Linkset.NumberOfChildren;
221
222 Linkset = parent.Linkset.AddMeToLinkset(this);
223
224 DetailLog("{0},BSPrim.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}",
225 LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren);
226 }
227 return;
228 } 204 }
229 205
230 // delink me from my linkset 206 // delink me from my linkset
231 public override void delink() { 207 public override void delink() {
232 // TODO: decide if this parent checking needs to happen at taint time
233 // Race condition here: if link() and delink() in same simulation tick, the delink will not happen
234
235 BSPhysObject parentBefore = Linkset.LinksetRoot;
236 int childrenBefore = Linkset.NumberOfChildren;
237
238 Linkset = Linkset.RemoveMeFromLinkset(this);
239
240 DetailLog("{0},BSPrim.delink,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}, ",
241 LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren);
242 return;
243 } 208 }
244 209
245 // Set motion values to zero. 210 // Set motion values to zero.
@@ -287,15 +252,8 @@ public sealed class BSPrim : BSPhysObject
287 } 252 }
288 public override OMV.Vector3 Position { 253 public override OMV.Vector3 Position {
289 get { 254 get {
290 /* NOTE: this refetch is not necessary. The simulator knows about linkset children
291 * and does not fetch this position info for children. Thus this is commented out.
292 // child prims move around based on their parent. Need to get the latest location
293 if (!Linkset.IsRoot(this))
294 _position = Linkset.PositionGet(this);
295 */
296
297 // don't do the GetObjectPosition for root elements because this function is called a zillion times. 255 // don't do the GetObjectPosition for root elements because this function is called a zillion times.
298 // _position = PhysicsScene.PE.GetObjectPosition2(PhysicsScene.World, BSBody) - PositionDisplacement; 256 // _position = ForcePosition;
299 return _position; 257 return _position;
300 } 258 }
301 set { 259 set {
@@ -313,24 +271,20 @@ public sealed class BSPrim : BSPhysObject
313 { 271 {
314 DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); 272 DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
315 ForcePosition = _position; 273 ForcePosition = _position;
316
317 // A linkset might need to know if a component information changed.
318 Linkset.UpdateProperties(UpdatedProperties.Position, this);
319
320 }); 274 });
321 } 275 }
322 } 276 }
323 277
324 public override OMV.Vector3 ForcePosition { 278 public override OMV.Vector3 ForcePosition {
325 get { 279 get {
326 _position = PhysicsScene.PE.GetPosition(PhysBody) - PositionDisplacement; 280 _position = PhysicsScene.PE.GetPosition(PhysBody);
327 return _position; 281 return _position;
328 } 282 }
329 set { 283 set {
330 _position = value; 284 _position = value;
331 if (PhysBody.HasPhysicalBody) 285 if (PhysBody.HasPhysicalBody)
332 { 286 {
333 PhysicsScene.PE.SetTranslation(PhysBody, _position + PositionDisplacement, _orientation); 287 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
334 ActivateIfPhysical(false); 288 ActivateIfPhysical(false);
335 } 289 }
336 } 290 }
@@ -398,12 +352,13 @@ public sealed class BSPrim : BSPhysObject
398 // If the simulator cares about the mass of the linkset, it will sum it itself. 352 // If the simulator cares about the mass of the linkset, it will sum it itself.
399 public override float Mass 353 public override float Mass
400 { 354 {
401 get 355 get { return _mass; }
402 { 356 }
403 return _mass; 357 // TotalMass returns the mass of the large object the prim may be in (overridden by linkset code)
404 } 358 public virtual float TotalMass
359 {
360 get { return _mass; }
405 } 361 }
406
407 // used when we only want this prim's mass and not the linkset thing 362 // used when we only want this prim's mass and not the linkset thing
408 public override float RawMass { 363 public override float RawMass {
409 get { return _mass; } 364 get { return _mass; }
@@ -467,13 +422,13 @@ public sealed class BSPrim : BSPhysObject
467 // Is this used? 422 // Is this used?
468 public override OMV.Vector3 CenterOfMass 423 public override OMV.Vector3 CenterOfMass
469 { 424 {
470 get { return Linkset.CenterOfMass; } 425 get { return RawPosition; }
471 } 426 }
472 427
473 // Is this used? 428 // Is this used?
474 public override OMV.Vector3 GeometricCenter 429 public override OMV.Vector3 GeometricCenter
475 { 430 {
476 get { return Linkset.GeometricCenter; } 431 get { return RawPosition; }
477 } 432 }
478 433
479 public override OMV.Vector3 Force { 434 public override OMV.Vector3 Force {
@@ -721,14 +676,6 @@ public sealed class BSPrim : BSPhysObject
721 } 676 }
722 public override OMV.Quaternion Orientation { 677 public override OMV.Quaternion Orientation {
723 get { 678 get {
724 /* NOTE: this refetch is not necessary. The simulator knows about linkset children
725 * and does not fetch this position info for children. Thus this is commented out.
726 // Children move around because tied to parent. Get a fresh value.
727 if (!Linkset.IsRoot(this))
728 {
729 _orientation = Linkset.OrientationGet(this);
730 }
731 */
732 return _orientation; 679 return _orientation;
733 } 680 }
734 set { 681 set {
@@ -739,10 +686,6 @@ public sealed class BSPrim : BSPhysObject
739 PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() 686 PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate()
740 { 687 {
741 ForceOrientation = _orientation; 688 ForceOrientation = _orientation;
742
743 // A linkset might need to know if a component information changed.
744 Linkset.UpdateProperties(UpdatedProperties.Orientation, this);
745
746 }); 689 });
747 } 690 }
748 } 691 }
@@ -758,7 +701,7 @@ public sealed class BSPrim : BSPhysObject
758 { 701 {
759 _orientation = value; 702 _orientation = value;
760 if (PhysBody.HasPhysicalBody) 703 if (PhysBody.HasPhysicalBody)
761 PhysicsScene.PE.SetTranslation(PhysBody, _position + PositionDisplacement, _orientation); 704 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
762 } 705 }
763 } 706 }
764 public override int PhysicsActorType { 707 public override int PhysicsActorType {
@@ -814,7 +757,7 @@ public sealed class BSPrim : BSPhysObject
814 // isSolid: other objects bounce off of this object 757 // isSolid: other objects bounce off of this object
815 // isVolumeDetect: other objects pass through but can generate collisions 758 // isVolumeDetect: other objects pass through but can generate collisions
816 // collisionEvents: whether this object returns collision events 759 // collisionEvents: whether this object returns collision events
817 public void UpdatePhysicalParameters() 760 public virtual void UpdatePhysicalParameters()
818 { 761 {
819 if (!PhysBody.HasPhysicalBody) 762 if (!PhysBody.HasPhysicalBody)
820 { 763 {
@@ -844,12 +787,6 @@ public sealed class BSPrim : BSPhysObject
844 // Rebuild its shape 787 // Rebuild its shape
845 PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody); 788 PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody);
846 789
847 // Recompute any linkset parameters.
848 // When going from non-physical to physical, this re-enables the constraints that
849 // had been automatically disabled when the mass was set to zero.
850 // For compound based linksets, this enables and disables interactions of the children.
851 Linkset.Refresh(this);
852
853 DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},cType={6},body={7},shape={8}", 790 DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},cType={6},body={7},shape={8}",
854 LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody.collisionType, PhysBody, PhysShape); 791 LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody.collisionType, PhysBody, PhysShape);
855 } 792 }
@@ -859,7 +796,7 @@ public sealed class BSPrim : BSPhysObject
859 // When dynamic, the object can fall and be pushed by others. 796 // When dynamic, the object can fall and be pushed by others.
860 // This is independent of its 'solidness' which controls what passes through 797 // This is independent of its 'solidness' which controls what passes through
861 // this object and what interacts with it. 798 // this object and what interacts with it.
862 private void MakeDynamic(bool makeStatic) 799 protected virtual void MakeDynamic(bool makeStatic)
863 { 800 {
864 if (makeStatic) 801 if (makeStatic)
865 { 802 {
@@ -889,9 +826,6 @@ public sealed class BSPrim : BSPhysObject
889 826
890 // This collides like a static object 827 // This collides like a static object
891 PhysBody.collisionType = CollisionType.Static; 828 PhysBody.collisionType = CollisionType.Static;
892
893 // There can be special things needed for implementing linksets
894 Linkset.MakeStatic(this);
895 } 829 }
896 else 830 else
897 { 831 {
@@ -908,10 +842,7 @@ public sealed class BSPrim : BSPhysObject
908 // PhysicsScene.PE.ClearAllForces(BSBody); 842 // PhysicsScene.PE.ClearAllForces(BSBody);
909 843
910 // For good measure, make sure the transform is set through to the motion state 844 // For good measure, make sure the transform is set through to the motion state
911 PhysicsScene.PE.SetTranslation(PhysBody, _position + PositionDisplacement, _orientation); 845 ForcePosition = _position;
912
913 // Center of mass is at the center of the object
914 // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(Linkset.LinksetRoot.PhysBody, _position, _orientation);
915 846
916 // A dynamic object has mass 847 // A dynamic object has mass
917 UpdatePhysicalMassProperties(RawMass, false); 848 UpdatePhysicalMassProperties(RawMass, false);
@@ -935,9 +866,6 @@ public sealed class BSPrim : BSPhysObject
935 // Force activation of the object so Bullet will act on it. 866 // Force activation of the object so Bullet will act on it.
936 // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects. 867 // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects.
937 PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG); 868 PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG);
938
939 // There might be special things needed for implementing linksets.
940 Linkset.MakeDynamic(this);
941 } 869 }
942 } 870 }
943 871
@@ -1643,16 +1571,6 @@ public sealed class BSPrim : BSPhysObject
1643 1571
1644 returnMass = Density * volume; 1572 returnMass = Density * volume;
1645 1573
1646 /* Comment out code that computes the mass of the linkset. That is done in the Linkset class.
1647 if (IsRootOfLinkset)
1648 {
1649 foreach (BSPrim prim in _childrenPrims)
1650 {
1651 returnMass += prim.CalculateMass();
1652 }
1653 }
1654 */
1655
1656 returnMass = Util.Clamp(returnMass, BSParam.MinimumObjectMass, BSParam.MaximumObjectMass); 1574 returnMass = Util.Clamp(returnMass, BSParam.MinimumObjectMass, BSParam.MaximumObjectMass);
1657 1575
1658 return returnMass; 1576 return returnMass;
@@ -1672,8 +1590,7 @@ public sealed class BSPrim : BSPhysObject
1672 // Called if the current prim body is about to be destroyed. 1590 // Called if the current prim body is about to be destroyed.
1673 // Remove all the physical dependencies on the old body. 1591 // Remove all the physical dependencies on the old body.
1674 // (Maybe someday make the changing of BSShape an event to be subscribed to by BSLinkset, ...) 1592 // (Maybe someday make the changing of BSShape an event to be subscribed to by BSLinkset, ...)
1675 Linkset.RemoveBodyDependencies(this); 1593 RemoveBodyDependencies();
1676 VehicleController.RemoveBodyDependencies(this);
1677 }); 1594 });
1678 1595
1679 // Make sure the properties are set on the new object 1596 // Make sure the properties are set on the new object
@@ -1681,57 +1598,50 @@ public sealed class BSPrim : BSPhysObject
1681 return; 1598 return;
1682 } 1599 }
1683 1600
1601 protected virtual void RemoveBodyDependencies()
1602 {
1603 VehicleController.RemoveBodyDependencies(this);
1604 }
1605
1684 // The physics engine says that properties have updated. Update same and inform 1606 // The physics engine says that properties have updated. Update same and inform
1685 // the world that things have changed. 1607 // the world that things have changed.
1686 public override void UpdateProperties(EntityProperties entprop) 1608 public override void UpdateProperties(EntityProperties entprop)
1687 { 1609 {
1688 // Updates only for individual prims and for the root object of a linkset. 1610 // A temporary kludge to suppress the rotational effects introduced on vehicles by Bullet
1689 if (Linkset.IsRoot(this)) 1611 // TODO: handle physics introduced by Bullet with computed vehicle physics.
1612 if (VehicleController.IsActive)
1690 { 1613 {
1691 // A temporary kludge to suppress the rotational effects introduced on vehicles by Bullet 1614 entprop.RotationalVelocity = OMV.Vector3.Zero;
1692 // TODO: handle physics introduced by Bullet with computed vehicle physics. 1615 }
1693 if (VehicleController.IsActive)
1694 {
1695 entprop.RotationalVelocity = OMV.Vector3.Zero;
1696 }
1697
1698 // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG
1699 1616
1700 // Undo any center-of-mass displacement that might have been done. 1617 // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG
1701 if (PositionDisplacement != OMV.Vector3.Zero)
1702 {
1703 // Correct for any rotation around the center-of-mass
1704 // TODO!!!
1705 entprop.Position -= PositionDisplacement;
1706 }
1707 1618
1708 // Assign directly to the local variables so the normal set actions do not happen 1619 // Assign directly to the local variables so the normal set actions do not happen
1709 _position = entprop.Position; 1620 _position = entprop.Position;
1710 _orientation = entprop.Rotation; 1621 _orientation = entprop.Rotation;
1711 _velocity = entprop.Velocity; 1622 _velocity = entprop.Velocity;
1712 _acceleration = entprop.Acceleration; 1623 _acceleration = entprop.Acceleration;
1713 _rotationalVelocity = entprop.RotationalVelocity; 1624 _rotationalVelocity = entprop.RotationalVelocity;
1714 1625
1715 // DetailLog("{0},BSPrim.UpdateProperties,afterAssign,entprop={1}", LocalID, entprop); // DEBUG DEBUG 1626 // DetailLog("{0},BSPrim.UpdateProperties,afterAssign,entprop={1}", LocalID, entprop); // DEBUG DEBUG
1716 1627
1717 // The sanity check can change the velocity and/or position. 1628 // The sanity check can change the velocity and/or position.
1718 if (PositionSanityCheck(true /* inTaintTime */ )) 1629 if (PositionSanityCheck(true /* inTaintTime */ ))
1719 { 1630 {
1720 entprop.Position = _position; 1631 entprop.Position = _position;
1721 entprop.Velocity = _velocity; 1632 entprop.Velocity = _velocity;
1722 entprop.RotationalVelocity = _rotationalVelocity; 1633 entprop.RotationalVelocity = _rotationalVelocity;
1723 entprop.Acceleration = _acceleration; 1634 entprop.Acceleration = _acceleration;
1724 } 1635 }
1725 1636
1726 OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG 1637 OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG
1727 DetailLog("{0},BSPrim.UpdateProperties,call,entProp={1},dir={2}", LocalID, entprop, direction); 1638 DetailLog("{0},BSPrim.UpdateProperties,call,entProp={1},dir={2}", LocalID, entprop, direction);
1728 1639
1729 // remember the current and last set values 1640 // remember the current and last set values
1730 LastEntityProperties = CurrentEntityProperties; 1641 LastEntityProperties = CurrentEntityProperties;
1731 CurrentEntityProperties = entprop; 1642 CurrentEntityProperties = entprop;
1732 1643
1733 base.RequestPhysicsterseUpdate(); 1644 base.RequestPhysicsterseUpdate();
1734 }
1735 /* 1645 /*
1736 else 1646 else
1737 { 1647 {
@@ -1741,9 +1651,6 @@ public sealed class BSPrim : BSPhysObject
1741 entprop.Acceleration, entprop.RotationalVelocity); 1651 entprop.Acceleration, entprop.RotationalVelocity);
1742 } 1652 }
1743 */ 1653 */
1744
1745 // The linkset implimentation might want to know about this.
1746 Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this);
1747 } 1654 }
1748} 1655}
1749} 1656}