aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin
diff options
context:
space:
mode:
authorRobert Adams2013-01-11 16:36:34 -0800
committerRobert Adams2013-01-11 16:47:53 -0800
commit459fcd81c9d6e7c92738b40f1b4b4fe746699379 (patch)
tree6555a0076aa18c3634ad89ef8c3d097d67edb08b /OpenSim/Region/Physics/BulletSPlugin
parentBulletSim: add osGetPhysicsEngineType() LSL function and update (diff)
downloadopensim-SC_OLD-459fcd81c9d6e7c92738b40f1b4b4fe746699379.zip
opensim-SC_OLD-459fcd81c9d6e7c92738b40f1b4b4fe746699379.tar.gz
opensim-SC_OLD-459fcd81c9d6e7c92738b40f1b4b4fe746699379.tar.bz2
opensim-SC_OLD-459fcd81c9d6e7c92738b40f1b4b4fe746699379.tar.xz
BulletSim: move center of gravity of linkset to its geometric center.
Necessitated allowing simulator and physical position of a body to get out of sync since Bullet assumes that <0,0,0> is the center of mass. Update DLLs and SOs for the UpdateChildTransform so positions of individual prim in a linkset can be implemented.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs9
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs1
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs2
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs13
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs4
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs55
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs10
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs40
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs2
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt2
10 files changed, 106 insertions, 32 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
index 14de2eb..0fef67c 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -327,6 +327,12 @@ public override void RemoveChildShapeFromCompoundShape(BulletShape shape, Bullet
327 BSAPICPP.RemoveChildShapeFromCompoundShape2(shapeu.ptr, removeShapeu.ptr); 327 BSAPICPP.RemoveChildShapeFromCompoundShape2(shapeu.ptr, removeShapeu.ptr);
328} 328}
329 329
330public override void UpdateChildTransform(BulletShape pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb)
331{
332 BulletShapeUnman shapeu = pShape as BulletShapeUnman;
333 BSAPICPP.UpdateChildTransform2(shapeu.ptr, childIndex, pos, rot, shouldRecalculateLocalAabb);
334}
335
330public override void RecalculateCompoundShapeLocalAabb(BulletShape shape) 336public override void RecalculateCompoundShapeLocalAabb(BulletShape shape)
331{ 337{
332 BulletShapeUnman shapeu = shape as BulletShapeUnman; 338 BulletShapeUnman shapeu = shape as BulletShapeUnman;
@@ -1357,6 +1363,9 @@ public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShap
1357public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape); 1363public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape);
1358 1364
1359[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 1365[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1366public static extern void UpdateChildTransform2(IntPtr pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb);
1367
1368[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1360public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape); 1369public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape);
1361 1370
1362[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 1371[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
index 0c7f315..b6ff52b 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
@@ -1212,6 +1212,7 @@ private sealed class BulletConstraintXNA : BulletConstraint
1212 1212
1213 public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) { /* TODO */ return null; } 1213 public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) { /* TODO */ return null; }
1214 public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape) { /* TODO */ } 1214 public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape) { /* TODO */ }
1215 public override void UpdateChildTransform(BulletShape pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb) { /* TODO */ }
1215 1216
1216 public override BulletShape CreateGroundPlaneShape(uint pLocalId, float pheight, float pcollisionMargin) 1217 public override BulletShape CreateGroundPlaneShape(uint pLocalId, float pheight, float pcollisionMargin)
1217 { 1218 {
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
index 794ee17..bc163eb 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
@@ -342,6 +342,8 @@ public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape c
342 342
343public abstract void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape); 343public abstract void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape);
344 344
345public abstract void UpdateChildTransform(BulletShape pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb);
346
345public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape); 347public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape);
346 348
347public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id); 349public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 80fdfb9..bcebaec 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -148,7 +148,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
148 enableAngularVerticalAttraction = false; 148 enableAngularVerticalAttraction = false;
149 enableAngularDeflection = false; 149 enableAngularDeflection = false;
150 enableAngularBanking = false; 150 enableAngularBanking = false;
151 VDetailLog("{0},BSDynamics.SetupVehicleDebugging,settingDebugMode", Prim.LocalID);
152 } 151 }
153 } 152 }
154 153
@@ -690,10 +689,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
690 } 689 }
691 690
692 if ((m_knownChanged & m_knownChangedForce) != 0) 691 if ((m_knownChanged & m_knownChangedForce) != 0)
693 Prim.AddForce((Vector3)m_knownForce, false, true); 692 Prim.AddForce((Vector3)m_knownForce, false /*pushForce*/, true /*inTaintTime*/);
694 693
695 if ((m_knownChanged & m_knownChangedForceImpulse) != 0) 694 if ((m_knownChanged & m_knownChangedForceImpulse) != 0)
696 Prim.AddForceImpulse((Vector3)m_knownForceImpulse, false, true); 695 Prim.AddForceImpulse((Vector3)m_knownForceImpulse, false /*pushforce*/, true /*inTaintTime*/);
697 696
698 if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) 697 if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0)
699 { 698 {
@@ -703,7 +702,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
703 702
704 if ((m_knownChanged & m_knownChangedRotationalForce) != 0) 703 if ((m_knownChanged & m_knownChangedRotationalForce) != 0)
705 { 704 {
706 Prim.AddAngularForce((Vector3)m_knownRotationalForce, false, true); 705 Prim.AddAngularForce((Vector3)m_knownRotationalForce, false /*pushForce*/, true /*inTaintTime*/);
707 } 706 }
708 707
709 // If we set one of the values (ie, the physics engine didn't do it) we must force 708 // If we set one of the values (ie, the physics engine didn't do it) we must force
@@ -970,7 +969,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
970 // Act against the inertia of the vehicle 969 // Act against the inertia of the vehicle
971 linearMotorForce *= m_vehicleMass; 970 linearMotorForce *= m_vehicleMass;
972 971
973 VehicleAddForceImpulse(linearMotorForce); 972 VehicleAddForceImpulse(linearMotorForce * pTimestep);
974 973
975 VDetailLog("{0}, MoveLinear,velocity,vehVel={1},step={2},stepVel={3},mix={4},force={5}", 974 VDetailLog("{0}, MoveLinear,velocity,vehVel={1},step={2},stepVel={3},mix={4},force={5}",
976 Prim.LocalID, VehicleVelocity, linearMotorStep, linearMotorVelocity, mixFactor, linearMotorForce); 975 Prim.LocalID, VehicleVelocity, linearMotorStep, linearMotorVelocity, mixFactor, linearMotorForce);
@@ -1033,7 +1032,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1033 { 1032 {
1034 // Error is positive if below the target and negative if above. 1033 // Error is positive if below the target and negative if above.
1035 float verticalError = m_VhoverTargetHeight - VehiclePosition.Z; 1034 float verticalError = m_VhoverTargetHeight - VehiclePosition.Z;
1036 float verticalCorrectionVelocity = verticalError / m_VhoverTimescale; 1035 float verticalCorrectionVelocity = verticalError / m_VhoverTimescale * pTimestep;
1037 1036
1038 // TODO: implement m_VhoverEfficiency correctly 1037 // TODO: implement m_VhoverEfficiency correctly
1039 VehicleAddForceImpulse(new Vector3(0f, 0f, verticalCorrectionVelocity)); 1038 VehicleAddForceImpulse(new Vector3(0f, 0f, verticalCorrectionVelocity));
@@ -1323,7 +1322,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1323 // this creates an over-correction and then wabbling as the target is overshot. 1322 // this creates an over-correction and then wabbling as the target is overshot.
1324 // TODO: rethink how the different correction computations inter-relate. 1323 // TODO: rethink how the different correction computations inter-relate.
1325 1324
1326 if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleVelocity != Vector3.Zero) 1325 if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleForwardSpeed > 0.2)
1327 { 1326 {
1328 // The direction the vehicle is moving 1327 // The direction the vehicle is moving
1329 Vector3 movingDirection = VehicleVelocity; 1328 Vector3 movingDirection = VehicleVelocity;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
index 756faed..cbd160f 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
@@ -152,6 +152,7 @@ public abstract class BSLinkset
152 if (IsRoot(child)) 152 if (IsRoot(child))
153 { 153 {
154 // Cannot remove the root from a linkset. 154 // Cannot remove the root from a linkset.
155 child.PositionDisplacement = OMV.Vector3.Zero;
155 return this; 156 return this;
156 } 157 }
157 RemoveChildFromLinkset(child); 158 RemoveChildFromLinkset(child);
@@ -159,6 +160,7 @@ public abstract class BSLinkset
159 } 160 }
160 161
161 // The child is down to a linkset of just itself 162 // The child is down to a linkset of just itself
163 child.PositionDisplacement = OMV.Vector3.Zero;
162 return BSLinkset.Factory(PhysicsScene, child); 164 return BSLinkset.Factory(PhysicsScene, child);
163 } 165 }
164 166
@@ -310,7 +312,7 @@ public abstract class BSLinkset
310 312
311 foreach (BSPhysObject bp in m_children) 313 foreach (BSPhysObject bp in m_children)
312 { 314 {
313 com += bp.Position * bp.RawMass; 315 com += bp.Position;
314 } 316 }
315 com /= (m_children.Count + 1); 317 com /= (m_children.Count + 1);
316 } 318 }
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index bd03d31..ad8024c 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -40,23 +40,33 @@ namespace OpenSim.Region.Physics.BulletSPlugin
40// removed from the linkset. 40// removed from the linkset.
41sealed class BSLinksetCompoundInfo : BSLinksetInfo 41sealed class BSLinksetCompoundInfo : BSLinksetInfo
42{ 42{
43 public OMV.Vector3 OffsetPos; 43 public int Index;
44 public OMV.Vector3 OffsetFromRoot;
45 public OMV.Vector3 OffsetFromCenterOfMass;
44 public OMV.Quaternion OffsetRot; 46 public OMV.Quaternion OffsetRot;
45 public BSLinksetCompoundInfo(OMV.Vector3 p, OMV.Quaternion r) 47 public BSLinksetCompoundInfo(int indx, OMV.Vector3 p, OMV.Quaternion r)
46 { 48 {
47 OffsetPos = p; 49 Index = indx;
50 OffsetFromRoot = p;
51 OffsetFromCenterOfMass = p;
48 OffsetRot = r; 52 OffsetRot = r;
49 } 53 }
50 public override void Clear() 54 public override void Clear()
51 { 55 {
52 OffsetPos = OMV.Vector3.Zero; 56 Index = 0;
57 OffsetFromRoot = OMV.Vector3.Zero;
58 OffsetFromCenterOfMass = OMV.Vector3.Zero;
53 OffsetRot = OMV.Quaternion.Identity; 59 OffsetRot = OMV.Quaternion.Identity;
54 } 60 }
55 public override string ToString() 61 public override string ToString()
56 { 62 {
57 StringBuilder buff = new StringBuilder(); 63 StringBuilder buff = new StringBuilder();
58 buff.Append("<p="); 64 buff.Append("<i=");
59 buff.Append(OffsetPos.ToString()); 65 buff.Append(Index.ToString());
66 buff.Append(",p=");
67 buff.Append(OffsetFromRoot.ToString());
68 buff.Append(",m=");
69 buff.Append(OffsetFromCenterOfMass.ToString());
60 buff.Append(",r="); 70 buff.Append(",r=");
61 buff.Append(OffsetRot.ToString()); 71 buff.Append(OffsetRot.ToString());
62 buff.Append(">"); 72 buff.Append(">");
@@ -170,6 +180,8 @@ public sealed class BSLinksetCompound : BSLinkset
170 return ret; 180 return ret;
171 } 181 }
172 182
183 // 'physicalUpdate' is true if these changes came directly from the physics engine. Don't need to rebuild then.
184 // Called at taint-time.
173 public override void UpdateProperties(BSPhysObject updated, bool physicalUpdate) 185 public override void UpdateProperties(BSPhysObject updated, bool physicalUpdate)
174 { 186 {
175 // The user moving a child around requires the rebuilding of the linkset compound shape 187 // The user moving a child around requires the rebuilding of the linkset compound shape
@@ -182,6 +194,7 @@ public sealed class BSLinksetCompound : BSLinkset
182 && !physicalUpdate 194 && !physicalUpdate
183 && PhysicsScene.TerrainManager.IsWithinKnownTerrain(LinksetRoot.RawPosition)) 195 && PhysicsScene.TerrainManager.IsWithinKnownTerrain(LinksetRoot.RawPosition))
184 { 196 {
197 // TODO: replace this with are calculation of the child prim's orientation and pos.
185 updated.LinksetInfo = null; 198 updated.LinksetInfo = null;
186 ScheduleRebuild(updated); 199 ScheduleRebuild(updated);
187 } 200 }
@@ -230,7 +243,7 @@ public sealed class BSLinksetCompound : BSLinkset
230 if (inTaintTime) 243 if (inTaintTime)
231 { 244 {
232 OMV.Vector3 oldPos = child.RawPosition; 245 OMV.Vector3 oldPos = child.RawPosition;
233 child.ForcePosition = LinksetRoot.RawPosition + lci.OffsetPos; 246 child.ForcePosition = LinksetRoot.RawPosition + lci.OffsetFromRoot;
234 child.ForceOrientation = LinksetRoot.RawOrientation * lci.OffsetRot; 247 child.ForceOrientation = LinksetRoot.RawOrientation * lci.OffsetRot;
235 DetailLog("{0},BSLinksetCompound.RecomputeChildWorldPosition,oldPos={1},lci={2},newPos={3}", 248 DetailLog("{0},BSLinksetCompound.RecomputeChildWorldPosition,oldPos={1},lci={2},newPos={3}",
236 child.LocalID, oldPos, lci, child.RawPosition); 249 child.LocalID, oldPos, lci, child.RawPosition);
@@ -238,7 +251,7 @@ public sealed class BSLinksetCompound : BSLinkset
238 else 251 else
239 { 252 {
240 // TaintedObject is not used here so the raw position is set now and not at taint-time. 253 // TaintedObject is not used here so the raw position is set now and not at taint-time.
241 child.Position = LinksetRoot.RawPosition + lci.OffsetPos; 254 child.Position = LinksetRoot.RawPosition + lci.OffsetFromRoot;
242 child.Orientation = LinksetRoot.RawOrientation * lci.OffsetRot; 255 child.Orientation = LinksetRoot.RawOrientation * lci.OffsetRot;
243 } 256 }
244 } 257 }
@@ -316,10 +329,23 @@ public sealed class BSLinksetCompound : BSLinkset
316 // Cause the root shape to be rebuilt as a compound object with just the root in it 329 // Cause the root shape to be rebuilt as a compound object with just the root in it
317 LinksetRoot.ForceBodyShapeRebuild(true); 330 LinksetRoot.ForceBodyShapeRebuild(true);
318 331
332 // The center of mass for the linkset is the geometric center of the group.
333 // Compute a displacement for each component so it is relative to the center-of-mass.
334 OMV.Vector3 centerOfMass = ComputeLinksetGeometricCenter();
335 OMV.Vector3 centerDisplacement = centerOfMass - LinksetRoot.RawPosition;
336
337 // Since we're displacing the center of the shape, we need to move the body in the world
338 LinksetRoot.PositionDisplacement = centerDisplacement * LinksetRoot.RawOrientation;
339
340 PhysicsScene.PE.UpdateChildTransform(LinksetRoot.PhysShape, 0, -centerDisplacement, OMV.Quaternion.Identity, false);
341 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,COM,com={1},rootPos={2},centerDisp={3}",
342 LinksetRoot.LocalID, centerOfMass, LinksetRoot.RawPosition, centerDisplacement);
343
319 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}", 344 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}",
320 LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren); 345 LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren);
321 346
322 // Add a shape for each of the other children in the linkset 347 // Add a shape for each of the other children in the linkset
348 int memberIndex = 1;
323 ForEachMember(delegate(BSPhysObject cPrim) 349 ForEachMember(delegate(BSPhysObject cPrim)
324 { 350 {
325 if (!IsRoot(cPrim)) 351 if (!IsRoot(cPrim))
@@ -337,13 +363,14 @@ public sealed class BSLinksetCompound : BSLinkset
337 OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation; 363 OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation;
338 364
339 // Save relative position for recomputing child's world position after moving linkset. 365 // Save relative position for recomputing child's world position after moving linkset.
340 lci = new BSLinksetCompoundInfo(displacementPos, displacementRot); 366 lci = new BSLinksetCompoundInfo(memberIndex, displacementPos, displacementRot);
367 lci.OffsetFromCenterOfMass = displacementPos - centerDisplacement;
341 cPrim.LinksetInfo = lci; 368 cPrim.LinksetInfo = lci;
342 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,creatingRelPos,lci={1}", cPrim.LocalID, lci); 369 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,creatingRelPos,lci={1}", cPrim.LocalID, lci);
343 } 370 }
344 371
345 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addMemberToShape,mID={1},mShape={2},dispPos={3},dispRot={4}", 372 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addMemberToShape,mID={1},mShape={2},lci={3}",
346 LinksetRoot.LocalID, cPrim.LocalID, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot); 373 LinksetRoot.LocalID, cPrim.LocalID, cPrim.PhysShape, lci);
347 374
348 if (cPrim.PhysShape.isNativeShape) 375 if (cPrim.PhysShape.isNativeShape)
349 { 376 {
@@ -359,7 +386,7 @@ public sealed class BSLinksetCompound : BSLinkset
359 PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); 386 PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null);
360 BulletShape newShape = cPrim.PhysShape; 387 BulletShape newShape = cPrim.PhysShape;
361 cPrim.PhysShape = saveShape; 388 cPrim.PhysShape = saveShape;
362 PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, newShape, lci.OffsetPos, lci.OffsetRot); 389 PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, newShape, lci.OffsetFromCenterOfMass, lci.OffsetRot);
363 } 390 }
364 else 391 else
365 { 392 {
@@ -371,8 +398,10 @@ public sealed class BSLinksetCompound : BSLinkset
371 PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", 398 PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}",
372 LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); 399 LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape);
373 } 400 }
374 PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot); 401 PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, lci.OffsetFromCenterOfMass, lci.OffsetRot);
375 } 402 }
403 lci.Index = memberIndex;
404 memberIndex++;
376 } 405 }
377 return false; // 'false' says to move onto the next child in the list 406 return false; // 'false' says to move onto the next child in the list
378 }); 407 });
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index 2c84293..185f111 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -73,6 +73,8 @@ public abstract class BSPhysObject : PhysicsActor
73 73
74 // A linkset of just me 74 // A linkset of just me
75 Linkset = BSLinkset.Factory(PhysicsScene, this); 75 Linkset = BSLinkset.Factory(PhysicsScene, this);
76 PositionDisplacement = OMV.Vector3.Zero;
77
76 LastAssetBuildFailed = false; 78 LastAssetBuildFailed = false;
77 79
78 // Default material type 80 // Default material type
@@ -157,6 +159,14 @@ public abstract class BSPhysObject : PhysicsActor
157 public abstract OMV.Vector3 RawPosition { get; set; } 159 public abstract OMV.Vector3 RawPosition { get; set; }
158 public abstract OMV.Vector3 ForcePosition { get; set; } 160 public abstract OMV.Vector3 ForcePosition { get; set; }
159 161
162 // Position is what the simulator thinks the positions of the prim is.
163 // Because Bullet needs the zero coordinate to be the center of mass of the linkset,
164 // sometimes it is necessary to displace the position the physics engine thinks
165 // the position is. PositionDisplacement must be added and removed from the
166 // position as the simulator position is stored and fetched from the physics
167 // engine.
168 public virtual OMV.Vector3 PositionDisplacement { get; set; }
169
160 public abstract OMV.Quaternion RawOrientation { get; set; } 170 public abstract OMV.Quaternion RawOrientation { get; set; }
161 public abstract OMV.Quaternion ForceOrientation { get; set; } 171 public abstract OMV.Quaternion ForceOrientation { get; set; }
162 172
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 02d06b4..003dc54 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -50,7 +50,10 @@ public sealed class BSPrim : BSPhysObject
50 private bool _grabbed; 50 private bool _grabbed;
51 private bool _isSelected; 51 private bool _isSelected;
52 private bool _isVolumeDetect; 52 private bool _isVolumeDetect;
53
54 // _position is what the simulator thinks the positions of the prim is.
53 private OMV.Vector3 _position; 55 private OMV.Vector3 _position;
56
54 private float _mass; // the mass of this object 57 private float _mass; // the mass of this object
55 private float _density; 58 private float _density;
56 private OMV.Vector3 _force; 59 private OMV.Vector3 _force;
@@ -320,18 +323,37 @@ public sealed class BSPrim : BSPhysObject
320 } 323 }
321 public override OMV.Vector3 ForcePosition { 324 public override OMV.Vector3 ForcePosition {
322 get { 325 get {
323 _position = PhysicsScene.PE.GetPosition(PhysBody); 326 _position = PhysicsScene.PE.GetPosition(PhysBody) - PositionDisplacement;
324 return _position; 327 return _position;
325 } 328 }
326 set { 329 set {
327 _position = value; 330 _position = value;
328 if (PhysBody.HasPhysicalBody) 331 if (PhysBody.HasPhysicalBody)
329 { 332 {
330 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); 333 PhysicsScene.PE.SetTranslation(PhysBody, _position + PositionDisplacement, _orientation);
331 ActivateIfPhysical(false); 334 ActivateIfPhysical(false);
332 } 335 }
333 } 336 }
334 } 337 }
338 // Override to have position displacement immediately update the physical position.
339 // A feeble attempt to keep the sim and physical positions in sync
340 // Must be called at taint time.
341 public override OMV.Vector3 PositionDisplacement
342 {
343 get
344 {
345 return base.PositionDisplacement;
346 }
347 set
348 {
349 base.PositionDisplacement = value;
350 PhysicsScene.TaintedObject(PhysicsScene.InTaintTime, "BSPrim.setPosition", delegate()
351 {
352 if (PhysBody.HasPhysicalBody)
353 PhysicsScene.PE.SetTranslation(PhysBody, _position + base.PositionDisplacement, _orientation);
354 });
355 }
356 }
335 357
336 // Check that the current position is sane and, if not, modify the position to make it so. 358 // Check that the current position is sane and, if not, modify the position to make it so.
337 // Check for being below terrain and being out of bounds. 359 // Check for being below terrain and being out of bounds.
@@ -590,6 +612,7 @@ public sealed class BSPrim : BSPhysObject
590 _velocity = value; 612 _velocity = value;
591 if (PhysBody.HasPhysicalBody) 613 if (PhysBody.HasPhysicalBody)
592 { 614 {
615 DetailLog("{0},BSPrim.ForceVelocity,taint,vel={1}", LocalID, _velocity);
593 PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity); 616 PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity);
594 ActivateIfPhysical(false); 617 ActivateIfPhysical(false);
595 } 618 }
@@ -654,12 +677,7 @@ public sealed class BSPrim : BSPhysObject
654 677
655 PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() 678 PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate()
656 { 679 {
657 if (PhysBody.HasPhysicalBody) 680 ForceOrientation = _orientation;
658 {
659 // _position = PhysicsScene.PE.GetObjectPosition(PhysicsScene.World, BSBody);
660 // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation);
661 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
662 }
663 }); 681 });
664 } 682 }
665 } 683 }
@@ -674,7 +692,8 @@ public sealed class BSPrim : BSPhysObject
674 set 692 set
675 { 693 {
676 _orientation = value; 694 _orientation = value;
677 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); 695 if (PhysBody.HasPhysicalBody)
696 PhysicsScene.PE.SetTranslation(PhysBody, _position + PositionDisplacement, _orientation);
678 } 697 }
679 } 698 }
680 public override int PhysicsActorType { 699 public override int PhysicsActorType {
@@ -813,7 +832,7 @@ public sealed class BSPrim : BSPhysObject
813 // PhysicsScene.PE.ClearAllForces(BSBody); 832 // PhysicsScene.PE.ClearAllForces(BSBody);
814 833
815 // For good measure, make sure the transform is set through to the motion state 834 // For good measure, make sure the transform is set through to the motion state
816 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); 835 PhysicsScene.PE.SetTranslation(PhysBody, _position + PositionDisplacement, _orientation);
817 836
818 // Center of mass is at the center of the object 837 // Center of mass is at the center of the object
819 // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(Linkset.LinksetRoot.PhysBody, _position, _orientation); 838 // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(Linkset.LinksetRoot.PhysBody, _position, _orientation);
@@ -1615,6 +1634,7 @@ public sealed class BSPrim : BSPhysObject
1615 } 1634 }
1616 1635
1617 // Assign directly to the local variables so the normal set actions do not happen 1636 // Assign directly to the local variables so the normal set actions do not happen
1637 entprop.Position -= PositionDisplacement;
1618 _position = entprop.Position; 1638 _position = entprop.Position;
1619 _orientation = entprop.Rotation; 1639 _orientation = entprop.Rotation;
1620 _velocity = entprop.Velocity; 1640 _velocity = entprop.Velocity;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index f0c6b99..addab29 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -906,7 +906,7 @@ public sealed class BSShapeCollection : IDisposable
906 } 906 }
907 } 907 }
908 908
909 // While we figure out the real problem, stick a simple native shape on the object. 909 // While we figure out the real problem, stick in a simple box for the object.
910 BulletShape fillinShape = 910 BulletShape fillinShape =
911 BuildPhysicalNativeShape(prim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX); 911 BuildPhysicalNativeShape(prim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX);
912 912
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
index 1540dbb..59cbab9 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
@@ -170,6 +170,8 @@ Avatar attachments have no mass? http://forums-archive.secondlife.com/54/f0/3179
170 170
171INTERNAL IMPROVEMENT/CLEANUP 171INTERNAL IMPROVEMENT/CLEANUP
172================================================= 172=================================================
173Can the 'inTaintTime' flag be cleaned up and used? For instance, a call to
174 BSScene.TaintedObject() could immediately execute the callback if already in taint time.
173Create the physical wrapper classes (BulletBody, BulletShape) by methods on 175Create the physical wrapper classes (BulletBody, BulletShape) by methods on
174 BSAPITemplate and make their actual implementation Bullet engine specific. 176 BSAPITemplate and make their actual implementation Bullet engine specific.
175 For the short term, just call the existing functions in ShapeCollection. 177 For the short term, just call the existing functions in ShapeCollection.