aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs20
1 files changed, 12 insertions, 8 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index 96626ca..1d94142 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -271,6 +271,8 @@ public sealed class BSLinksetCompound : BSLinkset
271 // to what they should be as if the root was not in a linkset. 271 // to what they should be as if the root was not in a linkset.
272 // Not that bad since we only get into this routine if there are children in the linkset and 272 // Not that bad since we only get into this routine if there are children in the linkset and
273 // something has been updated/changed. 273 // something has been updated/changed.
274 // Have to do the rebuild before checking for physical because this might be a linkset
275 // being destructed and going non-physical.
274 LinksetRoot.ForceBodyShapeRebuild(true); 276 LinksetRoot.ForceBodyShapeRebuild(true);
275 277
276 // There is no reason to build all this physical stuff for a non-physical linkset. 278 // There is no reason to build all this physical stuff for a non-physical linkset.
@@ -283,28 +285,29 @@ public sealed class BSLinksetCompound : BSLinkset
283 // Get a new compound shape to build the linkset shape in. 285 // Get a new compound shape to build the linkset shape in.
284 BSShape linksetShape = BSShapeCompound.GetReference(m_physicsScene); 286 BSShape linksetShape = BSShapeCompound.GetReference(m_physicsScene);
285 287
286 // The center of mass for the linkset is the geometric center of the group.
287 // Compute a displacement for each component so it is relative to the center-of-mass. 288 // Compute a displacement for each component so it is relative to the center-of-mass.
288 // Bullet presumes an object's origin (relative <0,0,0>) is its center-of-mass 289 // Bullet presumes an object's origin (relative <0,0,0>) is its center-of-mass
289 OMV.Vector3 centerOfMassW = ComputeLinksetCenterOfMass(); 290 OMV.Vector3 centerOfMassW = ComputeLinksetCenterOfMass();
290 291
291 OMV.Quaternion invRootOrientation = OMV.Quaternion.Normalize(OMV.Quaternion.Inverse(LinksetRoot.RawOrientation)); 292 OMV.Quaternion invRootOrientation = OMV.Quaternion.Normalize(OMV.Quaternion.Inverse(LinksetRoot.RawOrientation));
293 OMV.Vector3 origRootPosition = LinksetRoot.RawPosition;
292 294
293 // 'centerDisplacementV' is the value to subtract from children to give physical offset position 295 // 'centerDisplacementV' is the vehicle relative distance from the simulator root position to the center-of-mass
294 OMV.Vector3 centerDisplacementV = (centerOfMassW - LinksetRoot.RawPosition) * invRootOrientation; 296 OMV.Vector3 centerDisplacementV = (centerOfMassW - LinksetRoot.RawPosition) * invRootOrientation;
295 if (UseBulletSimRootOffsetHack || !BSParam.LinksetOffsetCenterOfMass) 297 if (UseBulletSimRootOffsetHack || !BSParam.LinksetOffsetCenterOfMass)
296 { 298 {
299 // Zero everything if center-of-mass displacement is not being done.
297 centerDisplacementV = OMV.Vector3.Zero; 300 centerDisplacementV = OMV.Vector3.Zero;
298 LinksetRoot.ClearDisplacement(); 301 LinksetRoot.ClearDisplacement();
299 } 302 }
300 else 303 else
301 { 304 {
302 LinksetRoot.SetEffectiveCenterOfMassDisplacement(centerDisplacementV);
303 // The actual center-of-mass could have been set by the user. 305 // The actual center-of-mass could have been set by the user.
304 centerDisplacementV = LinksetRoot.PositionDisplacement; 306 centerDisplacementV = LinksetRoot.SetEffectiveCenterOfMassDisplacement(centerDisplacementV);
305 } 307 }
308
306 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,COM,rootPos={1},com={2},comDisp={3}", 309 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,COM,rootPos={1},com={2},comDisp={3}",
307 LinksetRoot.LocalID, LinksetRoot.RawPosition, centerOfMassW, centerDisplacementV); 310 LinksetRoot.LocalID, origRootPosition, centerOfMassW, centerDisplacementV);
308 311
309 // Add the shapes of all the components of the linkset 312 // Add the shapes of all the components of the linkset
310 int memberIndex = 1; 313 int memberIndex = 1;
@@ -321,11 +324,11 @@ public sealed class BSLinksetCompound : BSLinkset
321 memberIndex++; 324 memberIndex++;
322 } 325 }
323 326
324 // Get a reference to the shape of the child and add that shape to the linkset compound shape 327 // Get a reference to the shape of the child for adding of that shape to the linkset compound shape
325 BSShape childShape = cPrim.PhysShape.GetReference(m_physicsScene, cPrim); 328 BSShape childShape = cPrim.PhysShape.GetReference(m_physicsScene, cPrim);
326 329
327 // Offset the child shape from the center-of-mass and rotate it to vehicle relative 330 // Offset the child shape from the center-of-mass and rotate it to vehicle relative.
328 OMV.Vector3 offsetPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation - centerDisplacementV; 331 OMV.Vector3 offsetPos = (cPrim.RawPosition - origRootPosition) * invRootOrientation - centerDisplacementV;
329 OMV.Quaternion offsetRot = OMV.Quaternion.Normalize(cPrim.RawOrientation) * invRootOrientation; 332 OMV.Quaternion offsetRot = OMV.Quaternion.Normalize(cPrim.RawOrientation) * invRootOrientation;
330 333
331 // Add the child shape to the compound shape being built 334 // Add the child shape to the compound shape being built
@@ -366,6 +369,7 @@ public sealed class BSLinksetCompound : BSLinkset
366 // This enables a feature in the C++ code to return the world coordinates of the first shape in the 369 // This enables a feature in the C++ code to return the world coordinates of the first shape in the
367 // compound shape. This aleviates the need to offset the returned physical position by the 370 // compound shape. This aleviates the need to offset the returned physical position by the
368 // center-of-mass offset. 371 // center-of-mass offset.
372 // TODO: either debug this feature or remove it.
369 m_physicsScene.PE.AddToCollisionFlags(LinksetRoot.PhysBody, CollisionFlags.BS_RETURN_ROOT_COMPOUND_SHAPE); 373 m_physicsScene.PE.AddToCollisionFlags(LinksetRoot.PhysBody, CollisionFlags.BS_RETURN_ROOT_COMPOUND_SHAPE);
370 } 374 }
371 } 375 }