aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
diff options
context:
space:
mode:
authorRobert Adams2012-09-27 19:57:35 -0700
committerRobert Adams2012-09-27 22:02:08 -0700
commit74dea4cfd52be75b4dd6277260c3ada80b939fbb (patch)
tree5781a9b2cb58bf27cb58d6189c535b33ca4af439 /OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
parentBulletSim: remove the trailing spaces from lines to make git happier (diff)
downloadopensim-SC_OLD-74dea4cfd52be75b4dd6277260c3ada80b939fbb.zip
opensim-SC_OLD-74dea4cfd52be75b4dd6277260c3ada80b939fbb.tar.gz
opensim-SC_OLD-74dea4cfd52be75b4dd6277260c3ada80b939fbb.tar.bz2
opensim-SC_OLD-74dea4cfd52be75b4dd6277260c3ada80b939fbb.tar.xz
BulletSim: rename some constraint variables to be consistant with other name use.
Added callbacks for shape and body changes in GetBodyAndShape() so the linkset constraints can be picked up and restored. A better design might be to have a "prim shape changed" event. Think about that. Added constraint types to general constraint class.
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs182
1 files changed, 117 insertions, 65 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
index b0cc63c..dff71af 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
@@ -88,6 +88,7 @@ public class BSLinkset
88 // Link to a linkset where the child knows the parent. 88 // Link to a linkset where the child knows the parent.
89 // Parent changing should not happen so do some sanity checking. 89 // Parent changing should not happen so do some sanity checking.
90 // We return the parent's linkset so the child can track its membership. 90 // We return the parent's linkset so the child can track its membership.
91 // Called at runtime.
91 public BSLinkset AddMeToLinkset(BSPhysObject child) 92 public BSLinkset AddMeToLinkset(BSPhysObject child)
92 { 93 {
93 lock (m_linksetActivityLock) 94 lock (m_linksetActivityLock)
@@ -102,6 +103,7 @@ public class BSLinkset
102 // Remove a child from a linkset. 103 // Remove a child from a linkset.
103 // Returns a new linkset for the child which is a linkset of one (just the 104 // Returns a new linkset for the child which is a linkset of one (just the
104 // orphened child). 105 // orphened child).
106 // Called at runtime.
105 public BSLinkset RemoveMeFromLinkset(BSPhysObject child) 107 public BSLinkset RemoveMeFromLinkset(BSPhysObject child)
106 { 108 {
107 lock (m_linksetActivityLock) 109 lock (m_linksetActivityLock)
@@ -113,27 +115,6 @@ public class BSLinkset
113 } 115 }
114 116
115 RemoveChildFromLinkset(child); 117 RemoveChildFromLinkset(child);
116
117 /* Alternate implementation that destroys the linkset of the root is removed.
118 * This fails because items are added and removed from linksets to build shapes.
119 * Code left for reference.
120 if (IsRoot(child))
121 {
122 // if root of linkset, take the linkset apart
123 while (m_children.Count > 0)
124 {
125 // Note that we don't do a foreach because the remove routine
126 // takes it out of the list.
127 RemoveChildFromOtherLinkset(m_children[0]);
128 }
129 m_children.Clear(); // just to make sure
130 }
131 else
132 {
133 // Just removing a child from an existing linkset
134 RemoveChildFromLinkset(child);
135 }
136 */
137 } 118 }
138 119
139 // The child is down to a linkset of just itself 120 // The child is down to a linkset of just itself
@@ -169,6 +150,106 @@ public class BSLinkset
169 return ret; 150 return ret;
170 } 151 }
171 152
153 // The object is going dynamic (physical). Do any setup necessary
154 // for a dynamic linkset.
155 // Only the state of the passed object can be modified. The rest of the linkset
156 // has not yet been fully constructed.
157 // Return 'true' if any properties updated on the passed object.
158 // Called at taint-time!
159 public bool MakeDynamic(BSPhysObject child)
160 {
161 // What is done for each object in BSPrim is what we want.
162 return false;
163 }
164
165 // The object is going static (non-physical). Do any setup necessary
166 // for a static linkset.
167 // Return 'true' if any properties updated on the passed object.
168 // Called at taint-time!
169 public bool MakeStatic(BSPhysObject child)
170 {
171 // What is done for each object in BSPrim is what we want.
172 return false;
173 }
174
175 // When physical properties are changed the linkset needs to recalculate
176 // its internal properties.
177 // Called at runtime.
178 public void Refresh(BSPhysObject requestor)
179 {
180 // If there are no children, there can't be any constraints to recompute
181 if (!HasAnyChildren)
182 return;
183
184 // Only the root does the recomputation
185 if (IsRoot(requestor))
186 {
187 PhysicsScene.TaintedObject("BSLinkSet.Refresh", delegate()
188 {
189 RecomputeLinksetConstraintVariables();
190 });
191 }
192 }
193
194 // Routine used when rebuilding the body of the root of the linkset
195 // Destroy all the constraints have have been made to root.
196 // This is called when the root body is changing.
197 // Called at taint-time!!
198 public void RemoveBodyDependencies(BSPrim child)
199 {
200 lock (m_linksetActivityLock)
201 {
202 if (IsRoot(child))
203 {
204 // If the one with the dependency is root, must undo all children
205 DetailLog("{0},BSLinkset.RemoveBodyDependencies,removeChildrenForRoot,rID={1},numChild={2}",
206 LinksetRoot.LocalID, m_children.Count);
207 foreach (BSPhysObject bpo in m_children)
208 {
209 PhysicallyUnlinkAChildFromRoot(LinksetRoot, LinksetRoot.BSBody, bpo, bpo.BSBody);
210 }
211 }
212 else
213 {
214 DetailLog("{0},BSLinkset.RemoveBodyDependencies,removeSingleChild,rID={1},rBody={2},cID={3},cBody={4}",
215 LinksetRoot.LocalID, LinksetRoot.BSBody.ptr.ToString("X"),
216 child.LocalID, child.BSBody.ptr.ToString("X"));
217 // Remove the dependency on the body of this one
218 PhysicallyUnlinkAChildFromRoot(LinksetRoot, LinksetRoot.BSBody, child, child.BSBody);
219 }
220 }
221 }
222
223 // Routine used when rebuilding the body of the root of the linkset
224 // This is called after RemoveAllLinksToRoot() to restore all the constraints.
225 // This is called when the root body has been changed.
226 // Called at taint-time!!
227 public void RestoreBodyDependencies(BSPrim child)
228 {
229 lock (m_linksetActivityLock)
230 {
231 if (IsRoot(child))
232 {
233 DetailLog("{0},BSLinkset.RestoreBodyDependencies,restoreChildrenForRoot,rID={1},numChild={2}",
234 LinksetRoot.LocalID, m_children.Count);
235 foreach (BSPhysObject bpo in m_children)
236 {
237 PhysicallyLinkAChildToRoot(LinksetRoot, LinksetRoot.BSBody, bpo, bpo.BSBody);
238 }
239 }
240 else
241 {
242 DetailLog("{0},BSLinkset.RestoreBodyDependencies,restoreSingleChild,rID={1},rBody={2},cID={3},cBody={4}",
243 LinksetRoot.LocalID, LinksetRoot.BSBody.ptr.ToString("X"),
244 child.LocalID, child.BSBody.ptr.ToString("X"));
245 PhysicallyLinkAChildToRoot(LinksetRoot, LinksetRoot.BSBody, child, child.BSBody);
246 }
247 }
248 }
249
250 // ================================================================
251 // Below this point is internal magic
252
172 private float ComputeLinksetMass() 253 private float ComputeLinksetMass()
173 { 254 {
174 float mass; 255 float mass;
@@ -220,46 +301,6 @@ public class BSLinkset
220 return com; 301 return com;
221 } 302 }
222 303
223 // The object is going dynamic (physical). Do any setup necessary
224 // for a dynamic linkset.
225 // Only the state of the passed object can be modified. The rest of the linkset
226 // has not yet been fully constructed.
227 // Return 'true' if any properties updated on the passed object.
228 // Called at taint-time!
229 public bool MakeDynamic(BSPhysObject child)
230 {
231 // What is done for each object in BSPrim is what we want.
232 return false;
233 }
234
235 // The object is going static (non-physical). Do any setup necessary
236 // for a static linkset.
237 // Return 'true' if any properties updated on the passed object.
238 // Called at taint-time!
239 public bool MakeStatic(BSPhysObject child)
240 {
241 // What is done for each object in BSPrim is what we want.
242 return false;
243 }
244
245 // When physical properties are changed the linkset needs to recalculate
246 // its internal properties.
247 public void Refresh(BSPhysObject requestor)
248 {
249 // If there are no children, there can't be any constraints to recompute
250 if (!HasAnyChildren)
251 return;
252
253 // Only the root does the recomputation
254 if (IsRoot(requestor))
255 {
256 PhysicsScene.TaintedObject("BSLinkSet.Refresh", delegate()
257 {
258 RecomputeLinksetConstraintVariables();
259 });
260 }
261 }
262
263 // Call each of the constraints that make up this linkset and recompute the 304 // Call each of the constraints that make up this linkset and recompute the
264 // various transforms and variables. Used when objects are added or removed 305 // various transforms and variables. Used when objects are added or removed
265 // from a linkset to make sure the constraints know about the new mass and 306 // from a linkset to make sure the constraints know about the new mass and
@@ -327,6 +368,11 @@ public class BSLinkset
327 BSPhysObject childx = child; 368 BSPhysObject childx = child;
328 BulletBody childBodyx = child.BSBody; 369 BulletBody childBodyx = child.BSBody;
329 370
371 DetailLog("{0},AddChildToLinkset,call,rID={1},rBody={2},cID={3},cBody={4}",
372 rootx.LocalID,
373 rootx.LocalID, rootBodyx.ptr.ToString("X"),
374 childx.LocalID, childBodyx.ptr.ToString("X"));
375
330 PhysicsScene.TaintedObject("AddChildToLinkset", delegate() 376 PhysicsScene.TaintedObject("AddChildToLinkset", delegate()
331 { 377 {
332 DetailLog("{0},AddChildToLinkset,taint,child={1}", LinksetRoot.LocalID, child.LocalID); 378 DetailLog("{0},AddChildToLinkset,taint,child={1}", LinksetRoot.LocalID, child.LocalID);
@@ -358,10 +404,14 @@ public class BSLinkset
358 BulletBody rootBodyx = LinksetRoot.BSBody; 404 BulletBody rootBodyx = LinksetRoot.BSBody;
359 BSPhysObject childx = child; 405 BSPhysObject childx = child;
360 BulletBody childBodyx = child.BSBody; 406 BulletBody childBodyx = child.BSBody;
407
408 DetailLog("{0},RemoveChildFromLinkset,call,child={1}",
409 rootx.LocalID,
410 rootx.LocalID, rootBodyx.ptr.ToString("X"),
411 childx.LocalID, childBodyx.ptr.ToString("X"));
412
361 PhysicsScene.TaintedObject("RemoveChildFromLinkset", delegate() 413 PhysicsScene.TaintedObject("RemoveChildFromLinkset", delegate()
362 { 414 {
363 DetailLog("{0},RemoveChildFromLinkset,taint,child={1}", LinksetRoot.LocalID, child.LocalID);
364
365 PhysicallyUnlinkAChildFromRoot(rootx, rootBodyx, childx, childBodyx); 415 PhysicallyUnlinkAChildFromRoot(rootx, rootBodyx, childx, childBodyx);
366 RecomputeLinksetConstraintVariables(); 416 RecomputeLinksetConstraintVariables();
367 }); 417 });
@@ -390,14 +440,15 @@ public class BSLinkset
390 // real world coordinate of midpoint between the two objects 440 // real world coordinate of midpoint between the two objects
391 OMV.Vector3 midPoint = rootPrim.Position + (childRelativePosition / 2); 441 OMV.Vector3 midPoint = rootPrim.Position + (childRelativePosition / 2);
392 442
393 // create a constraint that allows no freedom of movement between the two objects
394 // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818
395 DetailLog("{0},PhysicallyLinkAChildToRoot,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}", 443 DetailLog("{0},PhysicallyLinkAChildToRoot,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}",
396 rootPrim.LocalID, 444 rootPrim.LocalID,
397 rootPrim.LocalID, rootBody.ptr.ToString("X"), 445 rootPrim.LocalID, rootBody.ptr.ToString("X"),
398 childPrim.LocalID, childBody.ptr.ToString("X"), 446 childPrim.LocalID, childBody.ptr.ToString("X"),
399 rootPrim.Position, childPrim.Position, midPoint); 447 rootPrim.Position, childPrim.Position, midPoint);
400 448
449 // create a constraint that allows no freedom of movement between the two objects
450 // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818
451
401 // There is great subtlty in these paramters. Notice the check for a ptr of zero. 452 // There is great subtlty in these paramters. Notice the check for a ptr of zero.
402 // We pass the BulletBody structure into the taint in order to capture the pointer 453 // We pass the BulletBody structure into the taint in order to capture the pointer
403 // of the body at the time of constraint creation. This doesn't work for the very first 454 // of the body at the time of constraint creation. This doesn't work for the very first
@@ -416,6 +467,7 @@ public class BSLinkset
416 true, 467 true,
417 true 468 true
418 ); 469 );
470
419 /* NOTE: below is an attempt to build constraint with full frame computation, etc. 471 /* NOTE: below is an attempt to build constraint with full frame computation, etc.
420 * Using the midpoint is easier since it lets the Bullet code manipulate the transforms 472 * Using the midpoint is easier since it lets the Bullet code manipulate the transforms
421 * of the objects. 473 * of the objects.