diff options
author | Robert Adams | 2012-08-09 15:01:05 -0700 |
---|---|---|
committer | Robert Adams | 2012-08-09 15:01:05 -0700 |
commit | 38e79b80a87d213748d55d66e8b72021999d3945 (patch) | |
tree | f8da528b7cc0038e6df145c1ad70874c142a85e3 /OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | |
parent | BulletSim: add avatar code to keep avatars from ending up trapped under the t... (diff) | |
download | opensim-SC_OLD-38e79b80a87d213748d55d66e8b72021999d3945.zip opensim-SC_OLD-38e79b80a87d213748d55d66e8b72021999d3945.tar.gz opensim-SC_OLD-38e79b80a87d213748d55d66e8b72021999d3945.tar.bz2 opensim-SC_OLD-38e79b80a87d213748d55d66e8b72021999d3945.tar.xz |
BulletSim: separate out the constraints by type. The linksets use
6dof constraint but eventually others will be exposed so future
features can use all the Bullet capabilities.
Force children to generate a position update when unlinked.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs index d19c4b8..e265d6d 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | |||
@@ -101,7 +101,7 @@ public class BSLinkset | |||
101 | { | 101 | { |
102 | // Note that we don't do a foreach because the remove routine | 102 | // Note that we don't do a foreach because the remove routine |
103 | // takes it out of the list. | 103 | // takes it out of the list. |
104 | RemoveChildFromLinkset(m_children[0]); | 104 | RemoveChildFromOtherLinkset(m_children[0]); |
105 | } | 105 | } |
106 | m_children.Clear(); // just to make sure | 106 | m_children.Clear(); // just to make sure |
107 | } | 107 | } |
@@ -124,6 +124,7 @@ public class BSLinkset | |||
124 | 124 | ||
125 | lock (m_linksetActivityLock) | 125 | lock (m_linksetActivityLock) |
126 | { | 126 | { |
127 | // The body pointer is refetched in case anything has moved. | ||
127 | System.IntPtr aPtr = BulletSimAPI.GetBodyHandle2(m_scene.World.Ptr, m_linksetRoot.LocalID); | 128 | System.IntPtr aPtr = BulletSimAPI.GetBodyHandle2(m_scene.World.Ptr, m_linksetRoot.LocalID); |
128 | if (aPtr == System.IntPtr.Zero) | 129 | if (aPtr == System.IntPtr.Zero) |
129 | { | 130 | { |
@@ -155,7 +156,7 @@ public class BSLinkset | |||
155 | } | 156 | } |
156 | foreach (BSPrim bsp in toRemove) | 157 | foreach (BSPrim bsp in toRemove) |
157 | { | 158 | { |
158 | RemoveChildFromLinkset(bsp); | 159 | RemoveChildFromOtherLinkset(bsp); |
159 | } | 160 | } |
160 | } | 161 | } |
161 | } | 162 | } |
@@ -208,7 +209,8 @@ public class BSLinkset | |||
208 | com += bp.Position * bp.MassRaw; | 209 | com += bp.Position * bp.MassRaw; |
209 | totalMass += bp.MassRaw; | 210 | totalMass += bp.MassRaw; |
210 | } | 211 | } |
211 | com /= totalMass; | 212 | if (totalMass != 0f) |
213 | com /= totalMass; | ||
212 | 214 | ||
213 | return com; | 215 | return com; |
214 | } | 216 | } |
@@ -221,7 +223,7 @@ public class BSLinkset | |||
221 | { | 223 | { |
222 | com += bp.Position * bp.MassRaw; | 224 | com += bp.Position * bp.MassRaw; |
223 | } | 225 | } |
224 | com /= m_children.Count + 1; | 226 | com /= (m_children.Count + 1); |
225 | 227 | ||
226 | return com; | 228 | return com; |
227 | } | 229 | } |
@@ -237,13 +239,24 @@ public class BSLinkset | |||
237 | m_scene.TaintedObject(delegate() | 239 | m_scene.TaintedObject(delegate() |
238 | { | 240 | { |
239 | DebugLog("{0}: AddChildToLinkset: adding child {1} to {2}", LogHeader, child.LocalID, m_linksetRoot.LocalID); | 241 | DebugLog("{0}: AddChildToLinkset: adding child {1} to {2}", LogHeader, child.LocalID, m_linksetRoot.LocalID); |
240 | DetailLog("{0},AddChildToLinkset,child={1}", m_linksetRoot.LocalID, pchild.LocalID); | 242 | DetailLog("{0},AddChildToLinkset,taint,child={1}", m_linksetRoot.LocalID, pchild.LocalID); |
241 | PhysicallyLinkAChildToRoot(pchild); // build the physical binding between me and the child | 243 | PhysicallyLinkAChildToRoot(pchild); // build the physical binding between me and the child |
242 | }); | 244 | }); |
243 | } | 245 | } |
244 | return; | 246 | return; |
245 | } | 247 | } |
246 | 248 | ||
249 | // Forcefully removing a child from a linkset. | ||
250 | // This is not being called by the child so we have to make sure the child doesn't think | ||
251 | // it's still connected to the linkset. | ||
252 | // Normal OpenSimulator operation will never do this because other SceneObjectPart information | ||
253 | // has to be updated also (like pointer to prim's parent). | ||
254 | public void RemoveChildFromOtherLinkset(BSPrim pchild) | ||
255 | { | ||
256 | pchild.Linkset = new BSLinkset(m_scene, pchild); | ||
257 | RemoveChildFromLinkset(pchild); | ||
258 | } | ||
259 | |||
247 | // I am the root of a linkset and one of my children is being removed. | 260 | // I am the root of a linkset and one of my children is being removed. |
248 | // Safe to call even if the child is not really in my linkset. | 261 | // Safe to call even if the child is not really in my linkset. |
249 | public void RemoveChildFromLinkset(BSPrim pchild) | 262 | public void RemoveChildFromLinkset(BSPrim pchild) |
@@ -255,7 +268,7 @@ public class BSLinkset | |||
255 | m_scene.TaintedObject(delegate() | 268 | m_scene.TaintedObject(delegate() |
256 | { | 269 | { |
257 | DebugLog("{0}: RemoveChildFromLinkset: Removing constraint to {1}", LogHeader, child.LocalID); | 270 | DebugLog("{0}: RemoveChildFromLinkset: Removing constraint to {1}", LogHeader, child.LocalID); |
258 | DetailLog("{0},RemoveChildFromLinkset,child={1}", m_linksetRoot.LocalID, pchild.LocalID); | 271 | DetailLog("{0},RemoveChildFromLinkset,taint,child={1}", m_linksetRoot.LocalID, pchild.LocalID); |
259 | 272 | ||
260 | if (m_children.Count == 0) | 273 | if (m_children.Count == 0) |
261 | { | 274 | { |
@@ -294,13 +307,14 @@ public class BSLinkset | |||
294 | // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 | 307 | // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 |
295 | // DebugLog("{0}: CreateLinkset: Adding a constraint between root prim {1} and child prim {2}", LogHeader, LocalID, childPrim.LocalID); | 308 | // DebugLog("{0}: CreateLinkset: Adding a constraint between root prim {1} and child prim {2}", LogHeader, LocalID, childPrim.LocalID); |
296 | DetailLog("{0},LinkAChildToMe,taint,root={1},child={2}", m_linksetRoot.LocalID, m_linksetRoot.LocalID, childPrim.LocalID); | 309 | DetailLog("{0},LinkAChildToMe,taint,root={1},child={2}", m_linksetRoot.LocalID, m_linksetRoot.LocalID, childPrim.LocalID); |
297 | BSConstraint constrain = m_scene.Constraints.CreateConstraint( | 310 | BS6DofConstraint constrain = new BS6DofConstraint( |
298 | m_scene.World, m_linksetRoot.Body, childPrim.Body, | 311 | m_scene.World, m_linksetRoot.Body, childPrim.Body, |
299 | childRelativePosition, | 312 | childRelativePosition, |
300 | childRelativeRotation, | 313 | childRelativeRotation, |
301 | OMV.Vector3.Zero, | 314 | OMV.Vector3.Zero, |
302 | -childRelativeRotation | 315 | -childRelativeRotation |
303 | ); | 316 | ); |
317 | m_scene.Constraints.AddConstraint(constrain); | ||
304 | 318 | ||
305 | // zero linear and angular limits makes the objects unable to move in relation to each other | 319 | // zero linear and angular limits makes the objects unable to move in relation to each other |
306 | constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); | 320 | constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); |
@@ -319,11 +333,13 @@ public class BSLinkset | |||
319 | // Called at taint time! | 333 | // Called at taint time! |
320 | private void PhysicallyUnlinkAChildFromRoot(BSPrim childPrim) | 334 | private void PhysicallyUnlinkAChildFromRoot(BSPrim childPrim) |
321 | { | 335 | { |
322 | DebugLog("{0}: PhysicallyUnlinkAChildFromRoot: RemoveConstraint between root prim {1} and child prim {2}", | 336 | // DebugLog("{0}: PhysicallyUnlinkAChildFromRoot: RemoveConstraint between root prim {1} and child prim {2}", |
323 | LogHeader, m_linksetRoot.LocalID, childPrim.LocalID); | 337 | // LogHeader, m_linksetRoot.LocalID, childPrim.LocalID); |
324 | DetailLog("{0},PhysicallyUnlinkAChildFromRoot,taint,root={1},child={2}", m_linksetRoot.LocalID, m_linksetRoot.LocalID, childPrim.LocalID); | 338 | DetailLog("{0},PhysicallyUnlinkAChildFromRoot,taint,root={1},child={2}", m_linksetRoot.LocalID, m_linksetRoot.LocalID, childPrim.LocalID); |
325 | // BulletSimAPI.RemoveConstraint(_scene.WorldID, LocalID, childPrim.LocalID); | 339 | |
326 | m_scene.Constraints.RemoveAndDestroyConstraint(m_linksetRoot.Body, childPrim.Body); | 340 | m_scene.Constraints.RemoveAndDestroyConstraint(m_linksetRoot.Body, childPrim.Body); |
341 | // Make the child refresh its location | ||
342 | BulletSimAPI.PushUpdate2(childPrim.Body.Ptr); | ||
327 | } | 343 | } |
328 | 344 | ||
329 | // Remove linkage between myself and any possible children I might have | 345 | // Remove linkage between myself and any possible children I might have |
@@ -332,8 +348,8 @@ public class BSLinkset | |||
332 | { | 348 | { |
333 | // DebugLog("{0}: PhysicallyUnlinkAllChildren:", LogHeader); | 349 | // DebugLog("{0}: PhysicallyUnlinkAllChildren:", LogHeader); |
334 | DetailLog("{0},PhysicallyUnlinkAllChildren,taint", m_linksetRoot.LocalID); | 350 | DetailLog("{0},PhysicallyUnlinkAllChildren,taint", m_linksetRoot.LocalID); |
351 | |||
335 | m_scene.Constraints.RemoveAndDestroyConstraint(m_linksetRoot.Body); | 352 | m_scene.Constraints.RemoveAndDestroyConstraint(m_linksetRoot.Body); |
336 | // BulletSimAPI.RemoveConstraintByID(_scene.WorldID, LocalID); | ||
337 | } | 353 | } |
338 | 354 | ||
339 | // Invoke the detailed logger and output something if it's enabled. | 355 | // Invoke the detailed logger and output something if it's enabled. |