diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs index 5f6601d..7e784eb 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | |||
@@ -202,11 +202,33 @@ public class BSLinkset | |||
202 | return com; | 202 | return com; |
203 | } | 203 | } |
204 | 204 | ||
205 | // The object is going dynamic (physical). Do any setup necessary | ||
206 | // for a dynamic linkset. | ||
207 | // Only the state of the passed object can be modified. The rest of the linkset | ||
208 | // has not yet been fully constructed. | ||
209 | // Return 'true' if any properties updated on the passed object. | ||
210 | // Called at taint-time! | ||
211 | public bool MakeDynamic(BSPhysObject child) | ||
212 | { | ||
213 | bool ret = false; | ||
214 | return ret; | ||
215 | } | ||
216 | |||
217 | // The object is going static (non-physical). Do any setup necessary | ||
218 | // for a static linkset. | ||
219 | // Return 'true' if any properties updated on the passed object. | ||
220 | // Called at taint-time! | ||
221 | public bool MakeStatic(BSPhysObject child) | ||
222 | { | ||
223 | // What is done for each object in BSPrim is what we want. | ||
224 | return false; | ||
225 | } | ||
226 | |||
205 | // When physical properties are changed the linkset needs to recalculate | 227 | // When physical properties are changed the linkset needs to recalculate |
206 | // its internal properties. | 228 | // its internal properties. |
207 | public void Refresh(BSPhysObject requestor) | 229 | public void Refresh(BSPhysObject requestor) |
208 | { | 230 | { |
209 | // If there are no children, there aren't any constraints to recompute | 231 | // If there are no children, there can't be any constraints to recompute |
210 | if (!HasAnyChildren) | 232 | if (!HasAnyChildren) |
211 | return; | 233 | return; |
212 | 234 | ||
@@ -225,11 +247,12 @@ public class BSLinkset | |||
225 | // from a linkset to make sure the constraints know about the new mass and | 247 | // from a linkset to make sure the constraints know about the new mass and |
226 | // geometry. | 248 | // geometry. |
227 | // Must only be called at taint time!! | 249 | // Must only be called at taint time!! |
228 | private bool RecomputeLinksetConstraintVariables() | 250 | private void RecomputeLinksetConstraintVariables() |
229 | { | 251 | { |
230 | float linksetMass = LinksetMass; | 252 | float linksetMass = LinksetMass; |
231 | lock (m_linksetActivityLock) | 253 | lock (m_linksetActivityLock) |
232 | { | 254 | { |
255 | bool somethingMissing = false; | ||
233 | foreach (BSPhysObject child in m_children) | 256 | foreach (BSPhysObject child in m_children) |
234 | { | 257 | { |
235 | BSConstraint constrain; | 258 | BSConstraint constrain; |
@@ -241,16 +264,36 @@ public class BSLinkset | |||
241 | } | 264 | } |
242 | else | 265 | else |
243 | { | 266 | { |
244 | // Non-fatal error that can happen when children are being added to the linkset but | 267 | // Non-fatal error that happens when children are being added to the linkset but |
245 | // their constraints have not been created yet. | 268 | // their constraints have not been created yet. |
246 | // Caused by the fact that m_children is built at run time but building constraints | 269 | // Caused by the fact that m_children is built at run time but building constraints |
247 | // happens at taint time. | 270 | // happens at taint time. |
248 | // m_physicsScene.Logger.ErrorFormat("{0} RecomputeLinksetConstraintVariables: constraint not found for root={1}, child={2}", | 271 | somethingMissing = true; |
249 | // LogHeader, m_linksetRoot.Body.ID, child.Body.ID); | 272 | break; |
250 | } | 273 | } |
251 | } | 274 | } |
275 | |||
276 | // If the whole linkset is not here, doesn't make sense to recompute linkset wide values | ||
277 | if (!somethingMissing) | ||
278 | { | ||
279 | // If this is a multiple object linkset, set everybody's center of mass to the set's center of mass | ||
280 | OMV.Vector3 centerOfMass = ComputeLinksetCenterOfMass(); | ||
281 | BulletSimAPI.SetCenterOfMassByPosRot2(LinksetRoot.BSBody.Ptr, centerOfMass, OMV.Quaternion.Identity); | ||
282 | foreach (BSPhysObject child in m_children) | ||
283 | { | ||
284 | BulletSimAPI.SetCenterOfMassByPosRot2(child.BSBody.Ptr, centerOfMass, OMV.Quaternion.Identity); | ||
285 | } | ||
286 | /* | ||
287 | // The root prim takes on the weight of the whole linkset | ||
288 | OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(LinksetRoot.BSShape.Ptr, linksetMass); | ||
289 | BulletSimAPI.SetMassProps2(LinksetRoot.BSBody.Ptr, linksetMass, inertia); | ||
290 | OMV.Vector3 centerOfMass = ComputeLinksetCenterOfMass(); | ||
291 | BulletSimAPI.SetCenterOfMassByPosRot2(LinksetRoot.BSBody.Ptr, centerOfMass, OMV.Quaternion.Identity); | ||
292 | BulletSimAPI.UpdateInertiaTensor2(LinksetRoot.BSBody.Ptr); | ||
293 | */ | ||
294 | } | ||
252 | } | 295 | } |
253 | return false; | 296 | return; |
254 | } | 297 | } |
255 | 298 | ||
256 | // I am the root of a linkset and a new child is being added | 299 | // I am the root of a linkset and a new child is being added |
@@ -296,9 +339,9 @@ public class BSLinkset | |||
296 | DetailLog("{0},RemoveChildFromLinkset,taint,child={1}", m_linksetRoot.LocalID, child.LocalID); | 339 | DetailLog("{0},RemoveChildFromLinkset,taint,child={1}", m_linksetRoot.LocalID, child.LocalID); |
297 | 340 | ||
298 | PhysicallyUnlinkAChildFromRoot(rootx, childx); | 341 | PhysicallyUnlinkAChildFromRoot(rootx, childx); |
342 | RecomputeLinksetConstraintVariables(); | ||
299 | }); | 343 | }); |
300 | 344 | ||
301 | RecomputeLinksetConstraintVariables(); | ||
302 | } | 345 | } |
303 | else | 346 | else |
304 | { | 347 | { |
@@ -377,6 +420,10 @@ public class BSLinkset | |||
377 | PhysicsScene.Params.linkConstraintTransMotorMaxVel, | 420 | PhysicsScene.Params.linkConstraintTransMotorMaxVel, |
378 | PhysicsScene.Params.linkConstraintTransMotorMaxForce); | 421 | PhysicsScene.Params.linkConstraintTransMotorMaxForce); |
379 | constrain.SetCFMAndERP(PhysicsScene.Params.linkConstraintCFM, PhysicsScene.Params.linkConstraintERP); | 422 | constrain.SetCFMAndERP(PhysicsScene.Params.linkConstraintCFM, PhysicsScene.Params.linkConstraintERP); |
423 | if (PhysicsScene.Params.linkConstraintSolverIterations != 0f) | ||
424 | { | ||
425 | constrain.SetSolverIterations(PhysicsScene.Params.linkConstraintSolverIterations); | ||
426 | } | ||
380 | 427 | ||
381 | RecomputeLinksetConstraintVariables(); | 428 | RecomputeLinksetConstraintVariables(); |
382 | } | 429 | } |