aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs60
1 files changed, 45 insertions, 15 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
index a11bca0..35d5a08 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
@@ -59,6 +59,7 @@ public class BSPrimDisplaced : BSPrim
59 // are converted into simulator origin values before being passed to the base 59 // are converted into simulator origin values before being passed to the base
60 // class. 60 // class.
61 61
62 // PositionDisplacement is the vehicle relative distance from the root prim position to the center-of-mass.
62 public virtual OMV.Vector3 PositionDisplacement { get; set; } 63 public virtual OMV.Vector3 PositionDisplacement { get; set; }
63 64
64 public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, 65 public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size,
@@ -72,49 +73,77 @@ public class BSPrimDisplaced : BSPrim
72 // Does not clear the displacement set by the user. 73 // Does not clear the displacement set by the user.
73 public void ClearDisplacement() 74 public void ClearDisplacement()
74 { 75 {
75 SetEffectiveCenterOfMassDisplacement(OMV.Vector3.Zero); 76 if (UserSetCenterOfMassDisplacement.HasValue)
77 PositionDisplacement = (OMV.Vector3)UserSetCenterOfMassDisplacement;
78 else
79 PositionDisplacement = OMV.Vector3.Zero;
76 } 80 }
77 81
78 // Set this sets and computes the displacement from the passed prim to the center-of-mass. 82 // Set this sets and computes the displacement from the passed prim to the center-of-mass.
79 // A user set value for center-of-mass overrides whatever might be passed in here. 83 // A user set value for center-of-mass overrides whatever might be passed in here.
80 // The displacement is in local coordinates (relative to root prim in linkset oriented coordinates). 84 // The displacement is in local coordinates (relative to root prim in linkset oriented coordinates).
85 // Returns the relative offset from the root position to the center-of-mass.
81 // Called at taint time. 86 // Called at taint time.
82 public virtual void SetEffectiveCenterOfMassDisplacement(Vector3 centerOfMassDisplacement) 87 public virtual Vector3 SetEffectiveCenterOfMassDisplacement(Vector3 centerOfMassDisplacement)
83 { 88 {
89 PhysScene.AssertInTaintTime("BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement");
84 Vector3 comDisp; 90 Vector3 comDisp;
85 if (UserSetCenterOfMassDisplacement.HasValue) 91 if (UserSetCenterOfMassDisplacement.HasValue)
86 comDisp = (OMV.Vector3)UserSetCenterOfMassDisplacement; 92 comDisp = (OMV.Vector3)UserSetCenterOfMassDisplacement;
87 else 93 else
88 comDisp = centerOfMassDisplacement; 94 comDisp = centerOfMassDisplacement;
89 95
96 // Eliminate any jitter caused be very slight differences in masses and positions
90 if (comDisp.ApproxEquals(Vector3.Zero, 0.01f) ) 97 if (comDisp.ApproxEquals(Vector3.Zero, 0.01f) )
91 comDisp = Vector3.Zero; 98 comDisp = Vector3.Zero;
92 99
93 DetailLog("{0},BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement,userSet={1},comDisp={2}", 100 DetailLog("{0},BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement,userSet={1},comDisp={2}",
94 LocalID, UserSetCenterOfMassDisplacement.HasValue, comDisp); 101 LocalID, UserSetCenterOfMassDisplacement.HasValue, comDisp);
95 if ( comDisp != PositionDisplacement ) 102 if ( !comDisp.ApproxEquals(PositionDisplacement, 0.01f) )
96 { 103 {
97 // Displacement setting is changing. 104 // Displacement setting is changing.
98 // The relationship between the physical object and simulated object must be aligned. 105 // The relationship between the physical object and simulated object must be aligned.
99 PositionDisplacement = comDisp; 106 PositionDisplacement = comDisp;
100 this.ForcePosition = RawPosition; 107 this.ForcePosition = RawPosition;
101 } 108 }
109
110 return PositionDisplacement;
102 } 111 }
103 112
113 // 'ForcePosition' is the one way to set the physical position of the body in the physics engine.
114 // Displace the simulator idea of position (center of root prim) to the physical position.
104 public override Vector3 ForcePosition 115 public override Vector3 ForcePosition
105 { 116 {
106 get { return base.ForcePosition; } 117 get {
118 OMV.Vector3 physPosition = base.ForcePosition;
119 if (PositionDisplacement != OMV.Vector3.Zero)
120 {
121 // If there is some displacement, return the physical position (center-of-mass)
122 // location minus the displacement to give the center of the root prim.
123 OMV.Vector3 displacement = PositionDisplacement * ForceOrientation;
124 DetailLog("{0},BSPrimDisplaced.ForcePosition,get,physPos={1},disp={2},simPos={3}",
125 LocalID, physPosition, displacement, physPosition - displacement);
126 physPosition -= displacement;
127 }
128 return physPosition;
129 }
107 set 130 set
108 { 131 {
109 if (PositionDisplacement != OMV.Vector3.Zero) 132 if (PositionDisplacement != OMV.Vector3.Zero)
110 { 133 {
111 // The displacement is always relative to the vehicle so, when setting position, 134 // This value is the simulator's idea of where the prim is: the center of the root prim
112 // the caller means to set the position of the root prim. 135 RawPosition = value;
113 // This offsets the setting value to the center-of-mass and sends that to the 136
114 // physics engine. 137 // Move the passed root prim postion to the center-of-mass position and set in the physics engine.
115 OMV.Vector3 displacedPos = value - (PositionDisplacement * RawOrientation); 138 OMV.Vector3 displacement = PositionDisplacement * RawOrientation;
116 DetailLog("{0},BSPrimDisplaced.ForcePosition,val={1},disp={2},newPos={3}", LocalID, value, PositionDisplacement, displacedPos); 139 OMV.Vector3 displacedPos = RawPosition + displacement;
117 base.ForcePosition = displacedPos; 140 DetailLog("{0},BSPrimDisplaced.ForcePosition,set,simPos={1},disp={2},physPos={3}",
141 LocalID, RawPosition, displacement, displacedPos);
142 if (PhysBody.HasPhysicalBody)
143 {
144 PhysScene.PE.SetTranslation(PhysBody, displacedPos, RawOrientation);
145 ActivateIfPhysical(false);
146 }
118 } 147 }
119 else 148 else
120 { 149 {
@@ -143,10 +172,11 @@ public class BSPrimDisplaced : BSPrim
143 // These physical location must be back converted to be centered around the displaced 172 // These physical location must be back converted to be centered around the displaced
144 // root shape. 173 // root shape.
145 174
146 // The root position is the reported position displaced by the rotated displacement. 175 // Move the returned center-of-mass location to the root prim location.
147 OMV.Vector3 displacedPos = entprop.Position + (PositionDisplacement * entprop.Rotation); 176 OMV.Vector3 displacement = PositionDisplacement * entprop.Rotation;
148 DetailLog("{0},BSPrimDisplaced.UpdateProperties,physPos={1},disp={2},newPos={3}", 177 OMV.Vector3 displacedPos = entprop.Position - displacement;
149 LocalID, entprop.Position, PositionDisplacement, displacedPos); 178 DetailLog("{0},BSPrimDisplaced.UpdateProperties,physPos={1},disp={2},simPos={3}",
179 LocalID, entprop.Position, displacement, displacedPos);
150 entprop.Position = displacedPos; 180 entprop.Position = displacedPos;
151 } 181 }
152 182