diff options
4 files changed, 51 insertions, 101 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; | |||
35 | namespace OpenSim.Region.Physics.BulletSPlugin | 35 | namespace 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. | ||
42 | sealed 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 | |||
94 | public sealed class BSLinksetCompound : BSLinkset | 38 | public 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 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs index 9a05349..a11bca0 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs | |||
@@ -51,7 +51,7 @@ public class BSPrimDisplaced : BSPrim | |||
51 | // the prim/linkset by the location of the root prim. So, if center-of-mass is anywhere | 51 | // the prim/linkset by the location of the root prim. So, if center-of-mass is anywhere |
52 | // but the origin of the root prim, the physical origin is displaced from the simulator origin. | 52 | // but the origin of the root prim, the physical origin is displaced from the simulator origin. |
53 | // | 53 | // |
54 | // This routine works by capturing the Force* setting of position/orientation/... and | 54 | // This routine works by capturing ForcePosition and |
55 | // adjusting the simulator values (being set) into the physical values. | 55 | // adjusting the simulator values (being set) into the physical values. |
56 | // The conversion is also done in the opposite direction (physical origin -> simulator origin). | 56 | // The conversion is also done in the opposite direction (physical origin -> simulator origin). |
57 | // | 57 | // |
@@ -60,8 +60,6 @@ public class BSPrimDisplaced : BSPrim | |||
60 | // class. | 60 | // class. |
61 | 61 | ||
62 | public virtual OMV.Vector3 PositionDisplacement { get; set; } | 62 | public virtual OMV.Vector3 PositionDisplacement { get; set; } |
63 | public virtual OMV.Quaternion OrientationDisplacement { get; set; } | ||
64 | public virtual OMV.Quaternion OrientationDisplacementOrigInv { get; set; } | ||
65 | 63 | ||
66 | public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, | 64 | public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, |
67 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) | 65 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) |
@@ -70,15 +68,17 @@ public class BSPrimDisplaced : BSPrim | |||
70 | ClearDisplacement(); | 68 | ClearDisplacement(); |
71 | } | 69 | } |
72 | 70 | ||
71 | // Clears any center-of-mass displacement introduced by linksets, etc. | ||
72 | // Does not clear the displacement set by the user. | ||
73 | public void ClearDisplacement() | 73 | public void ClearDisplacement() |
74 | { | 74 | { |
75 | PositionDisplacement = OMV.Vector3.Zero; | 75 | SetEffectiveCenterOfMassDisplacement(OMV.Vector3.Zero); |
76 | OrientationDisplacement = OMV.Quaternion.Identity; | ||
77 | } | 76 | } |
78 | 77 | ||
79 | // Set this sets and computes the displacement from the passed prim to the center-of-mass. | 78 | // Set this sets and computes the displacement from the passed prim to the center-of-mass. |
80 | // A user set value for center-of-mass overrides whatever might be passed in here. | 79 | // A user set value for center-of-mass overrides whatever might be passed in here. |
81 | // The displacement is in local coordinates (relative to root prim in linkset oriented coordinates). | 80 | // The displacement is in local coordinates (relative to root prim in linkset oriented coordinates). |
81 | // Called at taint time. | ||
82 | public virtual void SetEffectiveCenterOfMassDisplacement(Vector3 centerOfMassDisplacement) | 82 | public virtual void SetEffectiveCenterOfMassDisplacement(Vector3 centerOfMassDisplacement) |
83 | { | 83 | { |
84 | Vector3 comDisp; | 84 | Vector3 comDisp; |
@@ -87,21 +87,17 @@ public class BSPrimDisplaced : BSPrim | |||
87 | else | 87 | else |
88 | comDisp = centerOfMassDisplacement; | 88 | comDisp = centerOfMassDisplacement; |
89 | 89 | ||
90 | if (comDisp.ApproxEquals(Vector3.Zero, 0.01f) ) | ||
91 | comDisp = Vector3.Zero; | ||
92 | |||
90 | DetailLog("{0},BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement,userSet={1},comDisp={2}", | 93 | DetailLog("{0},BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement,userSet={1},comDisp={2}", |
91 | LocalID, UserSetCenterOfMassDisplacement.HasValue, comDisp); | 94 | LocalID, UserSetCenterOfMassDisplacement.HasValue, comDisp); |
92 | if (comDisp == Vector3.Zero) | 95 | if ( comDisp != PositionDisplacement ) |
93 | { | 96 | { |
94 | // If there is no diplacement. Things get reset. | 97 | // Displacement setting is changing. |
95 | PositionDisplacement = OMV.Vector3.Zero; | 98 | // The relationship between the physical object and simulated object must be aligned. |
96 | OrientationDisplacement = OMV.Quaternion.Identity; | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | // Remember the displacement from root as well as the origional rotation of the | ||
101 | // new center-of-mass. | ||
102 | PositionDisplacement = comDisp; | 99 | PositionDisplacement = comDisp; |
103 | OrientationDisplacement = Quaternion.Normalize(RawOrientation); | 100 | this.ForcePosition = RawPosition; |
104 | OrientationDisplacementOrigInv = Quaternion.Inverse(OrientationDisplacement); | ||
105 | } | 101 | } |
106 | } | 102 | } |
107 | 103 | ||
@@ -112,7 +108,11 @@ public class BSPrimDisplaced : BSPrim | |||
112 | { | 108 | { |
113 | if (PositionDisplacement != OMV.Vector3.Zero) | 109 | if (PositionDisplacement != OMV.Vector3.Zero) |
114 | { | 110 | { |
115 | OMV.Vector3 displacedPos = value - (PositionDisplacement * (OrientationDisplacementOrigInv * RawOrientation)); | 111 | // The displacement is always relative to the vehicle so, when setting position, |
112 | // the caller means to set the position of the root prim. | ||
113 | // This offsets the setting value to the center-of-mass and sends that to the | ||
114 | // physics engine. | ||
115 | OMV.Vector3 displacedPos = value - (PositionDisplacement * RawOrientation); | ||
116 | DetailLog("{0},BSPrimDisplaced.ForcePosition,val={1},disp={2},newPos={3}", LocalID, value, PositionDisplacement, displacedPos); | 116 | DetailLog("{0},BSPrimDisplaced.ForcePosition,val={1},disp={2},newPos={3}", LocalID, value, PositionDisplacement, displacedPos); |
117 | base.ForcePosition = displacedPos; | 117 | base.ForcePosition = displacedPos; |
118 | } | 118 | } |
@@ -123,26 +123,12 @@ public class BSPrimDisplaced : BSPrim | |||
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | public override Quaternion ForceOrientation | 126 | // These are also overridden by BSPrimLinkable if the prim can be part of a linkset |
127 | { | ||
128 | get { return base.ForceOrientation; } | ||
129 | set | ||
130 | { | ||
131 | // Changing orientation also changes the position of the center-of-mass since | ||
132 | // the orientation passed is for a rotation around the root prim's center. | ||
133 | base.ForceOrientation = value; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | // TODO: decide if this is the right place for these variables. | ||
138 | // Somehow incorporate the optional settability by the user. | ||
139 | // Is this used? | ||
140 | public override OMV.Vector3 CenterOfMass | 127 | public override OMV.Vector3 CenterOfMass |
141 | { | 128 | { |
142 | get { return RawPosition; } | 129 | get { return RawPosition; } |
143 | } | 130 | } |
144 | 131 | ||
145 | // Is this used? | ||
146 | public override OMV.Vector3 GeometricCenter | 132 | public override OMV.Vector3 GeometricCenter |
147 | { | 133 | { |
148 | get { return RawPosition; } | 134 | get { return RawPosition; } |
@@ -151,18 +137,17 @@ public class BSPrimDisplaced : BSPrim | |||
151 | public override void UpdateProperties(EntityProperties entprop) | 137 | public override void UpdateProperties(EntityProperties entprop) |
152 | { | 138 | { |
153 | // Undo any center-of-mass displacement that might have been done. | 139 | // Undo any center-of-mass displacement that might have been done. |
154 | if (PositionDisplacement != OMV.Vector3.Zero || OrientationDisplacement != OMV.Quaternion.Identity) | 140 | if (PositionDisplacement != OMV.Vector3.Zero) |
155 | { | 141 | { |
156 | // The origional shape was offset from 'zero' by PositionDisplacement and rotated by OrientationDisplacement. | 142 | // The origional shape was offset from 'zero' by PositionDisplacement. |
157 | // These physical locations and rotation must be back converted to be centered around the displaced | 143 | // These physical location must be back converted to be centered around the displaced |
158 | // root shape. | 144 | // root shape. |
159 | 145 | ||
160 | // The root position is the reported position displaced by the rotated displacement. | 146 | // The root position is the reported position displaced by the rotated displacement. |
161 | OMV.Vector3 displacedPos = entprop.Position + (PositionDisplacement * (entprop.Rotation * OrientationDisplacementOrigInv)); | 147 | OMV.Vector3 displacedPos = entprop.Position + (PositionDisplacement * entprop.Rotation); |
162 | 148 | DetailLog("{0},BSPrimDisplaced.UpdateProperties,physPos={1},disp={2},newPos={3}", | |
163 | DetailLog("{0},BSPrimDisplaced.ForcePosition,physPos={1},disp={2},newPos={3}", LocalID, entprop.Position, PositionDisplacement, displacedPos); | 149 | LocalID, entprop.Position, PositionDisplacement, displacedPos); |
164 | entprop.Position = displacedPos; | 150 | entprop.Position = displacedPos; |
165 | // entprop.Rotation = something; | ||
166 | } | 151 | } |
167 | 152 | ||
168 | base.UpdateProperties(entprop); | 153 | base.UpdateProperties(entprop); |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs index 6d7de35..7058646 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs | |||
@@ -134,6 +134,16 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
134 | get { return Linkset.LinksetMass; } | 134 | get { return Linkset.LinksetMass; } |
135 | } | 135 | } |
136 | 136 | ||
137 | public override OMV.Vector3 CenterOfMass | ||
138 | { | ||
139 | get { return Linkset.CenterOfMass; } | ||
140 | } | ||
141 | |||
142 | public override OMV.Vector3 GeometricCenter | ||
143 | { | ||
144 | get { return Linkset.GeometricCenter; } | ||
145 | } | ||
146 | |||
137 | // Refresh the linkset structure and parameters when the prim's physical parameters are changed. | 147 | // Refresh the linkset structure and parameters when the prim's physical parameters are changed. |
138 | public override void UpdatePhysicalParameters() | 148 | public override void UpdatePhysicalParameters() |
139 | { | 149 | { |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 1645c98..e56a6f6 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | |||
@@ -785,7 +785,6 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
785 | { | 785 | { |
786 | // The simulation of the time interval took less than realtime. | 786 | // The simulation of the time interval took less than realtime. |
787 | // Do a sleep for the rest of realtime. | 787 | // Do a sleep for the rest of realtime. |
788 | DetailLog("{0},BulletSPluginPhysicsThread,sleeping={1}", BSScene.DetailLogZero, simulationTimeVsRealtimeDifferenceMS); | ||
789 | Thread.Sleep(simulationTimeVsRealtimeDifferenceMS); | 788 | Thread.Sleep(simulationTimeVsRealtimeDifferenceMS); |
790 | } | 789 | } |
791 | else | 790 | else |