diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs | 60 |
1 files changed, 26 insertions, 34 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs index d0b2a56..a06a44d 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs | |||
@@ -36,7 +36,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
36 | { | 36 | { |
37 | // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]"; | 37 | // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]"; |
38 | 38 | ||
39 | public BSLinksetConstraints(BSScene scene, BSPhysObject parent) : base(scene, parent) | 39 | public BSLinksetConstraints(BSScene scene, BSPrimLinkable parent) : base(scene, parent) |
40 | { | 40 | { |
41 | } | 41 | } |
42 | 42 | ||
@@ -44,14 +44,14 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
44 | // its internal properties. | 44 | // its internal properties. |
45 | // This is queued in the 'post taint' queue so the | 45 | // This is queued in the 'post taint' queue so the |
46 | // refresh will happen once after all the other taints are applied. | 46 | // refresh will happen once after all the other taints are applied. |
47 | public override void Refresh(BSPhysObject requestor) | 47 | public override void Refresh(BSPrimLinkable requestor) |
48 | { | 48 | { |
49 | base.Refresh(requestor); | 49 | base.Refresh(requestor); |
50 | 50 | ||
51 | if (HasAnyChildren && IsRoot(requestor)) | 51 | if (HasAnyChildren && IsRoot(requestor)) |
52 | { | 52 | { |
53 | // Queue to happen after all the other taint processing | 53 | // Queue to happen after all the other taint processing |
54 | PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate() | 54 | m_physicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate() |
55 | { | 55 | { |
56 | if (HasAnyChildren && IsRoot(requestor)) | 56 | if (HasAnyChildren && IsRoot(requestor)) |
57 | RecomputeLinksetConstraints(); | 57 | RecomputeLinksetConstraints(); |
@@ -65,7 +65,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
65 | // has not yet been fully constructed. | 65 | // has not yet been fully constructed. |
66 | // Return 'true' if any properties updated on the passed object. | 66 | // Return 'true' if any properties updated on the passed object. |
67 | // Called at taint-time! | 67 | // Called at taint-time! |
68 | public override bool MakeDynamic(BSPhysObject child) | 68 | public override bool MakeDynamic(BSPrimLinkable child) |
69 | { | 69 | { |
70 | // What is done for each object in BSPrim is what we want. | 70 | // What is done for each object in BSPrim is what we want. |
71 | return false; | 71 | return false; |
@@ -76,14 +76,14 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
76 | // This doesn't normally happen -- OpenSim removes the objects from the physical | 76 | // This doesn't normally happen -- OpenSim removes the objects from the physical |
77 | // world if it is a static linkset. | 77 | // world if it is a static linkset. |
78 | // Called at taint-time! | 78 | // Called at taint-time! |
79 | public override bool MakeStatic(BSPhysObject child) | 79 | public override bool MakeStatic(BSPrimLinkable child) |
80 | { | 80 | { |
81 | // What is done for each object in BSPrim is what we want. | 81 | // What is done for each object in BSPrim is what we want. |
82 | return false; | 82 | return false; |
83 | } | 83 | } |
84 | 84 | ||
85 | // Called at taint-time!! | 85 | // Called at taint-time!! |
86 | public override void UpdateProperties(BSPhysObject updated, bool inTaintTime) | 86 | public override void UpdateProperties(UpdatedProperties whichUpdated, BSPrimLinkable pObj) |
87 | { | 87 | { |
88 | // Nothing to do for constraints on property updates | 88 | // Nothing to do for constraints on property updates |
89 | } | 89 | } |
@@ -93,11 +93,11 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
93 | // up to rebuild the constraints before the next simulation step. | 93 | // up to rebuild the constraints before the next simulation step. |
94 | // Returns 'true' of something was actually removed and would need restoring | 94 | // Returns 'true' of something was actually removed and would need restoring |
95 | // Called at taint-time!! | 95 | // Called at taint-time!! |
96 | public override bool RemoveBodyDependencies(BSPrim child) | 96 | public override bool RemoveDependencies(BSPrimLinkable child) |
97 | { | 97 | { |
98 | bool ret = false; | 98 | bool ret = false; |
99 | 99 | ||
100 | DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}", | 100 | DetailLog("{0},BSLinksetConstraint.RemoveDependencies,removeChildrenForRoot,rID={1},rBody={2}", |
101 | child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString); | 101 | child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString); |
102 | 102 | ||
103 | lock (m_linksetActivityLock) | 103 | lock (m_linksetActivityLock) |
@@ -110,19 +110,11 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
110 | return ret; | 110 | return ret; |
111 | } | 111 | } |
112 | 112 | ||
113 | // Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true', | ||
114 | // this routine will restore the removed constraints. | ||
115 | // Called at taint-time!! | ||
116 | public override void RestoreBodyDependencies(BSPrim child) | ||
117 | { | ||
118 | // The Refresh operation queued by RemoveBodyDependencies() will build any missing constraints. | ||
119 | } | ||
120 | |||
121 | // ================================================================ | 113 | // ================================================================ |
122 | 114 | ||
123 | // Add a new child to the linkset. | 115 | // Add a new child to the linkset. |
124 | // Called while LinkActivity is locked. | 116 | // Called while LinkActivity is locked. |
125 | protected override void AddChildToLinkset(BSPhysObject child) | 117 | protected override void AddChildToLinkset(BSPrimLinkable child) |
126 | { | 118 | { |
127 | if (!HasChild(child)) | 119 | if (!HasChild(child)) |
128 | { | 120 | { |
@@ -138,19 +130,19 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
138 | 130 | ||
139 | // Remove the specified child from the linkset. | 131 | // Remove the specified child from the linkset. |
140 | // Safe to call even if the child is not really in my linkset. | 132 | // Safe to call even if the child is not really in my linkset. |
141 | protected override void RemoveChildFromLinkset(BSPhysObject child) | 133 | protected override void RemoveChildFromLinkset(BSPrimLinkable child) |
142 | { | 134 | { |
143 | if (m_children.Remove(child)) | 135 | if (m_children.Remove(child)) |
144 | { | 136 | { |
145 | BSPhysObject rootx = LinksetRoot; // capture the root and body as of now | 137 | BSPrimLinkable rootx = LinksetRoot; // capture the root and body as of now |
146 | BSPhysObject childx = child; | 138 | BSPrimLinkable childx = child; |
147 | 139 | ||
148 | DetailLog("{0},BSLinksetConstraints.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}", | 140 | DetailLog("{0},BSLinksetConstraints.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}", |
149 | childx.LocalID, | 141 | childx.LocalID, |
150 | rootx.LocalID, rootx.PhysBody.AddrString, | 142 | rootx.LocalID, rootx.PhysBody.AddrString, |
151 | childx.LocalID, childx.PhysBody.AddrString); | 143 | childx.LocalID, childx.PhysBody.AddrString); |
152 | 144 | ||
153 | PhysicsScene.TaintedObject("BSLinksetConstraints.RemoveChildFromLinkset", delegate() | 145 | m_physicsScene.TaintedObject("BSLinksetConstraints.RemoveChildFromLinkset", delegate() |
154 | { | 146 | { |
155 | PhysicallyUnlinkAChildFromRoot(rootx, childx); | 147 | PhysicallyUnlinkAChildFromRoot(rootx, childx); |
156 | }); | 148 | }); |
@@ -167,13 +159,13 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
167 | 159 | ||
168 | // Create a constraint between me (root of linkset) and the passed prim (the child). | 160 | // Create a constraint between me (root of linkset) and the passed prim (the child). |
169 | // Called at taint time! | 161 | // Called at taint time! |
170 | private void PhysicallyLinkAChildToRoot(BSPhysObject rootPrim, BSPhysObject childPrim) | 162 | private void PhysicallyLinkAChildToRoot(BSPrimLinkable rootPrim, BSPrimLinkable childPrim) |
171 | { | 163 | { |
172 | // Don't build the constraint when asked. Put it off until just before the simulation step. | 164 | // Don't build the constraint when asked. Put it off until just before the simulation step. |
173 | Refresh(rootPrim); | 165 | Refresh(rootPrim); |
174 | } | 166 | } |
175 | 167 | ||
176 | private BSConstraint BuildConstraint(BSPhysObject rootPrim, BSPhysObject childPrim) | 168 | private BSConstraint BuildConstraint(BSPrimLinkable rootPrim, BSPrimLinkable childPrim) |
177 | { | 169 | { |
178 | // Zero motion for children so they don't interpolate | 170 | // Zero motion for children so they don't interpolate |
179 | childPrim.ZeroMotion(true); | 171 | childPrim.ZeroMotion(true); |
@@ -195,7 +187,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
195 | // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 | 187 | // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 |
196 | 188 | ||
197 | BSConstraint6Dof constrain = new BSConstraint6Dof( | 189 | BSConstraint6Dof constrain = new BSConstraint6Dof( |
198 | PhysicsScene.World, rootPrim.PhysBody, childPrim.PhysBody, midPoint, true, true ); | 190 | m_physicsScene.World, rootPrim.PhysBody, childPrim.PhysBody, midPoint, true, true ); |
199 | // PhysicsScene.World, childPrim.BSBody, rootPrim.BSBody, midPoint, true, true ); | 191 | // PhysicsScene.World, childPrim.BSBody, rootPrim.BSBody, midPoint, true, true ); |
200 | 192 | ||
201 | /* NOTE: below is an attempt to build constraint with full frame computation, etc. | 193 | /* NOTE: below is an attempt to build constraint with full frame computation, etc. |
@@ -224,15 +216,15 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
224 | // ================================================================================== | 216 | // ================================================================================== |
225 | */ | 217 | */ |
226 | 218 | ||
227 | PhysicsScene.Constraints.AddConstraint(constrain); | 219 | m_physicsScene.Constraints.AddConstraint(constrain); |
228 | 220 | ||
229 | // zero linear and angular limits makes the objects unable to move in relation to each other | 221 | // zero linear and angular limits makes the objects unable to move in relation to each other |
230 | constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); | 222 | constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); |
231 | constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); | 223 | constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); |
232 | 224 | ||
233 | // tweek the constraint to increase stability | 225 | // tweek the constraint to increase stability |
234 | constrain.UseFrameOffset(BSParam.BoolNumeric(BSParam.LinkConstraintUseFrameOffset)); | 226 | constrain.UseFrameOffset(BSParam.LinkConstraintUseFrameOffset); |
235 | constrain.TranslationalLimitMotor(BSParam.BoolNumeric(BSParam.LinkConstraintEnableTransMotor), | 227 | constrain.TranslationalLimitMotor(BSParam.LinkConstraintEnableTransMotor, |
236 | BSParam.LinkConstraintTransMotorMaxVel, | 228 | BSParam.LinkConstraintTransMotorMaxVel, |
237 | BSParam.LinkConstraintTransMotorMaxForce); | 229 | BSParam.LinkConstraintTransMotorMaxForce); |
238 | constrain.SetCFMAndERP(BSParam.LinkConstraintCFM, BSParam.LinkConstraintERP); | 230 | constrain.SetCFMAndERP(BSParam.LinkConstraintCFM, BSParam.LinkConstraintERP); |
@@ -247,7 +239,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
247 | // The root and child bodies are passed in because we need to remove the constraint between | 239 | // The root and child bodies are passed in because we need to remove the constraint between |
248 | // the bodies that were present at unlink time. | 240 | // the bodies that were present at unlink time. |
249 | // Called at taint time! | 241 | // Called at taint time! |
250 | private bool PhysicallyUnlinkAChildFromRoot(BSPhysObject rootPrim, BSPhysObject childPrim) | 242 | private bool PhysicallyUnlinkAChildFromRoot(BSPrimLinkable rootPrim, BSPrimLinkable childPrim) |
251 | { | 243 | { |
252 | bool ret = false; | 244 | bool ret = false; |
253 | DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}", | 245 | DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}", |
@@ -256,10 +248,10 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
256 | childPrim.LocalID, childPrim.PhysBody.AddrString); | 248 | childPrim.LocalID, childPrim.PhysBody.AddrString); |
257 | 249 | ||
258 | // Find the constraint for this link and get rid of it from the overall collection and from my list | 250 | // Find the constraint for this link and get rid of it from the overall collection and from my list |
259 | if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody)) | 251 | if (m_physicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody)) |
260 | { | 252 | { |
261 | // Make the child refresh its location | 253 | // Make the child refresh its location |
262 | PhysicsScene.PE.PushUpdate(childPrim.PhysBody); | 254 | m_physicsScene.PE.PushUpdate(childPrim.PhysBody); |
263 | ret = true; | 255 | ret = true; |
264 | } | 256 | } |
265 | 257 | ||
@@ -269,11 +261,11 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
269 | // Remove linkage between myself and any possible children I might have. | 261 | // Remove linkage between myself and any possible children I might have. |
270 | // Returns 'true' of any constraints were destroyed. | 262 | // Returns 'true' of any constraints were destroyed. |
271 | // Called at taint time! | 263 | // Called at taint time! |
272 | private bool PhysicallyUnlinkAllChildrenFromRoot(BSPhysObject rootPrim) | 264 | private bool PhysicallyUnlinkAllChildrenFromRoot(BSPrimLinkable rootPrim) |
273 | { | 265 | { |
274 | DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAllChildren,taint", rootPrim.LocalID); | 266 | DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAllChildren,taint", rootPrim.LocalID); |
275 | 267 | ||
276 | return PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody); | 268 | return m_physicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody); |
277 | } | 269 | } |
278 | 270 | ||
279 | // Call each of the constraints that make up this linkset and recompute the | 271 | // Call each of the constraints that make up this linkset and recompute the |
@@ -289,7 +281,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
289 | DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}", | 281 | DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}", |
290 | LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, linksetMass); | 282 | LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, linksetMass); |
291 | 283 | ||
292 | foreach (BSPhysObject child in m_children) | 284 | foreach (BSPrimLinkable child in m_children) |
293 | { | 285 | { |
294 | // A child in the linkset physically shows the mass of the whole linkset. | 286 | // A child in the linkset physically shows the mass of the whole linkset. |
295 | // This allows Bullet to apply enough force on the child to move the whole linkset. | 287 | // This allows Bullet to apply enough force on the child to move the whole linkset. |
@@ -297,7 +289,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
297 | child.UpdatePhysicalMassProperties(linksetMass, true); | 289 | child.UpdatePhysicalMassProperties(linksetMass, true); |
298 | 290 | ||
299 | BSConstraint constrain; | 291 | BSConstraint constrain; |
300 | if (!PhysicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, child.PhysBody, out constrain)) | 292 | if (!m_physicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, child.PhysBody, out constrain)) |
301 | { | 293 | { |
302 | // If constraint doesn't exist yet, create it. | 294 | // If constraint doesn't exist yet, create it. |
303 | constrain = BuildConstraint(LinksetRoot, child); | 295 | constrain = BuildConstraint(LinksetRoot, child); |