[patch] btMultiSphereShape proper scaling

Post Reply
mdias
Posts: 12
Joined: Thu Jun 28, 2012 2:21 pm

[patch] btMultiSphereShape proper scaling

Post by mdias »

Usually btMultiSphereShape's setLocalScaling appears to scale only the spheres on their own origin, this patch I created appears to fix the problem:

Code: Select all

Index: src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp
===================================================================
--- src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp	(revision 2540)
+++ src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp	(working copy)
@@ -73,7 +73,7 @@
         int inner_count = MIN( numSpheres - k, 128 );
         for( long i = 0; i < inner_count; i++ )
         {
-            temp[i] = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();
+            temp[i] = (*pos)*m_localScaling +vec*m_localScaling*(*rad) - vec * getMargin();
             pos++;
             rad++;
         }
@@ -111,7 +111,7 @@
             int inner_count = MIN( numSpheres - k, 128 );
             for( long i = 0; i < inner_count; i++ )
             {
-                temp[i] = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();
+                temp[i] = (*pos)*m_localScaling +vec*m_localScaling*(*rad) - vec * getMargin();
                 pos++;
                 rad++;
             }
Should I put this on the issue tracker?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: [patch] btMultiSphereShape proper scaling

Post by Flix »

Old topic, I know :oops:

But I'd like to know if this mod actually works, because there were some scaling issues when using a scaled btMultisphereShape with vertices != (0,0,0), since the positions were not scaled at all.

As far as I can understand (if the modification does not break some internal collision algorithm) the only shapes affected by this change should be btMultisphereShapes with:
-> a scaling applied and at least one vertex!=(0,0,0).

That probably means that all the Bullet demos shouldn't be affected by this change as far as I can remember.
mdias
Posts: 12
Joined: Thu Jun 28, 2012 2:21 pm

Re: [patch] btMultiSphereShape proper scaling

Post by mdias »

I have tested the code before and it did work, however sometimes there were issues when the shape scaled down due to caching of contact points (if something was on top of the shape and it scaled down, it would remain there "floating" until it moved or something), however clearing the cache for these shapes did help.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: [patch] btMultiSphereShape proper scaling

Post by Flix »

mdias wrote:(if something was on top of the shape and it scaled down, it would remain there "floating" until it moved or something
Well, if this happens only when the btMultiSphereShaped body is (local) scaled at runtime, the problem can probably be solved by removing/readding the body from/to the world, so that the contact cache gets cleared (and I think this could happen with other shapes too: clearing the contact cache and re-activating the body can help).

I was just referring to the collision behavior of the body in general, and from your response it seems to be working.

I wonder why the original code does not allow scaling the positions... maybe they wanted to keep the bounding box as small as possible... but this is not consistent with the behavior of other shapes (btConvexHullShape). Or maybe just because in some particular cases scaling the radii without scaling the vertices can be useful to implement some kind of shape transformation... I don't know :cry:

Anyway thank you for your feedback: I hope your patch will be integrated into Bullet if there's nothing preventing it :)
mdias
Posts: 12
Joined: Thu Jun 28, 2012 2:21 pm

Re: [patch] btMultiSphereShape proper scaling

Post by mdias »

No problem :)

And yes, collision in general worked fine in the tests I made.

The bug was already reported almost a year ago here:
http://code.google.com/p/bullet/issues/detail?id=636

It seems there is a need to support the old behaviour by having a flag before it's integrated on master.
Post Reply