From 422f0fd6ec6e30c5200dbf81875c64223002f9c7 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 27 Dec 2012 22:02:38 -0800 Subject: BulletSim: fix physical object not interacting with static objects. Another instance of the underlying Bullet doing, ah, helpful things when items are added to the world. --- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 33 +++++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 2d429c4..5f3f0d1 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -438,7 +438,7 @@ public sealed class BSPrim : BSPhysObject if (inWorld) { - BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); + AddObjectToPhysicalWorld(); } // Must set gravity after it has been added to the world because, for unknown reasons, @@ -740,18 +740,11 @@ public sealed class BSPrim : BSPhysObject // Make solid or not (do things bounce off or pass through this object). MakeSolid(IsSolid); - BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); - - // TODO: Fix this. Total kludge because adding object to world resets its gravity to default. - // Replace this when the new AddObjectToWorld function is complete. - BulletSimAPI.SetGravity2(PhysBody.ptr, ComputeGravity()); + AddObjectToPhysicalWorld(); // Rebuild its shape BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); - // Collision filter can be set only when the object is in the world - PhysBody.ApplyCollisionMask(); - // Recompute any linkset parameters. // When going from non-physical to physical, this re-enables the constraints that // had been automatically disabled when the mass was set to zero. @@ -900,6 +893,28 @@ public sealed class BSPrim : BSPhysObject } } + // Add me to the physical world. + // Object MUST NOT already be in the world. + // This routine exists because some assorted properties get mangled by adding to the world. + internal void AddObjectToPhysicalWorld() + { + if (PhysBody.HasPhysicalBody) + { + BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); + + // TODO: Fix this. Total kludge because adding object to world resets its gravity to default. + // Replace this when the new AddObjectToWorld function is complete. + BulletSimAPI.SetGravity2(PhysBody.ptr, ComputeGravity()); + + // Collision filter can be set only when the object is in the world + if (!PhysBody.ApplyCollisionMask()) + { + m_log.ErrorFormat("{0} Failed setting object collision mask: id={1}", LogHeader, LocalID); + DetailLog("{0},BSPrim.UpdatePhysicalParameters,failedSetMaskGroup,cType={1}", LocalID, PhysBody.collisionType); + } + } + } + // prims don't fly public override bool Flying { get { return _flying; } -- cgit v1.1