aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs78
1 files changed, 17 insertions, 61 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index 30f6c8c..96626ca 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -35,62 +35,6 @@ using OMV = OpenMetaverse;
35namespace OpenSim.Region.Physics.BulletSPlugin 35namespace OpenSim.Region.Physics.BulletSPlugin
36{ 36{
37 37
38 /*
39// When a child is linked, the relationship position of the child to the parent
40// is remembered so the child's world position can be recomputed when it is
41// removed from the linkset.
42sealed class BSLinksetCompoundInfo : BSLinksetInfo
43{
44 public int Index;
45 public OMV.Vector3 OffsetFromRoot;
46 public OMV.Vector3 OffsetFromCenterOfMass;
47 public OMV.Quaternion OffsetRot;
48 public BSLinksetCompoundInfo(int indx, OMV.Vector3 p, OMV.Quaternion r)
49 {
50 Index = indx;
51 OffsetFromRoot = p;
52 OffsetFromCenterOfMass = p;
53 OffsetRot = r;
54 }
55 // 'centerDisplacement' is the distance from the root the the center-of-mass (Bullet 'zero' of the shape)
56 public BSLinksetCompoundInfo(int indx, BSPrimLinkable root, BSPrimLinkable child, OMV.Vector3 centerDisplacement)
57 {
58 // Each child position and rotation is given relative to the center-of-mass.
59 OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(root.RawOrientation);
60 OMV.Vector3 displacementFromRoot = (child.RawPosition - root.RawPosition) * invRootOrientation;
61 OMV.Vector3 displacementFromCOM = displacementFromRoot - centerDisplacement;
62 OMV.Quaternion displacementRot = child.RawOrientation * invRootOrientation;
63
64 // Save relative position for recomputing child's world position after moving linkset.
65 Index = indx;
66 OffsetFromRoot = displacementFromRoot;
67 OffsetFromCenterOfMass = displacementFromCOM;
68 OffsetRot = displacementRot;
69 }
70 public override void Clear()
71 {
72 Index = 0;
73 OffsetFromRoot = OMV.Vector3.Zero;
74 OffsetFromCenterOfMass = OMV.Vector3.Zero;
75 OffsetRot = OMV.Quaternion.Identity;
76 }
77 public override string ToString()
78 {
79 StringBuilder buff = new StringBuilder();
80 buff.Append("<i=");
81 buff.Append(Index.ToString());
82 buff.Append(",p=");
83 buff.Append(OffsetFromRoot.ToString());
84 buff.Append(",m=");
85 buff.Append(OffsetFromCenterOfMass.ToString());
86 buff.Append(",r=");
87 buff.Append(OffsetRot.ToString());
88 buff.Append(">");
89 return buff.ToString();
90 }
91};
92 */
93
94public sealed class BSLinksetCompound : BSLinkset 38public sealed class BSLinksetCompound : BSLinkset
95{ 39{
96 private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]"; 40 private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]";
@@ -151,7 +95,9 @@ public sealed class BSLinksetCompound : BSLinkset
151 public override bool MakeStatic(BSPrimLinkable child) 95 public override bool MakeStatic(BSPrimLinkable child)
152 { 96 {
153 bool ret = false; 97 bool ret = false;
98
154 DetailLog("{0},BSLinksetCompound.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child)); 99 DetailLog("{0},BSLinksetCompound.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child));
100 child.ClearDisplacement();
155 if (IsRoot(child)) 101 if (IsRoot(child))
156 { 102 {
157 // Schedule a rebuild to verify that the root shape is set to the real shape. 103 // Schedule a rebuild to verify that the root shape is set to the real shape.
@@ -364,16 +310,28 @@ public sealed class BSLinksetCompound : BSLinkset
364 int memberIndex = 1; 310 int memberIndex = 1;
365 ForEachMember(delegate(BSPrimLinkable cPrim) 311 ForEachMember(delegate(BSPrimLinkable cPrim)
366 { 312 {
367 // Root shape is always index zero. 313 if (IsRoot(cPrim))
368 cPrim.LinksetChildIndex = IsRoot(cPrim) ? 0 : memberIndex; 314 {
315 // Root shape is always index zero.
316 cPrim.LinksetChildIndex = 0;
317 }
318 else
319 {
320 cPrim.LinksetChildIndex = memberIndex;
321 memberIndex++;
322 }
369 323
370 // Get a reference to the shape of the child and add that shape to the linkset compound shape 324 // Get a reference to the shape of the child and add that shape to the linkset compound shape
371 BSShape childShape = cPrim.PhysShape.GetReference(m_physicsScene, cPrim); 325 BSShape childShape = cPrim.PhysShape.GetReference(m_physicsScene, cPrim);
326
327 // Offset the child shape from the center-of-mass and rotate it to vehicle relative
372 OMV.Vector3 offsetPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation - centerDisplacementV; 328 OMV.Vector3 offsetPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation - centerDisplacementV;
373 OMV.Quaternion offsetRot = OMV.Quaternion.Normalize(cPrim.RawOrientation) * invRootOrientation; 329 OMV.Quaternion offsetRot = OMV.Quaternion.Normalize(cPrim.RawOrientation) * invRootOrientation;
330
331 // Add the child shape to the compound shape being built
374 m_physicsScene.PE.AddChildShapeToCompoundShape(linksetShape.physShapeInfo, childShape.physShapeInfo, offsetPos, offsetRot); 332 m_physicsScene.PE.AddChildShapeToCompoundShape(linksetShape.physShapeInfo, childShape.physShapeInfo, offsetPos, offsetRot);
375 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addChild,indx={1},cShape={2},offPos={3},offRot={4}", 333 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addChild,indx={1},cShape={2},offPos={3},offRot={4}",
376 LinksetRoot.LocalID, memberIndex, childShape, offsetPos, offsetRot); 334 LinksetRoot.LocalID, cPrim.LinksetChildIndex, childShape, offsetPos, offsetRot);
377 335
378 // Since we are borrowing the shape of the child, disable the origional child body 336 // Since we are borrowing the shape of the child, disable the origional child body
379 if (!IsRoot(cPrim)) 337 if (!IsRoot(cPrim))
@@ -385,8 +343,6 @@ public sealed class BSLinksetCompound : BSLinkset
385 cPrim.PhysBody.collisionType = CollisionType.LinksetChild; 343 cPrim.PhysBody.collisionType = CollisionType.LinksetChild;
386 } 344 }
387 345
388 memberIndex++;
389
390 return false; // 'false' says to move onto the next child in the list 346 return false; // 'false' says to move onto the next child in the list
391 }); 347 });
392 348